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  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]
Date:   Tue, 10 Aug 2021 15:06:39 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Len Baker <len.baker@....com>
Cc:     Jonathan Cameron <Jonathan.Cameron@...wei.com>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Kees Cook <keescook@...omium.org>,
        linux-hardening@...r.kernel.org,
        linux-iio <linux-iio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy()

On Mon, Aug 9, 2021 at 7:14 PM Len Baker <len.baker@....com> wrote:
> On Mon, Aug 09, 2021 at 10:21:31AM +0100, Jonathan Cameron wrote:
> > On Sun, 8 Aug 2021 22:00:34 +0300
> > Andy Shevchenko <andy.shevchenko@...il.com> wrote:
> > > On Sun, Aug 8, 2021 at 7:25 PM Jonathan Cameron <jic23@...nel.org> wrote:
> > > > On Sat,  7 Aug 2021 17:22:25 +0200
> > > > Len Baker <len.baker@....com> wrote:

...

> > > Isn't it too early? Or am I missing something (see below)?

> > > > >                       /* use length + 2 for adding minus sign if needed */
> > > > > -                     str = devm_kzalloc(regmap_get_device(st->map),
> > > > > -                                        strlen(orient) + 2, GFP_KERNEL);
> > > > > +                     n = strlen(orient) + 2;
> > > > > +                     str = devm_kzalloc(regmap_get_device(st->map), n,
> > > > > +                                        GFP_KERNEL);
> > > > >                       if (str == NULL)
> > > > >                               return -ENOMEM;
> > > > >                       if (strcmp(orient, "0") == 0) {
> > > > > -                             strcpy(str, orient);
> > > > > +                             strscpy(str, orient, n);
> > > > >                       } else if (orient[0] == '-') {
> > > > > -                             strcpy(str, &orient[1]);
> > > > > +                             strscpy(str, &orient[1], n);
> > > > >                       } else {
> > > > >                               str[0] = '-';
> > > > > -                             strcpy(&str[1], orient);
> > > > > +                             strscpy(&str[1], orient, n - 1);

Even if we leave the logic as is, this might be better

if (orient[0] == '-')
   str = devm_kstrdup(dev, orient + 1, GFP_KERNEL);
else if (orient[0] != '0' || orient[1] != '\0')
   str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient);
else
   str = devm_kstrdup(dev, orient, GFP_KERNEL);
if (!str)
   return -ENOMEM;

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists