Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

radix-tree: fix radix_tree_create for sibling entries

If the radix tree user attempted to insert a colliding entry with an
existing multiorder entry, then radix_tree_create() could encounter a
sibling entry when walking down the tree to look for a slot. Use
radix_tree_descend() to fix the problem, and add a test-case to make
sure the problem doesn't come back in future.

Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Matthew Wilcox and committed by
Linus Torvalds
8a14f4d8 0fc9b8ca

+7 -2
+2 -2
lib/radix-tree.c
··· 548 548 /* Go a level down */ 549 549 height--; 550 550 shift -= RADIX_TREE_MAP_SHIFT; 551 - offset = (index >> shift) & RADIX_TREE_MAP_MASK; 552 551 node = indirect_to_ptr(slot); 553 - slot = node->slots[offset]; 552 + offset = (index >> shift) & RADIX_TREE_MAP_MASK; 553 + offset = radix_tree_descend(node, &slot, offset); 554 554 } 555 555 556 556 #ifdef CONFIG_RADIX_TREE_MULTIORDER
+5
tools/testing/radix-tree/multiorder.c
··· 135 135 item_check_absent(&tree, i); 136 136 for (i = max; i < 2*max; i++) 137 137 item_check_absent(&tree, i); 138 + for (i = min; i < max; i++) { 139 + static void *entry = (void *) 140 + (0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY); 141 + assert(radix_tree_insert(&tree, i, entry) == -EEXIST); 142 + } 138 143 139 144 assert(item_delete(&tree, index) != 0); 140 145