diff options
Diffstat (limited to 'arch/powerpc/kernel/security.c')
-rw-r--r-- | arch/powerpc/kernel/security.c | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c index d96fd14bd7c9..b34de62e65ce 100644 --- a/arch/powerpc/kernel/security.c +++ b/arch/powerpc/kernel/security.c @@ -10,7 +10,7 @@ #include <linux/memblock.h> #include <linux/nospec.h> #include <linux/prctl.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <linux/debugfs.h> #include <asm/asm-prototypes.h> @@ -144,31 +144,28 @@ void __init setup_spectre_v2(void) #ifdef CONFIG_PPC_BOOK3S_64 ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) { + struct printbuf s = PRINTBUF_EXTERN(buf, PAGE_SIZE); bool thread_priv; thread_priv = security_ftr_enabled(SEC_FTR_L1D_THREAD_PRIV); if (rfi_flush) { - struct seq_buf s; - seq_buf_init(&s, buf, PAGE_SIZE - 1); - seq_buf_printf(&s, "Mitigation: RFI Flush"); + prt_printf(&s, "Mitigation: RFI Flush"); if (thread_priv) - seq_buf_printf(&s, ", L1D private per thread"); - - seq_buf_printf(&s, "\n"); - - return s.len; + prt_printf(&s, ", L1D private per thread"); + + prt_printf(&s, "\n"); + } else if (thread_priv) { + prt_printf(&s, "Vulnerable: L1D private per thread\n"); + } else if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) && + !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR)) { + prt_printf(&s, "Not affected\n"); + } else { + prt_printf(&s, "Vulnerable\n"); } - if (thread_priv) - return sprintf(buf, "Vulnerable: L1D private per thread\n"); - - if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) && - !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR)) - return sprintf(buf, "Not affected\n"); - - return sprintf(buf, "Vulnerable\n"); + return printbuf_written(&s); } ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *buf) @@ -179,70 +176,66 @@ ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *b ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) { - struct seq_buf s; - - seq_buf_init(&s, buf, PAGE_SIZE - 1); + struct printbuf s = PRINTBUF_EXTERN(buf, PAGE_SIZE); if (security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR)) { if (barrier_nospec_enabled) - seq_buf_printf(&s, "Mitigation: __user pointer sanitization"); + prt_printf(&s, "Mitigation: __user pointer sanitization"); else - seq_buf_printf(&s, "Vulnerable"); + prt_printf(&s, "Vulnerable"); if (security_ftr_enabled(SEC_FTR_SPEC_BAR_ORI31)) - seq_buf_printf(&s, ", ori31 speculation barrier enabled"); + prt_printf(&s, ", ori31 speculation barrier enabled"); - seq_buf_printf(&s, "\n"); + prt_printf(&s, "\n"); } else - seq_buf_printf(&s, "Not affected\n"); + prt_printf(&s, "Not affected\n"); - return s.len; + return printbuf_written(&s); } ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) { - struct seq_buf s; + struct printbuf s = PRINTBUF_EXTERN(buf, PAGE_SIZE); bool bcs, ccd; - seq_buf_init(&s, buf, PAGE_SIZE - 1); - bcs = security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED); ccd = security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED); if (bcs || ccd) { - seq_buf_printf(&s, "Mitigation: "); + prt_printf(&s, "Mitigation: "); if (bcs) - seq_buf_printf(&s, "Indirect branch serialisation (kernel only)"); + prt_printf(&s, "Indirect branch serialisation (kernel only)"); if (bcs && ccd) - seq_buf_printf(&s, ", "); + prt_printf(&s, ", "); if (ccd) - seq_buf_printf(&s, "Indirect branch cache disabled"); + prt_printf(&s, "Indirect branch cache disabled"); } else if (count_cache_flush_type != BRANCH_CACHE_FLUSH_NONE) { - seq_buf_printf(&s, "Mitigation: Software count cache flush"); + prt_printf(&s, "Mitigation: Software count cache flush"); if (count_cache_flush_type == BRANCH_CACHE_FLUSH_HW) - seq_buf_printf(&s, " (hardware accelerated)"); + prt_printf(&s, " (hardware accelerated)"); } else if (btb_flush_enabled) { - seq_buf_printf(&s, "Mitigation: Branch predictor state flush"); + prt_printf(&s, "Mitigation: Branch predictor state flush"); } else { - seq_buf_printf(&s, "Vulnerable"); + prt_printf(&s, "Vulnerable"); } if (bcs || ccd || count_cache_flush_type != BRANCH_CACHE_FLUSH_NONE) { if (link_stack_flush_type != BRANCH_CACHE_FLUSH_NONE) - seq_buf_printf(&s, ", Software link stack flush"); + prt_printf(&s, ", Software link stack flush"); if (link_stack_flush_type == BRANCH_CACHE_FLUSH_HW) - seq_buf_printf(&s, " (hardware accelerated)"); + prt_printf(&s, " (hardware accelerated)"); } - seq_buf_printf(&s, "\n"); + prt_printf(&s, "\n"); - return s.len; + return printbuf_written(&s); } #ifdef CONFIG_PPC_BOOK3S_64 |