summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-08-10 21:04:35 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-09-12 11:10:25 +0200
commitebeff038744c498a036e7a92eb8e433ae0a386d7 (patch)
treed003222c2d46fce181950b9c4fccbec6dc3a154a /lib
parent8ff351ea12e918db1373b915c4c268815929cbe5 (diff)
downloadlinux-ebeff038744c498a036e7a92eb8e433ae0a386d7.tar.gz
linux-ebeff038744c498a036e7a92eb8e433ae0a386d7.tar.bz2
linux-ebeff038744c498a036e7a92eb8e433ae0a386d7.zip
lib/generic-radix-tree.c: Fix rare race in __genradix_ptr_alloc()
[ Upstream commit b2f11c6f3e1fc60742673b8675c95b78447f3dae ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/generic-radix-tree.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/generic-radix-tree.c b/lib/generic-radix-tree.c
index 7dfa88282b00..78f081d695d0 100644
--- a/lib/generic-radix-tree.c
+++ b/lib/generic-radix-tree.c
@@ -131,6 +131,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;
}
}