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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: 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: linux-hardening@xxxxxxxxxxxxxxx
> Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>

Thanks for the consolidation and refresh. :)

Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>

-- 
Kees Cook



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux