From aee4582fb5144e1dd493041a8d1fc0c08146a622 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Sep 2026 18:14:16 +0200 Subject: x86_64/cpu: isolate kernel and IST1 stack Previously, the kernel stack was allocated inside the .kernel_bss section, along other uninitialized data. While this works, it assumes that the section will always be laid out with the kernel stack at the top. If that is not the case, the allocated guard page before .kernel_bss would not trigger a #PF since out-of-bounds (overflow) access would quietly overwrite other data in the section, thus potentially corrupting global kernel data. At the same time, there was no separate section (and guard page) for the future #DF exception stack (IST1 in our case). Thus we allocate a section, and a guard page, while we are already modifying the linker script. --- arch/x86_64/scripts/kernel.ld | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'arch/x86_64') diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld index e6ae3425..8cd6c1c3 100644 --- a/arch/x86_64/scripts/kernel.ld +++ b/arch/x86_64/scripts/kernel.ld @@ -98,9 +98,21 @@ SECTIONS . += 4K; + .kernel_stack ALIGN(4K) : AT (ADDR (.kernel_stack) - TEACHOS_VMA) + { + *(.stack) + } :kernel_data + + . += 4K; + + .kernel_ist1_stack ALIGN(4K) : AT (ADDR (.kernel_ist1_stack) - TEACHOS_VMA) + { + *(.ist1_stack) + } :kernel_data + .kernel_bss ALIGN(4K) : AT (ADDR (.kernel_bss) - TEACHOS_VMA) { - *(.stack .bss*) + *(.bss*) } :kernel_data .kernel_text ALIGN(4K) : AT(ADDR (.kernel_text) - TEACHOS_VMA) -- cgit v1.2.3