Skip to content

Commit 2f4f2f8

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: Amit Shah <amit.shah@amd.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d5490df commit 2f4f2f8

6 files changed

Lines changed: 105 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
@@ -526,6 +526,7 @@ What: /sys/devices/system/cpu/vulnerabilities
526526
/sys/devices/system/cpu/vulnerabilities/srbds
527527
/sys/devices/system/cpu/vulnerabilities/tsa
528528
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort
529+
/sys/devices/system/cpu/vulnerabilities/vmscape
529530
Date: January 2018
530531
Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
531532
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
@@ -3107,6 +3107,7 @@
31073107
ssbd=force-off [ARM64]
31083108
nospectre_bhb [ARM64]
31093109
tsx_async_abort=off [X86]
3110+
vmscape=off [X86]
31103111

31113112
Exceptions:
31123113
This does not have any effect on
@@ -6399,6 +6400,16 @@
63996400
vmpoff= [KNL,S390] Perform z/VM CP command after power off.
64006401
Format: <command>
64016402

6403+
vmscape= [X86] Controls mitigation for VMscape attacks.
6404+
VMscape attacks can leak information from a userspace
6405+
hypervisor to a guest via speculative side-channels.
6406+
6407+
off - disable the mitigation
6408+
ibpb - use Indirect Branch Prediction Barrier
6409+
(IBPB) mitigation (default)
6410+
force - force vulnerability detection even on
6411+
unaffected processors
6412+
64026413
vsyscall= [X86-64]
64036414
Controls the behavior of vsyscalls (i.e. calls to
64046415
fixed addresses of 0xffffffffff600x00 from legacy

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,15 @@ config MITIGATION_TSA
25372537
security vulnerability on AMD CPUs which can lead to forwarding of
25382538
invalid info to subsequent instructions and thus can affect their
25392539
timing and thereby cause a leakage.
2540+
2541+
config MITIGATION_VMSCAPE
2542+
bool "Mitigate VMSCAPE"
2543+
depends on KVM
2544+
default y
2545+
help
2546+
Enable mitigation for VMSCAPE attacks. VMSCAPE is a hardware security
2547+
vulnerability on Intel and AMD CPUs that may allow a guest to do
2548+
Spectre v2 style attacks on userspace hypervisor.
25402549
endif
25412550

25422551
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
@@ -50,6 +50,7 @@ static void __init gds_select_mitigation(void);
5050
static void __init srso_select_mitigation(void);
5151
static void __init its_select_mitigation(void);
5252
static void __init tsa_select_mitigation(void);
53+
static void __init vmscape_select_mitigation(void);
5354

5455
/* The base value of the SPEC_CTRL MSR without task-specific bits set */
5556
u64 x86_spec_ctrl_base;
@@ -193,6 +194,7 @@ void __init cpu_select_mitigations(void)
193194
gds_select_mitigation();
194195
its_select_mitigation();
195196
tsa_select_mitigation();
197+
vmscape_select_mitigation();
196198
}
197199

198200
/*
@@ -2898,6 +2900,68 @@ static void __init srso_select_mitigation(void)
28982900
x86_pred_cmd = PRED_CMD_SBPB;
28992901
}
29002902

2903+
#undef pr_fmt
2904+
#define pr_fmt(fmt) "VMSCAPE: " fmt
2905+
2906+
enum vmscape_mitigations {
2907+
VMSCAPE_MITIGATION_NONE,
2908+
VMSCAPE_MITIGATION_AUTO,
2909+
VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER,
2910+
VMSCAPE_MITIGATION_IBPB_ON_VMEXIT,
2911+
};
2912+
2913+
static const char * const vmscape_strings[] = {
2914+
[VMSCAPE_MITIGATION_NONE] = "Vulnerable",
2915+
/* [VMSCAPE_MITIGATION_AUTO] */
2916+
[VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER] = "Mitigation: IBPB before exit to userspace",
2917+
[VMSCAPE_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT",
2918+
};
2919+
2920+
static enum vmscape_mitigations vmscape_mitigation __ro_after_init =
2921+
IS_ENABLED(CONFIG_MITIGATION_VMSCAPE) ? VMSCAPE_MITIGATION_AUTO : VMSCAPE_MITIGATION_NONE;
2922+
2923+
static int __init vmscape_parse_cmdline(char *str)
2924+
{
2925+
if (!str)
2926+
return -EINVAL;
2927+
2928+
if (!strcmp(str, "off")) {
2929+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
2930+
} else if (!strcmp(str, "ibpb")) {
2931+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
2932+
} else if (!strcmp(str, "force")) {
2933+
setup_force_cpu_bug(X86_BUG_VMSCAPE);
2934+
vmscape_mitigation = VMSCAPE_MITIGATION_AUTO;
2935+
} else {
2936+
pr_err("Ignoring unknown vmscape=%s option.\n", str);
2937+
}
2938+
2939+
return 0;
2940+
}
2941+
early_param("vmscape", vmscape_parse_cmdline);
2942+
2943+
static void __init vmscape_select_mitigation(void)
2944+
{
2945+
if (cpu_mitigations_off() ||
2946+
!boot_cpu_has_bug(X86_BUG_VMSCAPE) ||
2947+
!boot_cpu_has(X86_FEATURE_IBPB)) {
2948+
vmscape_mitigation = VMSCAPE_MITIGATION_NONE;
2949+
return;
2950+
}
2951+
2952+
if (vmscape_mitigation == VMSCAPE_MITIGATION_AUTO)
2953+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER;
2954+
2955+
if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ||
2956+
srso_mitigation == SRSO_MITIGATION_IBPB_ON_VMEXIT)
2957+
vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_ON_VMEXIT;
2958+
2959+
if (vmscape_mitigation == VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER)
2960+
setup_force_cpu_cap(X86_FEATURE_IBPB_EXIT_TO_USER);
2961+
2962+
pr_info("%s\n", vmscape_strings[vmscape_mitigation]);
2963+
}
2964+
29012965
#undef pr_fmt
29022966
#define pr_fmt(fmt) fmt
29032967

@@ -3146,6 +3210,11 @@ static ssize_t tsa_show_state(char *buf)
31463210
return sysfs_emit(buf, "%s\n", tsa_strings[tsa_mitigation]);
31473211
}
31483212

3213+
static ssize_t vmscape_show_state(char *buf)
3214+
{
3215+
return sysfs_emit(buf, "%s\n", vmscape_strings[vmscape_mitigation]);
3216+
}
3217+
31493218
static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
31503219
char *buf, unsigned int bug)
31513220
{
@@ -3210,6 +3279,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
32103279
case X86_BUG_TSA:
32113280
return tsa_show_state(buf);
32123281

3282+
case X86_BUG_VMSCAPE:
3283+
return vmscape_show_state(buf);
3284+
32133285
default:
32143286
break;
32153287
}
@@ -3299,4 +3371,9 @@ ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *bu
32993371
{
33003372
return cpu_show_common(dev, attr, buf, X86_BUG_TSA);
33013373
}
3374+
3375+
ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
3376+
{
3377+
return cpu_show_common(dev, attr, buf, X86_BUG_VMSCAPE);
3378+
}
33023379
#endif

drivers/base/cpu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ ssize_t __weak cpu_show_tsa(struct device *dev, struct device_attribute *attr, c
605605
{
606606
return sysfs_emit(buf, "Not affected\n");
607607
}
608+
ssize_t __weak cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
609+
{
610+
return sysfs_emit(buf, "Not affected\n");
611+
}
608612

609613
static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
610614
static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
@@ -622,6 +626,7 @@ static DEVICE_ATTR(spec_rstack_overflow, 0444, cpu_show_spec_rstack_overflow, NU
622626
static DEVICE_ATTR(reg_file_data_sampling, 0444, cpu_show_reg_file_data_sampling, NULL);
623627
static DEVICE_ATTR(indirect_target_selection, 0444, cpu_show_indirect_target_selection, NULL);
624628
static DEVICE_ATTR(tsa, 0444, cpu_show_tsa, NULL);
629+
static DEVICE_ATTR(vmscape, 0444, cpu_show_vmscape, NULL);
625630

626631
static struct attribute *cpu_root_vulnerabilities_attrs[] = {
627632
&dev_attr_meltdown.attr,
@@ -640,6 +645,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = {
640645
&dev_attr_reg_file_data_sampling.attr,
641646
&dev_attr_indirect_target_selection.attr,
642647
&dev_attr_tsa.attr,
648+
&dev_attr_vmscape.attr,
643649
NULL
644650
};
645651

include/linux/cpu.h

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

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

0 commit comments

Comments
 (0)