Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1557920 > unrolled thread

[PATCH] radix-tree: Fix private list warnings

Started byMatthew Wilcox <mawilcox@linuxonhyperv.com>
First post2017-01-13 00:50 +0100
Last post2017-01-15 02:00 +0100
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] radix-tree: Fix private list warnings Matthew Wilcox <mawilcox@linuxonhyperv.com> - 2017-01-13 00:50 +0100
    Re: [PATCH] radix-tree: Fix private list warnings Johannes Weiner <hannes@cmpxchg.org> - 2017-01-14 17:10 +0100
      RE: [PATCH] radix-tree: Fix private list warnings Matthew Wilcox <mawilcox@microsoft.com> - 2017-01-14 22:40 +0100
        Re: [PATCH] radix-tree: Fix private list warnings Johannes Weiner <hannes@cmpxchg.org> - 2017-01-15 02:00 +0100

#1557920 — [PATCH] radix-tree: Fix private list warnings

FromMatthew Wilcox <mawilcox@linuxonhyperv.com>
Date2017-01-13 00:50 +0100
Subject[PATCH] radix-tree: Fix private list warnings
Message-ID<sYXi2-1Pf-13@gated-at.bofh.it>
From: Matthew Wilcox <mawilcox@microsoft.com>

The newly introduced warning in radix_tree_free_nodes() was testing the
wrong variable; it should have been 'old' instead of 'node'.  Rather
than replace that one instance, I noticed that we can simply put the
WARN_ON_ONCE in radix_tree_node_free() and it will be just as effective.

Fixes: ea07b862ac8e ("mm: workingset: fix use-after-free in shadow node shrinker")
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
 lib/radix-tree.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 4a4ed3ee4222..3c4577cabc57 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -449,6 +449,7 @@ static void radix_tree_node_rcu_free(struct rcu_head *head)
 static inline void
 radix_tree_node_free(struct radix_tree_node *node)
 {
+	WARN_ON_ONCE(!list_empty(&node->private_list));
 	call_rcu(&node->rcu_head, radix_tree_node_rcu_free);
 }
 
@@ -734,7 +735,6 @@ static inline void radix_tree_shrink(struct radix_tree_root *root,
 				update_node(node, private);
 		}
 
-		WARN_ON_ONCE(!list_empty(&node->private_list));
 		radix_tree_node_free(node);
 	}
 }
@@ -766,7 +766,6 @@ static void delete_node(struct radix_tree_root *root,
 			root->rnode = NULL;
 		}
 
-		WARN_ON_ONCE(!list_empty(&node->private_list));
 		radix_tree_node_free(node);
 
 		node = parent;
@@ -868,7 +867,6 @@ static void radix_tree_free_nodes(struct radix_tree_node *node)
 			struct radix_tree_node *old = child;
 			offset = child->offset + 1;
 			child = child->parent;
-			WARN_ON_ONCE(!list_empty(&node->private_list));
 			radix_tree_node_free(old);
 			if (old == entry_to_node(node))
 				return;
-- 
2.11.0.296.g5800ad326.dirty

[toc] | [next] | [standalone]


#1559021

FromJohannes Weiner <hannes@cmpxchg.org>
Date2017-01-14 17:10 +0100
Message-ID<sZz3X-81T-7@gated-at.bofh.it>
In reply to#1557920
On Thu, Jan 12, 2017 at 05:28:23PM -0800, Matthew Wilcox wrote:
> From: Matthew Wilcox <mawilcox@microsoft.com>
> 
> The newly introduced warning in radix_tree_free_nodes() was testing the
> wrong variable; it should have been 'old' instead of 'node'.  Rather
> than replace that one instance, I noticed that we can simply put the
> WARN_ON_ONCE in radix_tree_node_free() and it will be just as effective.
> 
> Fixes: ea07b862ac8e ("mm: workingset: fix use-after-free in shadow node shrinker")
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>

Thanks for the fix in radix_tree_free_nodes(). But I intentionally
spread out the warnings to retain the line numbers. The inlining in
that code will obscure which tree operation ends up triggering.

[toc] | [prev] | [next] | [standalone]


#1559073

FromMatthew Wilcox <mawilcox@microsoft.com>
Date2017-01-14 22:40 +0100
Message-ID<sZEdk-2AG-13@gated-at.bofh.it>
In reply to#1559021
From: Johannes Weiner [mailto:hannes@cmpxchg.org]
> On Thu, Jan 12, 2017 at 05:28:23PM -0800, Matthew Wilcox wrote:
> > The newly introduced warning in radix_tree_free_nodes() was testing the
> > wrong variable; it should have been 'old' instead of 'node'.  Rather
> > than replace that one instance, I noticed that we can simply put the
> > WARN_ON_ONCE in radix_tree_node_free() and it will be just as effective.
> >
> > Fixes: ea07b862ac8e ("mm: workingset: fix use-after-free in shadow node
> shrinker")
> > Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> 
> Thanks for the fix in radix_tree_free_nodes(). But I intentionally
> spread out the warnings to retain the line numbers. The inlining in
> that code will obscure which tree operation ends up triggering.

The backtrace should make that fairly obvious though; even if radix_tree_node_free() gets inlined, the caller of radix_tree_free_nodes() probably doesn't also call radix_tree_shrink() or delete_node().  You're really looking for the caller in the backtrace that's outside of radix-tree.c.

By the way, if you'd run the radix tree test-suite, the WARN_ON_ONCE would have triggered (that's how I spotted the bug).  The test-suite is getting pretty useful these days; would you mind running it in future?

[toc] | [prev] | [next] | [standalone]


#1559123

FromJohannes Weiner <hannes@cmpxchg.org>
Date2017-01-15 02:00 +0100
Message-ID<sZHkS-4lP-7@gated-at.bofh.it>
In reply to#1559073
On Sat, Jan 14, 2017 at 09:31:51PM +0000, Matthew Wilcox wrote:
> From: Johannes Weiner [mailto:hannes@cmpxchg.org]
> > On Thu, Jan 12, 2017 at 05:28:23PM -0800, Matthew Wilcox wrote:
> > > The newly introduced warning in radix_tree_free_nodes() was testing the
> > > wrong variable; it should have been 'old' instead of 'node'.  Rather
> > > than replace that one instance, I noticed that we can simply put the
> > > WARN_ON_ONCE in radix_tree_node_free() and it will be just as effective.
> > >
> > > Fixes: ea07b862ac8e ("mm: workingset: fix use-after-free in shadow node
> > shrinker")
> > > Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> > 
> > Thanks for the fix in radix_tree_free_nodes(). But I intentionally
> > spread out the warnings to retain the line numbers. The inlining in
> > that code will obscure which tree operation ends up triggering.
> 
> The backtrace should make that fairly obvious though; even if
> radix_tree_node_free() gets inlined, the caller of
> radix_tree_free_nodes() probably doesn't also call
> radix_tree_shrink() or delete_node().  You're really looking for the
> caller in the backtrace that's outside of radix-tree.c.

Distinguishing between the radix_tree_shrink() and the delete_node()
sites was essential to find the bug whose fix added these warnings.
The former gets inlined into the latter. Not impossible to figure out
which one triggered from a full dump, but certainly less robust.

> By the way, if you'd run the radix tree test-suite, the WARN_ON_ONCE
> would have triggered (that's how I spotted the bug).  The test-suite
> is getting pretty useful these days; would you mind running it in
> future?

Thanks, I'll keep that in mind for future radix tree changes.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web