Small stack protector bits
Subsystems (2)
cover Small stack protector bits
Reworking my "static pie" series and going back
through comments from Willy and Thomas...
First patch was suggested by Willy as a preemptive clean up task before the series. So here it is.
Second one is an issue only appeared with relocation (because you shouldn't access global data before relocation) but seems sensible to do.
Daniel Palmer (2):
tools/nolibc: Rename __no_stack_protector to
__nolibc_no_stack_protector
tools/nolibc: Don't use stack protector before setting it up
tools/include/nolibc/arch-arm.h | 2 +- tools/include/nolibc/arch-arm64.h | 2 +- tools/include/nolibc/arch-loongarch.h | 2 +- tools/include/nolibc/arch-m68k.h | 2 +- tools/include/nolibc/arch-mips.h | 2 +- tools/include/nolibc/arch-powerpc.h | 8 ++++---- tools/include/nolibc/arch-riscv.h | 2 +- tools/include/nolibc/arch-s390.h | 2 +- tools/include/nolibc/arch-sh.h | 2 +- tools/include/nolibc/arch-sparc.h | 2 +- tools/include/nolibc/arch-x86.h | 4 ++-- tools/include/nolibc/compiler.h | 4 ++-- tools/include/nolibc/crt.h | 2 +- tools/include/nolibc/stackprotector.h | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 tools/nolibc: Rename __no_stack_protector to __nolibc_no_stack_protector
To avoid polluting the namespace rename __no_stack_protector to __nolibc_no_stack_protector so its now within the nolibc umbrella.
--- tools/include/nolibc/arch-arm.h | 2 +- tools/include/nolibc/arch-arm64.h | 2 +- tools/include/nolibc/arch-loongarch.h | 2 +- tools/include/nolibc/arch-m68k.h | 2 +- tools/include/nolibc/arch-mips.h | 2 +- tools/include/nolibc/arch-powerpc.h | 8 ++++---- tools/include/nolibc/arch-riscv.h | 2 +- tools/include/nolibc/arch-s390.h | 2 +- tools/include/nolibc/arch-sh.h | 2 +- tools/include/nolibc/arch-sparc.h | 2 +- tools/include/nolibc/arch-x86.h | 4 ++-- tools/include/nolibc/compiler.h | 4 ++-- tools/include/nolibc/stackprotector.h | 2 +- 13 files changed, 18 insertions(+), 18 deletions(-)
tools/include/nolibc/arch-arm.h +1 -1
@@ -186,7 +186,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "mov r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */
tools/include/nolibc/arch-arm64.h +1 -1
@@ -143,7 +143,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
tools/include/nolibc/arch-loongarch.h +1 -1
@@ -144,7 +144,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
tools/include/nolibc/arch-m68k.h +1 -1
@@ -130,7 +130,7 @@#ifndef NOLIBC_NO_RUNTIME void _start (void ); -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "movel %sp, %sp@-\n"
tools/include/nolibc/arch-mips.h +1 -1
@@ -257,7 +257,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code, note that it's called __start on MIPS */ void __start (void ); -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector __start(void) { __asm__volatile ( "move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
tools/include/nolibc/arch-powerpc.h +4 -4
@@ -177,15 +177,15 @@* "omit-frame-pointer" fails with __attribute__((no_stack_protector)) but * works with __attribute__((__optimize__("-fno-stack-protector"))) */ -#ifdef __no_stack_protector -#undef __no_stack_protector -#define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector"))) +#ifdef __nolibc_no_stack_protector +#undef __nolibc_no_stack_protector +#define __nolibc_no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))#endif #endif /* !__powerpc64__ */ #ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) {#ifdef __powerpc64__#if _CALL_ELF ==2
tools/include/nolibc/arch-riscv.h +1 -1
@@ -141,7 +141,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( ".option push\n"
tools/include/nolibc/arch-s390.h +1 -1
@@ -145,7 +145,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
tools/include/nolibc/arch-sh.h +1 -1
@@ -143,7 +143,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ void _start_wrapper (void ); -void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protector _start_wrapper(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start_wrapper(void) { __asm__volatile ( ".global _start\n" /* The C function will have a prologue, */
tools/include/nolibc/arch-sparc.h +1 -1
@@ -154,7 +154,7 @@#ifndef NOLIBC_NO_RUNTIME /* startup code */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__ volatile (/*
tools/include/nolibc/arch-x86.h +2 -2
@@ -165,7 +165,7 @@* 2) The deepest stack frame should be set to zero * */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "xor %ebp, %ebp\n" /* zero the stack frame */
@@ -333,7 +333,7 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s* 2) The deepest stack frame should be zero (the %rbp). * */ -void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) +void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector _start(void) { __asm__volatile ( "xor %ebp, %ebp\n" /* zero the stack frame */
tools/include/nolibc/compiler.h +2 -2
@@ -36,9 +36,9 @@#endif /* defined(__SSP__) ... */ #if __nolibc_has_attribute (no_stack_protector) -# define __no_stack_protector __attribute__((no_stack_protector)) +# define __nolibc_no_stack_protector __attribute__((no_stack_protector))#else -# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector"))) +# define __nolibc_no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))#endif /* __nolibc_has_attribute(no_stack_protector) */ #if __nolibc_has_attribute (__fallthrough__)
tools/include/nolibc/stackprotector.h +1 -1
@@ -40,7 +40,7 @@ void __stack_chk_fail_local(void) __attribute__((weak,used,section (".data.nolibc_stack_chk" )))uintptr_t __stack_chk_guard; -static __no_stack_protector void __stack_chk_init(void) +static __nolibc_no_stack_protector void __stack_chk_init(void) {__nolibc_syscall3 (__NR_getrandom, &__stack_chk_guard,sizeof (__stack_chk_guard),0 );/* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */
Signature · 1 line
2.53.0
Thomas Weißschuh
maintainerRe: [PATCH 1/2] tools/nolibc: Rename __no_stack_protector to __nolibc_no_stack_protector
Quoted 2 lines · Daniel Palmer
To avoid polluting the namespace rename
__no_stack_protectorto__nolibc_no_stack_protectorso its now within the nolibc umbrella.
Both patches applied, thanks!
Quoted 2 lines
Suggested-by Willy Tarreau <[email protected]>Signed-off-by Daniel Palmer <[email protected]>
(...)
PATCH 2/2 tools/nolibc: Don't use stack protector before setting it up
In reply to Daniel PalmerThe stack protector is configured in _start_c() so we shouldn't use it before then.
Add __nolibc_no_stack_protector to _start_c() to avoid the compiler generating stack protector code for _start_c() and thus using it before its configured.
--- tools/include/nolibc/crt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/nolibc/crt.h +1 -1
@@ -47,7 +47,7 @@ char *__nolibc_program_invocation_short_name(char *long_name)#endif /* NOLIBC_IGNORE_ERRNO */ void _start_c (long *sp); -__attribute__((weak,used))__nolibc_no_sanitize_undefined +__attribute__((weak, used)) __nolibc_no_sanitize_undefined __nolibc_no_stack_protectorvoid _start_c (long *sp) {long argc;
Signature · 1 line
2.53.0