Skip to content

Commit b2f11c6

Browse files
author
Kent Overstreet
committed
lib/generic-radix-tree.c: Fix rare race in __genradix_ptr_alloc()
If we need to increase the tree depth, allocate a new node, and then race with another thread that increased the tree depth before us, we'll still have a preallocated node that might be used later. If we then use that node for a new non-root node, it'll still have a pointer to the old root instead of being zeroed - fix this by zeroing it in the cmpxchg failure path. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 968feb8 commit b2f11c6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/generic-radix-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void *__genradix_ptr_alloc(struct __genradix *radix, size_t offset,
121121
if ((v = cmpxchg_release(&radix->root, r, new_root)) == r) {
122122
v = new_root;
123123
new_node = NULL;
124+
} else {
125+
new_node->children[0] = NULL;
124126
}
125127
}
126128

0 commit comments

Comments
 (0)