blob: 8c8b42d98707efef3dff7802f949bad18ad8e73d [file] [log] [blame]
From foo@baz Mon Feb 1 04:21:37 PM CET 2021
From: Lee Jones <lee.jones@linaro.org>
Date: Mon, 1 Feb 2021 15:12:10 +0000
Subject: futex: Sanitize exit state handling
To: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Lee Jones <lee.jones@linaro.org>
Message-ID: <20210201151214.2193508-9-lee.jones@linaro.org>
From: Thomas Gleixner <tglx@linutronix.de>
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>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/futex.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3276,16 +3276,19 @@ void futex_exit_recursive(struct task_st
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);