]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
procfs: move dropping pde and pid from ->evict_inode() to ->free_inode()
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 20 Sep 2023 03:52:58 +0000 (23:52 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 25 Feb 2024 07:10:32 +0000 (02:10 -0500)
that keeps both around until struct inode is freed, making access
to them safe from rcu-pathwalk

Acked-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/proc/base.c
fs/proc/inode.c

index 98a031ac26484544b8b07aec1ca72f40250ba2ca..18550c071d71c733204e3a94d274ac4d47c00119 100644 (file)
@@ -1878,8 +1878,6 @@ void proc_pid_evict_inode(struct proc_inode *ei)
                hlist_del_init_rcu(&ei->sibling_inodes);
                spin_unlock(&pid->lock);
        }
-
-       put_pid(pid);
 }
 
 struct inode *proc_pid_make_inode(struct super_block *sb,
index b33e490e3fd9f88f569e3453d603041e665cf6bf..05350f3c2812c57562e9208da69d0e98835dadc9 100644 (file)
@@ -30,7 +30,6 @@
 
 static void proc_evict_inode(struct inode *inode)
 {
-       struct proc_dir_entry *de;
        struct ctl_table_header *head;
        struct proc_inode *ei = PROC_I(inode);
 
@@ -38,17 +37,8 @@ static void proc_evict_inode(struct inode *inode)
        clear_inode(inode);
 
        /* Stop tracking associated processes */
-       if (ei->pid) {
+       if (ei->pid)
                proc_pid_evict_inode(ei);
-               ei->pid = NULL;
-       }
-
-       /* Let go of any associated proc directory entry */
-       de = ei->pde;
-       if (de) {
-               pde_put(de);
-               ei->pde = NULL;
-       }
 
        head = ei->sysctl;
        if (head) {
@@ -80,6 +70,13 @@ static struct inode *proc_alloc_inode(struct super_block *sb)
 
 static void proc_free_inode(struct inode *inode)
 {
+       struct proc_inode *ei = PROC_I(inode);
+
+       if (ei->pid)
+               put_pid(ei->pid);
+       /* Let go of any associated proc directory entry */
+       if (ei->pde)
+               pde_put(ei->pde);
        kmem_cache_free(proc_inode_cachep, PROC_I(inode));
 }