]> git.baikalelectronics.ru Git - kernel.git/commitdiff
proc: Put thread_pid in release_task not proc_flush_pid
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 24 Apr 2020 20:41:20 +0000 (15:41 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Fri, 24 Apr 2020 20:49:00 +0000 (15:49 -0500)
Oleg pointed out that in the unlikely event the kernel is compiled
with CONFIG_PROC_FS unset that release_task will now leak the pid.

Move the put_pid out of proc_flush_pid into release_task to fix this
and to guarantee I don't make that mistake again.

When possible it makes sense to keep get and put in the same function
so it can easily been seen how they pair up.

Fixes: a8c0c0ea9e09 ("proc: Use a list of inodes to flush from proc")
Reported-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
fs/proc/base.c
kernel/exit.c

index 6042b646ab2797acaa50ad0023e932300a7a42af..42f43c7b96691603c548aa8aa5713e350b45275a 100644 (file)
@@ -3274,7 +3274,6 @@ static const struct inode_operations proc_tgid_base_inode_operations = {
 void proc_flush_pid(struct pid *pid)
 {
        proc_invalidate_siblings_dcache(&pid->inodes, &pid->lock);
-       put_pid(pid);
 }
 
 static struct dentry *proc_pid_instantiate(struct dentry * dentry,
index 389a88cb308192babd68abfb4f2022803c3346c1..ce2a75bc0adeb2bc7edd19e4df6680b272f62d99 100644 (file)
@@ -219,6 +219,7 @@ repeat:
 
        write_unlock_irq(&tasklist_lock);
        proc_flush_pid(thread_pid);
+       put_pid(thread_pid);
        release_thread(p);
        put_task_struct_rcu_user(p);