Skip to content

Commit e4de726

Browse files
author
Al Viro
committed
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>
1 parent 27cd1bf commit e4de726

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

security/inode.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,20 @@ static struct dentry *securityfs_create_dentry(const char *name, umode_t mode,
112112
struct dentry *dentry;
113113
struct inode *dir, *inode;
114114
int error;
115+
bool pinned = false;
115116

116117
if (!(mode & S_IFMT))
117118
mode = (mode & S_IALLUGO) | S_IFREG;
118119

119120
pr_debug("securityfs: creating file '%s'\n",name);
120121

121-
error = simple_pin_fs(&fs_type, &mount, &mount_count);
122-
if (error)
123-
return ERR_PTR(error);
124-
125-
if (!parent)
122+
if (!parent) {
123+
error = simple_pin_fs(&fs_type, &mount, &mount_count);
124+
if (error)
125+
return ERR_PTR(error);
126+
pinned = true;
126127
parent = mount->mnt_root;
128+
}
127129

128130
dir = d_inode(parent);
129131

@@ -167,7 +169,8 @@ static struct dentry *securityfs_create_dentry(const char *name, umode_t mode,
167169
dentry = ERR_PTR(error);
168170
out:
169171
inode_unlock(dir);
170-
simple_release_fs(&mount, &mount_count);
172+
if (pinned)
173+
simple_release_fs(&mount, &mount_count);
171174
return dentry;
172175
}
173176

@@ -307,13 +310,15 @@ void securityfs_remove(struct dentry *dentry)
307310
simple_unlink(dir, dentry);
308311
}
309312
inode_unlock(dir);
310-
simple_release_fs(&mount, &mount_count);
313+
if (dir == dir->i_sb->s_root->d_inode)
314+
simple_release_fs(&mount, &mount_count);
311315
}
312316
EXPORT_SYMBOL_GPL(securityfs_remove);
313317

314318
static void remove_one(struct dentry *victim)
315319
{
316-
simple_release_fs(&mount, &mount_count);
320+
if (victim->d_parent == victim->d_sb->s_root)
321+
simple_release_fs(&mount, &mount_count);
317322
}
318323

319324
/**

0 commit comments

Comments
 (0)