]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
securityfs: use kstrdup_const() to manage symlink targets
authorDmitry Antipov <dmantipov@yandex.ru>
Tue, 17 Mar 2026 14:11:35 +0000 (17:11 +0300)
committerPaul Moore <paul@paul-moore.com>
Tue, 17 Mar 2026 21:13:36 +0000 (17:13 -0400)
Since 'target' argument of 'securityfs_create_symlink()' is (for
now at least) a compile-time constant, it may be reasonable to
use 'kstrdup_const()' / 'kree_const()' to manage 'i_link' member
of the corresponding inode in attempt to reuse .rodata instance
rather than making a copy.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/inode.c

index 81fb5d6dd33e56e6134718bfb26e2feff8cded9a..08040236767418f5f8362a0b6f421781750a9949 100644 (file)
@@ -30,7 +30,7 @@ static int mount_count;
 static void securityfs_free_inode(struct inode *inode)
 {
        if (S_ISLNK(inode->i_mode))
-               kfree(inode->i_link);
+               kfree_const(inode->i_link);
        free_inode_nonrcu(inode);
 }
 
@@ -258,17 +258,17 @@ struct dentry *securityfs_create_symlink(const char *name,
                                         const struct inode_operations *iops)
 {
        struct dentry *dent;
-       char *link = NULL;
+       const char *link = NULL;
 
        if (target) {
-               link = kstrdup(target, GFP_KERNEL);
+               link = kstrdup_const(target, GFP_KERNEL);
                if (!link)
                        return ERR_PTR(-ENOMEM);
        }
        dent = securityfs_create_dentry(name, S_IFLNK | 0444, parent,
-                                       link, NULL, iops);
+                                       (void *)link, NULL, iops);
        if (IS_ERR(dent))
-               kfree(link);
+               kfree_const(link);
 
        return dent;
 }