872d298
From a2ef990ab5a6705a356d146dd773a3b359787497 Mon Sep 17 00:00:00 2001
872d298
From: Xiaotian Feng <xtfeng@gmail.com>
872d298
Date: Thu, 12 Jan 2012 17:17:08 -0800
872d298
Subject: [PATCH] proc: fix null pointer deref in proc_pid_permission()
872d298
872d298
get_proc_task() can fail to search the task and return NULL,
872d298
put_task_struct() will then bomb the kernel with following oops:
872d298
872d298
  BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
872d298
  IP: [<ffffffff81217d34>] proc_pid_permission+0x64/0xe0
872d298
  PGD 112075067 PUD 112814067 PMD 0
872d298
  Oops: 0002 [#1] PREEMPT SMP
872d298
872d298
This is a regression introduced by commit 0499680a ("procfs: add hidepid=
872d298
and gid= mount options").  The kernel should return -ESRCH if
872d298
get_proc_task() failed.
872d298
872d298
Signed-off-by: Xiaotian Feng <dannyfeng@tencent.com>
872d298
Cc: Al Viro <viro@zeniv.linux.org.uk>
872d298
Cc: Vasiliy Kulikov <segoon@openwall.com>
872d298
Cc: Stephen Wilson <wilsons@start.ca>
872d298
Acked-by: David Rientjes <rientjes@google.com>
872d298
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
872d298
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
872d298
---
872d298
 fs/proc/base.c |    2 ++
872d298
 1 files changed, 2 insertions(+), 0 deletions(-)
872d298
872d298
diff --git a/fs/proc/base.c b/fs/proc/base.c
872d298
index 8173dfd..5485a53 100644
872d298
--- a/fs/proc/base.c
872d298
+++ b/fs/proc/base.c
872d298
@@ -654,6 +654,8 @@ static int proc_pid_permission(struct inode *inode, int mask)
872d298
 	bool has_perms;
872d298
 
872d298
 	task = get_proc_task(inode);
872d298
+	if (!task)
872d298
+		return -ESRCH;
872d298
 	has_perms = has_pid_permissions(pid, task, 1);
872d298
 	put_task_struct(task);
872d298
 
872d298
-- 
872d298
1.7.7.5
872d298