Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp408850pxu; Tue, 1 Dec 2020 14:32:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtA2UWc7tVQKbtj+Xmgm1iYE0uhSH+WZrJyOJiCSFCCfS90rZxOB5WOdvpqnkyZBiBbGgp X-Received: by 2002:aa7:d61a:: with SMTP id c26mr5135434edr.212.1606861938663; Tue, 01 Dec 2020 14:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861938; cv=none; d=google.com; s=arc-20160816; b=DoekFHJYZ1aZ/NM67ekB6smQLQIk9c+qM0u5LkQNP0g0CtwJm60ylIc7jfpNZi7Cqh th3Oyl10EcDHjf/Y4LXkeoun9GWnujPU94dYUJ2jTRugAjLCJl/hppVo0L1PUpues7cH kkmSoon9s02c0XmK102Xn2BNHrSHpuxmtWb5+aq8jHE33OlFJKbyzalmXBXEU1gxOpi6 7uy8u9m5Hkv3GMwZHDou5p9Vspo3fA5ElC7xfMzZoN/Q1ForJQAjMuMwFZvlSusJi/m/ QBtIb/5deeNdoiZrgxw0lznSTmjvvsKUC9PduJKPHdHgZzgmEldJMD+MBQXHjkjjhO+7 soJA== 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=m6TzLxkl6XbkJtAEHKQh7KCbqHUGnxAcLrototx5Fa0=; b=iK2HTyidkqRHqcb/sPo4lJzNT6fCDx5EN75XR5o+rTisQRNcgW0F1OVnib/u7Ky7DJ 22derBA7ey7XiIzZOQmz4l+1cfzZoJZpvOjtka/ELqMHgi9Wxv/9TRvh2GndpBVkDQV2 1TBusMpE/EeBmyZQI3VXIFwOuHysazX8ZE2Znwn0XR5pf/m5YYbXwtvMqUItDQ/BKCqT pTKZWD0SorHNwMcETbnFD4E0tck5BFxT8OCeh+XdhrKVYBN+UL4hru7vDM9BnknlPjke KkFfO5Xb6qnfHOm+McdKlM/stNN3bqoUGLpXGeeeFWO1BjzsQlmXCu16revzfPIEEKHl PLAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PBQSR5D2; 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 cc10si853097edb.156.2020.12.01.14.31.56; Tue, 01 Dec 2020 14:32:18 -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=PBQSR5D2; 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 S2390657AbgLAJ1a (ORCPT + 99 others); Tue, 1 Dec 2020 04:27:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:39486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729298AbgLAJCe (ORCPT ); Tue, 1 Dec 2020 04:02:34 -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 C1D9E20770; Tue, 1 Dec 2020 09:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813313; bh=Fqd08q6ULXgk8oeFymIU9Q5qSM6g/VApXQdxsacXWFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBQSR5D20OKCMBmYyJGTrJ7RgMWJjwUltAkXmKygt5K6+HO1QObVtxcKcWwpenodF PU+VFIuVeQ9paqO98MgTNGLHbvhyRztA/KZHF9s8SUk0Dm1atFoRpKReGMNboC2+hR jwSJgt649armY5eo2bYJno+kIHBZSLDMCuErRKlA= 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.19 54/57] x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb Date: Tue, 1 Dec 2020 09:53:59 +0100 Message-Id: <20201201084651.760469216@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084647.751612010@linuxfoundation.org> References: <20201201084647.751612010@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 @@ -733,11 +733,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: @@ -751,8 +753,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; } /*