[PATCH] sys_getppid-oopses-on-debug-kernel-v2-simplify

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On top of Kirill's sys_getppid-oopses-on-debug-kernel-v2.patch

- We don't need ->group_leader->real_parent, all threads should
  have the same ->real_parent.

- We don't need tasklist_lock, task_struct is freed by RCU, so
  rcu_read_lock() should be enough.

(Compile tested)

Signed-off-by: Oleg Nesterov <[email protected]>

--- 2.6.18-rc3/kernel/timer.c~	2006-08-09 22:08:51.000000000 +0400
+++ 2.6.18-rc3/kernel/timer.c	2006-08-09 22:15:35.000000000 +0400
@@ -1324,28 +1324,18 @@ asmlinkage long sys_getpid(void)
 }
 
 /*
- * Accessing ->group_leader->real_parent is not SMP-safe, it could
- * change from under us. However, rather than getting any lock
- * we can use an optimistic algorithm: get the parent
- * pid, and go back and check that the parent is still
- * the same. If it has changed (which is extremely unlikely
- * indeed), we just try again..
- *
- * NOTE! This depends on the fact that even if we _do_
- * get an old value of "parent", we can happily dereference
- * the pointer (it was and remains a dereferencable kernel pointer
- * no matter what): we just can't necessarily trust the result
- * until we know that the parent pointer is valid.
- *
- * NOTE2: ->group_leader never changes from under us.
+ * Accessing ->real_parent is not SMP-safe, it could
+ * change from under us. However, we can use a stale
+ * value of ->real_parent under rcu_read_lock(), see
+ * release_task()->call_rcu(delayed_put_task_struct).
  */
 asmlinkage long sys_getppid(void)
 {
 	int pid;
 
-	read_lock(&tasklist_lock);
-	pid = current->group_leader->real_parent->tgid;
-	read_unlock(&tasklist_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(current->real_parent)->tgid;
+	rcu_read_unlock();
 
 	return pid;
 }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux