futex: Provide state handling for exec() as well
authorThomas Gleixner <tglx@linutronix.de>
Wed, 6 Nov 2019 21:55:43 +0000 (22:55 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 20 Nov 2019 08:40:09 +0000 (09:40 +0100)
commitaf8cbda2cfcaa5515d61ec500498d46e9a8247e2
treed0155e66a8b7ff398e0f817eb3ea8de4775e8a0c
parent4a8e991b91aca9e20705d434677ac013974e0e30
futex: Provide state handling for exec() as well

exec() attempts to handle potentially held futexes gracefully by running
the futex exit handling code like exit() does.

The current implementation has no protection against concurrent incoming
waiters. The reason is that the futex state cannot be set to
FUTEX_STATE_DEAD after the cleanup because the task struct is still active
and just about to execute the new binary.

While its arguably buggy when a task holds a futex over exec(), for
consistency sake the state handling can at least cover the actual futex
exit cleanup section. This provides state consistency protection accross
the cleanup. As the futex state of the task becomes FUTEX_STATE_OK after the
cleanup has been finished, this cannot prevent subsequent attempts to
attach to the task in case that the cleanup was not successfull in mopping
up all leftovers.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20191106224556.753355618@linutronix.de
kernel/futex.c