Skip to content

Commit

Permalink
mm/kmemleak: replace strncpy() with strscpy()
Browse files Browse the repository at this point in the history
Replace the depreciated[1] strncpy() calls with strscpy().  Uses of
object->comm do not depend on the padding side-effect.

Link: KSPP#90 [1]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Kees Cook <[email protected]>
Acked-by: Catalin Marinas <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
kees authored and akpm00 committed Jul 18, 2024
1 parent 53dabce commit 0b84780
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/*
Expand All @@ -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 */
Expand Down

0 comments on commit 0b84780

Please sign in to comment.