Skip to content

Commit 242db75

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/boot/32: Disable stackprotector and tracing for mk_early_pgtbl_32()
Stackprotector cannot work before paging is enabled. The read from the per CPU variable __stack_chk_guard is always accessing the virtual address either directly on UP or via FS on SMP. In physical address mode this results in an access to memory above 3GB. So this works by chance as the hardware returns the same value when there is no RAM at this physical address. When there is RAM populated above 3G then the read is by chance the same as nothing changes that memory during the very early boot stage. Stop relying on pure luck and disable the stack protector for the only C function which is called during early boot before paging is enabled. Remove function tracing from the whole source file as there is no way to trace this at all, but in case of CONFIG_DYNAMIC_FTRACE=n mk_early_pgtbl_32() would access global function tracer variables in physical address mode which again might work by chance. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231002115902.156063939@linutronix.de
1 parent 2e9064f commit 242db75

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

arch/x86/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CFLAGS_REMOVE_kvmclock.o = -pg
1616
CFLAGS_REMOVE_ftrace.o = -pg
1717
CFLAGS_REMOVE_early_printk.o = -pg
1818
CFLAGS_REMOVE_head64.o = -pg
19+
CFLAGS_REMOVE_head32.o = -pg
1920
CFLAGS_REMOVE_sev.o = -pg
2021
CFLAGS_REMOVE_rethook.o = -pg
2122
endif

arch/x86/kernel/head32.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ asmlinkage __visible void __init __noreturn i386_start_kernel(void)
7070
* always zero at this stage.
7171
*/
7272
void __init mk_early_pgtbl_32(void);
73-
void __init mk_early_pgtbl_32(void)
73+
74+
void __init __no_stack_protector mk_early_pgtbl_32(void)
7475
{
7576
#ifdef __pa
7677
#undef __pa

0 commit comments

Comments
 (0)