2023-08-31 16:29:44

by Oded Gabbay

[permalink] [raw]
Subject: Re: [PATCH] accel/habanalabs: refactor deprecated strncpy to strscpy_pad

On Sat, Aug 26, 2023 at 1:13 AM Kees Cook <[email protected]> wrote:
>
> On Fri, Aug 25, 2023 at 10:09:51PM +0000, Justin Stitt wrote:
> > `strncpy` is deprecated for use on NUL-terminated destination strings [1].
> >
> > We see that `prop->cpucp_info.card_name` is supposed to be
> > NUL-terminated based on its usage within `__hwmon_device_register()`
> > (wherein it's called "name"):
> > | if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
> > | dev_warn(dev,
> > | "hwmon: '%s' is not a valid name attribute, please fix\n",
> > | name);
> >
> > A suitable replacement is `strscpy_pad` [2] due to the fact that it
> > guarantees both NUL-termination and NUL-padding on its destination
> > buffer.
> >
> > NUL-padding on `prop->cpucp_info.card_name` is not strictly necessary as
> > `hdev->prop` is explicitly zero-initialized but should be used
> > regardless as it gets copied out to userspace directly -- as per Kees' suggestion.
> >
> > Link: http://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1]
> > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
> > Link: https://github.com/KSPP/linux/issues/90
> > Cc: [email protected]
> > Signed-off-by: Justin Stitt <[email protected]>
>
> Thanks for the consolidation and refresh. :)
>
> Reviewed-by: Kees Cook <[email protected]>
>
> --
> Kees Cook
Pushed to habanalabs-next-6.7

Thanks for the patch,
Oded.