Panic on stack protector crash instead of exit (#2955)

Newlib has a stack protector fail handler which write(2)s a
message to STDERR which doesn't work here.  Override with a
call to panic().

Tell GCC to protect all functions for stack protection instead of
ones that it heuristically decides need protection.  Slower but
safer, and only when stack protection is enabled.
This commit is contained in:
Earle F. Philhower, III 2025-05-14 07:38:25 -07:00 committed by GitHub
parent de7f1a7e83
commit d5e844b2bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 137 additions and 128 deletions

File diff suppressed because it is too large Load diff

View file

@ -244,3 +244,10 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols) {
} }
const String emptyString = ""; const String emptyString = "";
extern "C" void __attribute__((__noreturn__)) __wrap___stack_chk_fail() {
while (true) {
panic("*** stack smashing detected ***: terminated\n");
}
}

View file

@ -67,3 +67,5 @@
-Wl,--wrap=cyw43_tcpip_link_status -Wl,--wrap=cyw43_tcpip_link_status
-Wl,--wrap=cyw43_cb_tcpip_init -Wl,--wrap=cyw43_cb_tcpip_init
-Wl,--wrap=cyw43_cb_tcpip_deinit -Wl,--wrap=cyw43_cb_tcpip_deinit
-Wl,--wrap=__stack_chk_fail

View file

@ -112,7 +112,7 @@ def BuildStackProtect(name):
print("%s.menu.stackprotect.Disabled=Disabled" % (name)) print("%s.menu.stackprotect.Disabled=Disabled" % (name))
print("%s.menu.stackprotect.Disabled.build.flags.stackprotect=" % (name)) print("%s.menu.stackprotect.Disabled.build.flags.stackprotect=" % (name))
print("%s.menu.stackprotect.Enabled=Enabled" % (name)) print("%s.menu.stackprotect.Enabled=Enabled" % (name))
print("%s.menu.stackprotect.Enabled.build.flags.stackprotect=-fstack-protector" % (name)) print("%s.menu.stackprotect.Enabled.build.flags.stackprotect=-fstack-protector-all" % (name))
def BuildExceptions(name): def BuildExceptions(name):
print("%s.menu.exceptions.Disabled=Disabled" % (name)) print("%s.menu.exceptions.Disabled=Disabled" % (name))