]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 25 Jan 2026 21:00:15 +0000 (22:00 +0100)
committerJohn Johansen <john.johansen@canonical.com>
Wed, 22 Apr 2026 17:57:52 +0000 (10:57 -0700)
Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by
a manual NUL termination.  No functional changes.

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/lsm.c

index d3af2d10fc22c505439e098e6109e0adec468eb6..553f4127d59f53c16c4dea9cd0b7c819d6a41060 100644 (file)
@@ -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;