Skip to content

Commit 893387c

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 1500628 commit 893387c

6 files changed

Lines changed: 106 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
@@ -3297,6 +3297,7 @@
32973297
srbds=off [X86,INTEL]
32983298
ssbd=force-off [ARM64]
32993299
tsx_async_abort=off [X86]
3300+
vmscape=off [X86]
33003301

33013302
Exceptions:
33023303
This does not have any effect on
@@ -6813,6 +6814,16 @@
68136814
vmpoff= [KNL,S390] Perform z/VM CP command after power off.
68146815
Format: <command>
68156816

6817+
vmscape= [X86] Controls mitigation for VMscape attacks.
6818+
VMscape attacks can leak information from a userspace
6819+
hypervisor to a guest via speculative side-channels.
6820+
6821+
off - disable the mitigation
6822+
ibpb - use Indirect Branch Prediction Barrier
6823+
(IBPB) mitigation (default)
6824+
force - force vulnerability detection even on
6825+
unaffected processors
6826+
68166827
vsyscall= [X86-64]
68176828
Controls the behavior of vsyscalls (i.e. calls to
68186829
fixed addresses of 0xffffffffff600x00 from legacy

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,15 @@ config MITIGATION_TSA
25952595
security vulnerability on AMD CPUs which can lead to forwarding of
25962596
invalid info to subsequent instructions and thus can affect their
25972597
timing and thereby cause a leakage.
2598+
2599+
config MITIGATION_VMSCAPE
2600+
bool "Mitigate VMSCAPE"
2601+
depends on KVM
2602+
default y
2603+
help
2604+
Enable mitigation for VMSCAPE attacks. VMSCAPE is a hardware security
2605+
vulnerability on Intel and AMD CPUs that may allow a guest to do
2606+
Spectre v2 style attacks on userspace hypervisor.
25982607
endif
25992608

26002609
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ ssize_t __weak cpu_show_tsa(struct device *dev, struct device_attribute *attr, c
606606
return sysfs_emit(buf, "Not affected\n");
607607
}
608608

609+
ssize_t __weak cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char *buf)
610+
{
611+
return sysfs_emit(buf, "Not affected\n");
612+
}
613+
609614
static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
610615
static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
611616
static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
@@ -622,6 +627,7 @@ static DEVICE_ATTR(spec_rstack_overflow, 0444, cpu_show_spec_rstack_overflow, NU
622627
static DEVICE_ATTR(reg_file_data_sampling, 0444, cpu_show_reg_file_data_sampling, NULL);
623628
static DEVICE_ATTR(indirect_target_selection, 0444, cpu_show_indirect_target_selection, NULL);
624629
static DEVICE_ATTR(tsa, 0444, cpu_show_tsa, NULL);
630+
static DEVICE_ATTR(vmscape, 0444, cpu_show_vmscape, NULL);
625631

626632
static struct attribute *cpu_root_vulnerabilities_attrs[] = {
627633
&dev_attr_meltdown.attr,
@@ -640,6 +646,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = {
640646
&dev_attr_reg_file_data_sampling.attr,
641647
&dev_attr_indirect_target_selection.attr,
642648
&dev_attr_tsa.attr,
649+
&dev_attr_vmscape.attr,
643650
NULL
644651
};
645652

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)