Skip to content

Commit 33fc379

Browse files
akmistrysuryasaimadhu
authored andcommitted
x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb
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 21998a3 ("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 1978b3a ("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: 21998a3 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.") Fixes: 1978b3a ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP") Signed-off-by: Anand K Mistry <amistry@google.com> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: <stable@vger.kernel.org> Link: https://lkml.kernel.org/r/20201110123349.1.Id0cbf996d2151f4c143c90f9028651a5b49a5908@changeid
1 parent 7589992 commit 33fc379

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

arch/x86/kernel/cpu/bugs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,13 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
739739
if (boot_cpu_has(X86_FEATURE_IBPB)) {
740740
setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
741741

742+
spectre_v2_user_ibpb = mode;
742743
switch (cmd) {
743744
case SPECTRE_V2_USER_CMD_FORCE:
744745
case SPECTRE_V2_USER_CMD_PRCTL_IBPB:
745746
case SPECTRE_V2_USER_CMD_SECCOMP_IBPB:
746747
static_branch_enable(&switch_mm_always_ibpb);
748+
spectre_v2_user_ibpb = SPECTRE_V2_USER_STRICT;
747749
break;
748750
case SPECTRE_V2_USER_CMD_PRCTL:
749751
case SPECTRE_V2_USER_CMD_AUTO:
@@ -757,8 +759,6 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
757759
pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n",
758760
static_key_enabled(&switch_mm_always_ibpb) ?
759761
"always-on" : "conditional");
760-
761-
spectre_v2_user_ibpb = mode;
762762
}
763763

764764
/*

0 commit comments

Comments
 (0)