diff mbox series

mm/kmemleak: Replace strncpy() with strscpy()

Message ID 20240710001300.work.004-kees@kernel.org (mailing list archive)
State Mainlined
Commit 0b84780134fb02525ef29ddcb88c3d560ba88a9c
Headers show
Series mm/kmemleak: Replace strncpy() with strscpy() | expand

Commit Message

Kees Cook July 10, 2024, 12:13 a.m. UTC
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 [1]
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
---
 mm/kmemleak.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Catalin Marinas July 11, 2024, 6:08 p.m. UTC | #1
On Tue, Jul 09, 2024 at 05:13:08PM -0700, Kees Cook wrote:
> 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 [1]
> Signed-off-by: Kees Cook <kees@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

(usually Andrew picks the kmemleak patches up)
diff mbox series

Patch

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index d5b6fba44fc9..764b08100570 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -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 */