Skip to content

Commit 34e5667

Browse files
pa1guptagregkh
authored andcommitted
x86/vmscape: Enable the mitigation
Commit 556c1ad upstream. 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: Borislav Petkov (AMD) <bp@alien8.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f866eef commit 34e5667

6 files changed

Lines changed: 102 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ What: /sys/devices/system/cpu/vulnerabilities
528528
/sys/devices/system/cpu/vulnerabilities/srbds
529529
/sys/devices/system/cpu/vulnerabilities/tsa
530530
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort
531+
/sys/devices/system/cpu/vulnerabilities/vmscape
531532
Date: January 2018
532533
Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
533534
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
@@ -3368,6 +3368,7 @@
33683368
srbds=off [X86,INTEL]
33693369
ssbd=force-off [ARM64]
33703370
tsx_async_abort=off [X86]
3371+
vmscape=off [X86]
33713372

33723373
Exceptions:
33733374
This does not have any effect on
@@ -7074,6 +7075,16 @@
70747075
vmpoff= [KNL,S390] Perform z/VM CP command after power off.
70757076
Format: <command>
70767077

7078+
vmscape= [X86] Controls mitigation for VMscape attacks.
7079+
VMscape attacks can leak information from a userspace
7080+
hypervisor to a guest via speculative side-channels.
7081+
7082+
off - disable the mitigation
7083+
ibpb - use Indirect Branch Prediction Barrier
7084+
(IBPB) mitigation (default)
7085+
force - force vulnerability detection even on
7086+
unaffected processors
7087+
70777088
vsyscall= [X86-64]
70787089
Controls the behavior of vsyscalls (i.e. calls to
70797090
fixed addresses of 0xffffffffff600x00 from legacy

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,15 @@ config MITIGATION_TSA
26302630
security vulnerability on AMD CPUs which can lead to forwarding of
26312631
invalid info to subsequent instructions and thus can affect their
26322632
timing and thereby cause a leakage.
2633+
2634+
config MITIGATION_VMSCAPE
2635+
bool "Mitigate VMSCAPE"
2636+
depends on KVM
2637+
default y
2638+
help
2639+
Enable mitigation for VMSCAPE attacks. VMSCAPE is a hardware security
2640+
vulnerability on Intel and AMD CPUs that may allow a guest to do
2641+
Spectre v2 style attacks on userspace hypervisor.
26332642
endif
26342643

26352644
config ARCH_HAS_ADD_PAGES

arch/x86/kernel/cpu/bugs.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static void __init srso_select_mitigation(void);
5151
static void __init gds_select_mitigation(void);
5252
static void __init its_select_mitigation(void);
5353
static void __init tsa_select_mitigation(void);
54+
static void __init vmscape_select_mitigation(void);
5455

5556
/* The base value of the SPEC_CTRL MSR without task-specific bits set */
5657
u64 x86_spec_ctrl_base;
@@ -194,6 +195,7 @@ void __init cpu_select_mitigations(void)
194195
gds_select_mitigation();
195196
its_select_mitigation();
196197
tsa_select_mitigation();
198+
vmscape_select_mitigation();
197199
}
198200

199201
/*
@@ -2949,6 +2951,68 @@ static void __init srso_select_mitigation(void)
29492951
x86_pred_cmd = PRED_CMD_SBPB;
29502952
}
29512953

2954+
#undef pr_fmt
2955+
#define pr_fmt(fmt) "VMSCAPE: " fmt
2956+
2957+
enum vmscape_mitigations {
2958+
VMSCAPE_MITIGATION_NONE,
2959+
VMSCAPE_MITIGATION_AUTO,
2960+
VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER,
2961+
VMSCAPE_MITIGATION_IBPB_ON_VMEXIT,
2962+
};
2963+
2964+
static const char * const vmscape_strings[] = {
2965+
[VMSCAPE_MITIGATION_NONE] = "Vulnerable",
2966+
/* [VMSCAPE_MITIGATION_AUTO] */
2967+
[VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER] = "Mitigation: IBPB before exit to userspace",
2968+
[VMSCAPE_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT",
2969+
};
2970+
2971+
static enum vmscape_mitigations vmscape_mitigation __ro_after_init =
2972+
IS_ENABLED(CONFIG_MITIGATION_VMSCAPE) ? VMSCAPE_MITIGATION_AUTO : VMSCAPE_MITIGATION_NONE;
2973+
2974+
static int __init vmscape_parse_cmdline(char *str)
2975+
{
2976+
if (!str)
2977+
return -EINVAL;
2978+
2979+
if (!strcmp(str, "off")) {
2980+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
2981+
} else if (!strcmp(str, "ibpb")) {
2982+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
2983+
} else if (!strcmp(str, "force")) {
2984+
setup_force_cpu_bug(X86_BUG_VMSCAPE);
2985+
vmscape_mitigation = VMSCAPE_MITIGATION_AUTO;
2986+
} else {
2987+
pr_err("Ignoring unknown vmscape=%s option.\n", str);
2988+
}
2989+
2990+
return 0;
2991+
}
2992+
early_param("vmscape", vmscape_parse_cmdline);
2993+
2994+
static void __init vmscape_select_mitigation(void)
2995+
{
2996+
if (cpu_mitigations_off() ||
2997+
!boot_cpu_has_bug(X86_BUG_VMSCAPE) ||
2998+
!boot_cpu_has(X86_FEATURE_IBPB)) {
2999+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
3000+
return;
3001+
}
3002+
3003+
if (vmscape_mitigation == VMSCAPE_MITIGATION_AUTO)
3004+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
3005+
3006+
if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ||
3007+
srso_mitigation == SRSO_MITIGATION_IBPB_ON_VMEXIT)
3008+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_ON_VMEXIT;
3009+
3010+
if (vmscape_mitigation == VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER)
3011+
setup_force_cpu_cap(X86_FEATURE_IBPB_EXIT_TO_USER);
3012+
3013+
pr_info("%s\n", vmscape_strings[vmscape_mitigation]);
3014+
}
3015+
29523016
#undef pr_fmt
29533017
#define pr_fmt(fmt) fmt
29543018

@@ -3195,6 +3259,11 @@ static ssize_t tsa_show_state(char *buf)
31953259
return sysfs_emit(buf, "%s\n", tsa_strings[tsa_mitigation]);
31963260
}
31973261

3262+
static ssize_t vmscape_show_state(char *buf)
3263+
{
3264+
return sysfs_emit(buf, "%s\n", vmscape_strings[vmscape_mitigation]);
3265+
}
3266+
31983267
static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
31993268
char *buf, unsigned int bug)
32003269
{
@@ -3259,6 +3328,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
32593328
case X86_BUG_TSA:
32603329
return tsa_show_state(buf);
32613330

3331+
case X86_BUG_VMSCAPE:
3332+
return vmscape_show_state(buf);
3333+
32623334
default:
32633335
break;
32643336
}
@@ -3348,4 +3420,9 @@ ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *bu
33483420
{
33493421
return cpu_show_common(dev, attr, buf, X86_BUG_TSA);
33503422
}
3423+
3424+
ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
3425+
{
3426+
return cpu_show_common(dev, attr, buf, X86_BUG_VMSCAPE);
3427+
}
33513428
#endif

drivers/base/cpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ CPU_SHOW_VULN_FALLBACK(gds);
568568
CPU_SHOW_VULN_FALLBACK(reg_file_data_sampling);
569569
CPU_SHOW_VULN_FALLBACK(indirect_target_selection);
570570
CPU_SHOW_VULN_FALLBACK(tsa);
571+
CPU_SHOW_VULN_FALLBACK(vmscape);
571572

572573
static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
573574
static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
@@ -585,6 +586,7 @@ static DEVICE_ATTR(gather_data_sampling, 0444, cpu_show_gds, NULL);
585586
static DEVICE_ATTR(reg_file_data_sampling, 0444, cpu_show_reg_file_data_sampling, NULL);
586587
static DEVICE_ATTR(indirect_target_selection, 0444, cpu_show_indirect_target_selection, NULL);
587588
static DEVICE_ATTR(tsa, 0444, cpu_show_tsa, NULL);
589+
static DEVICE_ATTR(vmscape, 0444, cpu_show_vmscape, NULL);
588590

589591
static struct attribute *cpu_root_vulnerabilities_attrs[] = {
590592
&dev_attr_meltdown.attr,
@@ -603,6 +605,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = {
603605
&dev_attr_reg_file_data_sampling.attr,
604606
&dev_attr_indirect_target_selection.attr,
605607
&dev_attr_tsa.attr,
608+
&dev_attr_vmscape.attr,
606609
NULL
607610
};
608611

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)