Skip to content

Commit 7320428

Browse files
koct9itorvalds
authored andcommitted
radix-tree: fix oops after radix_tree_iter_retry
Helper radix_tree_iter_retry() resets next_index to the current index. In following radix_tree_next_slot current chunk size becomes zero. This isn't checked and it tries to dereference null pointer in slot. Tagged iterator is fine because retry happens only at slot 0 where tag bitmask in iter->tags is filled with single bit. Fixes: 46437f9 ("radix-tree: fix race in gang lookup") Signed-off-by: Konstantin Khlebnikov <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ohad Ben-Cohen <[email protected]> Cc: Jeremiah Mahler <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b14fd33 commit 7320428

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/linux/radix-tree.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ void **radix_tree_iter_retry(struct radix_tree_iter *iter)
400400
* @iter: pointer to radix tree iterator
401401
* Returns: current chunk size
402402
*/
403-
static __always_inline unsigned
403+
static __always_inline long
404404
radix_tree_chunk_size(struct radix_tree_iter *iter)
405405
{
406406
return iter->next_index - iter->index;
@@ -434,9 +434,9 @@ radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags)
434434
return slot + offset + 1;
435435
}
436436
} else {
437-
unsigned size = radix_tree_chunk_size(iter) - 1;
437+
long size = radix_tree_chunk_size(iter);
438438

439-
while (size--) {
439+
while (--size > 0) {
440440
slot++;
441441
iter->index++;
442442
if (likely(*slot))

0 commit comments

Comments
 (0)