Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern thmap(9): Handle memory allocation failure in root_...
details: https://anonhg.NetBSD.org/src/rev/542b5503280f
branches: trunk
changeset: 364616:542b5503280f
user: riastradh <riastradh%NetBSD.org@localhost>
date: Fri Apr 01 00:16:40 2022 +0000
description:
thmap(9): Handle memory allocation failure in root_try_put.
Reported-by: syzbot+8ded6e17a394e39d6291%syzkaller.appspotmail.com@localhost
diffstat:
sys/kern/subr_thmap.c | 24 +++++++++++++++++-------
1 files changed, 17 insertions(+), 7 deletions(-)
diffs (81 lines):
diff -r c7941de4b610 -r 542b5503280f sys/kern/subr_thmap.c
--- a/sys/kern/subr_thmap.c Thu Mar 31 19:30:15 2022 +0000
+++ b/sys/kern/subr_thmap.c Fri Apr 01 00:16:40 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_thmap.c,v 1.10 2022/02/13 19:20:33 riastradh Exp $ */
+/* $NetBSD: subr_thmap.c,v 1.11 2022/04/01 00:16:40 riastradh Exp $ */
/*-
* Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu>
@@ -112,7 +112,7 @@
#include "utils.h"
#endif
-THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.10 2022/02/13 19:20:33 riastradh Exp $");
+THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.11 2022/04/01 00:16:40 riastradh Exp $");
#include <crypto/blake2/blake2s.h>
@@ -515,7 +515,7 @@
* => Implies release operation on success.
* => Implies no ordering on failure.
*/
-static inline bool
+static inline int
root_try_put(thmap_t *thmap, const thmap_query_t *query, thmap_leaf_t *leaf)
{
thmap_ptr_t expected;
@@ -530,7 +530,7 @@
* this changes from null.
*/
if (atomic_load_relaxed(&thmap->root[i])) {
- return false;
+ return EEXIST;
}
/*
@@ -539,13 +539,16 @@
* release it to readers.
*/
node = node_create(thmap, NULL);
+ if (__predict_false(node == NULL)) {
+ return ENOMEM;
+ }
slot = hashval_getl0slot(thmap, query, leaf);
node_insert(node, slot, THMAP_GETOFF(thmap, leaf) | THMAP_LEAF_BIT);
nptr = THMAP_GETOFF(thmap, node);
again:
if (atomic_load_relaxed(&thmap->root[i])) {
thmap->ops->free(nptr, THMAP_INODE_LEN);
- return false;
+ return EEXIST;
}
/* Release to subsequent consume in find_edge_node(). */
expected = THMAP_NULL;
@@ -553,7 +556,7 @@
nptr, memory_order_release, memory_order_relaxed)) {
goto again;
}
- return true;
+ return 0;
}
/*
@@ -703,9 +706,16 @@
/*
* Try to insert into the root first, if its slot is empty.
*/
- if (root_try_put(thmap, &query, leaf)) {
+ switch (root_try_put(thmap, &query, leaf)) {
+ case 0:
/* Success: the leaf was inserted; no locking involved. */
return val;
+ case EEXIST:
+ break;
+ case ENOMEM:
+ return NULL;
+ default:
+ __unreachable();
}
/*
Home |
Main Index |
Thread Index |
Old Index