Commit c6400ba7 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

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: default avatarMatthew Wilcox <>
Cc: Hugh Dickins <>
Cc: Ohad Ben-Cohen <>
Cc: Konstantin Khlebnikov <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 46437f9a
...@@ -313,6 +313,10 @@ int of_hwspin_lock_get_id(struct device_node *np, int index) ...@@ -313,6 +313,10 @@ int of_hwspin_lock_get_id(struct device_node *np, int index)
hwlock = radix_tree_deref_slot(slot); hwlock = radix_tree_deref_slot(slot);
if (unlikely(!hwlock)) if (unlikely(!hwlock))
continue; continue;
if (radix_tree_is_indirect_ptr(hwlock)) {
slot = radix_tree_iter_retry(&iter);
if (hwlock->bank->dev->of_node == { if (hwlock->bank->dev->of_node == {
ret = 0; ret = 0;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment