]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
make securityfs_remove() remove the entire subtree
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 14 May 2024 05:36:53 +0000 (23:36 -0600)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 11 Jun 2025 22:19:46 +0000 (18:19 -0400)
... 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>
include/linux/security.h
security/inode.c

index dba349629229c1f7f58801a07a03d4d1ca4b8991..386463b5e8487da01e17ba10e8ff97f6c44d5776 100644 (file)
@@ -2211,7 +2211,6 @@ struct dentry *securityfs_create_symlink(const char *name,
                                         const char *target,
                                         const struct inode_operations *iops);
 extern void securityfs_remove(struct dentry *dentry);
-extern void securityfs_recursive_remove(struct dentry *dentry);
 
 #else /* CONFIG_SECURITYFS */
 
@@ -2243,6 +2242,8 @@ static inline void securityfs_remove(struct dentry *dentry)
 
 #endif
 
+#define securityfs_recursive_remove securityfs_remove
+
 #ifdef CONFIG_BPF_SYSCALL
 union bpf_attr;
 struct bpf_map;
index 1ecb8859c27205fe5e84fb09c4b6f643fa3d8d7d..43382ef8896e1dfe16eb1d5f035c8141004ff625 100644 (file)
@@ -281,6 +281,12 @@ struct dentry *securityfs_create_symlink(const char *name,
 }
 EXPORT_SYMBOL_GPL(securityfs_create_symlink);
 
+static void remove_one(struct dentry *victim)
+{
+       if (victim->d_parent == victim->d_sb->s_root)
+               simple_release_fs(&mount, &mount_count);
+}
+
 /**
  * securityfs_remove - removes a file or directory from the securityfs filesystem
  *
@@ -293,44 +299,11 @@ EXPORT_SYMBOL_GPL(securityfs_create_symlink);
  * This function is required to be called in order for the file to be
  * removed. No automatic cleanup of files will happen when a module is
  * removed; you are responsible here.
- */
-void securityfs_remove(struct dentry *dentry)
-{
-       struct inode *dir;
-
-       if (IS_ERR_OR_NULL(dentry))
-               return;
-
-       dir = d_inode(dentry->d_parent);
-       inode_lock(dir);
-       if (simple_positive(dentry)) {
-               if (d_is_dir(dentry))
-                       simple_rmdir(dir, dentry);
-               else
-                       simple_unlink(dir, dentry);
-       }
-       inode_unlock(dir);
-       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)
-{
-       if (victim->d_parent == victim->d_sb->s_root)
-               simple_release_fs(&mount, &mount_count);
-}
-
-/**
- * securityfs_recursive_remove - recursively removes a file or directory
- *
- * @dentry: a pointer to a the dentry of the file or directory to be removed.
  *
- * This function recursively removes a file or directory in securityfs that was
- * previously created with a call to another securityfs function (like
- * securityfs_create_file() or variants thereof.)
+ * AV: when applied to directory it will take all children out; no need to call
+ * it for descendents if ancestor is getting killed.
  */
-void securityfs_recursive_remove(struct dentry *dentry)
+void securityfs_remove(struct dentry *dentry)
 {
        if (IS_ERR_OR_NULL(dentry))
                return;
@@ -339,7 +312,7 @@ void securityfs_recursive_remove(struct dentry *dentry)
        simple_recursive_removal(dentry, remove_one);
        simple_release_fs(&mount, &mount_count);
 }
-EXPORT_SYMBOL_GPL(securityfs_recursive_remove);
+EXPORT_SYMBOL_GPL(securityfs_remove);
 
 #ifdef CONFIG_SECURITY
 static struct dentry *lsm_dentry;