aboutsummaryrefslogtreecommitdiffstats
path: root/security/inode.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2024-05-14 08:46:00 -0600
committerAl Viro <viro@zeniv.linux.org.uk>2025-06-11 18:00:00 -0400
commite4de72650202e3da56b107f8e537d2b4a0341e40 (patch)
tree10c0451dd1cbd9f2645c2a3e2d77899c25dffa3b /security/inode.c
parent27cd1bf1240d482e4f02ca4f9812e748f3106e4f (diff)
downloadbpf-next-e4de72650202e3da56b107f8e537d2b4a0341e40.tar.gz
securityfs: pin filesystem only for objects directly in root
Nothing on securityfs ever changes parents, so we don't need to pin the internal mount if it's already pinned for parent. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'security/inode.c')
-rw-r--r--security/inode.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/security/inode.c b/security/inode.c
index 93460eab8216bb..1ecb8859c27205 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -112,18 +112,20 @@ static struct dentry *securityfs_create_dentry(const char *name, umode_t mode,
struct dentry *dentry;
struct inode *dir, *inode;
int error;
+ bool pinned = false;
if (!(mode & S_IFMT))
mode = (mode & S_IALLUGO) | S_IFREG;
pr_debug("securityfs: creating file '%s'\n",name);
- error = simple_pin_fs(&fs_type, &mount, &mount_count);
- if (error)
- return ERR_PTR(error);
-
- if (!parent)
+ if (!parent) {
+ error = simple_pin_fs(&fs_type, &mount, &mount_count);
+ if (error)
+ return ERR_PTR(error);
+ pinned = true;
parent = mount->mnt_root;
+ }
dir = d_inode(parent);
@@ -167,7 +169,8 @@ out1:
dentry = ERR_PTR(error);
out:
inode_unlock(dir);
- simple_release_fs(&mount, &mount_count);
+ if (pinned)
+ simple_release_fs(&mount, &mount_count);
return dentry;
}
@@ -307,13 +310,15 @@ void securityfs_remove(struct dentry *dentry)
simple_unlink(dir, dentry);
}
inode_unlock(dir);
- simple_release_fs(&mount, &mount_count);
+ if (dir == dir->i_sb->s_root->d_inode)
+ simple_release_fs(&mount, &mount_count);
}
EXPORT_SYMBOL_GPL(securityfs_remove);
static void remove_one(struct dentry *victim)
{
- simple_release_fs(&mount, &mount_count);
+ if (victim->d_parent == victim->d_sb->s_root)
+ simple_release_fs(&mount, &mount_count);
}
/**