lkml.org 
[lkml]   [2023]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH] accel/habanalabs: refactor deprecated strncpy to strscpy_pad
    On Sat, Aug 26, 2023 at 1:13 AM Kees Cook <keescook@chromium.org> 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: 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@vger.kernel.org
    > > Signed-off-by: Justin Stitt <justinstitt@google.com>
    >
    > Thanks for the consolidation and refresh. :)
    >
    > Reviewed-by: Kees Cook <keescook@chromium.org>
    >
    > --
    > Kees Cook
    Pushed to habanalabs-next-6.7

    Thanks for the patch,
    Oded.

    \
     
     \ /
      Last update: 2023-08-31 15:11    [W:7.287 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site