public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] radix-tree: get_slot_offset() returns invalid offset when parent is NULL
@ 2017-10-10  2:52 Wei Yang
  2017-10-10 20:53 ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Wei Yang @ 2017-10-10  2:52 UTC (permalink / raw)
  To: mawilcox, akpm; +Cc: linux-kernel, Wei Yang

When parent is NULL, get_slot_offset() returns almost the address of slot.
This is an invalid value for offset.

One possible scenario happens on deleting #0 index, when it is the only one
in tree.

Current behavior doesn't harm the system, because the offset will not be
used when parent is NULL in the following procedure or parent is checked
before get_slot_offset() called. While it is still not safe to return an
invalid offset.

This patch returns 0 when parent is NULL in get_slot_offset().

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 lib/radix-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 898e87998417..f006f6928eda 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -119,7 +119,7 @@ bool is_sibling_entry(const struct radix_tree_node *parent, void *node)
 static inline unsigned long
 get_slot_offset(const struct radix_tree_node *parent, void __rcu **slot)
 {
-	return slot - parent->slots;
+	return parent ? (slot - parent->slots):0;
 }
 
 static unsigned int radix_tree_descend(const struct radix_tree_node *parent,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-13 15:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-10  2:52 [PATCH] radix-tree: get_slot_offset() returns invalid offset when parent is NULL Wei Yang
2017-10-10 20:53 ` Andrew Morton
2017-10-11  2:33   ` Wei Yang
2017-10-11 23:39     ` Andrew Morton
2017-10-12  2:20       ` Wei Yang
2017-10-13 15:40         ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox