From: Glenn Washburn Date: Tue, 18 Jul 2023 05:47:14 +0000 (-0500) Subject: kern/efi/init: Disable stack smashing protection on grub_efi_init() X-Git-Tag: grub-2.12~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3bdf263f63b57394fee836cde3e582a4576e6fd;p=thirdparty%2Fgrub.git kern/efi/init: Disable stack smashing protection on grub_efi_init() GCC is electing to instrument grub_efi_init() to give it stack smashing protection when configuring with --enable-stack-protector on the x86_64-efi target. In the function prologue, the canary at the top of the stack frame is set to the value of the stack guard. And in the epilogue, the canary is checked to verify if it is equal to the guard and if not to call the stack check fail function. The issue is that grub_efi_init() sets up the guard by initializing it with random bytes, if the firmware supports the RNG protocol. So in its prologue the canary will be set with the value of the uninitialized guard, likely NUL bytes. Then the guard is initialized, and finally the epilogue checks the canary against the guard, which will almost certainly be different. This causes the code path for a smashed stack to be taken, causing the machine to print out a message that stack smashing was detected, wait 5 seconds, and then reboot. Disable grub_efi_init() instrumentation so there is no stack smashing false positive generated. Signed-off-by: Glenn Washburn Reviewed-by: Daniel Kiper --- diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 6fe1ff8c8..e759cc315 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -102,7 +102,7 @@ stack_protector_init (void) grub_addr_t grub_modbase; -void +__attribute__ ((__optimize__ ("-fno-stack-protector"))) void grub_efi_init (void) { grub_modbase = grub_efi_section_addr ("mods");