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] [thread-next>] [day] [month] [year] [list]
Message-ID: <0d32d8092289498a9702b76d44074017@AcuMS.aculab.com>
Date:   Tue, 25 Aug 2020 09:07:47 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Alex Dewar' <alex.dewar90@...il.com>
CC:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Gustavo A. R. Silva" <gustavoars@...nel.org>,
        "accessrunner-general@...ts.sourceforge.net" 
        <accessrunner-general@...ts.sourceforge.net>,
        "linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

From: Alex Dewar
> Sent: 25 August 2020 09:18
> On Tue, Aug 25, 2020 at 08:12:05AM +0000, David Laight wrote:
> > From: Alex Dewar
> > > Sent: 24 August 2020 23:23
> > > kernel/cpu.c: don't use snprintf() for sysfs attrs
> > >
> > > As per the documentation (Documentation/filesystems/sysfs.rst),
> > > snprintf() should not be used for formatting values returned by sysfs.
> > >
> > > In all of these cases, sprintf() suffices as we know that the formatted
> > > strings will be less than PAGE_SIZE in length.
> >
> > Hmmmm....
> > I much prefer to see bounded string ops.
> > sysfs really ought to be passing through the buffer length.
> > The buffer size should probably be SYSFS_BUF_LEN not PAGE_SIZE
> > (even it happens to typically be the same).
> > If PAGE_SIZE is big (or small) passing a 4k buffer may be
> > more appropriate than a PAGE_SIZE one.
> >
> > 	David
> 
> We could use scnprintf() instead I guess. But an expression like:
> 	return sprintf(buf, "%d\n", value);
> will never overflow if buf is PAGE_SIZE, right...?

Certainly the return value from snprintf() isn't what you
want here (it almost never is) - so scnprintf() is much better.

A simple "%d" or "%u" wont overflow, but a "%s" might (even
if it is really expected that it shouldn't).
Even a "%*d" can go horribly wrong.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ