public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sys_getppid oopses on debug kernel
@ 2006-08-08 10:22 Kirill Korotaev
  2006-08-08 15:26 ` Dave Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: Kirill Korotaev @ 2006-08-08 10:22 UTC (permalink / raw)
  To: Andrew Morton, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 164 bytes --]

sys_getppid() optimization can access a freed memory.
On kernels with DEBUG_SLAB turned ON, this results in
Oops.

Signed-Off-By: Kirill Korotaev <dev@openvz.org>


[-- Attachment #2: diff-get-ppid-with-slab-debug --]
[-- Type: text/plain, Size: 717 bytes --]

--- ./kernel/timer.c.ppiddbg	2006-07-14 19:11:06.000000000 +0400
+++ ./kernel/timer.c	2006-08-08 14:19:24.000000000 +0400
@@ -1342,6 +1342,7 @@ asmlinkage long sys_getpid(void)
 asmlinkage long sys_getppid(void)
 {
 	int pid;
+#ifndef CONFIG_DEBUG_SLAB
 	struct task_struct *me = current;
 	struct task_struct *parent;
 
@@ -1364,6 +1365,16 @@ asmlinkage long sys_getppid(void)
 #endif
 		break;
 	}
+#else
+	/*
+	 * ->real_parent could be released before dereference and
+	 * we accessed freed kernel memory, which faults with debugging on.
+	 * Keep it simple and stupid.
+	 */
+	read_lock(&tasklist_lock);
+	pid = current->group_leader->real_parent->tgid;
+	read_unlock(&tasklist_lock);
+#endif
 	return pid;
 }
 

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-08-09  3:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-08 10:22 [PATCH] sys_getppid oopses on debug kernel Kirill Korotaev
2006-08-08 15:26 ` Dave Hansen
2006-08-08 15:34   ` Björn Steinbrink
2006-08-08 15:41     ` Dave Hansen
2006-08-08 15:43   ` Kirill Korotaev
2006-08-08 15:49     ` Dave Hansen
2006-08-08 15:54       ` Kirill Korotaev
2006-08-08 15:58       ` Martin Schwidefsky
2006-08-09  3:09     ` Andi Kleen
2006-08-09  3:31       ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox