Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp746896ybl; Wed, 4 Dec 2019 10:11:01 -0800 (PST) X-Google-Smtp-Source: APXvYqz67nLCM4KWEL38qBKB8Uof3fOjgcdB2mPt4hZmOhLXrtDPEa6wcFmSuxHzYaCL5/ChPNwa X-Received: by 2002:a05:6830:1e2d:: with SMTP id t13mr3645587otr.128.1575483061134; Wed, 04 Dec 2019 10:11:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575483061; cv=none; d=google.com; s=arc-20160816; b=vBkX0uZxEavZputWlQw2ne6BepHC3Yn11p8WgNqqfNKsHbp9vLNg6SldeqnVO8kgZ0 XWSVqT2PhKO+cugaiJ1KVuIir9fN2c28GUFCuhbDONZWYs9GtSY+Lhw0YKJ1n/Vi9CdD 86axv+D7t1xCnpQj24vLyCsApGXyGZ2GpgX1AUZQfqlS0ebqtLUiC2XAbY+spDFiUHEK zHEACtQTHQhaPBNYswl/osliTgNc3qynLGyQiZVbhwObWdPKEZa2LLhFqNZ+NMIPCRMm rCD9c+SuFU75HfZR4IV7iFOfo70vfaeGaX9v9+0TAZsY/DsmcSSmqLYBQnmH+jERIsNl ym9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6C++UW1RAVIlNWlhG9Y9pQEFhVSIVLYom7yPsfN7S7g=; b=lPhbW1hrKFNefB2zoer58C+9L3LMzmJPXRqYjabK1IFQxDiP41Z8oK1L8Q7JfzaYIN jwjqV+KI7ieqYhDXVURHicENEM4qodU0TFCy7kLTY8PofP4qfWhRObQJTII6rsXzQuT4 4nju8xIT5C14V1+iPR+gOBw3JN3KvbQVml5cd40wWLungBzZ+ALF7EmdMmbr3oEME3vD d0q/AQcbbAb3EIpkwc0e5VSncRIxX4vvntZYpvR9xxc/Wx2lJzjTlxZaOtPr7heYs4zh IvlNb3eV698tRlZOQUz6k6thTfWrA6Lk6ab/no/JBv53XcNplKaPczUEF5tVZ0TG+iof jcQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KFi640vS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si3651428oic.18.2019.12.04.10.10.48; Wed, 04 Dec 2019 10:11:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KFi640vS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731131AbfLDSJs (ORCPT + 99 others); Wed, 4 Dec 2019 13:09:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:35904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730415AbfLDSJp (ORCPT ); Wed, 4 Dec 2019 13:09:45 -0500 Received: from localhost (unknown [217.68.49.72]) (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 7771420833; Wed, 4 Dec 2019 18:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482985; bh=CIYWjrQB1Yla/YD6iEyhdovrzYBqTTehPpIQsk9KBY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KFi640vSNFS5yBuQjIpgxMk6VIdGC00K9LiwzEGdoMR1Cew1O/XnD4Z0qbwU/onkd YgzEQic2sO0rCbzz2EHNgfP2XDLDcV1XF14mBoXldB+NvcwpEShvDHat71bT1SxtAL uf1uJGjdoDpbJ7/euDydLOvsTM2+8zdyiwrsAX7s= 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 4.14 193/209] futex: Sanitize exit state handling Date: Wed, 4 Dec 2019 18:56:45 +0100 Message-Id: <20191204175336.773715138@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175321.609072813@linuxfoundation.org> References: <20191204175321.609072813@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -3726,16 +3726,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);