From 04b6e5e3e4ad44a2eb554f4e9c27c1aea56f3f53 Mon Sep 17 00:00:00 2001 From: Vasiliy Kulikov Date: Fri, 16 Dec 2011 15:50:43 +1100 Subject: [PATCH] proc: fix task_struct memleak proc_pid_permission() doesn't put task_struct on every /proc/$pid/ access. A demo from Hugh Dickins: while :; do ps; grep KernelStack /proc/meminfo; sleep 1; done Reported-by: Hugh Dickins Tested-by: Hugh Dickins Signed-off-by: Vasiliy Kulikov Cc: Alexey Dobriyan Signed-off-by: Andrew Morton --- fs/proc/base.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index f201e6431dfa..22524d0adfe8 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -650,9 +650,14 @@ static bool has_pid_permissions(struct pid_namespace *pid, static int proc_pid_permission(struct inode *inode, int mask) { struct pid_namespace *pid = inode->i_sb->s_fs_info; - struct task_struct *task = get_proc_task(inode); + struct task_struct *task; + bool has_perms; + + task = get_proc_task(inode); + has_perms = has_pid_permissions(pid, task, 1); + put_task_struct(task); - if (!has_pid_permissions(pid, task, 1)) { + if (!has_perms) { if (pid->hide_pid == 2) { /* * Let's make getdents(), stat(), and open() -- 2.39.5