]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
proc: Clear the pieces of proc_inode that proc_evict_inode cares about
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 20 Feb 2020 17:17:28 +0000 (11:17 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:25:01 +0000 (18:25 +0200)
[ Upstream commit 71448011ea2a1cd36d8f5cbdab0ed716c454d565 ]

This just keeps everything tidier, and allows for using flags like
SLAB_TYPESAFE_BY_RCU where slabs are not always cleared before reuse.
I don't see reuse without reinitializing happening with the proc_inode
but I had a false alarm while reworking flushing of proc dentries and
indoes when a process dies that caused me to tidy this up.

The code is a little easier to follow and reason about this
way so I figured the changes might as well be kept.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Stable-dep-of: b969f9614885 ("fix proc_sys_compare() handling of in-lookup dentries")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/proc/inode.c

index 3f0c89001fcffcc8fb3cbff491e641dcaf7fbd68..a6bb1b5c903e6473f1a675c05259e70ac69b3d2d 100644 (file)
@@ -33,21 +33,27 @@ 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);
 
        truncate_inode_pages_final(&inode->i_data);
        clear_inode(inode);
 
        /* Stop tracking associated processes */
-       put_pid(PROC_I(inode)->pid);
+       if (ei->pid) {
+               put_pid(ei->pid);
+               ei->pid = NULL;
+       }
 
        /* Let go of any associated proc directory entry */
-       de = PDE(inode);
-       if (de)
+       de = ei->pde;
+       if (de) {
                pde_put(de);
+               ei->pde = NULL;
+       }
 
-       head = PROC_I(inode)->sysctl;
+       head = ei->sysctl;
        if (head) {
-               RCU_INIT_POINTER(PROC_I(inode)->sysctl, NULL);
+               RCU_INIT_POINTER(ei->sysctl, NULL);
                proc_sys_evict_inode(inode, head);
        }
 }