Skip to content

Commit 25e7301

Browse files
nickdesaulniersgregkh
authored andcommitted
start_kernel: Add __no_stack_protector function attribute
commit 514ca14 upstream. Back during the discussion of commit a9a3ed1 ("x86: Fix early boot crash on gcc-10, third try") we discussed the need for a function attribute to control the omission of stack protectors on a per-function basis; at the time Clang had support for no_stack_protector but GCC did not. This was fixed in gcc-11. Now that the function attribute is available, let's start using it. Callers of boot_init_stack_canary need to use this function attribute unless they're compiled with -fno-stack-protector, otherwise the canary stored in the stack slot of the caller will differ upon the call to boot_init_stack_canary. This will lead to a call to __stack_chk_fail() then panic. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94722 Link: https://lore.kernel.org/all/20200316130414.GC12561@hirez.programming.kicks-ass.net/ Tested-by: Nathan Chancellor <nathan@kernel.org> Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc) Acked-by: Miguel Ojeda <ojeda@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Link: https://lore.kernel.org/r/20230412-no_stackp-v2-1-116f9fe4bbe7@google.com Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: ndesaulniers@google.com <ndesaulniers@google.com>
1 parent 160f412 commit 25e7301

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

arch/powerpc/kernel/smp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ static void add_cpu_to_masks(int cpu)
16051605
}
16061606

16071607
/* Activate a secondary processor. */
1608+
__no_stack_protector
16081609
void start_secondary(void *unused)
16091610
{
16101611
unsigned int cpu = raw_smp_processor_id();

include/linux/compiler_attributes.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@
255255
*/
256256
#define __noreturn __attribute__((__noreturn__))
257257

258+
/*
259+
* Optional: only supported since GCC >= 11.1, clang >= 7.0.
260+
*
261+
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fstack_005fprotector-function-attribute
262+
* clang: https://clang.llvm.org/docs/AttributeReference.html#no-stack-protector-safebuffers
263+
*/
264+
#if __has_attribute(__no_stack_protector__)
265+
# define __no_stack_protector __attribute__((__no_stack_protector__))
266+
#else
267+
# define __no_stack_protector
268+
#endif
269+
258270
/*
259271
* Optional: not supported by gcc.
260272
*

init/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,8 @@ static void __init print_unknown_bootoptions(void)
877877
memblock_free(unknown_options, len);
878878
}
879879

880-
asmlinkage __visible void __init __no_sanitize_address __noreturn start_kernel(void)
880+
asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector
881+
void start_kernel(void)
881882
{
882883
char *command_line;
883884
char *after_dashes;

0 commit comments

Comments
 (0)