From: Andrew Morton <akpm@linux-foundation.org>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: mawilcox@microsoft.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] radix-tree: get_slot_offset() returns invalid offset when parent is NULL
Date: Tue, 10 Oct 2017 13:53:11 -0700 [thread overview]
Message-ID: <20171010135311.008c61a83c75f06b840815c2@linux-foundation.org> (raw)
In-Reply-To: <20171010025201.5895-1-richard.weiyang@gmail.com>
On Tue, 10 Oct 2017 10:52:01 +0800 Wei Yang <richard.weiyang@gmail.com> wrote:
> 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().
>
I'm confused. If parent=NULL, get_slot_offset() will crash the kernel.
So why "Current behavior doesn't harm the system"?
> --- 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,
next prev parent reply other threads:[~2017-10-10 20:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 2:52 Wei Yang
2017-10-10 20:53 ` Andrew Morton [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171010135311.008c61a83c75f06b840815c2@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mawilcox@microsoft.com \
--cc=richard.weiyang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®