2020-08-10 09:22:40

by kernel test robot

[permalink] [raw]
Subject: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings

From: kernel test robot <[email protected]>

drivers/video/fbdev/core/fbcon.c:3509:8-16: WARNING: use scnprintf or sprintf
drivers/video/fbdev/core/fbcon.c:3484:8-16: WARNING: use scnprintf or sprintf


From Documentation/filesystems/sysfs.txt:
show() must not use snprintf() when formatting the value to be
returned to user space. If you can guarantee that an overflow
will never happen you can use sprintf() otherwise you must use
scnprintf().

Generated by: scripts/coccinelle/api/device_attr_show.cocci

Fixes: abfc19ff202d ("coccinelle: api: add device_attr_show script")
CC: Denis Efremov <[email protected]>
Signed-off-by: kernel test robot <[email protected]>
---

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7
commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script

Please take the patch only if it's a positive warning. Thanks!

fbcon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -3481,7 +3481,7 @@ static ssize_t show_rotate(struct device
rotate = fbcon_get_rotate(info);
err:
console_unlock();
- return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
+ return scnprintf(buf, PAGE_SIZE, "%d\n", rotate);
}

static ssize_t show_cursor_blink(struct device *device,
@@ -3506,7 +3506,7 @@ static ssize_t show_cursor_blink(struct
blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
err:
console_unlock();
- return snprintf(buf, PAGE_SIZE, "%d\n", blink);
+ return scnprintf(buf, PAGE_SIZE, "%d\n", blink);
}

static ssize_t store_cursor_blink(struct device *device,


Subject: Re: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings


Hi,

On 8/10/20 11:21 AM, kernel test robot wrote:
> From: kernel test robot <[email protected]>
>
> drivers/video/fbdev/core/fbcon.c:3509:8-16: WARNING: use scnprintf or sprintf
> drivers/video/fbdev/core/fbcon.c:3484:8-16: WARNING: use scnprintf or sprintf
>
>
> From Documentation/filesystems/sysfs.txt:
> show() must not use snprintf() when formatting the value to be
> returned to user space. If you can guarantee that an overflow
> will never happen you can use sprintf() otherwise you must use
> scnprintf().
>
> Generated by: scripts/coccinelle/api/device_attr_show.cocci
>
> Fixes: abfc19ff202d ("coccinelle: api: add device_attr_show script")
> CC: Denis Efremov <[email protected]>
> Signed-off-by: kernel test robot <[email protected]>
> ---
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7
> commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script
>
> Please take the patch only if it's a positive warning. Thanks!
>
> fbcon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c
> @@ -3481,7 +3481,7 @@ static ssize_t show_rotate(struct device
> rotate = fbcon_get_rotate(info);
> err:
> console_unlock();
> - return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
> + return scnprintf(buf, PAGE_SIZE, "%d\n", rotate);

buf length is at least PAGE_SIZE and rotate val is an int so
shouldn't this be converted to use sprintf() instead?

> }
>
> static ssize_t show_cursor_blink(struct device *device,
> @@ -3506,7 +3506,7 @@ static ssize_t show_cursor_blink(struct
> blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
> err:
> console_unlock();
> - return snprintf(buf, PAGE_SIZE, "%d\n", blink);
> + return scnprintf(buf, PAGE_SIZE, "%d\n", blink);

ditto for blink val

> }
>
> static ssize_t store_cursor_blink(struct device *device,
>

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

2020-09-08 19:53:10

by Julia Lawall

[permalink] [raw]
Subject: Re: [kbuild-all] Re: [PATCH] coccinelle: api: fix device_attr_show.cocci warnings



On Tue, 8 Sep 2020, Bartlomiej Zolnierkiewicz wrote:

>
> Hi,
>
> On 8/10/20 11:21 AM, kernel test robot wrote:
> > From: kernel test robot <[email protected]>
> >
> > drivers/video/fbdev/core/fbcon.c:3509:8-16: WARNING: use scnprintf or sprintf
> > drivers/video/fbdev/core/fbcon.c:3484:8-16: WARNING: use scnprintf or sprintf
> >
> >
> > From Documentation/filesystems/sysfs.txt:
> > show() must not use snprintf() when formatting the value to be
> > returned to user space. If you can guarantee that an overflow
> > will never happen you can use sprintf() otherwise you must use
> > scnprintf().
> >
> > Generated by: scripts/coccinelle/api/device_attr_show.cocci
> >
> > Fixes: abfc19ff202d ("coccinelle: api: add device_attr_show script")
> > CC: Denis Efremov <[email protected]>
> > Signed-off-by: kernel test robot <[email protected]>
> > ---
> >
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7
> > commit: abfc19ff202d287742483e15fd478ddd6ada2187 coccinelle: api: add device_attr_show script
> >
> > Please take the patch only if it's a positive warning. Thanks!
> >
> > fbcon.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > --- a/drivers/video/fbdev/core/fbcon.c
> > +++ b/drivers/video/fbdev/core/fbcon.c
> > @@ -3481,7 +3481,7 @@ static ssize_t show_rotate(struct device
> > rotate = fbcon_get_rotate(info);
> > err:
> > console_unlock();
> > - return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
> > + return scnprintf(buf, PAGE_SIZE, "%d\n", rotate);
>
> buf length is at least PAGE_SIZE and rotate val is an int so
> shouldn't this be converted to use sprintf() instead?

The rule is evolving in this direction. Thanks for the feedback.

julia

>
> > }
> >
> > static ssize_t show_cursor_blink(struct device *device,
> > @@ -3506,7 +3506,7 @@ static ssize_t show_cursor_blink(struct
> > blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
> > err:
> > console_unlock();
> > - return snprintf(buf, PAGE_SIZE, "%d\n", blink);
> > + return scnprintf(buf, PAGE_SIZE, "%d\n", blink);
>
> ditto for blink val
>
> > }
> >
> > static ssize_t store_cursor_blink(struct device *device,
> >
>
> Best regards,
> --
> Bartlomiej Zolnierkiewicz
> Samsung R&D Institute Poland
> Samsung Electronics
> _______________________________________________
> kbuild-all mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
>