exit: make setting exit_state consistent
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
--- kernel/exit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
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); + }/* mt-exec, de_thread() is waiting for group leader */ if (unlikely (tsk->signal->notify_count <0 ))
Signature · 1 line
2.22.0
Quoted 12 lines · Christian Brauner
Since commit [1] we unconditionally set
exit_statetoEXIT_ZOMBIEbefore calling intodo_notify_parent(). This was done to eliminate a race when queryingexit_stateindo_notify_pidfd().
Back then we decided to do the absolute minimal thing to fix this and not touch the rest of theexit_notify()function whereexit_stateis set.
Since this fix has not caused any issues change the setting ofexit_statetoEXIT_DEADin the autoreap case to account for the fact hatexit_stateis set toEXIT_ZOMBIEunconditionally. 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 settingexit_state")
[2]: https://lore.kernel.org/lkml/CAHk-=wigcxGFR2szue4wavJtH5cYTTeNES=toUBVGsmX0rzX+g@mail.gmail.comSigned-off-by Christian Brauner <[email protected]>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
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); + }