Skip to content

Commit c6400ba

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
drivers/hwspinlock: fix race between radix tree insertion and lookup
of_hwspin_lock_get_id() is protected by the RCU lock, which means that insertions can occur simultaneously with the lookup. If the radix tree transitions from a height of 0, we can see a slot with the indirect_ptr bit set, which will cause us to at least read random memory, and could cause other havoc. Fix this by using the newly introduced radix_tree_iter_retry(). Signed-off-by: Matthew Wilcox <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ohad Ben-Cohen <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 46437f9 commit c6400ba

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/hwspinlock/hwspinlock_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ int of_hwspin_lock_get_id(struct device_node *np, int index)
313313
hwlock = radix_tree_deref_slot(slot);
314314
if (unlikely(!hwlock))
315315
continue;
316+
if (radix_tree_is_indirect_ptr(hwlock)) {
317+
slot = radix_tree_iter_retry(&iter);
318+
continue;
319+
}
316320

317321
if (hwlock->bank->dev->of_node == args.np) {
318322
ret = 0;

0 commit comments

Comments
 (0)