2022-02-12 00:45:54 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2022-03-08 03:28:32 +08:00
|
|
|
#include <linux/bpf.h>
|
2022-02-12 00:45:54 +08:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
|
|
|
#include <asm/spectre.h>
|
|
|
|
|
2022-03-08 03:28:32 +08:00
|
|
|
static bool _unprivileged_ebpf_enabled(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BPF_SYSCALL
|
|
|
|
return !sysctl_unprivileged_bpf_disabled;
|
|
|
|
#else
|
2022-03-09 03:18:20 +08:00
|
|
|
return false;
|
2022-03-08 03:28:32 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-02-12 00:45:54 +08:00
|
|
|
ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "Mitigation: __user pointer sanitization\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int spectre_v2_state;
|
|
|
|
static unsigned int spectre_v2_methods;
|
|
|
|
|
|
|
|
void spectre_v2_update_state(unsigned int state, unsigned int method)
|
|
|
|
{
|
|
|
|
if (state > spectre_v2_state)
|
|
|
|
spectre_v2_state = state;
|
|
|
|
spectre_v2_methods |= method;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
const char *method;
|
|
|
|
|
|
|
|
if (spectre_v2_state == SPECTRE_UNAFFECTED)
|
|
|
|
return sprintf(buf, "%s\n", "Not affected");
|
|
|
|
|
|
|
|
if (spectre_v2_state != SPECTRE_MITIGATED)
|
|
|
|
return sprintf(buf, "%s\n", "Vulnerable");
|
|
|
|
|
2022-03-08 03:28:32 +08:00
|
|
|
if (_unprivileged_ebpf_enabled())
|
|
|
|
return sprintf(buf, "Vulnerable: Unprivileged eBPF enabled\n");
|
|
|
|
|
2022-02-12 00:45:54 +08:00
|
|
|
switch (spectre_v2_methods) {
|
|
|
|
case SPECTRE_V2_METHOD_BPIALL:
|
|
|
|
method = "Branch predictor hardening";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPECTRE_V2_METHOD_ICIALLU:
|
|
|
|
method = "I-cache invalidation";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPECTRE_V2_METHOD_SMC:
|
|
|
|
case SPECTRE_V2_METHOD_HVC:
|
|
|
|
method = "Firmware call";
|
|
|
|
break;
|
|
|
|
|
2022-02-11 00:05:45 +08:00
|
|
|
case SPECTRE_V2_METHOD_LOOP8:
|
|
|
|
method = "History overwrite";
|
|
|
|
break;
|
|
|
|
|
2022-02-12 00:45:54 +08:00
|
|
|
default:
|
|
|
|
method = "Multiple mitigations";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(buf, "Mitigation: %s\n", method);
|
|
|
|
}
|