lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 8 Apr 2021 15:13:58 +0200
From:   Jinpu Wang <jinpu.wang@...os.com>
To:     Gioh Kim <gi-oh.kim@...os.com>
Cc:     open list <linux-kernel@...r.kernel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Dan Williams <dan.j.williams@...el.com>,
        laniel_francis@...vacyrequired.com,
        Kees Cook <keescook@...omium.org>, dja@...ens.net,
        Andrew Morton <akpm@...ux-foundation.org>,
        Haris Iqbal <haris.iqbal@...os.com>
Subject: Re: [PATCH v4] lib/string: Introduce sysfs_streqcase

On Thu, Apr 8, 2021 at 3:06 PM Gioh Kim <gi-oh.kim@...os.com> wrote:
>
> As the name shows, it checks if strings are equal in case insensitive
> manner.
>
> 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".
>
> I found some more cases using strncasecmp to check the entire string
> such as rtrs-clt-sysfs.c does. drivers/pnp/interface.c checks
> "disable" command with strncasecmp but it would also work if the
> command is "disable-wrong".
>
> Signed-off-by: Gioh Kim <gi-oh.kim@...os.com>
you should add the
Reported-by: kernel test robot <lkp@...el.com>
> ---
you can add the changelog here after the ---
v4->v3:  removed #ifdef CONFIG_SYSFS ~ #endif.

The string comparison doesn't depends on CONFIG_SYSFS at all.

It looks good to me.
Reviewed-by: Jack Wang <jinpu.wang@...os.com>



>  include/linux/string.h |  1 +
>  lib/string.c           | 36 ++++++++++++++++++++++++++++--------
>  2 files changed, 29 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 4fcfb56abcf5..36d00ff8013e 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -184,6 +184,7 @@ extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
>  extern void argv_free(char **argv);
>
>  extern bool sysfs_streq(const char *s1, const char *s2);
> +extern bool sysfs_streqcase(const char *s1, const char *s2);
>  extern int kstrtobool(const char *s, bool *res);
>  static inline int strtobool(const char *s, bool *res)
>  {
> diff --git a/lib/string.c b/lib/string.c
> index 7548eb715ddb..d0fb02efd5da 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -687,6 +687,17 @@ char *strsep(char **s, const char *ct)
>  EXPORT_SYMBOL(strsep);
>  #endif
>
> +static inline bool __streq_terminal(const char *s1, const char *s2)
> +{
> +       if (*s1 == *s2)
> +               return true;
> +       if (!*s1 && *s2 == '\n' && !s2[1])
> +               return true;
> +       if (*s1 == '\n' && !s1[1] && !*s2)
> +               return true;
> +       return false;
> +}
> +
>  /**
>   * sysfs_streq - return true if strings are equal, modulo trailing newline
>   * @s1: one string
> @@ -703,17 +714,26 @@ bool sysfs_streq(const char *s1, const char *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;
> +       return __streq_terminal(s1, 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++;
> +       }
> +       return __streq_terminal(s1, s2);
> +}
> +EXPORT_SYMBOL(sysfs_streqcase);
> +
>  /**
>   * match_string - matches given string in an array
>   * @array:     array of strings
> --
> 2.25.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ