From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 239F5C43215 for ; Wed, 27 Nov 2019 21:16:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5E81216F4 for ; Wed, 27 Nov 2019 21:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574889393; bh=QB5ztak5vf3qBvLSbGqa5oiijJClK7MMBtx45SuTxbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=AiKJGlQCkoD1+U4x0reRuaoz43ctI1No0iFCTZ0/h0muCqX9zB8AfwuPKCGEW9mEQ rwyUtUQB3eosxEU8mjgra5HFZfdmsQ+UObv+6S4n8HNJvksMxLdHH0dxv5Y5Xk57WN 8jVgndElGFuBx51zgJOoXY6OpZ8b5B4B+tNXS2Gc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387514AbfK0VOF (ORCPT ); Wed, 27 Nov 2019 16:14:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:47162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387511AbfK0VOE (ORCPT ); Wed, 27 Nov 2019 16:14:04 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 880E521771; Wed, 27 Nov 2019 21:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574889244; bh=QB5ztak5vf3qBvLSbGqa5oiijJClK7MMBtx45SuTxbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qBAaCJ9y0aV6ovCdBSrdXmaFICvDDW/xmtJnlMGHzwMf6tFDECeXh2MRmPBVGfMta leNq48ZhtxZ5NCn0Rn+a6FJlqydwoO/GsobZBFLv/cZxr+8TiyySPtYd6il72I7JHI FgjNDkkt8wV+0ZCjGBRB7L/S6wOCKimGb+LtvF5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "Peter Zijlstra (Intel)" Subject: [PATCH 5.4 42/66] futex: Sanitize exit state handling Date: Wed, 27 Nov 2019 21:32:37 +0100 Message-Id: <20191127202724.089292927@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127202632.536277063@linuxfoundation.org> References: <20191127202632.536277063@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thomas Gleixner 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 Reviewed-by: Ingo Molnar Acked-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20191106224556.645603214@linutronix.de Signed-off-by: Greg Kroah-Hartman --- kernel/futex.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) --- a/kernel/futex.c +++ b/kernel/futex.c @@ -3703,16 +3703,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);