Skip to content

Commit 34bb492

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/boot/compressed/64: Switch to __KERNEL_CS after GDT is loaded
When the pre-decompression code loads its first GDT in startup_64(), it is still running on the CS value of the previous GDT. In the case of SEV-ES, this is the EFI GDT but it can be anything depending on what has loaded the kernel (boot loader, container runtime, etc.) To make exception handling work (especially IRET) the CPU needs to switch to a CS value in the current GDT, so jump to __KERNEL_CS after the first GDT is loaded. This is prudent also as a general sanitization of CS to a known good value. [ bp: Massage commit message. ] Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 40ba930 commit 34bb492

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/boot/compressed/head_64.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ SYM_CODE_START(startup_64)
393393
addq %rax, 2(%rax)
394394
lgdt (%rax)
395395

396+
/* Reload CS so IRET returns to a CS actually in the GDT */
397+
pushq $__KERNEL_CS
398+
leaq .Lon_kernel_cs(%rip), %rax
399+
pushq %rax
400+
lretq
401+
402+
.Lon_kernel_cs:
403+
396404
/*
397405
* paging_prepare() sets up the trampoline and checks if we need to
398406
* enable 5-level paging.

0 commit comments

Comments
 (0)