summaryrefslogtreecommitdiff
path: root/security/apparmor
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2025-10-16 17:41:10 +0200
committerJohn Johansen <john.johansen@canonical.com>2026-01-22 04:52:25 -0800
commit1c90ed1f14c9892c24d5252a2966470f4937f7a2 (patch)
tree417ebf4b7a1afa212f0ed8b6627daf50f2c86f4d /security/apparmor
parent00b67657535dfea56e84d11492f5c0f61d0af297 (diff)
downloadlinux-next-1c90ed1f14c9892c24d5252a2966470f4937f7a2.tar.gz
linux-next-1c90ed1f14c9892c24d5252a2966470f4937f7a2.zip
apparmor: Replace deprecated strcpy with memcpy in gen_symlink_name
strcpy() is deprecated; use memcpy() instead. Unlike strcpy(), memcpy() does not copy the NUL terminator from the source string, which would be overwritten anyway on every iteration when using strcpy(). snprintf() then ensures that 'char *s' is NUL-terminated. Replace the hard-coded path length to remove the magic number 6, and add a comment explaining the extra 11 bytes. Closes: https://github.com/KSPP/linux/issues/88 Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: John Johansen <john.johansen@canonical.com>
Diffstat (limited to 'security/apparmor')
-rw-r--r--security/apparmor/apparmorfs.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 907bd2667e28..91c1fcb78ac8 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -1607,16 +1607,20 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname)
{
char *buffer, *s;
int error;
- int size = depth * 6 + strlen(dirname) + strlen(fname) + 11;
+ const char *path = "../../";
+ size_t path_len = strlen(path);
+ int size;
+ /* Extra 11 bytes: "raw_data" (9) + two slashes "//" (2) */
+ size = depth * path_len + strlen(dirname) + strlen(fname) + 11;
s = buffer = kmalloc(size, GFP_KERNEL);
if (!buffer)
return ERR_PTR(-ENOMEM);
for (; depth > 0; depth--) {
- strcpy(s, "../../");
- s += 6;
- size -= 6;
+ memcpy(s, path, path_len);
+ s += path_len;
+ size -= path_len;
}
error = snprintf(s, size, "raw_data/%s/%s", dirname, fname);