From: Thorsten Blum Date: Sun, 25 Jan 2026 21:00:15 +0000 (+0100) Subject: apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr X-Git-Tag: v7.1-rc1~32^2~7 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=46401cc99c6237ba825cfd65ef023955ce2a6316;p=thirdparty%2Flinux.git 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 --- 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;