Skip to content

Commit 556c1ad

Browse files
pa1guptahansendc
authored andcommitted
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 <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Dave Hansen <[email protected]>
1 parent 2f8f173 commit 556c1ad

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
@@ -586,6 +586,7 @@ What: /sys/devices/system/cpu/vulnerabilities
586586
/sys/devices/system/cpu/vulnerabilities/srbds
587587
/sys/devices/system/cpu/vulnerabilities/tsa
588588
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort
589+
/sys/devices/system/cpu/vulnerabilities/vmscape
589590
Date: January 2018
590591
Contact: Linux kernel mailing list <[email protected]>
591592
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
@@ -3829,6 +3829,7 @@
38293829
srbds=off [X86,INTEL]
38303830
ssbd=force-off [ARM64]
38313831
tsx_async_abort=off [X86]
3832+
vmscape=off [X86]
38323833

38333834
Exceptions:
38343835
This does not have any effect on
@@ -8041,6 +8042,16 @@
80418042
vmpoff= [KNL,S390] Perform z/VM CP command after power off.
80428043
Format: <command>
80438044

8045+
vmscape= [X86] Controls mitigation for VMscape attacks.
8046+
VMscape attacks can leak information from a userspace
8047+
hypervisor to a guest via speculative side-channels.
8048+
8049+
off - disable the mitigation
8050+
ibpb - use Indirect Branch Prediction Barrier
8051+
(IBPB) mitigation (default)
8052+
force - force vulnerability detection even on
8053+
unaffected processors
8054+
80448055
vsyscall= [X86-64,EARLY]
80458056
Controls the behavior of vsyscalls (i.e. calls to
80468057
fixed addresses of 0xffffffffff600x00 from legacy

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,15 @@ config MITIGATION_TSA
27012701
security vulnerability on AMD CPUs which can lead to forwarding of
27022702
invalid info to subsequent instructions and thus can affect their
27032703
timing and thereby cause a leakage.
2704+
2705+
config MITIGATION_VMSCAPE
2706+
bool "Mitigate VMSCAPE"
2707+
depends on KVM
2708+
default y
2709+
help
2710+
Enable mitigation for VMSCAPE attacks. VMSCAPE is a hardware security
2711+
vulnerability on Intel and AMD CPUs that may allow a guest to do
2712+
Spectre v2 style attacks on userspace hypervisor.
27042713
endif
27052714

27062715
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;
@@ -270,6 +273,7 @@ void __init cpu_select_mitigations(void)
270273
its_select_mitigation();
271274
bhi_select_mitigation();
272275
tsa_select_mitigation();
276+
vmscape_select_mitigation();
273277

274278
/*
275279
* After mitigations are selected, some may need to update their
@@ -301,6 +305,7 @@ void __init cpu_select_mitigations(void)
301305
bhi_update_mitigation();
302306
/* srso_update_mitigation() depends on retbleed_update_mitigation(). */
303307
srso_update_mitigation();
308+
vmscape_update_mitigation();
304309

305310
spectre_v1_apply_mitigation();
306311
spectre_v2_apply_mitigation();
@@ -318,6 +323,7 @@ void __init cpu_select_mitigations(void)
318323
its_apply_mitigation();
319324
bhi_apply_mitigation();
320325
tsa_apply_mitigation();
326+
vmscape_apply_mitigation();
321327
}
322328

323329
/*
@@ -3322,6 +3328,77 @@ static void __init srso_apply_mitigation(void)
33223328
}
33233329
}
33243330

3331+
#undef pr_fmt
3332+
#define pr_fmt(fmt) "VMSCAPE: " fmt
3333+
3334+
enum vmscape_mitigations {
3335+
VMSCAPE_MITIGATION_NONE,
3336+
VMSCAPE_MITIGATION_AUTO,
3337+
VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER,
3338+
VMSCAPE_MITIGATION_IBPB_ON_VMEXIT,
3339+
};
3340+
3341+
static const char * const vmscape_strings[] = {
3342+
[VMSCAPE_MITIGATION_NONE] = "Vulnerable",
3343+
/* [VMSCAPE_MITIGATION_AUTO] */
3344+
[VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER] = "Mitigation: IBPB before exit to userspace",
3345+
[VMSCAPE_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT",
3346+
};
3347+
3348+
static enum vmscape_mitigations vmscape_mitigation __ro_after_init =
3349+
IS_ENABLED(CONFIG_MITIGATION_VMSCAPE) ? VMSCAPE_MITIGATION_AUTO : VMSCAPE_MITIGATION_NONE;
3350+
3351+
static int __init vmscape_parse_cmdline(char *str)
3352+
{
3353+
if (!str)
3354+
return -EINVAL;
3355+
3356+
if (!strcmp(str, "off")) {
3357+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
3358+
} else if (!strcmp(str, "ibpb")) {
3359+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
3360+
} else if (!strcmp(str, "force")) {
3361+
setup_force_cpu_bug(X86_BUG_VMSCAPE);
3362+
vmscape_mitigation = VMSCAPE_MITIGATION_AUTO;
3363+
} else {
3364+
pr_err("Ignoring unknown vmscape=%s option.\n", str);
3365+
}
3366+
3367+
return 0;
3368+
}
3369+
early_param("vmscape", vmscape_parse_cmdline);
3370+
3371+
static void __init vmscape_select_mitigation(void)
3372+
{
3373+
if (cpu_mitigations_off() ||
3374+
!boot_cpu_has_bug(X86_BUG_VMSCAPE) ||
3375+
!boot_cpu_has(X86_FEATURE_IBPB)) {
3376+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
3377+
return;
3378+
}
3379+
3380+
if (vmscape_mitigation == VMSCAPE_MITIGATION_AUTO)
3381+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
3382+
}
3383+
3384+
static void __init vmscape_update_mitigation(void)
3385+
{
3386+
if (!boot_cpu_has_bug(X86_BUG_VMSCAPE))
3387+
return;
3388+
3389+
if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ||
3390+
srso_mitigation == SRSO_MITIGATION_IBPB_ON_VMEXIT)
3391+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_ON_VMEXIT;
3392+
3393+
pr_info("%s\n", vmscape_strings[vmscape_mitigation]);
3394+
}
3395+
3396+
static void __init vmscape_apply_mitigation(void)
3397+
{
3398+
if (vmscape_mitigation == VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER)
3399+
setup_force_cpu_cap(X86_FEATURE_IBPB_EXIT_TO_USER);
3400+
}
3401+
33253402
#undef pr_fmt
33263403
#define pr_fmt(fmt) fmt
33273404

@@ -3570,6 +3647,11 @@ static ssize_t tsa_show_state(char *buf)
35703647
return sysfs_emit(buf, "%s\n", tsa_strings[tsa_mitigation]);
35713648
}
35723649

3650+
static ssize_t vmscape_show_state(char *buf)
3651+
{
3652+
return sysfs_emit(buf, "%s\n", vmscape_strings[vmscape_mitigation]);
3653+
}
3654+
35733655
static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
35743656
char *buf, unsigned int bug)
35753657
{
@@ -3636,6 +3718,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
36363718
case X86_BUG_TSA:
36373719
return tsa_show_state(buf);
36383720

3721+
case X86_BUG_VMSCAPE:
3722+
return vmscape_show_state(buf);
3723+
36393724
default:
36403725
break;
36413726
}
@@ -3727,6 +3812,11 @@ ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *bu
37273812
{
37283813
return cpu_show_common(dev, attr, buf, X86_BUG_TSA);
37293814
}
3815+
3816+
ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
3817+
{
3818+
return cpu_show_common(dev, attr, buf, X86_BUG_VMSCAPE);
3819+
}
37303820
#endif
37313821

37323822
void __warn_thunk(void)

drivers/base/cpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ CPU_SHOW_VULN_FALLBACK(ghostwrite);
603603
CPU_SHOW_VULN_FALLBACK(old_microcode);
604604
CPU_SHOW_VULN_FALLBACK(indirect_target_selection);
605605
CPU_SHOW_VULN_FALLBACK(tsa);
606+
CPU_SHOW_VULN_FALLBACK(vmscape);
606607

607608
static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
608609
static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
@@ -622,6 +623,7 @@ static DEVICE_ATTR(ghostwrite, 0444, cpu_show_ghostwrite, NULL);
622623
static DEVICE_ATTR(old_microcode, 0444, cpu_show_old_microcode, NULL);
623624
static DEVICE_ATTR(indirect_target_selection, 0444, cpu_show_indirect_target_selection, NULL);
624625
static DEVICE_ATTR(tsa, 0444, cpu_show_tsa, NULL);
626+
static DEVICE_ATTR(vmscape, 0444, cpu_show_vmscape, NULL);
625627

626628
static struct attribute *cpu_root_vulnerabilities_attrs[] = {
627629
&dev_attr_meltdown.attr,
@@ -642,6 +644,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = {
642644
&dev_attr_old_microcode.attr,
643645
&dev_attr_indirect_target_selection.attr,
644646
&dev_attr_tsa.attr,
647+
&dev_attr_vmscape.attr,
645648
NULL
646649
};
647650

include/linux/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extern ssize_t cpu_show_old_microcode(struct device *dev,
8383
extern ssize_t cpu_show_indirect_target_selection(struct device *dev,
8484
struct device_attribute *attr, char *buf);
8585
extern ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *buf);
86+
extern ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf);
8687

8788
extern __printf(4, 5)
8889
struct device *cpu_device_create(struct device *parent, void *drvdata,

0 commit comments

Comments
 (0)