public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] sys_getppid oopses on debug kernel (v2)
@ 2006-08-09 14:38 Oleg Nesterov
  2006-08-09 12:08 ` Kirill Korotaev
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2006-08-09 14:38 UTC (permalink / raw)
  To: Andrew Morton, Kirill Korotaev; +Cc: Dave Hansen, linux-kernel

Andrew Morton wrote:
>
> Although I'm not sure it's needed for this problem. A getppid() which does
>
> asmlinkage long sys_getppid(void)
> {
> 	int pid;
>
> 	read_lock(&tasklist_lock);
> 	pid = current->group_leader->real_parent->tgid;
> 	read_unlock(&tasklist_lock);
>
> 	return pid;
> }
>
> seems like a fine implementation to me ;)

Why do we need to use ->group_leader? All threads should have the same
->real_parent.

Why do we need tasklist_lock? I think rcu_read_lock() is enough.

In other words, do you see any problems with this code

	smlinkage long sys_getppid(void)
	{
		int pid;

		rcu_read_lock();
		pid = rcu_dereference(current->real_parent)->tgid;
		rcu_read_unlock();

		return pid;
	}

? Yes, we may read a stale value for ->real_parent, but the memory
can't be freed while we are under rcu_read_lock(). And in this case
the returned value is ok because the task could be reparented just
after return anyway.

Oleg.


^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH] sys_getppid oopses on debug kernel (v2)
@ 2006-08-08 15:50 Kirill Korotaev
  2006-08-08 16:09 ` Dave Hansen
  0 siblings, 1 reply; 7+ messages in thread
From: Kirill Korotaev @ 2006-08-08 15:50 UTC (permalink / raw)
  To: Andrew Morton, Linux Kernel Mailing List, alan, muli,
	B.Steinbrink, stable, Dave Hansen

sys_getppid() optimization can access a freed memory.
On kernels with DEBUG_SLAB turned ON, this results in Oops.
As Dave Hansen noted, this optimization is also unsafe
for memory hotplug.

So this patch always takes the lock to be safe.

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


--- ./kernel/timer.c.ppiddbg	2006-07-14 19:11:06.000000000 +0400
+++ ./kernel/timer.c	2006-08-08 19:45:57.000000000 +0400
@@ -1342,28 +1342,11 @@ asmlinkage long sys_getpid(void)
 asmlinkage long sys_getppid(void)
 {
 	int pid;
-	struct task_struct *me = current;
-	struct task_struct *parent;
 
-	parent = me->group_leader->real_parent;
-	for (;;) {
-		pid = parent->tgid;
-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
-{
-		struct task_struct *old = parent;
+	read_lock(&tasklist_lock);
+	pid = current->group_leader->real_parent->tgid;
+	read_unlock(&tasklist_lock);
 
-		/*
-		 * Make sure we read the pid before re-reading the
-		 * parent pointer:
-		 */
-		smp_rmb();
-		parent = me->group_leader->real_parent;
-		if (old != parent)
-			continue;
-}
-#endif
-		break;
-	}
 	return pid;
 }
 

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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-09 14:38 [PATCH] sys_getppid oopses on debug kernel (v2) Oleg Nesterov
2006-08-09 12:08 ` Kirill Korotaev
2006-08-09 16:54   ` Oleg Nesterov
2006-08-09 13:02     ` Kirill Korotaev
2006-08-09 18:24       ` [PATCH] sys_getppid-oopses-on-debug-kernel-v2-simplify Oleg Nesterov
  -- strict thread matches above, loose matches on Subject: below --
2006-08-08 15:50 [PATCH] sys_getppid oopses on debug kernel (v2) Kirill Korotaev
2006-08-08 16:09 ` Dave Hansen

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