powerpc/security mitigation updates
Nicholas Piggin
reviewercover powerpc/security mitigation updates
This series adds a few missing bits added to recent pseries H_GET_CPU_CHARACTERISTICS and implements them, also removes a restriction from powernv for some of the flushes.
This is tested mianly in qemu where I just submitted a patch that adds support for these bits (not upstream yet).
Nicholas Piggin (4):
powerpc/pseries: Get entry and uaccess flush required bits from
H_GET_CPU_CHARACTERISTICS
powerpc/security: Add a security feature for STF barrier powerpc/pesries: Get STF barrier requirement from
H_GET_CPU_CHARACTERISTICS
powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess
flushes
arch/powerpc/include/asm/hvcall.h | 3 +++ arch/powerpc/include/asm/security_features.h | 4 ++++ arch/powerpc/kernel/security.c | 7 ++----- arch/powerpc/platforms/powernv/setup.c | 9 --------- arch/powerpc/platforms/pseries/setup.c | 9 +++++++++ 5 files changed, 18 insertions(+), 14 deletions(-)
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH 1/4 powerpc/pseries: Get entry and uaccess flush required bits from H_GET_CPU_CHARACTERISTICS
This allows the hypervisor / firmware to describe these workarounds to the guest.
--- arch/powerpc/include/asm/hvcall.h | 2 ++ arch/powerpc/platforms/pseries/setup.c | 6 ++++++ 2 files changed, 8 insertions(+)
arch/powerpc/include/asm/hvcall.h +2 -0
@@ -393,6 +393,8 @@#define H_CPU_BEHAV_FAVOUR_SECURITY_H (1ull << 60) // IBM bit 3#define H_CPU_BEHAV_FLUSH_COUNT_CACHE (1ull << 58) // IBM bit 5#define H_CPU_BEHAV_FLUSH_LINK_STACK (1ull << 57) // IBM bit 6 +#define H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY (1ull << 56) // IBM bit 7 +#define H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS (1ull << 55) // IBM bit 8/* Flag values used in H_REGISTER_PROC_TBL hcall */ #define PROC_TABLE_OP_MASK 0x18
arch/powerpc/platforms/pseries/setup.c +6 -0
@@ -549,6 +549,12 @@ static void init_cpu_char_feature_flags(struct h_cpu_char_result *result)if (!(result->behaviour &H_CPU_BEHAV_L1D_FLUSH_PR ))security_ftr_clear (SEC_FTR_L1D_FLUSH_PR ); +if (result->behaviour &H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY ) +security_ftr_clear (SEC_FTR_L1D_FLUSH_ENTRY ); + +if (result->behaviour &H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS ) +security_ftr_clear (SEC_FTR_L1D_FLUSH_UACCESS ); +if (!(result->behaviour &H_CPU_BEHAV_BNDS_CHK_SPEC_BAR ))security_ftr_clear (SEC_FTR_BNDS_CHK_SPEC_BAR ); }
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH 2/4 powerpc/security: Add a security feature for STF barrier
In reply to Nicholas PigginRather than tying this mitigation to RFI L1D flush requirement, add a new bit for it.
--- arch/powerpc/include/asm/security_features.h | 4 ++++ arch/powerpc/kernel/security.c | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/security_features.h +4 -0
@@ -92,6 +92,9 @@ static inline bool security_ftr_enabled(u64 feature)// The L1-D cache should be flushed after user accesses from the kernel #define SEC_FTR_L1D_FLUSH_UACCESS 0x0000000000008000ull +// The STF flush should be executed on privilege state switch +#define SEC_FTR_STF_BARRIER 0x0000000000010000ull +// Features enabled by default #define SEC_FTR_DEFAULT \ (SEC_FTR_L1D_FLUSH_HV | \
@@ -99,6 +102,7 @@ static inline bool security_ftr_enabled(u64 feature) SEC_FTR_BNDS_CHK_SPEC_BAR | \ SEC_FTR_L1D_FLUSH_ENTRY | \ SEC_FTR_L1D_FLUSH_UACCESS | \ + SEC_FTR_STF_BARRIER | \ SEC_FTR_FAVOUR_SECURITY)#endif /* _ASM_POWERPC_SECURITY_FEATURES_H */
arch/powerpc/kernel/security.c +2 -5
@@ -300,9 +300,7 @@ static void stf_barrier_enable(bool enable)void setup_stf_barrier (void ) {enum stf_barrier_type type; -bool enable, hv; - - hv =cpu_has_feature (CPU_FTR_HVMODE ); +bool enable;/* Default to fallback in case fw-features are not available */ if (cpu_has_feature (CPU_FTR_ARCH_300 ))
@@ -315,8 +313,7 @@ void setup_stf_barrier(void) type =STF_BARRIER_NONE ; enable =security_ftr_enabled (SEC_FTR_FAVOUR_SECURITY ) && - (security_ftr_enabled (SEC_FTR_L1D_FLUSH_PR ) || - (security_ftr_enabled (SEC_FTR_L1D_FLUSH_HV ) && hv)); +security_ftr_enabled (SEC_FTR_STF_BARRIER );if (type ==STF_BARRIER_FALLBACK ) {pr_info ("stf-barrier: fallback barrier available\n" );
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH 3/4 powerpc/pesries: Get STF barrier requirement from H_GET_CPU_CHARACTERISTICS
In reply to Nicholas PigginThis allows the hypervisor / firmware to describe this workarounds to the guest.
--- arch/powerpc/include/asm/hvcall.h | 1 + arch/powerpc/platforms/pseries/setup.c | 3 +++ 2 files changed, 4 insertions(+)
arch/powerpc/include/asm/hvcall.h +1 -0
@@ -395,6 +395,7 @@#define H_CPU_BEHAV_FLUSH_LINK_STACK (1ull << 57) // IBM bit 6#define H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY (1ull << 56) // IBM bit 7#define H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS (1ull << 55) // IBM bit 8 +#define H_CPU_BEHAV_NO_STF_BARRIER (1ull << 54) // IBM bit 9/* Flag values used in H_REGISTER_PROC_TBL hcall */ #define PROC_TABLE_OP_MASK 0x18
arch/powerpc/platforms/pseries/setup.c +3 -0
@@ -555,6 +555,9 @@ static void init_cpu_char_feature_flags(struct h_cpu_char_result *result)if (result->behaviour &H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS )security_ftr_clear (SEC_FTR_L1D_FLUSH_UACCESS ); +if (result->behaviour &H_CPU_BEHAV_NO_STF_BARRIER ) +security_ftr_clear (SEC_FTR_STF_BARRIER ); +if (!(result->behaviour &H_CPU_BEHAV_BNDS_CHK_SPEC_BAR ))security_ftr_clear (SEC_FTR_BNDS_CHK_SPEC_BAR ); }
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH 4/4 powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess flushes
In reply to Nicholas PigginThese aren't necessarily POWER9 only, and it's not to say some new vulnerability may not get discovered on other processors for which we would like the flexibility of having the workaround enabled by firmware.
Remove the restriction that they only apply to POWER9.
--- arch/powerpc/platforms/powernv/setup.c | 9 --------- 1 file changed, 9 deletions(-)
arch/powerpc/platforms/powernv/setup.c +0 -9
@@ -122,15 +122,6 @@ static void pnv_setup_security_mitigations(void) type =L1D_FLUSH_ORI ; } -/* -* If we are non-Power9 bare metal, we don't need to flush on kernel -* entry or after user access: they fix a P9 specific vulnerability. -*/ -if (!pvr_version_is (PVR_POWER9 )) { -security_ftr_clear (SEC_FTR_L1D_FLUSH_ENTRY ); -security_ftr_clear (SEC_FTR_L1D_FLUSH_UACCESS ); - } - enable =security_ftr_enabled (SEC_FTR_FAVOUR_SECURITY ) && \ (security_ftr_enabled (SEC_FTR_L1D_FLUSH_PR ) || \security_ftr_enabled (SEC_FTR_L1D_FLUSH_HV ));
Signature · 1 line
2.23.0
Re: [PATCH 4/4] powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess flushes
Quoted 7 lines · Nicholas Piggin
These aren't necessarily POWER9 only, and it's not to say some new vulnerability may not get discovered on other processors for which we would like the flexibility of having the workaround enabled by firmware.
Remove the restriction that they only apply to POWER9.
I was wondering how these worked which led me to reviewing your patch. From what I could see, these are enabled by default (SEC_FTR_DEFAULT in arch/powerpc/include/asm/security_features.h), so unless all non-POWER9 machines have set the "please don't" bit in their firmware this patch will enable the feature for those machines. Is that what you wanted?
Quoted 29 lines
Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/platforms/powernv/setup.c | 9 --------- 1 file changed, 9 deletions(-)arch/powerpc/platforms/powernv/setup.c +0
-10@@ -122,15 +122,6 @@ static void pnv_setup_security_mitigations(void) type =L1D_FLUSH_ORI ; } -/* -* If we are non-Power9 bare metal, we don't need to flush on kernel -* entry or after user access: they fix a P9 specific vulnerability. -*/ -if (!pvr_version_is (PVR_POWER9 )) { -security_ftr_clear (SEC_FTR_L1D_FLUSH_ENTRY ); -security_ftr_clear (SEC_FTR_L1D_FLUSH_UACCESS ); - } - enable =security_ftr_enabled (SEC_FTR_FAVOUR_SECURITY ) && \ (security_ftr_enabled (SEC_FTR_L1D_FLUSH_PR ) || \security_ftr_enabled (SEC_FTR_L1D_FLUSH_HV )); --2.23.0
Nicholas Piggin
reviewerRe: [PATCH 4/4] powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess flushes
Excerpts from Joel Stanley's message of May 4, 2021 10:51 am:
Quoted 7 lines · Nicholas Piggin
Quoted 6 lines
These aren't necessarily POWER9 only, and it's not to say some new vulnerability may not get discovered on other processors for which we would like the flexibility of having the workaround enabled by firmware.
Quoted 8 lines
Quoted 1 line
Remove the restriction that they only apply to POWER9.
I was wondering how these worked which led me to reviewing your patch. From what I could see, these are enabled by default (
SEC_FTR_DEFAULTinarch/powerpc/include/asm/security_features.h), so unless all non-POWER9 machines have set the "please don't" bit in their firmware this patch will enable the feature for those machines. Is that what you wanted?
Yes. POWER7/8 should be affected (it's similar mechanism that requires the meltdown RFI flush, which those processors need).
POWER10 we haven't released a bare metal firmware with the right bits yet. Not urgent at the moment but wouldn't hurt to specify them and add the Linux code for them.
Thanks,
Nick
Quoted 31 lines
Quoted 30 lines
Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/platforms/powernv/setup.c | 9 --------- 1 file changed, 9 deletions(-)arch/powerpc/platforms/powernv/setup.c +0
-10@@ -122,15 +122,6 @@ static void pnv_setup_security_mitigations(void) type =L1D_FLUSH_ORI ; } -/* -* If we are non-Power9 bare metal, we don't need to flush on kernel -* entry or after user access: they fix a P9 specific vulnerability. -*/ -if (!pvr_version_is (PVR_POWER9 )) { -security_ftr_clear (SEC_FTR_L1D_FLUSH_ENTRY ); -security_ftr_clear (SEC_FTR_L1D_FLUSH_UACCESS ); - } - enable =security_ftr_enabled (SEC_FTR_FAVOUR_SECURITY ) && \ (security_ftr_enabled (SEC_FTR_L1D_FLUSH_PR ) || \security_ftr_enabled (SEC_FTR_L1D_FLUSH_HV )); --2.23.0
Joel Stanley
Reviewed-byRe: [PATCH 4/4] powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess flushes
Quoted 18 lines · Nicholas Piggin
Excerpts from Joel Stanley's message of May 4, 2021 10:51 am:
Quoted 7 lines · Nicholas Piggin
Quoted 6 lines
These aren't necessarily POWER9 only, and it's not to say some new vulnerability may not get discovered on other processors for which we would like the flexibility of having the workaround enabled by firmware.
Quoted 8 lines
Quoted 1 line
Remove the restriction that they only apply to POWER9.
I was wondering how these worked which led me to reviewing your patch. From what I could see, these are enabled by default (
SEC_FTR_DEFAULTinarch/powerpc/include/asm/security_features.h), so unless all non-POWER9 machines have set the "please don't" bit in their firmware this patch will enable the feature for those machines. Is that what you wanted?
Quoted 6 lines
Yes. POWER7/8 should be affected (it's similar mechanism that requires the meltdown RFI flush, which those processors need).
POWER10 we haven't released a bare metal firmware with the right bits yet. Not urgent at the moment but wouldn't hurt to specify them and add the Linux code for them.
Thanks for the explanation. This could go in the commit message if you re-spin.
Nicholas Piggin
reviewerRe: [PATCH 4/4] powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess flushes
Excerpts from Joel Stanley's message of May 5, 2021 11:43 am:
Quoted 22 lines · Nicholas Piggin
Quoted 21 lines
Excerpts from Joel Stanley's message of May 4, 2021 10:51 am:
Quoted 7 lines · Nicholas Piggin
Quoted 6 lines
These aren't necessarily POWER9 only, and it's not to say some new vulnerability may not get discovered on other processors for which we would like the flexibility of having the workaround enabled by firmware.
Quoted 8 lines
Quoted 1 line
Remove the restriction that they only apply to POWER9.
I was wondering how these worked which led me to reviewing your patch. From what I could see, these are enabled by default (
SEC_FTR_DEFAULTinarch/powerpc/include/asm/security_features.h), so unless all non-POWER9 machines have set the "please don't" bit in their firmware this patch will enable the feature for those machines. Is that what you wanted?Yes. POWER7/8 should be affected (it's similar mechanism that requires the meltdown RFI flush, which those processors need).
Quoted 8 lines
Quoted 3 lines
POWER10 we haven't released a bare metal firmware with the right bits yet. Not urgent at the moment but wouldn't hurt to specify them and add the Linux code for them.
Thanks for the explanation. This could go in the commit message if you re-spin.
Reviewed-by Joel Stanley <[email protected]>
I was talking about the same thing with Michael and he dug up an old email chain that proves me wrong. P7/8 are actually slightly different. I'm not sure what I can explain of it in public unfortunately.
How about this?
---
These aren't necessarily POWER9 only, and it's not to say some new vulnerability may not get discovered on other processors for which we would like the flexibility of having the workaround enabled by firmware.
Remove the restriction that the workarounds only apply to POWER9.
However POWER7 and POWER8 are not affected, and they may not have older firmware that does not advertise this, so clear these workarounds manually.
--- arch/powerpc/platforms/powernv/setup.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powernv/setup.c +7 -3
@@ -123,10 +123,14 @@ static void pnv_setup_security_mitigations(void) }/* -* If we are non-Power9 bare metal, we don't need to flush on kernel -* entry or after user access: they fix a P9 specific vulnerability. +* The issues addressed by the entry and uaccess flush don't affect P7 +* or P8, so on bare metal disable them explicitly in case firmware +* does not include these bits. POWER9 and newer processors should +* have the right firmware bits. */ -if (!pvr_version_is (PVR_POWER9 )) { +if (pvr_version_is (PVR_POWER7 ) ||pvr_version_is (PVR_POWER7p) || +pvr_version_is (PVR_POWER8E ) ||pvr_version_is (PVR_POWER8NVL ) || +pvr_version_is (PVR_POWER8 )) {security_ftr_clear (SEC_FTR_L1D_FLUSH_ENTRY );security_ftr_clear (SEC_FTR_L1D_FLUSH_UACCESS ); }
Signature · 1 line
2.23.0
Quoted 8 lines · Nicholas Piggin
This series adds a few missing bits added to recent pseries
H_GET_CPU_CHARACTERISTICSand implements them, also removes a restriction from powernv for some of the flushes.This is tested mianly in qemu where I just submitted a patch that adds support for these bits (not upstream yet).
[...]
Patches 1-3 applied to powerpc/next.
[1/4] powerpc/pseries: Get entry and uaccess flush required bits from H_GET_CPU_CHARACTERISTICS
https://git.kernel.org/powerpc/c/65c7d070850e109a8a75a431f5a7f6eb4c007b77 [2/4] powerpc/security: Add a security feature for STF barrier https://git.kernel.org/powerpc/c/84ed26fd00c514da57cd46aa3728a48f1f9b35cd [3/4] powerpc/pesries: Get STF barrier requirement from H_GET_CPU_CHARACTERISTICS https://git.kernel.org/powerpc/c/393eff5a7b357a23db3e786e24b5ba8762cc6820
cheers
Quoted 8 lines · Nicholas Piggin
This series adds a few missing bits added to recent pseries
H_GET_CPU_CHARACTERISTICSand implements them, also removes a restriction from powernv for some of the flushes.This is tested mianly in qemu where I just submitted a patch that adds support for these bits (not upstream yet).
[...]
Patch 4 applied to powerpc/next.
[4/4] powerpc/powernv: Remove POWER9 PVR version check for entry and uaccess flushes
https://git.kernel.org/powerpc/c/d02fa40d759ff9a53c93b10d8a4b591688982b26
cheers