Skip to content

Commit 459274c

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 <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d7ddc93 commit 459274c

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-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 <[email protected]>
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
@@ -3548,6 +3548,7 @@
35483548
srbds=off [X86,INTEL]
35493549
ssbd=force-off [ARM64]
35503550
tsx_async_abort=off [X86]
3551+
vmscape=off [X86]
35513552

35523553
Exceptions:
35533554
This does not have any effect on
@@ -7425,6 +7426,16 @@
74257426
vmpoff= [KNL,S390] Perform z/VM CP command after power off.
74267427
Format: <command>
74277428

7429+
vmscape= [X86] Controls mitigation for VMscape attacks.
7430+
VMscape attacks can leak information from a userspace
7431+
hypervisor to a guest via speculative side-channels.
7432+
7433+
off - disable the mitigation
7434+
ibpb - use Indirect Branch Prediction Barrier
7435+
(IBPB) mitigation (default)
7436+
force - force vulnerability detection even on
7437+
unaffected processors
7438+
74287439
vsyscall= [X86-64,EARLY]
74297440
Controls the behavior of vsyscalls (i.e. calls to
74307441
fixed addresses of 0xffffffffff600x00 from legacy

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,15 @@ config MITIGATION_TSA
27692769
security vulnerability on AMD CPUs which can lead to forwarding of
27702770
invalid info to subsequent instructions and thus can affect their
27712771
timing and thereby cause a leakage.
2772+
2773+
config MITIGATION_VMSCAPE
2774+
bool "Mitigate VMSCAPE"
2775+
depends on KVM
2776+
default y
2777+
help
2778+
Enable mitigation for VMSCAPE attacks. VMSCAPE is a hardware security
2779+
vulnerability on Intel and AMD CPUs that may allow a guest to do
2780+
Spectre v2 style attacks on userspace hypervisor.
27722781
endif
27732782

27742783
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
/*
@@ -2958,6 +2960,68 @@ static void __init srso_select_mitigation(void)
29582960
pr_info("%s\n", srso_strings[srso_mitigation]);
29592961
}
29602962

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

@@ -3204,6 +3268,11 @@ static ssize_t tsa_show_state(char *buf)
32043268
return sysfs_emit(buf, "%s\n", tsa_strings[tsa_mitigation]);
32053269
}
32063270

3271+
static ssize_t vmscape_show_state(char *buf)
3272+
{
3273+
return sysfs_emit(buf, "%s\n", vmscape_strings[vmscape_mitigation]);
3274+
}
3275+
32073276
static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
32083277
char *buf, unsigned int bug)
32093278
{
@@ -3268,6 +3337,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
32683337
case X86_BUG_TSA:
32693338
return tsa_show_state(buf);
32703339

3340+
case X86_BUG_VMSCAPE:
3341+
return vmscape_show_state(buf);
3342+
32713343
default:
32723344
break;
32733345
}
@@ -3357,6 +3429,11 @@ ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *bu
33573429
{
33583430
return cpu_show_common(dev, attr, buf, X86_BUG_TSA);
33593431
}
3432+
3433+
ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
3434+
{
3435+
return cpu_show_common(dev, attr, buf, X86_BUG_VMSCAPE);
3436+
}
33603437
#endif
33613438

33623439
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)