From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Len Baker <len.baker@gmx.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
David Laight <David.Laight@aculab.com>,
Kees Cook <keescook@chromium.org>,
linux-hardening@vger.kernel.org,
linux-iio <linux-iio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] drivers/iio: Remove all strcpy() uses
Date: Sat, 14 Aug 2021 13:08:48 +0300 [thread overview]
Message-ID: <CAHp75VfxYd0pS-WmE62F5w4SFWchDS=7iedaG1rY0Nc9+092RQ@mail.gmail.com> (raw)
In-Reply-To: <20210814090618.8920-1-len.baker@gmx.com>
On Sat, Aug 14, 2021 at 12:06 PM Len Baker <len.baker@gmx.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
Thanks for an update, my comments below.
...
> This patch doesn't change the logic. I think it is better to use the
> current logic and not use always the plus and minus signs as suggested
> in the previous version. I don't like the idea that 0 has sign.
Agree on that, the safest way to go with.
...
> const char *orient;
> char *str;
> int i;
> + struct device *dev;
Please, keep this in reversed xmas tree order (longer lines first).
...
> + dev = regmap_get_device(st->map);
I haven't checked the code in between, but maybe it's possible to move
an assignment directly to the definition block above.
...
> + /*
> + * The value is inverted according to the following
"to one of the"
And technically speaking "inversion" is not the same as negation
(which is "sign inversion").
> + * rules:
> + *
> + * 1) Drop leading minus.
> + * 2) Add leading minus.
> + * 3) Leave 0 as is.
> + */
> + 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);
I would go with the logic I suggested later on, i.e.
else if (orient[0] == '0' && orient[1] == '\0')
str = devm_kstrdup(dev, orient, GFP_KERNEL);
and below changed accordingly. It will clarify the "0" check.
> + else
> + str = devm_kstrdup(dev, orient, GFP_KERNEL);
> +
Redundant blank line.
> + if (!str)
> return -ENOMEM;
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2021-08-14 10:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-14 9:06 [PATCH v3] drivers/iio: Remove all strcpy() uses Len Baker
2021-08-14 10:08 ` Andy Shevchenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHp75VfxYd0pS-WmE62F5w4SFWchDS=7iedaG1rY0Nc9+092RQ@mail.gmail.com' \
--to=andy.shevchenko@gmail.com \
--cc=David.Laight@aculab.com \
--cc=jic23@kernel.org \
--cc=keescook@chromium.org \
--cc=lars@metafoo.de \
--cc=len.baker@gmx.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).