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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMRc=Mdny7t4NvsE3DQCQKs+DWOkp9Ee1XK3XmvVGGhbqQvq4Q@mail.gmail.com>
Date: Fri, 19 Jul 2024 16:29:12 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Arnd Bergmann <arnd@...db.de>
Cc: Arnd Bergmann <arnd@...nel.org>, Linus Walleij <linus.walleij@...aro.org>, 
	"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] gpio: virtuser: avoid non-constant format string

On Fri, Jul 19, 2024 at 4:28 PM Arnd Bergmann <arnd@...db.de> wrote:
>
> On Fri, Jul 19, 2024, at 16:10, Bartosz Golaszewski wrote:
> >> diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c
> >> index 0e0d55da4f01..c55b72e426c7 100644
> >> --- a/drivers/gpio/gpio-virtuser.c
> >> +++ b/drivers/gpio/gpio-virtuser.c
> >> @@ -805,7 +805,7 @@ static int gpio_virtuser_dbgfs_init_line_attrs(struct device *dev,
> >>                 return -ENOMEM;
> >>
> >>         data->ad.desc = desc;
> >> -       sprintf(data->consumer, id);
> >> +       sprintf(data->consumer, "%s", id);
> >>         atomic_set(&data->irq, 0);
> >>         atomic_set(&data->irq_count, 0);
> >>
> >> --
> >> 2.39.2
> >>
> >
> > I know this should not happen as the string is checked for length when
> > it is set over configfs but while we're at it: maybe make it 100%
> > correct by using snprintf(data->consumer, sizeof(data->consumer), ...?
>
> Actually I now think this should just be
>
>      strscpy(data->consumer, id);
>
> There was never a reason to use sprintf() here at all.
> strscpy() does both the correct size check and avoids
> treating it as a format string.
>
>       Arnd

Even better!

Bart

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ