[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1453929472-25566-3-git-send-email-matthew.r.wilcox@intel.com>
Date: Wed, 27 Jan 2016 16:17:49 -0500
From: Matthew Wilcox <matthew.r.wilcox@...el.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Hugh Dickins <hughd@...gle.com>,
Ohad Ben-Cohen <ohad@...ery.com>
Cc: Matthew Wilcox <willy@...ux.intel.com>,
Konstantin Khlebnikov <khlebnikov@...nvz.org>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org, stable@...r.kernel.org
Subject: [PATCH 2/5] hwspinlock: Fix race between radix tree insertion and lookup
From: Matthew Wilcox <willy@...ux.intel.com>
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 <willy@...ux.intel.com>
Cc: stable@...r.kernel.org
---
drivers/hwspinlock/hwspinlock_core.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
index 52f708bcf77f..d50c701b19d6 100644
--- a/drivers/hwspinlock/hwspinlock_core.c
+++ b/drivers/hwspinlock/hwspinlock_core.c
@@ -313,6 +313,10 @@ int of_hwspin_lock_get_id(struct device_node *np, int index)
hwlock = radix_tree_deref_slot(slot);
if (unlikely(!hwlock))
continue;
+ if (radix_tree_is_indirect_ptr(hwlock)) {
+ slot = radix_tree_iter_retry(&iter);
+ continue;
+ }
if (hwlock->bank->dev->of_node == args.np) {
ret = 0;
--
2.7.0.rc3
Powered by blists - more mailing lists