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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210815163639.GA97260@titan>
Date:   Sun, 15 Aug 2021 18:36:39 +0200
From:   Len Baker <len.baker@....com>
To:     Joe Perches <joe@...ches.com>
Cc:     Andy Shevchenko <andy.shevchenko@...il.com>,
        Len Baker <len.baker@....com>,
        Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        David Laight <David.Laight@...lab.com>,
        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 v4] drivers/iio: Remove all strcpy() uses

Hi Joe,

On Sun, Aug 15, 2021 at 08:06:45AM -0700, Joe Perches wrote:
> On Sat, 2021-08-14 at 22:36 +0300, Andy Shevchenko wrote:
> > On Sat, Aug 14, 2021 at 4:55 PM Len Baker <len.baker@....com> wrote:
> > >
> > > strcpy() performs no bounds checking on the destination buffer. This
> > > could result in linear overflows beyond the end of the buffer, leading
> > > to all kinds of misbehaviors. So, remove all the uses and add
> > > devm_kstrdup() or devm_kasprintf() instead.
> > >
> > > This patch is an effort to clean up the proliferation of str*()
> > > functions in the kernel and a previous step in the path to remove
> > > the strcpy function from the kernel entirely [1].
> > >
> > > [1] https://github.com/KSPP/linux/issues/88
> >
> > Thank you very much for doing this!
> > Now I like the result,
> > Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
> []
> > > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c
> []
> > > @@ -261,6 +261,7 @@ int inv_mpu_magn_set_rate(const struct inv_mpu6050_state *st, int fifo_rate)
> > >   */
> > >  int inv_mpu_magn_set_orient(struct inv_mpu6050_state *st)
> > >  {
> > > +       struct device *dev = regmap_get_device(st->map);
> > >         const char *orient;
> > >         char *str;
> > >         int i;
> > > @@ -281,19 +282,24 @@ int inv_mpu_magn_set_orient(struct inv_mpu6050_state *st)
> > >                 /* z <- -z */
> > >                 for (i = 0; i < 3; ++i) {
> > >                         orient = st->orientation.rotation[6 + i];
> > > -                       /* use length + 2 for adding minus sign if needed */
> > > -                       str = devm_kzalloc(regmap_get_device(st->map),
> > > -                                          strlen(orient) + 2, GFP_KERNEL);
> > > -                       if (str == NULL)
> > > +
> > > +                       /*
> > > +                        * The value is negated according to one of the following
> > > +                        * rules:
> > > +                        *
> > > +                        * 1) Drop leading minus.
> > > +                        * 2) Leave 0 as is.
> > > +                        * 3) Add leading minus.
> > > +                        */
> > > +                       if (orient[0] == '-')
> > > +                               str = devm_kstrdup(dev, orient + 1, GFP_KERNEL);
> > > +                       else if (orient[0] == '0' && orient[1] == '\0')
>
> bikeshed:
>
> I think this change is less intelligible than the original strcmp.

So, if I understand correctly you suggest to change the above line for:
                              else if (strcmp(orient, "0") == 0)

And yes, this line will be more readable ;)

>
> And separately, perhaps for loop would be more readable as
>
> 	for (i = 6; i < 9; i++)
>
> converting the 6 + i uses to just i.

Ok, no problem. If there are no objections I will send a new version with
these 2 changes.

Regards,
Len

>
> > > +                               str = devm_kstrdup(dev, orient, GFP_KERNEL);
> > > +                       else
> > > +                               str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient);
> > > +                       if (!str)
> > >                                 return -ENOMEM;
> > > -                       if (strcmp(orient, "0") == 0) {
> > > -                               strcpy(str, orient);
> > > -                       } else if (orient[0] == '-') {
> > > -                               strcpy(str, &orient[1]);
> > > -                       } else {
> > > -                               str[0] = '-';
> > > -                               strcpy(&str[1], orient);
> > > -                       }
> > > +
> > >                         st->magn_orient.rotation[6 + i] = str;
> > >                 }
> > >                 break;
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ