summaryrefslogtreecommitdiffstats
path: root/kernel/futex.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2019-11-06 22:55:42 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-01-30 13:32:12 +0100
commitb45696340f5321cd7bd4f4865bae86c229d2bcc1 (patch)
treee348008896a42dfee465b49564e49766d316ff4e /kernel/futex.c
parent226eed1ef71dbc0e505e15954c41a97275b87058 (diff)
downloadlinux-stable-b45696340f5321cd7bd4f4865bae86c229d2bcc1.tar.gz
linux-stable-b45696340f5321cd7bd4f4865bae86c229d2bcc1.tar.bz2
linux-stable-b45696340f5321cd7bd4f4865bae86c229d2bcc1.zip
futex: Sanitize exit state handling
commit 4a8e991b91aca9e20705d434677ac013974e0e30 upstream Instead of having a smp_mb() and an empty lock/unlock of task::pi_lock move the state setting into to the lock section. 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.645603214@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index f995270a238a..6f4b9bd7ac15 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3740,16 +3740,19 @@ void futex_exit_recursive(struct task_struct *tsk)
void futex_exit_release(struct task_struct *tsk)
{
- tsk->futex_state = FUTEX_STATE_EXITING;
- /*
- * Ensure that all new tsk->pi_lock acquisitions must observe
- * FUTEX_STATE_EXITING. Serializes against attach_to_pi_owner().
- */
- smp_mb();
/*
- * Ensure that we must observe the pi_state in exit_pi_state_list().
+ * Switch the state to FUTEX_STATE_EXITING under tsk->pi_lock.
+ *
+ * This ensures that all subsequent checks of tsk->futex_state in
+ * attach_to_pi_owner() must observe FUTEX_STATE_EXITING with
+ * tsk->pi_lock held.
+ *
+ * It guarantees also that a pi_state which was queued right before
+ * the state change under tsk->pi_lock by a concurrent waiter must
+ * be observed in exit_pi_state_list().
*/
raw_spin_lock_irq(&tsk->pi_lock);
+ tsk->futex_state = FUTEX_STATE_EXITING;
raw_spin_unlock_irq(&tsk->pi_lock);
futex_exec_release(tsk);