sysfs/cpu: Implement generic vulnerabilites directory
Subsystems (4)
v2 cover sysfs/cpu: Implement generic vulnerabilites directory
The meltdown/spectre vulnerabilities affect several architectures and people are asking for a common way to figure out whether a system is affected or not.
Create
/sys/devices/system/cpu/vulnerabilites
and the files
/sys/devices/system/cpu/vulnerabilites/meltdown /sys/devices/system/cpu/vulnerabilites/spectre_v1 /sys/devices/system/cpu/vulnerabilites/spectre_v2
Add the x86 implementation which shows:
meltdown Mitigation: PTI spectre_v1 Vulnerable sepctre_v1 Vulnerable
On an AMD CPU the output of meltdown is: Not affected.
If PTI is turned off and the CPU is affected of meltdown the output
becomes: Vulnerable
That series applies on top of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/pti
V1 -> V2: Add documentation and use sprintf
Thanks,
tglx
PATCH v2 1/2 sysfs/cpu: Add vulnerability folder
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well.
Create /sys/devices/system/cpu/vulnerabilities folder and files for meltdown, spectre_v1 and spectre_v2.
Allow architectures to override the show function.
--- Documentation/ABI/testing/sysfs-devices-system-cpu | 16 +++++++ drivers/base/Kconfig | 3 + drivers/base/cpu.c | 48 +++++++++++++++++++++ include/linux/cpu.h | 7 +++ 4 files changed, 74 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu +16 -0
@@ -373,3 +373,19 @@ Contact: Linux kernel mailing list <linu Description: information about CPUs heterogeneity. cpu_capacity: capacity of cpu#. + +What: /sys/devices/system/cpu/vulnerabilities + /sys/devices/system/cpu/vulnerabilities/meltdown + /sys/devices/system/cpu/vulnerabilities/spectre_v1 + /sys/devices/system/cpu/vulnerabilities/spectre_v2 +Date: Januar 2018 +Contact: Linux kernel mailing list <[email protected]> +Description: Information about CPU vulnerabilities + + The files are named after the code names of CPU + vulnerabilities. The output of those files reflects the + state of the CPUs in the system. Possible output values: + + "Not affected" CPU is not affected by the vulnerability + "Vulnerable" CPU is affected and no mitigation in effect + "Mitigation: $M" CPU is affetcted and mitigation $M is in effect
drivers/base/Kconfig +3 -0
@@ -235,6 +235,9 @@ config GENERIC_CPU_DEVICES config GENERIC_CPU_AUTOPROBE bool +config GENERIC_CPU_VULNERABILITIES + bool + config SOC_BUS bool select GLOB
drivers/base/cpu.c +48 -0
58 lines not on this page · raw message
include/linux/cpu.h +7 -0
@@ -47,6 +47,13 @@ extern void cpu_remove_dev_attr(struct dextern int cpu_add_dev_attr_group (struct attribute_group *attrs);extern void cpu_remove_dev_attr_group (struct attribute_group *attrs); +extern ssize_t cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spectre_v1 (struct device *dev, +struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf); + extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups,
Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
Quoted 21 lines · Thomas Gleixner
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well.
Create
/sys/devices/system/cpu/vulnerabilitiesfolder and files for meltdown,spectre_v1andspectre_v2.Allow architectures to override the show function.
Signed-off-by Thomas Gleixner <[email protected]>--- Documentation/ABI/testing/sysfs-devices-system-cpu | 16 +++++++ drivers/base/Kconfig | 3 + drivers/base/cpu.c | 48 +++++++++++++++++++++ include/linux/cpu.h | 7 +++ 4 files changed, 74 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu Contact: Linux kernel mailing list <linu · line 381
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +6
-0@@ -373,3 +373,19 @@ Contact: Linux kernel mailing list <linu Description: information about CPUs heterogeneity. cpu_capacity: capacity of cpu#. + +What: /sys/devices/system/cpu/vulnerabilities + /sys/devices/system/cpu/vulnerabilities/meltdown + /sys/devices/system/cpu/vulnerabilities/spectre_v1 + /sys/devices/system/cpu/vulnerabilities/spectre_v2 +Date: Januar 2018
s/Januar/January/
and with that
Thank you!
Quoted 73 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +48
-0+#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES + +ssize_t __weak cpu_show_meltdown(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "Not affected\n"); +} + +ssize_t __weak cpu_show_spectre_v1(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "Not affected\n"); +} + +ssize_t __weak cpu_show_spectre_v2(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "Not affected\n"); +} + +static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); +static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); +static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); + +static struct attribute *cpu_root_vulnerabilities_attrs[] = { + &dev_attr_meltdown.attr, + &dev_attr_spectre_v1.attr, + &dev_attr_spectre_v2.attr, + NULL +}; + +static const struct attribute_group cpu_root_vulnerabilities_group = { + .name = "vulnerabilities", + .attrs = cpu_root_vulnerabilities_attrs, +}; + +static void __init cpu_register_vulnerabilities(void) +{ + if (sysfs_create_group(&cpu_subsys.dev_root->kobj, + &cpu_root_vulnerabilities_group)) + pr_err("Unable to register CPU vulnerabilities\n"); +} + +#else +static inline void cpu_register_vulnerabilities(void) { } +#endif + void __init cpu_dev_init(void) { if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups)) panic("Failed to register CPU subsystem"); cpu_dev_register_generic(); + cpu_register_vulnerabilities(); }include/linux/cpu.h +7
-0@@ -47,6 +47,13 @@ extern void cpu_remove_dev_attr(struct dextern int cpu_add_dev_attr_group (struct attribute_group *attrs);extern void cpu_remove_dev_attr_group (struct attribute_group *attrs); +extern ssize_t cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spectre_v1 (struct device *dev, +struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf); + extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups,
Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
In reply to Thomas GleixnerQuoted 11 lines · Thomas Gleixner
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well.
Create
/sys/devices/system/cpu/vulnerabilitiesfolder and files for meltdown,spectre_v1andspectre_v2.Allow architectures to override the show function.
Signed-off-by Thomas Gleixner <[email protected]>
Thanks for the documentation update, looks good to me:
Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
In reply to Thomas GleixnerQuoted 26 lines · Thomas Gleixner
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well.
Create
/sys/devices/system/cpu/vulnerabilitiesfolder and files for meltdown,spectre_v1andspectre_v2.Allow architectures to override the show function.
Signed-off-by Thomas Gleixner <[email protected]>--- Documentation/ABI/testing/sysfs-devices-system-cpu | 16 +++++++ drivers/base/Kconfig | 3 + drivers/base/cpu.c | 48 +++++++++++++++++++++ include/linux/cpu.h | 7 +++ 4 files changed, 74 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +2
-0@@ -373,3 +373,19 @@ Contact: Linux kernel mailing list <linu Description: information about CPUs heterogeneity. cpu_capacity: capacity of cpu#. + +What: /sys/devices/system/cpu/vulnerabilities
Documentation/ABI/testing/sysfs-devices-system-cpu Contact: Linux kernel mailing list <linu · line 387
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +10
-0+ /sys/devices/system/cpu/vulnerabilities/meltdown + /sys/devices/system/cpu/vulnerabilities/spectre_v1 + /sys/devices/system/cpu/vulnerabilities/spectre_v2 +Date: Januar 2018 +Contact: Linux kernel mailing list <[email protected]> +Description: Information about CPU vulnerabilities + + The files are named after the code names of CPU + vulnerabilities. The output of those files reflects the + state of the CPUs in the system.
Currently, your code sets X86_BUG_SPECTRE_V[12] unconditionally on x86 CPUs. However, to my understanding some CPUs which do not execute code out-of-order aren't affected. As it is better to err on the safe side for now, what about adding a disclaimer at the end of this sentence, such as:
", but may contain false positives"
Thanks,
Dominik
Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
Quoted 43 lines · Dominik Brodowski
Quoted 26 lines · Thomas Gleixner
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well.
Create
/sys/devices/system/cpu/vulnerabilitiesfolder and files for meltdown,spectre_v1andspectre_v2.Allow architectures to override the show function.
Signed-off-by Thomas Gleixner <[email protected]>--- Documentation/ABI/testing/sysfs-devices-system-cpu | 16 +++++++ drivers/base/Kconfig | 3 + drivers/base/cpu.c | 48 +++++++++++++++++++++ include/linux/cpu.h | 7 +++ 4 files changed, 74 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +2
-0@@ -373,3 +373,19 @@ Contact: Linux kernel mailing list <linu Description: information about CPUs heterogeneity. cpu_capacity: capacity of cpu#. + +What: /sys/devices/system/cpu/vulnerabilitiesDocumentation/ABI/testing/sysfs-devices-system-cpu Contact: Linux kernel mailing list <linu · line 387
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +10
-0+ /sys/devices/system/cpu/vulnerabilities/meltdown + /sys/devices/system/cpu/vulnerabilities/spectre_v1 + /sys/devices/system/cpu/vulnerabilities/spectre_v2 +Date: Januar 2018 +Contact: Linux kernel mailing list <[email protected]> +Description: Information about CPU vulnerabilities + + The files are named after the code names of CPU + vulnerabilities. The output of those files reflects the + state of the CPUs in the system.Currently, your code sets X86_BUG_SPECTRE_V[12] unconditionally on x86 CPUs. However, to my understanding some CPUs which do not execute code out-of-order aren't affected. As it is better to err on the safe side for now, what about adding a disclaimer at the end of this sentence, such as:
Quoted 1 line
", but may contain false positives"
We do that in the same way as we did with BUG_INSECURE (now MELTDOWN). Err out on the safe side and get the exceptions in place when people are confident about them. It's not going to take long I assume.
Thanks,
tglx
tip-bot for Thomas Gleixner
merge bot[tip:x86/pti] sysfs/cpu: Add vulnerability folder
In reply to Thomas Gleixnersysfs/cpu: Add vulnerability folder
Commit-ID: 87590ce6e373d1a5401f6539f0c59ef92dd924a9 Gitweb: https://git.kernel.org/tip/87590ce6e373d1a5401f6539f0c59ef92dd924a9 Author: Thomas Gleixner <[email protected]> AuthorDate: Sun, 7 Jan 2018 22:48:00 +0100 Committer: Thomas Gleixner <[email protected]> CommitDate: Mon, 8 Jan 2018 11:10:33 +0100
sysfs/cpu: Add vulnerability folder
As the meltdown/spectre problem affects several CPU architectures, it makes sense to have common way to express whether a system is affected by a particular vulnerability or not. If affected the way to express the mitigation should be common as well.
Create /sys/devices/system/cpu/vulnerabilities folder and files for meltdown, spectre_v1 and spectre_v2.
Allow architectures to override the show function.
--- Documentation/ABI/testing/sysfs-devices-system-cpu | 16 ++++++++ drivers/base/Kconfig | 3 ++ drivers/base/cpu.c | 48 ++++++++++++++++++++++ include/linux/cpu.h | 7 ++++ 4 files changed, 74 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu +16 -0
@@ -373,3 +373,19 @@ Contact: Linux kernel mailing list <[email protected]> Description: information about CPUs heterogeneity. cpu_capacity: capacity of cpu#. + +What: /sys/devices/system/cpu/vulnerabilities + /sys/devices/system/cpu/vulnerabilities/meltdown + /sys/devices/system/cpu/vulnerabilities/spectre_v1 + /sys/devices/system/cpu/vulnerabilities/spectre_v2 +Date: Januar 2018 +Contact: Linux kernel mailing list <[email protected]> +Description: Information about CPU vulnerabilities + + The files are named after the code names of CPU + vulnerabilities. The output of those files reflects the + state of the CPUs in the system. Possible output values: + + "Not affected" CPU is not affected by the vulnerability + "Vulnerable" CPU is affected and no mitigation in effect + "Mitigation: $M" CPU is affetcted and mitigation $M is in effect
drivers/base/Kconfig +3 -0
@@ -235,6 +235,9 @@ config GENERIC_CPU_DEVICES config GENERIC_CPU_AUTOPROBE bool +config GENERIC_CPU_VULNERABILITIES + bool + config SOC_BUS bool select GLOB
drivers/base/cpu.c +48 -0
58 lines not on this page · raw message
include/linux/cpu.h +7 -0
@@ -47,6 +47,13 @@ extern void cpu_remove_dev_attr(struct device_attribute *attr);extern int cpu_add_dev_attr_group (struct attribute_group *attrs);extern void cpu_remove_dev_attr_group (struct attribute_group *attrs); +extern ssize_t cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spectre_v1 (struct device *dev, +struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf); + extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups,
Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
In reply to Thomas GleixnerHello,
Review
Quoted 3 lines · Thomas Gleixner
(quoted diff) +3
-0+static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); +static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); +static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
This sysfs feature implemented as above is weakening kernel security, it should be 0400 above.
It doesn't make sense to expose to luser when a software fix (or even only a software mitigation) has been disabled at build time to gain all performance back (see CONFIG_RETPOLINE=n config option).
$ cat /boot/kernel-`uname -r` cat: /boot/kernel-4.15.0-rc9+: Permission denied $ cat /lib/modules/`uname -r`/kernel/arch/x86/kvm/kvm.ko cat: /lib/modules/4.15.0-rc9+/kernel/arch/x86/kvm/kvm.ko: Permission denied $ dmesg dmesg: read kernel buffer failed: Operation not permitted
Noticing when cr3 is flipped in kernel/exit is easy, but noticing when the syscall table or the whole kernel has been built with retpolines is not trivial to detect. Same for variant#1.
Exploiting spectre variant#2 for an attacker is not without risk of being detected while the setup is being mounted, as the CPU load would spike for hours.
I may notice if a random background network daemon suddenly starts running at 100% CPU load for hours (especially on mobile devices that would be physically noticeable).
Containers shouldn't have sysfs and you can workaround the above if you run all network daemons behind mount namespaces, but in general leaving this directory readable by luser is weaking security because it exposes when mounting a variant#2 attack can succeed.
It even tells when it is worth to focus on the syscall_table indirect call or if the attack needs to dig deeper because asm retpolines were used, but the kernel was built with a gcc without retpolines.
The only case where the above isn't weakening security is when the full fix is on for all the variants is enabled (and variant#1 for now just shows vulnerable..).
For the same reasons the whole directory, not just the files, should be 0500, especially if this would be used for any other equivalent issue in the future and it won't stick to these 3 files, I didn't implement that yet, because it's less urgent if nobody adds any more files soon.
Quoted 1 line
From
578b411c8dcb1435dd1f94a6cd062f4eedb70fb5Mon Sep 17 00:00:00 2001
From: Andrea Arcangeli <[email protected]>
Date: Wed, 24 Jan 2018 19:19:36 +0100
Subject: [PATCH 1/1] x86/spectre/meltdown: avoid the vulnerability directory
to weaken kernel security
If any of the fixes is disabled to gain some performance back at runtime or build time, should not be exposed to unprivileged userland.
--- drivers/base/cpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/base/cpu.c +3 -3
@@ -531,9 +531,9 @@ ssize_t __weak cpu_show_spectre_v2(struct device *dev,return sprintf (buf,"Not affected\n" ); } -static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); -static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); -static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); +static DEVICE_ATTR(meltdown, 0400, cpu_show_meltdown, NULL); +static DEVICE_ATTR(spectre_v1, 0400, cpu_show_spectre_v1, NULL); +static DEVICE_ATTR(spectre_v2, 0400, cpu_show_spectre_v2, NULL);static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr,
Greg Kroah-Hartman
maintainerRe: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
Quoted 9 lines · Andrea Arcangeli
Hello,
Review
Quoted 3 lines · Thomas Gleixner
(quoted diff) +3
-0+static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); +static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); +static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);This sysfs feature implemented as above is weakening kernel security, it should be 0400 above.
See the patch from Jason A. Donenfeld <[email protected]> to do just that:
Subject: [PATCH] cpu: do not leak vulnerabilities to unprivileged users Message-Id: <[email protected]>
I'll be queueing it up for 4.16-rc1 and backport it everywhere.
thanks,
greg k-h
Re: [patch V2 1/2] sysfs/cpu: Add vulnerability folder
In reply to Thomas GleixnerQuoted 9 lines · Thomas Gleixner
drivers/base/cpu.c +9
-0+#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES + +ssize_t __weak cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"Not affected\n" ); +} + +ssize_t __weak cpu_show_spectre_v1(struct device *dev,
drivers/base/cpu.c static void __init cpu_dev_register_gene · line 522
Quoted 10 lines
drivers/base/cpu.c +10
-0+ struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "Not affected\n"); +} + +ssize_t __weak cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"Not affected\n" ); +}
Just wondering aloud (after the merge) here but shouldn't the default be "unknown", at least for Spectre? It's pervasive enough.
Jon.
PATCH v2 2/2 x86/cpu: Implement CPU vulnerabilites sysfs functions
In reply to Thomas GleixnerImplement the CPU vulnerabilty show functions for meltdown, spectre_v1 and spectre_v2.
--- arch/x86/Kconfig | 1 + arch/x86/kernel/cpu/bugs.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
arch/x86/Kconfig +1 -0
@@ -89,6 +89,7 @@ config X86 select GENERIC_CLOCKEVENTS_MIN_ADJUST select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_FIND_FIRST_BIT select GENERIC_IOMAP
arch/x86/kernel/cpu/bugs.c +29 -0
@@ -10,6 +10,7 @@*/ #include <linux/init.h> #include <linux/utsname.h> +#include <linux/cpu.h> #include <asm/bugs.h> #include <asm/processor.h> #include <asm/processor-flags.h>
@@ -60,3 +61,31 @@ void __init check_bugs(void)set_memory_4k ((unsigned long )__va (0 ),1 );#endif } + +#ifdef CONFIG_SYSFS +ssize_t cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_CPU_MELTDOWN )) +return sprintf (buf,"Not affected\n" ); +if (boot_cpu_has (X86_FEATURE_PTI )) +return sprintf (buf,"Mitigation: PTI\n" ); +return sprintf (buf,"Vulnerable\n" ); +} + +ssize_t cpu_show_spectre_v1 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V1 )) +return sprintf (buf,"Not affected\n" ); +return sprintf (buf,"Vulnerable\n" ); +} + +ssize_t cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V2 )) +return sprintf (buf,"Not affected\n" ); +return sprintf (buf,"Vulnerable\n" ); +} +#endif
Re: [patch V2 2/2] x86/cpu: Implement CPU vulnerabilites sysfs functions
Quoted 4 lines · Thomas Gleixner
Implement the CPU vulnerabilty show functions for meltdown,
spectre_v1andspectre_v2.Signed-off-by Thomas Gleixner <[email protected]>
Thank you!
Quoted 59 lines
--- arch/x86/Kconfig | 1 + arch/x86/kernel/cpu/bugs.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)arch/x86/Kconfig +1
-0@@ -89,6 +89,7 @@ config X86 select GENERIC_CLOCKEVENTS_MIN_ADJUST select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_FIND_FIRST_BIT select GENERIC_IOMAParch/x86/kernel/cpu/bugs.c +29
-0@@ -10,6 +10,7 @@*/ #include <linux/init.h> #include <linux/utsname.h> +#include <linux/cpu.h> #include <asm/bugs.h> #include <asm/processor.h> #include <asm/processor-flags.h> @@ -60,3 +61,31 @@ void __init check_bugs(void)set_memory_4k ((unsigned long )__va (0 ),1 );#endif } + +#ifdef CONFIG_SYSFS +ssize_t cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_CPU_MELTDOWN )) +return sprintf (buf,"Not affected\n" ); +if (boot_cpu_has (X86_FEATURE_PTI )) +return sprintf (buf,"Mitigation: PTI\n" ); +return sprintf (buf,"Vulnerable\n" ); +} + +ssize_t cpu_show_spectre_v1 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V1 )) +return sprintf (buf,"Not affected\n" ); +return sprintf (buf,"Vulnerable\n" ); +} + +ssize_t cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V2 )) +return sprintf (buf,"Not affected\n" ); +return sprintf (buf,"Vulnerable\n" ); +} +#endif
Re: [patch V2 2/2] x86/cpu: Implement CPU vulnerabilites sysfs functions
In reply to Thomas GleixnerQuoted 8 lines · Thomas Gleixner
Implement the CPU vulnerabilty show functions for meltdown,
spectre_v1andspectre_v2.Signed-off-by Thomas Gleixner <[email protected]>--- arch/x86/Kconfig | 1 + arch/x86/kernel/cpu/bugs.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
tip-bot for Thomas Gleixner
merge bot[tip:x86/pti] x86/cpu: Implement CPU vulnerabilites sysfs functions
In reply to Thomas Gleixnerx86/cpu: Implement CPU vulnerabilites sysfs functions
Commit-ID: 61dc0f555b5c761cdafb0ba5bd41ecf22d68a4c4 Gitweb: https://git.kernel.org/tip/61dc0f555b5c761cdafb0ba5bd41ecf22d68a4c4 Author: Thomas Gleixner <[email protected]> AuthorDate: Sun, 7 Jan 2018 22:48:01 +0100 Committer: Thomas Gleixner <[email protected]> CommitDate: Mon, 8 Jan 2018 11:10:40 +0100
x86/cpu: Implement CPU vulnerabilites sysfs functions
Implement the CPU vulnerabilty show functions for meltdown, spectre_v1 and spectre_v2.
--- arch/x86/Kconfig | 1 + arch/x86/kernel/cpu/bugs.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
arch/x86/Kconfig +1 -0
@@ -89,6 +89,7 @@ config X86 select GENERIC_CLOCKEVENTS_MIN_ADJUST select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_FIND_FIRST_BIT select GENERIC_IOMAP
arch/x86/kernel/cpu/bugs.c +29 -0
@@ -10,6 +10,7 @@*/ #include <linux/init.h> #include <linux/utsname.h> +#include <linux/cpu.h> #include <asm/bugs.h> #include <asm/processor.h> #include <asm/processor-flags.h>
@@ -60,3 +61,31 @@ void __init check_bugs(void)set_memory_4k ((unsigned long )__va (0 ),1 );#endif } + +#ifdef CONFIG_SYSFS +ssize_t cpu_show_meltdown (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_CPU_MELTDOWN )) +return sprintf (buf,"Not affected\n" ); +if (boot_cpu_has (X86_FEATURE_PTI )) +return sprintf (buf,"Mitigation: PTI\n" ); +return sprintf (buf,"Vulnerable\n" ); +} + +ssize_t cpu_show_spectre_v1 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V1 )) +return sprintf (buf,"Not affected\n" ); +return sprintf (buf,"Vulnerable\n" ); +} + +ssize_t cpu_show_spectre_v2 (struct device *dev, +struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V2 )) +return sprintf (buf,"Not affected\n" ); +return sprintf (buf,"Vulnerable\n" ); +} +#endif