drm/nouveau/nvif: refactor deprecated strncpy
authorJustin Stitt <justinstitt@google.com>
Thu, 14 Sep 2023 21:30:37 +0000 (21:30 +0000)
committerLyude Paul <lyude@redhat.com>
Fri, 15 Sep 2023 17:36:26 +0000 (13:36 -0400)
`strncpy` is deprecated and as such we should prefer more robust and
less ambiguous string interfaces.

A suitable replacement is `strscpy_pad` due to the fact that it
guarantees NUL-termination on the destination buffer whilst also
maintaining the NUL-padding behavior that `strncpy` provides. I am not
sure whether NUL-padding is strictly needed but I see in
`nvif_object_ctor()` args is memcpy'd elsewhere so I figured we'd keep
the same functionality.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230914-strncpy-drivers-gpu-drm-nouveau-nvif-client-c-v1-1-dc3b3719fcb4@google.com
drivers/gpu/drm/nouveau/nvif/client.c

index a3264a0e933a5995614d4c04ade98f8d5900b7e0..3a27245f467f80868a560504d15b5dd2181430a0 100644 (file)
@@ -69,7 +69,7 @@ nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
        } nop = {};
        int ret;
 
-       strncpy(args.name, name, sizeof(args.name));
+       strscpy_pad(args.name, name, sizeof(args.name));
        ret = nvif_object_ctor(parent != client ? &parent->object : NULL,
                               name ? name : "nvifClient", 0,
                               NVIF_CLASS_CLIENT, &args, sizeof(args),