Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp400798pxu; Tue, 1 Dec 2020 14:18:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq8n+n9jcHuorx9JRNgnMVBli4/dXxKldq3FAhLAztmC2N/uYeZXzMMd6zED2Z+DBdp5hd X-Received: by 2002:a50:ccdb:: with SMTP id b27mr5144799edj.253.1606861116443; Tue, 01 Dec 2020 14:18:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861116; cv=none; d=google.com; s=arc-20160816; b=StLGKGvQOdnFhcVYP052XtJ2WII7VkbWRrhQL3BdhnVR3NyXG+rZ0k0Skn4VM9iN3D TnfhdveIYiaOR8tW+JLPaqiHBvRDhbrv7c8lnBIHAJRCSS4gnRxwPbTX9USK9fFWTtJK 3Exji1VqzMJCYkGXPSFvcMbrm/Oah3NSK3j57Jn4ysMG1Mt5hGRlTn9zHbxBAw0U/pNX /hOg0ZqbPFlEfZbr5kXtaMHoTgjW/JV44oeX4KSdCV98Vesd4WJZ/IDyJiL3vgGwYqz/ ed4oxyyt4nTDIyseoFnAUvpUW81BTrg71N+zDZVRHKA2yXTDz3LsprmVa+1jOg9c34Tc Z3kA== 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=JexVVPC1BHKdUyrCWKaYTckohZ5wFD7fxj40u42Bp/w=; b=ME+wep9G1rKDgKBs8at4VNf8VkQt5EcjFr/WXWil8oHSU9UTWFEcjZEVzW6JHUhs7a o3+yLEucynrJkx0SXspQp1o4cZaYSQ5UIRqZSoUXKsC3SZCmlkvWftD/XbhvoZgJ0kUa A1kzTzaPYnzkA5urVRoiIVyy+jj5zvIz6bI3j5SPa9rHk9idTAEHtVOMWNtrsXaKMhKk Wm4svysdRuvAXzBqf2OWS2PDcWX7b776HO6csZ+5L89+MkAWnKTqmCIls/l+wyxb+g4A EBY1C9aftyMuSV7eGO9YHlcPwOb2FCl51gYcHxGC5wRBpUsJoXd+dc7i6PyCA/szlmCJ qt1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l6x9NpsF; 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 r4si786625edm.79.2020.12.01.14.18.13; Tue, 01 Dec 2020 14:18:36 -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=l6x9NpsF; 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 S1729180AbgLAI4g (ORCPT + 99 others); Tue, 1 Dec 2020 03:56:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:59034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729140AbgLAI4Y (ORCPT ); Tue, 1 Dec 2020 03:56:24 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 7916422240; Tue, 1 Dec 2020 08:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606812969; bh=30qxOdba0SGU317bjycn3Qc0y33qxUee770q+x1BktM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l6x9NpsFAe+KWx3uPx7huj9X+3ljRspd62Ssq9wr1DdYvni03nAuAzJU9ESZHu0qL bGwtl7WYY+I31ho/EPRQLJ/a8YXcify5svtV+JN44V9cObwqIVrV4bpTJvhESHdiG7 eTK/hLvwNOybvRXFfHUlO4FQzHdUebOwQKw4sr88= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand K Mistry , Borislav Petkov Subject: [PATCH 4.9 38/42] x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb Date: Tue, 1 Dec 2020 09:53:36 +0100 Message-Id: <20201201084645.598458089@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084642.194933793@linuxfoundation.org> References: <20201201084642.194933793@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: Anand K Mistry commit 33fc379df76b4991e5ae312f07bcd6820811971e upstream. When spectre_v2_user={seccomp,prctl},ibpb is specified on the command line, IBPB is force-enabled and STIPB is conditionally-enabled (or not available). However, since 21998a351512 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.") the spectre_v2_user_ibpb variable is set to SPECTRE_V2_USER_{PRCTL,SECCOMP} instead of SPECTRE_V2_USER_STRICT, which is the actual behaviour. Because the issuing of IBPB relies on the switch_mm_*_ibpb static branches, the mitigations behave as expected. Since 1978b3a53a74 ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP") this discrepency caused the misreporting of IB speculation via prctl(). On CPUs with STIBP always-on and spectre_v2_user=seccomp,ibpb, prctl(PR_GET_SPECULATION_CTRL) would return PR_SPEC_PRCTL | PR_SPEC_ENABLE instead of PR_SPEC_DISABLE since both IBPB and STIPB are always on. It also allowed prctl(PR_SET_SPECULATION_CTRL) to set the IB speculation mode, even though the flag is ignored. Similarly, for CPUs without SMT, prctl(PR_GET_SPECULATION_CTRL) should also return PR_SPEC_DISABLE since IBPB is always on and STIBP is not available. [ bp: Massage commit message. ] Fixes: 21998a351512 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.") Fixes: 1978b3a53a74 ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP") Signed-off-by: Anand K Mistry Signed-off-by: Borislav Petkov Cc: Link: https://lkml.kernel.org/r/20201110123349.1.Id0cbf996d2151f4c143c90f9028651a5b49a5908@changeid Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -732,11 +732,13 @@ spectre_v2_user_select_mitigation(enum s if (boot_cpu_has(X86_FEATURE_IBPB)) { setup_force_cpu_cap(X86_FEATURE_USE_IBPB); + spectre_v2_user_ibpb = mode; switch (cmd) { case SPECTRE_V2_USER_CMD_FORCE: case SPECTRE_V2_USER_CMD_PRCTL_IBPB: case SPECTRE_V2_USER_CMD_SECCOMP_IBPB: static_branch_enable(&switch_mm_always_ibpb); + spectre_v2_user_ibpb = SPECTRE_V2_USER_STRICT; break; case SPECTRE_V2_USER_CMD_PRCTL: case SPECTRE_V2_USER_CMD_AUTO: @@ -750,8 +752,6 @@ spectre_v2_user_select_mitigation(enum s pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n", static_key_enabled(&switch_mm_always_ibpb) ? "always-on" : "conditional"); - - spectre_v2_user_ibpb = mode; } /*