From: Steven Rostedt <rostedt@goodmis.org>
To: Gavin Shan <gshan@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
catalin.marinas@arm.com, linux-kernel@vger.kernel.org,
shan.gavin@gmail.com, will@kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm64/mm: Reject invalid NUMA option
Date: Mon, 27 Apr 2020 22:54:06 -0400 [thread overview]
Message-ID: <20200427225406.7cacc796@gandalf.local.home> (raw)
In-Reply-To: <f83c0ce1-b1b2-31f4-60c8-15567b87a8ff@redhat.com>
On Tue, 28 Apr 2020 10:59:14 +1000
Gavin Shan <gshan@redhat.com> wrote:
> Hi Mark,
>
> On 4/24/20 8:11 PM, Mark Rutland wrote:
> > [Adding Steve, who added str_has_prefix()]
> >
> > On Fri, Apr 24, 2020 at 02:53:14PM +1000, Gavin Shan wrote:
> >> The NUMA option is parsed by str_has_prefix() and the invalid option
> >> like "numa=o" can be regarded as "numa=off" wrongly.
> >
> > Are you certain that can pass? If that can happen, str_has_prefix() is
> > misnamed and does not seem to do what its kerneldoc says it does, as
> > "off" is not a prefix of "o".
> >
>
> Yes, It's possible. str_has_prefix() depends on strncmp(). In this particular
> case, it's equal to the snippet of code as below: strncmp() returns zero.
> str_has_prefix() returns 3.
Wait! strncmp("o", "off", 3) returns zero?
That to me looks like a bug!
This means str_has_prefix() is broken in other areas as well.
>
> int strncmp(const char *cs, const char *ct, size_t count)
> {
> unsigned char c1, c2;
>
> while (count) {
> c1 = *cs++;
> c2 = *ct++;
> if (c1 != c2)
> return c1 < c2 ? -1 : 1;
> if (!c1) /* break after first character is compared */
Crap! That is totally wrong!
/me goes to fix...
-- Steve
> break;
> count--;
> }
> return 0; /* 0 returned */
> }
>
> static __always_inline size_t str_has_prefix(const char *str, const char *prefix)
> {
> size_t len = strlen("o");
> return strncmp("o", "off", 1) == 0 ? len : 0;
> }
>
> >> This fixes the issue with sysfs_streq(), which have more sanity checks,
> >> to avoid accepting the invalid options.
> >
> > That doesn't sound immediately right, since this is an early parameter,
> > which has nothing to do with sysfs. Perhaps that's just a misleading
> > name?
> >
>
> sysfs_streq() was introduced to compare the parameters received from sysfs
> entry, but I don't think it has to be necessarily tied with sysfs entry.
> So the name is bit misleading. Alternatively, we also can fix it in another
> way (as below) if we try to avoid using sysfs_streq().
>
> diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c
> index 4decf1659700..b0c1ec78f50f 100644
> --- a/arch/arm64/mm/numa.c
> +++ b/arch/arm64/mm/numa.c
> @@ -29,9 +29,13 @@ static __init int numa_parse_early_param(char *opt)
> {
> if (!opt)
> return -EINVAL;
> - if (str_has_prefix(opt, "off"))
> +
> + if (strlen(opt) >= 3 && str_has_prefix(opt, "off"))
> numa_off = true;
>
> > Thanks,
> > Mark.
> >
>
> Thanks,
> Gavin
>
> >> Signed-off-by: Gavin Shan <gshan@redhat.com>
> >> ---
> >> arch/arm64/mm/numa.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c
> >> index 4decf1659700..bd458b28616a 100644
> >> --- a/arch/arm64/mm/numa.c
> >> +++ b/arch/arm64/mm/numa.c
> >> @@ -29,7 +29,8 @@ static __init int numa_parse_early_param(char *opt)
> >> {
> >> if (!opt)
> >> return -EINVAL;
> >> - if (str_has_prefix(opt, "off"))
> >> +
> >> + if (sysfs_streq(opt, "off"))
> >> numa_off = true;
> >>
> >> return 0;
> >> --
> >> 2.23.0
> >>
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> >
next prev parent reply other threads:[~2020-04-28 2:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 4:53 [PATCH] arm64/mm: Reject invalid NUMA option Gavin Shan
2020-04-24 10:11 ` Mark Rutland
2020-04-28 0:59 ` Gavin Shan
2020-04-28 2:54 ` Steven Rostedt [this message]
2020-04-28 2:59 ` Steven Rostedt
2020-04-28 3:09 ` Steven Rostedt
2020-04-28 4:35 ` Gavin Shan
2020-04-28 7:25 ` Will Deacon
2020-04-28 8:56 ` Gavin Shan
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=20200427225406.7cacc796@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=catalin.marinas@arm.com \
--cc=gshan@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=shan.gavin@gmail.com \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).