projects/linux·commit 6ade99ec

proc: Put thread_pid in release_task not proc_flush_pid

6ade99ec · Eric W. Biederman <[email protected]> · 2020-04-24 15:41:20 -05:00

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: 7bc3e6e55acf ("proc: Use a list of inodes to flush from proc")
Reported-by: Oleg Nesterov <[email protected]>
Signed-off-by: "Eric W. Biederman" <[email protected]>
Commit
6ade99ec6175ab2b54c227521e181e1c3c2bfc8a
Parents
61e713bd

Changes

2 files changed · +1 −1

FileStatusAddDelContent
fs/proc/base.cmodified+0−1View file
kernel/exit.cmodified+1−0View file

fs/proc/base.c

View file
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 6042b64..42f43c7 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -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,

kernel/exit.c

View file
diff --git a/kernel/exit.c b/kernel/exit.c
index 389a88c..ce2a75b 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -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);