Skip to content

Commit 29d673b

Browse files
author
Al Viro
committed
make securityfs_remove() remove the entire subtree
... and fix the mount leak when anything's mounted there. securityfs_recursive_remove becomes an alias for securityfs_remove - we'll probably need to remove it in a cycle or two. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 2c58d42 commit 29d673b

2 files changed

Lines changed: 12 additions & 38 deletions

File tree

include/linux/security.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,6 @@ struct dentry *securityfs_create_symlink(const char *name,
22112211
const char *target,
22122212
const struct inode_operations *iops);
22132213
extern void securityfs_remove(struct dentry *dentry);
2214-
extern void securityfs_recursive_remove(struct dentry *dentry);
22152214

22162215
#else /* CONFIG_SECURITYFS */
22172216

@@ -2243,6 +2242,8 @@ static inline void securityfs_remove(struct dentry *dentry)
22432242

22442243
#endif
22452244

2245+
#define securityfs_recursive_remove securityfs_remove
2246+
22462247
#ifdef CONFIG_BPF_SYSCALL
22472248
union bpf_attr;
22482249
struct bpf_map;

security/inode.c

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ struct dentry *securityfs_create_symlink(const char *name,
281281
}
282282
EXPORT_SYMBOL_GPL(securityfs_create_symlink);
283283

284+
static void remove_one(struct dentry *victim)
285+
{
286+
if (victim->d_parent == victim->d_sb->s_root)
287+
simple_release_fs(&mount, &mount_count);
288+
}
289+
284290
/**
285291
* securityfs_remove - removes a file or directory from the securityfs filesystem
286292
*
@@ -293,44 +299,11 @@ EXPORT_SYMBOL_GPL(securityfs_create_symlink);
293299
* This function is required to be called in order for the file to be
294300
* removed. No automatic cleanup of files will happen when a module is
295301
* removed; you are responsible here.
296-
*/
297-
void securityfs_remove(struct dentry *dentry)
298-
{
299-
struct inode *dir;
300-
301-
if (IS_ERR_OR_NULL(dentry))
302-
return;
303-
304-
dir = d_inode(dentry->d_parent);
305-
inode_lock(dir);
306-
if (simple_positive(dentry)) {
307-
if (d_is_dir(dentry))
308-
simple_rmdir(dir, dentry);
309-
else
310-
simple_unlink(dir, dentry);
311-
}
312-
inode_unlock(dir);
313-
if (dir == dir->i_sb->s_root->d_inode)
314-
simple_release_fs(&mount, &mount_count);
315-
}
316-
EXPORT_SYMBOL_GPL(securityfs_remove);
317-
318-
static void remove_one(struct dentry *victim)
319-
{
320-
if (victim->d_parent == victim->d_sb->s_root)
321-
simple_release_fs(&mount, &mount_count);
322-
}
323-
324-
/**
325-
* securityfs_recursive_remove - recursively removes a file or directory
326-
*
327-
* @dentry: a pointer to a the dentry of the file or directory to be removed.
328302
*
329-
* This function recursively removes a file or directory in securityfs that was
330-
* previously created with a call to another securityfs function (like
331-
* securityfs_create_file() or variants thereof.)
303+
* AV: when applied to directory it will take all children out; no need to call
304+
* it for descendents if ancestor is getting killed.
332305
*/
333-
void securityfs_recursive_remove(struct dentry *dentry)
306+
void securityfs_remove(struct dentry *dentry)
334307
{
335308
if (IS_ERR_OR_NULL(dentry))
336309
return;
@@ -339,7 +312,7 @@ void securityfs_recursive_remove(struct dentry *dentry)
339312
simple_recursive_removal(dentry, remove_one);
340313
simple_release_fs(&mount, &mount_count);
341314
}
342-
EXPORT_SYMBOL_GPL(securityfs_recursive_remove);
315+
EXPORT_SYMBOL_GPL(securityfs_remove);
343316

344317
#ifdef CONFIG_SECURITY
345318
static struct dentry *lsm_dentry;

0 commit comments

Comments
 (0)