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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190409213950.GA19223@yury-thinkpad>
Date:   Tue, 9 Apr 2019 14:39:50 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Rasmus Villemoes <linux@...musvillemoes.dk>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Amritha Nambiar <amritha.nambiar@...el.com>,
        "David S. Miller" <davem@...emloft.net>, Tejun Heo <tj@...nel.org>,
        Willem de Bruijn <willemb@...gle.com>,
        Yury Norov <ynorov@...vell.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] cpumask: fix double string traverse in cpumask_parse

On Tue, Apr 09, 2019 at 11:31:50PM +0200, Rasmus Villemoes wrote:
> On 09/04/2019 22.42, Yury Norov wrote:
> > From: Yury Norov <ynorov@...vell.com>
> > 
> > cpumask_parse() finds first occurrence of either \n or \0 by calling
> > strchr() and strlen(). We can do it better with a single call of
> > strchrnul().
> > 
> > Signed-off-by: Yury Norov <ynorov@...vell.com>
> > ---
> >  include/linux/cpumask.h | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> > index 147bdec42215..2b87f35c586c 100644
> > --- a/include/linux/cpumask.h
> > +++ b/include/linux/cpumask.h
> > @@ -633,8 +633,7 @@ static inline int cpumask_parselist_user(const char __user *buf, int len,
> >   */
> >  static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
> >  {
> > -	char *nl = strchr(buf, '\n');
> > -	unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
> > +	unsigned int len = (unsigned int)(strchrnul(buf, '\n') - buf);
> 
> ack, but please drop the cast. "len = strchrnul(buf, '\n') - buf;"

Indeed. See below.

Thanks,
Yury

Subject: [PATCH] cpumask: fix double string traverse in cpumask_parse

From: Yury Norov <ynorov@...vell.com>

cpumask_parse() finds first occurrence of either \n or \0 by calling
strchr() and strlen(). We can do it better with a single call of
strchrnul().

Signed-off-by: Yury Norov <ynorov@...vell.com>
Acked-by: Rasmus Villemoes <linux@...musvillemoes.dk>
---
 include/linux/cpumask.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 147bdec42215..2b87f35c586c 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -633,8 +633,7 @@ static inline int cpumask_parselist_user(const char __user *buf, int len,
  */
 static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
 {
-	char *nl = strchr(buf, '\n');
-	unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
+	unsigned int len = strchrnul(buf, '\n') - buf;
 
 	return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
 }
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ