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