Skip to content

Commit 6ade99e

Browse files
committed
proc: Put thread_pid in release_task not proc_flush_pid
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: 7bc3e6e ("proc: Use a list of inodes to flush from proc") Reported-by: Oleg Nesterov <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 61e713b commit 6ade99e

File tree

2 files changed

+1
-1
lines changed

2 files changed

+1
-1
lines changed

fs/proc/base.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3274,7 +3274,6 @@ static const struct inode_operations proc_tgid_base_inode_operations = {
32743274
void proc_flush_pid(struct pid *pid)
32753275
{
32763276
proc_invalidate_siblings_dcache(&pid->inodes, &pid->lock);
3277-
put_pid(pid);
32783277
}
32793278

32803279
static struct dentry *proc_pid_instantiate(struct dentry * dentry,

kernel/exit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ void release_task(struct task_struct *p)
219219

220220
write_unlock_irq(&tasklist_lock);
221221
proc_flush_pid(thread_pid);
222+
put_pid(thread_pid);
222223
release_thread(p);
223224
put_task_struct_rcu_user(p);
224225

0 commit comments

Comments
 (0)