Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp720390pxb; Tue, 2 Feb 2021 16:38:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwI6BHoKturCHP4MAcQKP6PBBUbYNvH/m8RfbQZzw2lY5xPzSUSCB/rkb6cXAD4Z/BPzGke X-Received: by 2002:a17:906:719:: with SMTP id y25mr598207ejb.180.1612312724273; Tue, 02 Feb 2021 16:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612312724; cv=none; d=google.com; s=arc-20160816; b=FtDvgUjeRbRkbOUqpqkQKlOVg0kYa6FNb+mlccccRJAZi7B4tKSN0D8uQU/IlxJF5e IBQa4RD/2hw24o6cUFb5MGKs6xwKF2XYCyKpbKwOQCpKHfqQVnFoycGQbFgscA41HnEe 2/WeaElhYlyNoMd0qXczx1IEmjHMKVGxqxgd5Q1LQZ6+3ZEDxF+uTXbvSc9zwas+rHsB pKDpz8lUJ6aNBDUDsykP8L4gaVpNj2IGPhxeNetrv2Rgg6mvWmKOetBykaKYLpRSwYKK j+k0J6+dQDzRE9hV0sRy597nEAEIFt3cch6NLxHLQbCK2/557Vary8ZgIDfsHVR4gfKG z7kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Se29HG4qtbbiVeA31yvYNAWsm2kjpMqxU0PTlq882Sc=; b=tKYGbeVtvXaAgStsdfVhVbBdkTtCeSk83PjJOQyDKM0WTBH4Fchkk50QhWzbRZ8Fq/ fuH0tsixvQMgyLp2HXAcc8frKiAfsw6zc6KObCYr3hA22BCtM9K9c3Kky/Kx4/rs1mWD Dy11pAhvBvVKRMY1+THoGn3PIX/3yO8M6bj6TlDVR4nVotEdRrUFeQ4WWizQBwWTHlJ3 AFiNlfDYqQyaXmMCNHEQWZLKEy2QvxgJeXlYhXi/x63vesHkEIoUMVf0i3MwUEnjom48 mLx1wkAWQMLAnTgCwX98LyD48L1vpHRNvxt9KajKaUs9xzw1hW7VvTRuwiC9H4cECjjq J1Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UpWOUSs4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s1si269071ejq.292.2021.02.02.16.38.20; Tue, 02 Feb 2021 16:38:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UpWOUSs4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238635AbhBBS1a (ORCPT + 99 others); Tue, 2 Feb 2021 13:27:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:47988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233631AbhBBOFw (ORCPT ); Tue, 2 Feb 2021 09:05:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 801B06501B; Tue, 2 Feb 2021 13:49:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612273744; bh=pLmKFZTcxLOU4xQtZ4hkVgIgfzlM+qFqfenDMYaOsXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpWOUSs432Ecnpdwz9b5FZ9aOUpP2BVFUcDh3FkY1fZcfc+BkB18JCmHVMVYrsX7n brNC3Zh7yt1RfWzMYP81NRRBjK1m0q9Bw6Xc0ISnoa/NUtMJ/YGVXkqwAz2saf9OAe H9o5ahOjnlIYqtbMSJgj5w8U/Jhoq0LA2Oqv0lkg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Thomas Gleixner , Ingo Molnar , "Peter Zijlstra (Intel)" , Lee Jones Subject: [PATCH 4.4 14/28] futex: Sanitize exit state handling Date: Tue, 2 Feb 2021 14:38:34 +0100 Message-Id: <20210202132941.759808490@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210202132941.180062901@linuxfoundation.org> References: <20210202132941.180062901@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Lee Jones 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 @@ -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);