]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/efi/init: Disable stack smashing protection on grub_efi_init()
authorGlenn Washburn <development@efficientek.com>
Tue, 18 Jul 2023 05:47:14 +0000 (00:47 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 12 Oct 2023 15:47:28 +0000 (17:47 +0200)
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 <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/efi/init.c

index 6fe1ff8c868e7911146ce85aa32a0d8f61b8212d..e759cc315b8517cd622a4bc3a7e03cf24afd1233 100644 (file)
@@ -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");