* + radix-tree-fix-multi-order-iteration-race.patch added to -mm tree
@ 2018-05-10 22:15 akpm
2018-05-10 22:29 ` Dan Williams
0 siblings, 1 reply; 3+ messages in thread
From: akpm @ 2018-05-10 22:15 UTC (permalink / raw)
To: mm-commits, willy, stable, sapthagirish.cr, jack, hch, david,
dan.j.williams, ross.zwisler
The patch titled
Subject: radix tree: fix multi-order iteration race
has been added to the -mm tree. Its filename is
radix-tree-fix-multi-order-iteration-race.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/radix-tree-fix-multi-order-iteration-race.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/radix-tree-fix-multi-order-iteration-race.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Ross Zwisler <ross.zwisler@linux.intel.com>
Subject: radix tree: fix multi-order iteration race
Fix a race in the multi-order iteration code which causes the kernel to
hit a GP fault. This was first seen with a production v4.15 based kernel
(4.15.6-300.fc27.x86_64) utilizing a DAX workload which used order 9 PMD
DAX entries.
The race has to do with how we tear down multi-order sibling entries when
we are removing an item from the tree. Remember for example that an order
2 entry looks like this:
struct radix_tree_node.slots[] = [entry][sibling][sibling][sibling]
where 'entry' is in some slot in the struct radix_tree_node, and the three
slots following 'entry' contain sibling pointers which point back to
'entry.'
When we delete 'entry' from the tree, we call :
radix_tree_delete()
radix_tree_delete_item()
__radix_tree_delete()
replace_slot()
replace_slot() first removes the siblings in order from the first to the
last, then at then replaces 'entry' with NULL. This means that for a
brief period of time we end up with one or more of the siblings removed,
so:
struct radix_tree_node.slots[] = [entry][NULL][sibling][sibling]
This causes an issue if you have a reader iterating over the slots in the
tree via radix_tree_for_each_slot() while only under
rcu_read_lock()/rcu_read_unlock() protection. This is a common case in
mm/filemap.c.
The issue is that when __radix_tree_next_slot() => skip_siblings() tries
to skip over the sibling entries in the slots, it currently does so with
an exact match on the slot directly preceding our current slot. Normally
this works:
V preceding slot
struct radix_tree_node.slots[] = [entry][sibling][sibling][sibling]
^ current slot
This lets you find the first sibling, and you skip them all in order.
But in the case where one of the siblings is NULL, that slot is skipped
and then our sibling detection is interrupted:
V preceding slot
struct radix_tree_node.slots[] = [entry][NULL][sibling][sibling]
^ current slot
This means that the sibling pointers aren't recognized since they point
all the way back to 'entry', so we think that they are normal internal
radix tree pointers. This causes us to think we need to walk down to a
struct radix_tree_node starting at the address of 'entry'.
In a real running kernel this will crash the thread with a GP fault when
you try and dereference the slots in your broken node starting at 'entry'.
We fix this race by fixing the way that skip_siblings() detects sibling
nodes. Instead of testing against the preceding slot we instead look for
siblings via is_sibling_entry() which compares against the position of the
struct radix_tree_node.slots[] array. This ensures that sibling entries
are properly identified, even if they are no longer contiguous with the
'entry' they point to.
Link: http://lkml.kernel.org/r/20180503192430.7582-6-ross.zwisler@linux.intel.com
Fixes: 148deab223b2 ("radix-tree: improve multiorder iterators")
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Reported-by: CR, Sapthagirish <sapthagirish.cr@intel.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
lib/radix-tree.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff -puN lib/radix-tree.c~radix-tree-fix-multi-order-iteration-race lib/radix-tree.c
--- a/lib/radix-tree.c~radix-tree-fix-multi-order-iteration-race
+++ a/lib/radix-tree.c
@@ -1612,11 +1612,9 @@ static void set_iter_tags(struct radix_t
static void __rcu **skip_siblings(struct radix_tree_node **nodep,
void __rcu **slot, struct radix_tree_iter *iter)
{
- void *sib = node_to_entry(slot - 1);
-
while (iter->index < iter->next_index) {
*nodep = rcu_dereference_raw(*slot);
- if (*nodep && *nodep != sib)
+ if (*nodep && !is_sibling_entry(iter->node, *nodep))
return slot;
slot++;
iter->index = __radix_tree_iter_add(iter, 1);
@@ -1631,7 +1629,7 @@ void __rcu **__radix_tree_next_slot(void
struct radix_tree_iter *iter, unsigned flags)
{
unsigned tag = flags & RADIX_TREE_ITER_TAG_MASK;
- struct radix_tree_node *node = rcu_dereference_raw(*slot);
+ struct radix_tree_node *node;
slot = skip_siblings(&node, slot, iter);
_
Patches currently in -mm which might be from ross.zwisler@linux.intel.com are
radix-tree-test-suite-fix-mapshift-build-target.patch
radix-tree-test-suite-fix-compilation-issue.patch
radix-tree-test-suite-add-item_delete_rcu.patch
radix-tree-test-suite-multi-order-iteration-race.patch
radix-tree-fix-multi-order-iteration-race.patch
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: + radix-tree-fix-multi-order-iteration-race.patch added to -mm tree
2018-05-10 22:15 + radix-tree-fix-multi-order-iteration-race.patch added to -mm tree akpm
@ 2018-05-10 22:29 ` Dan Williams
2018-05-10 22:49 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2018-05-10 22:29 UTC (permalink / raw)
To: Andrew Morton
Cc: mm-commits, Matthew Wilcox, stable, CR, Sapthagirish, Jan Kara,
Christoph Hellwig, david, Ross Zwisler, Stephen Rothwell
On Thu, May 10, 2018 at 3:15 PM, <akpm@linux-foundation.org> wrote:
>
> The patch titled
> Subject: radix tree: fix multi-order iteration race
> has been added to the -mm tree. Its filename is
> radix-tree-fix-multi-order-iteration-race.patch
>
> This patch should soon appear at
> http://ozlabs.org/~akpm/mmots/broken-out/radix-tree-fix-multi-order-iteration-race.patch
> and later at
> http://ozlabs.org/~akpm/mmotm/broken-out/radix-tree-fix-multi-order-iteration-race.patch
Hi Andrew,
I just pushed this out for some -next testing. I'll go ahead and
withdraw it and let you carry since I have nothing else pending for
4.17-rc. Just letting you know in case Stephen pulled my tree before
grabbing your latest.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: + radix-tree-fix-multi-order-iteration-race.patch added to -mm tree
2018-05-10 22:29 ` Dan Williams
@ 2018-05-10 22:49 ` Andrew Morton
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2018-05-10 22:49 UTC (permalink / raw)
To: Dan Williams
Cc: Matthew Wilcox, stable, CR, Sapthagirish, Jan Kara,
Christoph Hellwig, david, Ross Zwisler, Stephen Rothwell
On Thu, 10 May 2018 15:29:51 -0700 Dan Williams <dan.j.williams@intel.com> wrote:
> On Thu, May 10, 2018 at 3:15 PM, <akpm@linux-foundation.org> wrote:
> >
> > The patch titled
> > Subject: radix tree: fix multi-order iteration race
> > has been added to the -mm tree. Its filename is
> > radix-tree-fix-multi-order-iteration-race.patch
> >
> > This patch should soon appear at
> > http://ozlabs.org/~akpm/mmots/broken-out/radix-tree-fix-multi-order-iteration-race.patch
> > and later at
> > http://ozlabs.org/~akpm/mmotm/broken-out/radix-tree-fix-multi-order-iteration-race.patch
>
> Hi Andrew,
>
> I just pushed this out for some -next testing. I'll go ahead and
> withdraw it and let you carry since I have nothing else pending for
> 4.17-rc. Just letting you know in case Stephen pulled my tree before
> grabbing your latest.
Yup, thanks, I just discovered that.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-10 22:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-10 22:15 + radix-tree-fix-multi-order-iteration-race.patch added to -mm tree akpm
2018-05-10 22:29 ` Dan Williams
2018-05-10 22:49 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox