Skip to contentSkip to conversation

x86/boot/compressed: use .data for globals that are accessed early

PATCH Applied Michael Roth 2 participants 2 messages Apr 20, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot/compressed: use .data for globals that are accessed early

The helpers in efi.c might be used during early boot to access the EFI system/config tables, and in some cases these EFI helpers might attempt to print debug/error messages, before console_init() has been called. __putstr() checks some variables to avoid printing anything before the console has been initialized, but this isn't enough since those variables live in .bss, which may not have been cleared yet. This can lead to a triple-fault occurring, primarily when booting in legacy/CSM mode (where EFI helpers will attempt to print some debug messages).

Fix this by declaring these globals in .data section instead so there is no dependency on BSS being cleared before accessing them.

Fixes c01fce9cef849 ("x86/compressed: Add SEV-SNP feature detection/setup")
---
 arch/x86/boot/compressed/early_serial_console.c | 3 ++-
 arch/x86/boot/compressed/misc.c                 | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/early_serial_console.c +2 -1
index 261e81fb9582..70a8d1706d0f 100644
@@ -1,5 +1,6 @@
 #include "misc.h"
 
-int early_serial_base;
+/* This might be accessed before .bss is cleared, so use .data instead. */
+int early_serial_base __section(".data");
 
 #include "../early_serial_console.c"
arch/x86/boot/compressed/misc.c +4 -1
index fa8969fad011..cf690d8712f4 100644
@@ -55,7 +55,10 @@ memptr free_mem_end_ptr;
 
 static char *vidmem;
 static int vidport;
-static int lines, cols;
+
+/* These might be accessed before .bss is cleared, so use .data instead. */
+static int lines __section(".data");
+static int cols __section(".data");
 
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
Signature · 1 line
2.25.1
merge bot Applied
#1 lore raw

[tip: x86/sev] x86/boot: Put globals that are accessed early into the .data section

The following commit has been merged into the x86/sev branch of tip:

The following commit has been merged into the x86/sev branch of tip:

Commit-ID:     6044d159b5d826259a7397d42fa3ad0bfc4dbd13
Gitweb:        https://git.kernel.org/tip/6044d159b5d826259a7397d42fa3ad0bfc4dbd13
Author:        Michael Roth <[email protected]>
AuthorDate:    Wed, 20 Apr 2022 10:26:13 -05:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Wed, 20 Apr 2022 20:10:54 +02:00

x86/boot: Put globals that are accessed early into the .data section

The helpers in arch/x86/boot/compressed/efi.c might be used during early boot to access the EFI system/config tables, and in some cases these EFI helpers might attempt to print debug/error messages, before console_init() has been called.

__putstr() checks some variables to avoid printing anything before the console has been initialized, but this isn't enough since those variables live in .bss, which may not have been cleared yet. This can lead to a triple-fault occurring, primarily when booting in legacy/CSM mode (where EFI helpers will attempt to print some debug messages).

Fix this by declaring these globals in .data section instead so there is no dependency on .bss being cleared before accessing them.

Fixes c01fce9cef849 ("x86/compressed: Add SEV-SNP feature detection/setup")
---
 arch/x86/boot/compressed/early_serial_console.c | 3 ++-
 arch/x86/boot/compressed/misc.c                 | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/early_serial_console.c +2 -1
index 261e81f..70a8d17 100644
@@ -1,5 +1,6 @@
 #include "misc.h"
 
-int early_serial_base;
+/* This might be accessed before .bss is cleared, so use .data instead. */
+int early_serial_base __section(".data");
 
 #include "../early_serial_console.c"
arch/x86/boot/compressed/misc.c +4 -1
index 1cdcaf3..ca6820f 100644
@@ -53,7 +53,10 @@ memptr free_mem_end_ptr;
 
 static char *vidmem;
 static int vidport;
-static int lines, cols;
+
+/* These might be accessed before .bss is cleared, so use .data instead. */
+static int lines __section(".data");
+static int cols __section(".data");
 
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"