All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Gioh Kim <gi-oh.kim@ionos.com>,
	LKML <linux-kernel@vger.kernel.org>,
	jinpu.wang@ionos.com, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] lib/string: Introduce sysfs_streqcase
Date: Fri, 2 Apr 2021 11:23:58 -0700	[thread overview]
Message-ID: <202104021122.7896C66@keescook> (raw)
In-Reply-To: <CAKwvOdkFJ_WFpt2+rnNR3tbrdFky2NnEOWSG7MhgLrBHJAOEVw@mail.gmail.com>

On Fri, Apr 02, 2021 at 11:17:13AM -0700, Nick Desaulniers wrote:
> Thanks for the patch!
> 
> + akpm (please remember to run ./scripts/get_maintainer.pl on your patch files)
> 
> On Fri, Apr 2, 2021 at 2:41 AM Gioh Kim <gi-oh.kim@ionos.com> wrote:
> >
> > As the name shows, it checks if strings are equal in case insensitive
> > manner. I found some cases using strncasecmp to check the entire
> > strings and they would not work as intended.
> >
> > For example, drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c uses
> > strncasecmp to check that the input via sysfs is "mi". But it would
> > work even-if the input is "min-wrongcommand".
> > And also drivers/pnp/interface.c checks "disable" command with
> > strncasecmp but it would also work if the command is "disable-wrong".
> 
> Perhaps those callers should be using strcasecmp then, rather than strncasecmp?
> 
> Also, if they're being liberal in accepting either case, I don't see
> why the sysfs nodes should be strict in rejecting trailing input at
> that point.

I think this shouldn't be prefixed "sysfs_" -- name it for what it does,
not where it gets used, if it's a general utility function.

-Kees

> 
> >
> > Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com>
> > ---
> >  lib/string.c | 23 +++++++++++++++++++++++
> >  1 file changed, 23 insertions(+)
> >
> > diff --git a/lib/string.c b/lib/string.c
> > index 7548eb715ddb..5e6bc0d3d5c6 100644
> > --- a/lib/string.c
> > +++ b/lib/string.c
> > @@ -714,6 +714,29 @@ bool sysfs_streq(const char *s1, const char *s2)
> >  }
> >  EXPORT_SYMBOL(sysfs_streq);
> >
> > +/**
> > + * sysfs_streqcase - same to sysfs_streq and case insensitive
> > + * @s1: one string
> > + * @s2: another string
> > + *
> > + */
> > +bool sysfs_streqcase(const char *s1, const char *s2)
> > +{
> > +       while (*s1 && tolower(*s1) == tolower(*s2)) {
> > +               s1++;
> > +               s2++;
> > +       }
> > +
> > +       if (*s1 == *s2)
> > +               return true;
> > +       if (!*s1 && *s2 == '\n' && !s2[1])
> > +               return true;
> > +       if (*s1 == '\n' && !s1[1] && !*s2)
> > +               return true;
> > +       return false;
> > +}
> > +EXPORT_SYMBOL(sysfs_streqcase);
> 
> This should be declared in
> include/linux/string.h
> in order for others to use this (as 0day bot notes).
> 
> > +
> >  /**
> >   * match_string - matches given string in an array
> >   * @array:     array of strings
> > --
> > 2.25.1
> >
> 
> 
> --
> Thanks,
> ~Nick Desaulniers

-- 
Kees Cook

  reply	other threads:[~2021-04-02 18:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02  9:40 [PATCH] lib/string: Introduce sysfs_streqcase Gioh Kim
2021-04-02 17:59 ` kernel test robot
2021-04-02 17:59   ` kernel test robot
2021-04-02 18:17 ` Nick Desaulniers
2021-04-02 18:23   ` Kees Cook [this message]
2021-04-02 19:43     ` Gioh Kim
2021-04-02 19:41   ` Gioh Kim
  -- strict thread matches above, loose matches on Subject: below --
2021-04-07  6:14 Gioh Kim
2021-04-07 20:06 ` Nick Desaulniers
2021-04-08  7:25   ` Gioh Kim

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=202104021122.7896C66@keescook \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=gi-oh.kim@ionos.com \
    --cc=jinpu.wang@ionos.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.