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]
Date:   Tue, 6 Sep 2022 12:11:51 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Phil Auld <pauld@...hat.com>
Cc:     linux-kernel@...r.kernel.org,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Rafael J . Wysocki" <rafael@...nel.org>,
        Barry Song <21cnbao@...il.com>,
        Tian Tao <tiantao6@...ilicon.com>,
        feng xiangjun <fengxj325@...il.com>, stable@...r.kernel.org
Subject: Re: [PATCH] drivers/base: Fix unsigned comparison to -1 in
 CPUMAP_FILE_MAX_BYTES

On Tue, Sep 06, 2022 at 02:57:41PM -0400, Phil Auld wrote:
> On Tue, Sep 06, 2022 at 11:09:53AM -0700 Yury Norov wrote:
> > On Tue, Sep 06, 2022 at 12:04:30PM -0400, Phil Auld wrote:
> > > As PAGE_SIZE is unsigned long, -1 > PAGE_SIZE when NR_CPUS <= 3.
> > > This leads to very large file sizes:
> > > 
> > > topology$ ls -l
> > > total 0
> > > -r--r--r-- 1 root root 18446744073709551615 Sep  5 11:59 core_cpus
> > > -r--r--r-- 1 root root                 4096 Sep  5 11:59 core_cpus_list
> > > -r--r--r-- 1 root root                 4096 Sep  5 10:58 core_id
> > > -r--r--r-- 1 root root 18446744073709551615 Sep  5 10:10 core_siblings
> > > -r--r--r-- 1 root root                 4096 Sep  5 11:59 core_siblings_list
> > > -r--r--r-- 1 root root 18446744073709551615 Sep  5 11:59 die_cpus
> > > -r--r--r-- 1 root root                 4096 Sep  5 11:59 die_cpus_list
> > > -r--r--r-- 1 root root                 4096 Sep  5 11:59 die_id
> > > -r--r--r-- 1 root root 18446744073709551615 Sep  5 11:59 package_cpus
> > > -r--r--r-- 1 root root                 4096 Sep  5 11:59 package_cpus_list
> > > -r--r--r-- 1 root root                 4096 Sep  5 10:58 physical_package_id
> > > -r--r--r-- 1 root root 18446744073709551615 Sep  5 10:10 thread_siblings
> > > -r--r--r-- 1 root root                 4096 Sep  5 11:59 thread_siblings_list
> > > 
> > > Adjust the inequality to catch the case when NR_CPUS is configured
> > > to a small value.
> > > 
> > > Fixes: 7ee951acd31a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist")
> > > Reported-by: feng xiangjun <fengxj325@...il.com>
> > > Signed-off-by: Phil Auld <pauld@...hat.com>
> > > Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> > > Cc: "Rafael J. Wysocki" <rafael@...nel.org>
> > > Cc: Yury Norov <yury.norov@...il.com>
> > > Cc: stable@...r.kernel.org
> > > Cc: feng xiangjun <fengxj325@...il.com>
> > > ---
> > >  include/linux/cpumask.h | 5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> > > index bd047864c7ac..7b1349612d6d 100644
> > > --- a/include/linux/cpumask.h
> > > +++ b/include/linux/cpumask.h
> > > @@ -1127,9 +1127,10 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
> > >   * cover a worst-case of every other cpu being on one of two nodes for a
> > >   * very large NR_CPUS.
> > >   *
> > > - *  Use PAGE_SIZE as a minimum for smaller configurations.
> > > + *  Use PAGE_SIZE as a minimum for smaller configurations while avoiding
> > > + *  unsigned comparison to -1.
> > >   */
> > > -#define CPUMAP_FILE_MAX_BYTES  ((((NR_CPUS * 9)/32 - 1) > PAGE_SIZE) \
> > > +#define CPUMAP_FILE_MAX_BYTES  ((((NR_CPUS * 9)/32) > PAGE_SIZE + 1) \
> > 
> > Maybe it would be easier to read with less braces and '>=' instead of '>'?
> >   #define CPUMAP_FILE_MAX_BYTES \
> >         (NR_CPUS * 9 / 32 >= PAGE_SIZE ? NR_CPUS * 9 / 32 - 1 : PAGE_SIZE)
> > 
> > Anyways, this is a good catch. If you think it doesn't worth an
> > update, I can take it in bitmap-for-next as-is.
> >
> 
> It would work as
>    #define CPUMAP_FILE_MAX_BYTES  (((NR_CPUS * 9)/32 > PAGE_SIZE) \
>    	   			     ? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE)
> 
> Since 4097 > PAGE_SIZE and then you'd get PAGE_SIZE anyway. That is we could just
> leave the 1 out of the inequality completely. 
> 
> If I recall at least some of the parens are needed to make the compiler happy.
> 
> I can resend with the above if you want.  

Yes, please

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ