Skip to content

Commit 57a0591

Browse files
oleg-nesterovtorvalds
authored andcommitted
exit: reparent: cleanup the changing of ->parent
1. Cosmetic, but "if (t->parent == father)" looks a bit confusing. We need to change t->parent if and only if t is not traced. 2. If we actually want this BUG_ON() to ensure that parent/ptrace match each other, then we should also take ptrace_reparented() case into account too. 3. Change this code to use for_each_thread() instead of deprecated while_each_thread(). [dan.carpenter@oracle.com: silence a bogus static checker warning] Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Aaron Tomlin <atomlin@redhat.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com>, Cc: Sterling Alexander <stalexan@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Roland McGrath <roland@hack.frob.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent dc2fd4b commit 57a0591

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

kernel/exit.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,
557557

558558
static void forget_original_parent(struct task_struct *father)
559559
{
560-
struct task_struct *p, *n, *reaper;
560+
struct task_struct *p, *t, *n, *reaper;
561561
LIST_HEAD(dead_children);
562562

563563
write_lock_irq(&tasklist_lock);
@@ -569,18 +569,15 @@ static void forget_original_parent(struct task_struct *father)
569569
reaper = find_new_reaper(father);
570570

571571
list_for_each_entry_safe(p, n, &father->children, sibling) {
572-
struct task_struct *t = p;
573-
574-
do {
572+
for_each_thread(p, t) {
575573
t->real_parent = reaper;
576-
if (t->parent == father) {
577-
BUG_ON(t->ptrace);
574+
BUG_ON((!t->ptrace) != (t->parent == father));
575+
if (likely(!t->ptrace))
578576
t->parent = t->real_parent;
579-
}
580577
if (t->pdeath_signal)
581578
group_send_sig_info(t->pdeath_signal,
582579
SEND_SIG_NOINFO, t);
583-
} while_each_thread(p, t);
580+
}
584581
reparent_leader(father, p, &dead_children);
585582
}
586583
write_unlock_irq(&tasklist_lock);

0 commit comments

Comments
 (0)