diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-08-11 04:04:35 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-08-14 05:56:50 +0300 |
commit | b2f11c6f3e1fc60742673b8675c95b78447f3dae (patch) | |
tree | 60d2b5a8e31c6b660d9da0985eac6a686c3d5358 /lib/generic-radix-tree.c | |
parent | 968feb854a86b59cc4bc72af3105989706ca2c7d (diff) | |
download | linux-b2f11c6f3e1fc60742673b8675c95b78447f3dae.tar.xz |
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 <kent.overstreet@linux.dev>
Diffstat (limited to 'lib/generic-radix-tree.c')
-rw-r--r-- | lib/generic-radix-tree.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/generic-radix-tree.c b/lib/generic-radix-tree.c index aaefb9b678c8..fa692c86f069 100644 --- a/lib/generic-radix-tree.c +++ b/lib/generic-radix-tree.c @@ -121,6 +121,8 @@ void *__genradix_ptr_alloc(struct __genradix *radix, size_t offset, if ((v = cmpxchg_release(&radix->root, r, new_root)) == r) { v = new_root; new_node = NULL; + } else { + new_node->children[0] = NULL; } } |