From 46401cc99c6237ba825cfd65ef023955ce2a6316 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Sun, 25 Jan 2026 22:00:15 +0100 Subject: apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by a manual NUL termination. No functional changes. Reviewed-by: Serge Hallyn Signed-off-by: Thorsten Blum Signed-off-by: John Johansen --- security/apparmor/lsm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index d3af2d10fc22..553f4127d59f 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -856,12 +856,9 @@ static int do_setattr(u64 attr, void *value, size_t size) /* AppArmor requires that the buffer must be null terminated atm */ if (args[size - 1] != '\0') { - /* null terminate */ - largs = args = kmalloc(size + 1, GFP_KERNEL); + largs = args = kmemdup_nul(value, size, GFP_KERNEL); if (!args) return -ENOMEM; - memcpy(args, value, size); - args[size] = '\0'; } error = -EINVAL; -- cgit v1.2.3