powerpc: Avoid broken GCC __attribute__((optimize))
authorArd Biesheuvel <ardb@kernel.org>
Wed, 28 Oct 2020 08:04:33 +0000 (09:04 +0100)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 19 Nov 2020 03:50:14 +0000 (14:50 +1100)
Commit 7053f80d9696 ("powerpc/64: Prevent stack protection in early
boot") introduced a couple of uses of __attribute__((optimize)) with
function scope, to disable the stack protector in some early boot
code.

Unfortunately, and this is documented in the GCC man pages [0],
overriding function attributes for optimization is broken, and is only
supported for debug scenarios, not for production: the problem appears
to be that setting GCC -f flags using this method will cause it to
forget about some or all other optimization settings that have been
applied.

So the only safe way to disable the stack protector is to disable it
for the entire source file.

[0] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

Fixes: 7053f80d9696 ("powerpc/64: Prevent stack protection in early boot")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
[mpe: Drop one remaining use of __nostackprotector, reported by snowpatch]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201028080433.26799-1-ardb@kernel.org
arch/powerpc/kernel/Makefile
arch/powerpc/kernel/paca.c
arch/powerpc/kernel/setup.h
arch/powerpc/kernel/setup_64.c

index bf0bf1b900d21266cfd7eab9b6c7f797342239fb..fe2ef598e2ead0a5f429cd30a90e0edd48e22664 100644 (file)
@@ -173,6 +173,9 @@ KCOV_INSTRUMENT_cputable.o := n
 KCOV_INSTRUMENT_setup_64.o := n
 KCOV_INSTRUMENT_paca.o := n
 
+CFLAGS_setup_64.o              += -fno-stack-protector
+CFLAGS_paca.o                  += -fno-stack-protector
+
 extra-$(CONFIG_PPC_FPU)                += fpu.o
 extra-$(CONFIG_ALTIVEC)                += vector.o
 extra-$(CONFIG_PPC64)          += entry_64.o
index 0ad15768d762cf37f29b7b29ebfcdbf1abeb5d62..7f5aae3c387d29e4b6862b7fd0aa16c98732ff4f 100644 (file)
@@ -208,7 +208,7 @@ static struct rtas_args * __init new_rtas_args(int cpu, unsigned long limit)
 struct paca_struct **paca_ptrs __read_mostly;
 EXPORT_SYMBOL(paca_ptrs);
 
-void __init __nostackprotector initialise_paca(struct paca_struct *new_paca, int cpu)
+void __init initialise_paca(struct paca_struct *new_paca, int cpu)
 {
 #ifdef CONFIG_PPC_PSERIES
        new_paca->lppaca_ptr = NULL;
@@ -241,7 +241,7 @@ void __init __nostackprotector initialise_paca(struct paca_struct *new_paca, int
 }
 
 /* Put the paca pointer into r13 and SPRG_PACA */
-void __nostackprotector setup_paca(struct paca_struct *new_paca)
+void setup_paca(struct paca_struct *new_paca)
 {
        /* Setup r13 */
        local_paca = new_paca;
index 2ec835574cc940c6b3cd1902b985deae776e1b8d..2dd0d9cb5a208601c443004df41d255fe27beb79 100644 (file)
@@ -8,12 +8,6 @@
 #ifndef __ARCH_POWERPC_KERNEL_SETUP_H
 #define __ARCH_POWERPC_KERNEL_SETUP_H
 
-#ifdef CONFIG_CC_IS_CLANG
-#define __nostackprotector
-#else
-#define __nostackprotector __attribute__((__optimize__("no-stack-protector")))
-#endif
-
 void initialize_cache_info(void);
 void irqstack_early_init(void);
 
index bb9cab3641d7d5b399b0663bee55204afad11cfc..da447a62ea1e7f13dd5150ed5557148cf39b1051 100644 (file)
@@ -283,7 +283,7 @@ void __init record_spr_defaults(void)
  * device-tree is not accessible via normal means at this point.
  */
 
-void __init __nostackprotector early_setup(unsigned long dt_ptr)
+void __init early_setup(unsigned long dt_ptr)
 {
        static __initdata struct paca_struct boot_paca;