Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-28 Thread Joe Perches
On Fri, 2020-08-28 at 01:10 -0700, Joe Perches wrote: > On Fri, 2020-08-28 at 00:58 -0700, Kees Cook wrote: > > On Thu, Aug 27, 2020 at 09:12:06PM -0700, Joe Perches wrote: > > > Perhaps something like the below with a sample conversion > > > that uses single and multiple sysfs_emit uses. > > > >

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-28 Thread Joe Perches
On Fri, 2020-08-28 at 00:58 -0700, Kees Cook wrote: > On Thu, Aug 27, 2020 at 09:12:06PM -0700, Joe Perches wrote: > > Perhaps something like the below with a sample conversion > > that uses single and multiple sysfs_emit uses. > > On quick review, I like it. :) > > > [...] > > +int sysfs_emit(ch

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-28 Thread Kees Cook
On Thu, Aug 27, 2020 at 09:12:06PM -0700, Joe Perches wrote: > Perhaps something like the below with a sample conversion > that uses single and multiple sysfs_emit uses. On quick review, I like it. :) > [...] > +int sysfs_emit(char *buf, char *pos, const char *fmt, ...) > +{ > + int len; > +

RE: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-28 Thread David Laight
From: Kees Cook > Sent: 27 August 2020 23:21 ... > > Agreed. This just makes me cringe. If the API design declares that when > a show() callback starts, buf has been allocated with PAGE_SIZE bytes, > then that's how the logic should proceed, and it should be using > scnprintf... > > show(...) { >

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 15:45 -0700, Joe Perches wrote: > On Thu, 2020-08-27 at 15:20 -0700, Kees Cook wrote: > > On Fri, Aug 28, 2020 at 12:01:34AM +0300, Denis Efremov wrote: > > > Just FYI, I've send an addition to the device_attr_show.cocci script[1] > > > to turn > > > simple cases of snprintf

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Fri, 2020-08-28 at 01:38 +0300, Denis Efremov wrote: > > This will match it (the difference is in the ';'): thanks.

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 15:20 -0700, Kees Cook wrote: > On Fri, Aug 28, 2020 at 12:01:34AM +0300, Denis Efremov wrote: > > Just FYI, I've send an addition to the device_attr_show.cocci script[1] to > > turn > > simple cases of snprintf (e.g. "%i") to sprintf. Looks like many developers > > would >

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Denis Efremov
> > I tried: > @@ > identifier f_show =~ "^.*_show$"; This will miss this kind of functions: ./drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c:1953:static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version, ./drivers/gpu/drm/amd/amdgpu/df_v3_6.c:266:static DEVICE_ATTR(df_cntr_avail

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Kees Cook
On Fri, Aug 28, 2020 at 12:01:34AM +0300, Denis Efremov wrote: > Just FYI, I've send an addition to the device_attr_show.cocci script[1] to > turn > simple cases of snprintf (e.g. "%i") to sprintf. Looks like many developers > would > like it more than changing snprintf to scnprintf. As for me, I

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Kees Cook
On Thu, Aug 27, 2020 at 03:11:57PM -0700, Joe Perches wrote: > On Thu, 2020-08-27 at 22:03 +, David Laight wrote: > > From: Joe Perches > > > Sent: 27 August 2020 21:30 > > ... > > > Perhaps what's necessary is to find any > > > appropriate .show function and change > > > any use of strcpy/spri

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 22:03 +, David Laight wrote: > From: Joe Perches > > Sent: 27 August 2020 21:30 > ... > > Perhaps what's necessary is to find any > > appropriate .show function and change > > any use of strcpy/sprintf within those > > function to some other name. > > > > For instance: >

RE: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread David Laight
From: Joe Perches > Sent: 27 August 2020 21:30 ... > Perhaps what's necessary is to find any > appropriate .show function and change > any use of strcpy/sprintf within those > function to some other name. > > For instance: > > drivers/isdn/mISDN/core.c-static ssize_t name_show(struct device *dev,

RE: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread David Laight
> Subject: Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs > > On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > > On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > > > On 27/08/2020 15.18, Alex Dewar wrote: > > > >

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 23:36 +0200, Julia Lawall wrote: > On Fri, 28 Aug 2020, Denis Efremov wrote: [] > Regarding current device_attr_show.cocci implementation, it detects the > functions > > by declaration: > > ssize_t any_name(struct device *dev, struct device_attribute *attr, char > > *buf) >

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Julia Lawall
On Fri, 28 Aug 2020, Denis Efremov wrote: > Hi all, > > On 8/27/20 10:42 PM, Julia Lawall wrote: > > > > > > On Thu, 27 Aug 2020, Joe Perches wrote: > > > >> On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > >>> On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > On 27

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Julia Lawall
On Thu, 27 Aug 2020, Joe Perches wrote: > On Thu, 2020-08-27 at 21:42 +0200, Julia Lawall wrote: > > > > On Thu, 27 Aug 2020, Joe Perches wrote: > > > > > On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > > > > On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > > > > > On

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Denis Efremov
Hi all, On 8/27/20 10:42 PM, Julia Lawall wrote: > > > On Thu, 27 Aug 2020, Joe Perches wrote: > >> On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: >>> On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: On 27/08/2020 15.18, Alex Dewar wrote: > On Thu, Aug 27, 2020 a

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 13:29 -0700, Joe Perches wrote: > On Thu, 2020-08-27 at 21:42 +0200, Julia Lawall wrote: > > On Thu, 27 Aug 2020, Joe Perches wrote: > > > > > On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > > > > On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > > >

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 21:42 +0200, Julia Lawall wrote: > > On Thu, 27 Aug 2020, Joe Perches wrote: > > > On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > > > On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > > > > On 27/08/2020 15.18, Alex Dewar wrote: > > > > > On Thu, Au

Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Julia Lawall
On Thu, 27 Aug 2020, Joe Perches wrote: > On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > > On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > > > On 27/08/2020 15.18, Alex Dewar wrote: > > > > On Thu, Aug 27, 2020 at 09:15:37AM +0200, Greg Kroah-Hartman wrote: > > > > >

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Greg Kroah-Hartman
On Thu, Aug 27, 2020 at 09:49:04AM -0700, Kees Cook wrote: > On Tue, Aug 25, 2020 at 10:24:06AM +0200, Greg Kroah-Hartman wrote: > > On Tue, Aug 25, 2020 at 08:12:05AM +, David Laight wrote: > > > From: Alex Dewar > > > > Sent: 24 August 2020 23:23 > > > > kernel/cpu.c: don't use snprintf() for

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 15:48 +0100, Alex Dewar wrote: > On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > > On 27/08/2020 15.18, Alex Dewar wrote: > > > On Thu, Aug 27, 2020 at 09:15:37AM +0200, Greg Kroah-Hartman wrote: > > > > On Thu, Aug 27, 2020 at 08:42:06AM +0200, Rasmus Vill

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Kees Cook
On Tue, Aug 25, 2020 at 10:24:06AM +0200, Greg Kroah-Hartman wrote: > On Tue, Aug 25, 2020 at 08:12:05AM +, 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/fil

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Rasmus Villemoes
On 27/08/2020 15.18, Alex Dewar wrote: > On Thu, Aug 27, 2020 at 09:15:37AM +0200, Greg Kroah-Hartman wrote: >> On Thu, Aug 27, 2020 at 08:42:06AM +0200, Rasmus Villemoes wrote: >>> On 25/08/2020 00.23, Alex Dewar wrote: kernel/cpu.c: don't use snprintf() for sysfs attrs As per the d

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Alex Dewar
On Thu, Aug 27, 2020 at 03:41:06PM +0200, Rasmus Villemoes wrote: > On 27/08/2020 15.18, Alex Dewar wrote: > > On Thu, Aug 27, 2020 at 09:15:37AM +0200, Greg Kroah-Hartman wrote: > >> On Thu, Aug 27, 2020 at 08:42:06AM +0200, Rasmus Villemoes wrote: > >>> On 25/08/2020 00.23, Alex Dewar wrote: > >>

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Alex Dewar
On Thu, Aug 27, 2020 at 09:15:37AM +0200, Greg Kroah-Hartman wrote: > On Thu, Aug 27, 2020 at 08:42:06AM +0200, Rasmus Villemoes wrote: > > On 25/08/2020 00.23, Alex Dewar wrote: > > > kernel/cpu.c: don't use snprintf() for sysfs attrs > > > > > > As per the documentation (Documentation/filesystem

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-27 Thread Greg Kroah-Hartman
On Thu, Aug 27, 2020 at 08:42:06AM +0200, Rasmus Villemoes wrote: > On 25/08/2020 00.23, Alex Dewar wrote: > > 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

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-26 Thread Rasmus Villemoes
On 25/08/2020 00.23, Alex Dewar wrote: > 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. > Sure. But then the security guys come along and send a patch s

RE: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-25 Thread David Laight
From: Alex Dewar > Sent: 25 August 2020 09:18 > On Tue, Aug 25, 2020 at 08:12:05AM +, 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), >

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-25 Thread Greg Kroah-Hartman
On Tue, Aug 25, 2020 at 08:12:05AM +, 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 ret

Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-25 Thread Alex Dewar
On Tue, Aug 25, 2020 at 08:12:05AM +, 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 ret

RE: [PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-25 Thread David Laight
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

[PATCH] usb: atm: don't use snprintf() for sysfs attrs

2020-08-24 Thread Alex Dewar
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