Skip to contentSkip to conversation

exit: make setting exit_state consistent

PATCH In review Christian Brauner 2 participants 3 messages Jul 29, 2019 – Jul 30, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exit: make setting exit_state consistent

Since commit [1] we unconditionally set exit_state to EXIT_ZOMBIE before calling into do_notify_parent(). This was done to eliminate a race when querying exit_state in do_notify_pidfd().
Back then we decided to do the absolute minimal thing to fix this and not touch the rest of the exit_notify() function where exit_state is set.
Since this fix has not caused any issues change the setting of exit_state to EXIT_DEAD in the autoreap case to account for the fact hat exit_state is set to EXIT_ZOMBIE unconditionally. This fix was planned but also explicitly requested in [2] and makes the whole code more consistent.

/* References */
[1]: b191d6491be6 ("pidfd: fix a poll race when setting exit_state")
[2]: https://lore.kernel.org/lkml/CAHk-=wigcxGFR2szue4wavJtH5cYTTeNES=toUBVGsmX0rzX+g@mail.gmail.com

Cc Oleg Nesterov <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 kernel/exit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/exit.c +3 -2
index 4436158a6d30..5b4a5dcce8f8 100644
@@ -734,9 +734,10 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 		autoreap = true;
 	}
 
-	tsk->exit_state = autoreap ? EXIT_DEAD : EXIT_ZOMBIE;
-	if (tsk->exit_state == EXIT_DEAD)
+	if (autoreap) {
+		tsk->exit_state = EXIT_DEAD;
 		list_add(&tsk->ptrace_entry, &dead);
+	}
 
 	/* mt-exec, de_thread() is waiting for group leader */
 	if (unlikely(tsk->signal->notify_count < 0))
Signature · 1 line
2.22.0
#1 lore raw
Quoted 12 lines · Christian Brauner

Since commit [1] we unconditionally set exit_state to EXIT_ZOMBIE before calling into do_notify_parent(). This was done to eliminate a race when querying exit_state in do_notify_pidfd().
Back then we decided to do the absolute minimal thing to fix this and not touch the rest of the exit_notify() function where exit_state is set.
Since this fix has not caused any issues change the setting of exit_state to EXIT_DEAD in the autoreap case to account for the fact hat exit_state is set to EXIT_ZOMBIE unconditionally. This fix was planned but also explicitly requested in [2] and makes the whole code more consistent.

Quoted 7 lines

/* References */
[1]: b191d6491be6 ("pidfd: fix a poll race when setting exit_state")
[2]: https://lore.kernel.org/lkml/CAHk-=wigcxGFR2szue4wavJtH5cYTTeNES=toUBVGsmX0rzX+g@mail.gmail.com

Cc Oleg Nesterov <[email protected]>
Cc Linus Torvalds <[email protected]>

I plan on sending this together with a few other fixes later. (Assuming the change here is correct of course.)

Christian

Acked-by on v1 1/1
#2 lore raw
In reply to Christian Brauner
Quoted 4 lines · Christian Brauner

kernel/exit.c static void exit_notify(struct task_struct *tsk, int group_dead) · line 741

Quoted 10 lines
kernel/exit.c +3 -2
@@ -734,9 +734,10 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 		autoreap = true;
 	}
 
-	tsk->exit_state = autoreap ? EXIT_DEAD : EXIT_ZOMBIE;
-	if (tsk->exit_state == EXIT_DEAD)
+	if (autoreap) {
+		tsk->exit_state = EXIT_DEAD;
 		list_add(&tsk->ptrace_entry, &dead);
+	}