Skip to content

Commit 63ac98e

Browse files
committed
x86/vmscape: Enable the mitigation
JIRA: https://issues.redhat.com/browse/RHEL-114277 CVE: CVE-2025-40300 Conflicts: Context diff's with various drivers/base/cpu.c hunks due to missing upstream commit 4e2c719 ("x86/cpu: Help users notice when running old Intel microcode"). commit 556c1ad Author: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Date: Thu, 14 Aug 2025 10:20:42 -0700 x86/vmscape: Enable the mitigation Enable the previously added mitigation for VMscape. Add the cmdline vmscape={off|ibpb|force} and sysfs reporting. Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent b2e050a commit 63ac98e

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ What: /sys/devices/system/cpu/vulnerabilities
525525
/sys/devices/system/cpu/vulnerabilities/srbds
526526
/sys/devices/system/cpu/vulnerabilities/tsa
527527
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort
528+
/sys/devices/system/cpu/vulnerabilities/vmscape
528529
Date: January 2018
529530
Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
530531
Description: Information about CPU vulnerabilities

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,7 @@
35633563
srbds=off [X86,INTEL]
35643564
ssbd=force-off [ARM64]
35653565
tsx_async_abort=off [X86]
3566+
vmscape=off [X86]
35663567

35673568
Exceptions:
35683569
This does not have any effect on
@@ -7500,6 +7501,16 @@
75007501
vmpoff= [KNL,S390] Perform z/VM CP command after power off.
75017502
Format: <command>
75027503

7504+
vmscape= [X86] Controls mitigation for VMscape attacks.
7505+
VMscape attacks can leak information from a userspace
7506+
hypervisor to a guest via speculative side-channels.
7507+
7508+
off - disable the mitigation
7509+
ibpb - use Indirect Branch Prediction Barrier
7510+
(IBPB) mitigation (default)
7511+
force - force vulnerability detection even on
7512+
unaffected processors
7513+
75037514
vsyscall= [X86-64,EARLY]
75047515
Controls the behavior of vsyscalls (i.e. calls to
75057516
fixed addresses of 0xffffffffff600x00 from legacy

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,15 @@ config MITIGATION_TSA
27802780
security vulnerability on AMD CPUs which can lead to forwarding of
27812781
invalid info to subsequent instructions and thus can affect their
27822782
timing and thereby cause a leakage.
2783+
2784+
config MITIGATION_VMSCAPE
2785+
bool "Mitigate VMSCAPE"
2786+
depends on KVM
2787+
default y
2788+
help
2789+
Enable mitigation for VMSCAPE attacks. VMSCAPE is a hardware security
2790+
vulnerability on Intel and AMD CPUs that may allow a guest to do
2791+
Spectre v2 style attacks on userspace hypervisor.
27832792
endif
27842793

27852794
config ARCH_HAS_ADD_PAGES

arch/x86/kernel/cpu/bugs.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ static void __init its_update_mitigation(void);
9696
static void __init its_apply_mitigation(void);
9797
static void __init tsa_select_mitigation(void);
9898
static void __init tsa_apply_mitigation(void);
99+
static void __init vmscape_select_mitigation(void);
100+
static void __init vmscape_update_mitigation(void);
101+
static void __init vmscape_apply_mitigation(void);
99102

100103
/* The base value of the SPEC_CTRL MSR without task-specific bits set */
101104
u64 x86_spec_ctrl_base;
@@ -236,6 +239,7 @@ void __init cpu_select_mitigations(void)
236239
its_select_mitigation();
237240
bhi_select_mitigation();
238241
tsa_select_mitigation();
242+
vmscape_select_mitigation();
239243

240244
/*
241245
* After mitigations are selected, some may need to update their
@@ -267,6 +271,7 @@ void __init cpu_select_mitigations(void)
267271
bhi_update_mitigation();
268272
/* srso_update_mitigation() depends on retbleed_update_mitigation(). */
269273
srso_update_mitigation();
274+
vmscape_update_mitigation();
270275

271276
spectre_v1_apply_mitigation();
272277
spectre_v2_apply_mitigation();
@@ -284,6 +289,7 @@ void __init cpu_select_mitigations(void)
284289
its_apply_mitigation();
285290
bhi_apply_mitigation();
286291
tsa_apply_mitigation();
292+
vmscape_apply_mitigation();
287293
}
288294

289295
/*
@@ -3138,6 +3144,77 @@ static void __init srso_apply_mitigation(void)
31383144
}
31393145
}
31403146

3147+
#undef pr_fmt
3148+
#define pr_fmt(fmt) "VMSCAPE: " fmt
3149+
3150+
enum vmscape_mitigations {
3151+
VMSCAPE_MITIGATION_NONE,
3152+
VMSCAPE_MITIGATION_AUTO,
3153+
VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER,
3154+
VMSCAPE_MITIGATION_IBPB_ON_VMEXIT,
3155+
};
3156+
3157+
static const char * const vmscape_strings[] = {
3158+
[VMSCAPE_MITIGATION_NONE] = "Vulnerable",
3159+
/* [VMSCAPE_MITIGATION_AUTO] */
3160+
[VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER] = "Mitigation: IBPB before exit to userspace",
3161+
[VMSCAPE_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT",
3162+
};
3163+
3164+
static enum vmscape_mitigations vmscape_mitigation __ro_after_init =
3165+
IS_ENABLED(CONFIG_MITIGATION_VMSCAPE) ? VMSCAPE_MITIGATION_AUTO : VMSCAPE_MITIGATION_NONE;
3166+
3167+
static int __init vmscape_parse_cmdline(char *str)
3168+
{
3169+
if (!str)
3170+
return -EINVAL;
3171+
3172+
if (!strcmp(str, "off")) {
3173+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
3174+
} else if (!strcmp(str, "ibpb")) {
3175+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
3176+
} else if (!strcmp(str, "force")) {
3177+
setup_force_cpu_bug(X86_BUG_VMSCAPE);
3178+
vmscape_mitigation = VMSCAPE_MITIGATION_AUTO;
3179+
} else {
3180+
pr_err("Ignoring unknown vmscape=%s option.\n", str);
3181+
}
3182+
3183+
return 0;
3184+
}
3185+
early_param("vmscape", vmscape_parse_cmdline);
3186+
3187+
static void __init vmscape_select_mitigation(void)
3188+
{
3189+
if (cpu_mitigations_off() ||
3190+
!boot_cpu_has_bug(X86_BUG_VMSCAPE) ||
3191+
!boot_cpu_has(X86_FEATURE_IBPB)) {
3192+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
3193+
return;
3194+
}
3195+
3196+
if (vmscape_mitigation == VMSCAPE_MITIGATION_AUTO)
3197+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
3198+
}
3199+
3200+
static void __init vmscape_update_mitigation(void)
3201+
{
3202+
if (!boot_cpu_has_bug(X86_BUG_VMSCAPE))
3203+
return;
3204+
3205+
if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ||
3206+
srso_mitigation == SRSO_MITIGATION_IBPB_ON_VMEXIT)
3207+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_ON_VMEXIT;
3208+
3209+
pr_info("%s\n", vmscape_strings[vmscape_mitigation]);
3210+
}
3211+
3212+
static void __init vmscape_apply_mitigation(void)
3213+
{
3214+
if (vmscape_mitigation == VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER)
3215+
setup_force_cpu_cap(X86_FEATURE_IBPB_EXIT_TO_USER);
3216+
}
3217+
31413218
#undef pr_fmt
31423219
#define pr_fmt(fmt) fmt
31433220

@@ -3381,6 +3458,11 @@ static ssize_t tsa_show_state(char *buf)
33813458
return sysfs_emit(buf, "%s\n", tsa_strings[tsa_mitigation]);
33823459
}
33833460

3461+
static ssize_t vmscape_show_state(char *buf)
3462+
{
3463+
return sysfs_emit(buf, "%s\n", vmscape_strings[vmscape_mitigation]);
3464+
}
3465+
33843466
static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
33853467
char *buf, unsigned int bug)
33863468
{
@@ -3444,6 +3526,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
34443526
case X86_BUG_TSA:
34453527
return tsa_show_state(buf);
34463528

3529+
case X86_BUG_VMSCAPE:
3530+
return vmscape_show_state(buf);
3531+
34473532
default:
34483533
break;
34493534
}
@@ -3530,6 +3615,11 @@ ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *bu
35303615
{
35313616
return cpu_show_common(dev, attr, buf, X86_BUG_TSA);
35323617
}
3618+
3619+
ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
3620+
{
3621+
return cpu_show_common(dev, attr, buf, X86_BUG_VMSCAPE);
3622+
}
35333623
#endif
35343624

35353625
void __warn_thunk(void)

drivers/base/cpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ CPU_SHOW_VULN_FALLBACK(gds);
601601
CPU_SHOW_VULN_FALLBACK(reg_file_data_sampling);
602602
CPU_SHOW_VULN_FALLBACK(indirect_target_selection);
603603
CPU_SHOW_VULN_FALLBACK(tsa);
604+
CPU_SHOW_VULN_FALLBACK(vmscape);
604605

605606
static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
606607
static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
@@ -618,6 +619,7 @@ static DEVICE_ATTR(gather_data_sampling, 0444, cpu_show_gds, NULL);
618619
static DEVICE_ATTR(reg_file_data_sampling, 0444, cpu_show_reg_file_data_sampling, NULL);
619620
static DEVICE_ATTR(indirect_target_selection, 0444, cpu_show_indirect_target_selection, NULL);
620621
static DEVICE_ATTR(tsa, 0444, cpu_show_tsa, NULL);
622+
static DEVICE_ATTR(vmscape, 0444, cpu_show_vmscape, NULL);
621623

622624
static struct attribute *cpu_root_vulnerabilities_attrs[] = {
623625
&dev_attr_meltdown.attr,
@@ -636,6 +638,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = {
636638
&dev_attr_reg_file_data_sampling.attr,
637639
&dev_attr_indirect_target_selection.attr,
638640
&dev_attr_tsa.attr,
641+
&dev_attr_vmscape.attr,
639642
NULL
640643
};
641644

include/linux/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ extern ssize_t cpu_show_reg_file_data_sampling(struct device *dev,
8080
extern ssize_t cpu_show_indirect_target_selection(struct device *dev,
8181
struct device_attribute *attr, char *buf);
8282
extern ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *buf);
83+
extern ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf);
8384

8485
extern __printf(4, 5)
8586
struct device *cpu_device_create(struct device *parent, void *drvdata,

0 commit comments

Comments
 (0)