]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
powerpc/pseries: Set or clear security feature flags
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 27 Mar 2018 12:01:46 +0000 (23:01 +1100)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 15 May 2018 05:35:35 +0000 (07:35 +0200)
Now that we have feature flags for security related things, set or
clear them based on what we receive from the hypercall.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
[backport: hunk 2: make pseries_setup_rfi_flush() static]
Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
CVE-2018-3639 (powerpc)

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/powerpc/platforms/pseries/setup.c

index fb575a554dfde79aaffe21d4e4a674bf09779336..1b7c3a233a6c489731e6435d044d295d128387a7 100644 (file)
@@ -67,6 +67,7 @@
 #include <asm/plpar_wrappers.h>
 #include <asm/kexec.h>
 #include <asm/isa-bridge.h>
+#include <asm/security_features.h>
 
 #include "pseries.h"
 
@@ -455,6 +456,40 @@ static void __init find_and_init_phbs(void)
        of_pci_check_probe_only();
 }
 
+static void init_cpu_char_feature_flags(struct h_cpu_char_result *result)
+{
+       if (result->character & H_CPU_CHAR_SPEC_BAR_ORI31)
+               security_ftr_set(SEC_FTR_SPEC_BAR_ORI31);
+
+       if (result->character & H_CPU_CHAR_BCCTRL_SERIALISED)
+               security_ftr_set(SEC_FTR_BCCTRL_SERIALISED);
+
+       if (result->character & H_CPU_CHAR_L1D_FLUSH_ORI30)
+               security_ftr_set(SEC_FTR_L1D_FLUSH_ORI30);
+
+       if (result->character & H_CPU_CHAR_L1D_FLUSH_TRIG2)
+               security_ftr_set(SEC_FTR_L1D_FLUSH_TRIG2);
+
+       if (result->character & H_CPU_CHAR_L1D_THREAD_PRIV)
+               security_ftr_set(SEC_FTR_L1D_THREAD_PRIV);
+
+       if (result->character & H_CPU_CHAR_COUNT_CACHE_DISABLED)
+               security_ftr_set(SEC_FTR_COUNT_CACHE_DISABLED);
+
+       /*
+        * The features below are enabled by default, so we instead look to see
+        * if firmware has *disabled* them, and clear them if so.
+        */
+       if (!(result->character & H_CPU_BEHAV_FAVOUR_SECURITY))
+               security_ftr_clear(SEC_FTR_FAVOUR_SECURITY);
+
+       if (!(result->character & H_CPU_BEHAV_L1D_FLUSH_PR))
+               security_ftr_clear(SEC_FTR_L1D_FLUSH_PR);
+
+       if (!(result->character & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR))
+               security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR);
+}
+
 static void pseries_setup_rfi_flush(void)
 {
        struct h_cpu_char_result result;
@@ -468,6 +503,8 @@ static void pseries_setup_rfi_flush(void)
 
        rc = plpar_get_cpu_characteristics(&result);
        if (rc == H_SUCCESS) {
+               init_cpu_char_feature_flags(&result);
+
                if (result.character & H_CPU_CHAR_L1D_FLUSH_TRIG2)
                        types |= L1D_FLUSH_MTTRIG;
                if (result.character & H_CPU_CHAR_L1D_FLUSH_ORI30)
@@ -478,6 +515,12 @@ static void pseries_setup_rfi_flush(void)
                        enable = false;
        }
 
+       /*
+        * We're the guest so this doesn't apply to us, clear it to simplify
+        * handling of it elsewhere.
+        */
+       security_ftr_clear(SEC_FTR_L1D_FLUSH_HV);
+
        setup_rfi_flush(types, enable);
 }