mm/kmemleak: replace strncpy() with strscpy()
authorKees Cook <kees@kernel.org>
Wed, 10 Jul 2024 00:13:08 +0000 (17:13 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 18 Jul 2024 04:05:18 +0000 (21:05 -0700)
Replace the depreciated[1] strncpy() calls with strscpy().  Uses of
object->comm do not depend on the padding side-effect.

Link: https://github.com/KSPP/linux/issues/90
Link: https://lkml.kernel.org/r/20240710001300.work.004-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/kmemleak.c

index d5b6fba44fc9f088696ff3085e0e0d3e2e2f217d..764b08100570b82ebf5ecd840a3a5705d5a31f6a 100644 (file)
@@ -657,10 +657,10 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp)
        /* task information */
        if (in_hardirq()) {
                object->pid = 0;
-               strncpy(object->comm, "hardirq", sizeof(object->comm));
+               strscpy(object->comm, "hardirq");
        } else if (in_serving_softirq()) {
                object->pid = 0;
-               strncpy(object->comm, "softirq", sizeof(object->comm));
+               strscpy(object->comm, "softirq");
        } else {
                object->pid = current->pid;
                /*
@@ -669,7 +669,7 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp)
                 * dependency issues with current->alloc_lock. In the worst
                 * case, the command line is not correct.
                 */
-               strncpy(object->comm, current->comm, sizeof(object->comm));
+               strscpy(object->comm, current->comm);
        }
 
        /* kernel backtrace */