Skip to content

Commit ac46112

Browse files
torvaldsKAGA-KOKO
authored andcommitted
x86-32: Fix kexec with stack canary (CONFIG_CC_STACKPROTECTOR)
Commit e802a51 ("x86/idt: Consolidate IDT invalidation") cleaned up and unified the IDT invalidation that existed in a couple of places. It changed no actual real code. Despite not changing any actual real code, it _did_ change code generation: by implementing the common idt_invalidate() function in archx86/kernel/idt.c, it made the use of the function in arch/x86/kernel/machine_kexec_32.c be a real function call rather than an (accidental) inlining of the function. That, in turn, exposed two issues: - in load_segments(), we had incorrectly reset all the segment registers, which then made the stack canary load (which gcc does using offset of %gs) cause a trap. Instead of %gs pointing to the stack canary, it will be the normal zero-based kernel segment, and the stack canary load will take a page fault at address 0x14. - to make this even harder to debug, we had invalidated the GDT just before calling idt_invalidate(), which meant that the fault happened with an invalid GDT, which in turn causes a triple fault and immediate reboot. Fix this by (a) not reloading the special segments in load_segments(). We currently don't do any percpu accesses (which would require %fs on x86-32) in this area, but there's no reason to think that we might not want to do them, and like %gs, it's pointless to break it. (b) doing idt_invalidate() before invalidating the GDT, to keep things at least _slightly_ more debuggable for a bit longer. Without a IDT, traps will not work. Without a GDT, traps also will not work, but neither will any segment loads etc. So in a very real sense, the GDT is even more core than the IDT. Fixes: e802a51 ("x86/idt: Consolidate IDT invalidation") Reported-and-tested-by: Alexandru Chirvasitu <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 7ac139e commit ac46112

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

arch/x86/kernel/machine_kexec_32.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ static void load_segments(void)
4848
"\tmovl $"STR(__KERNEL_DS)",%%eax\n"
4949
"\tmovl %%eax,%%ds\n"
5050
"\tmovl %%eax,%%es\n"
51-
"\tmovl %%eax,%%fs\n"
52-
"\tmovl %%eax,%%gs\n"
5351
"\tmovl %%eax,%%ss\n"
5452
: : : "eax", "memory");
5553
#undef STR
@@ -232,8 +230,8 @@ void machine_kexec(struct kimage *image)
232230
* The gdt & idt are now invalid.
233231
* If you want to load them you must set up your own idt & gdt.
234232
*/
235-
set_gdt(phys_to_virt(0), 0);
236233
idt_invalidate(phys_to_virt(0));
234+
set_gdt(phys_to_virt(0), 0);
237235

238236
/* now call it */
239237
image->start = relocate_kernel_ptr((unsigned long)image->head,

0 commit comments

Comments
 (0)