Skip to contentSkip to conversation

Fix broken reparenting in forget_original_parent() (resubmit)

PATCH New Dave McCracken 1 participant 1 message Oct 22, 2001

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix broken reparenting in forget_original_parent() (resubmit)

The code in forget_original_parent() that attempts to reparent a task to another task in the thread group is broken. It's not safe to parent to any task other than init because of the race condition it introduces (init is only safe as long as it never dies, in fact).

The patch to change forget_original_parent() to always use init is below.

Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

---------------------

kernel/exit.c +0 -0
@@ -149,28 +149,21 @@

}

/*
- * When we die, we re-parent all our children.
- * Try to give them to another thread in our process
- * group, and if no such member exists, give it to
+ * When we die, we re-parent all our children to
* the global child reaper process (ie "init")
*/
static inline void forget_original_parent(struct task_struct * father) {
- struct task_struct * p, *reaper;
+ struct task_struct * p;

	read_lock(&tasklist_lock);

- /* Next in our thread group */
- reaper = next_thread(father);
- if (reaper == father)
- reaper = child_reaper;
-

	for_each_task(p) {
		if (p->p_opptr == father) {
			/* We dont want people slaying init */
			p->exit_signal = SIGCHLD;
			p->self_exec_id++;
-			p->p_opptr = reaper;
+			p->p_opptr = child_reaper;
			if (p->pdeath_signal) send_sig(p->pdeath_signal, p, 0);
		}
	}

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059