linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exit: make setting exit_state consistent
@ 2019-07-29 16:27 Christian Brauner
  2019-07-29 16:30 ` Christian Brauner
  2019-07-30 16:32 ` Oleg Nesterov
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Brauner @ 2019-07-29 16:27 UTC (permalink / raw)
  To: oleg, linux-kernel
  Cc: akpm, tj, tglx, prsood, avagin, Christian Brauner, Linus Torvalds

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

Signed-off-by: Christian Brauner <christian@brauner.io>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
 kernel/exit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 4436158a6d30..5b4a5dcce8f8 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -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))
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] exit: make setting exit_state consistent
  2019-07-29 16:27 [PATCH] exit: make setting exit_state consistent Christian Brauner
@ 2019-07-29 16:30 ` Christian Brauner
  2019-07-30 16:32 ` Oleg Nesterov
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2019-07-29 16:30 UTC (permalink / raw)
  To: oleg, linux-kernel; +Cc: akpm, tj, tglx, prsood, avagin, Linus Torvalds

On Mon, Jul 29, 2019 at 06:27:57PM +0200, Christian Brauner wrote:
> 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
> 
> Signed-off-by: Christian Brauner <christian@brauner.io>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>

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

Christian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] exit: make setting exit_state consistent
  2019-07-29 16:27 [PATCH] exit: make setting exit_state consistent Christian Brauner
  2019-07-29 16:30 ` Christian Brauner
@ 2019-07-30 16:32 ` Oleg Nesterov
  1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2019-07-30 16:32 UTC (permalink / raw)
  To: Christian Brauner
  Cc: linux-kernel, akpm, tj, tglx, prsood, avagin, Linus Torvalds

On 07/29, Christian Brauner wrote:
>
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -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);
> +	}
>  

Acked-by: Oleg Nesterov <oleg@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-30 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 16:27 [PATCH] exit: make setting exit_state consistent Christian Brauner
2019-07-29 16:30 ` Christian Brauner
2019-07-30 16:32 ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).