Skip to content

Commit b17a45b

Browse files
nivedita76suryasaimadhu
authored andcommitted
x86/boot/64: Explicitly map boot_params and command line
Commits ca0e22d ("x86/boot/compressed/64: Always switch to own page table") 8570978 ("x86/boot/compressed/64: Don't pre-map memory in KASLR code") set up a new page table in the decompressor stub, but without explicit mappings for boot_params and the kernel command line, relying on the #PF handler instead. This is fragile, as boot_params and the command line mappings are required for the main kernel. If EARLY_PRINTK and RANDOMIZE_BASE are disabled, a QEMU/OVMF boot never accesses the command line in the decompressor stub, and so it never gets mapped. The main kernel accesses it from the identity mapping if AMD_MEM_ENCRYPT is enabled, and will crash. Fix this by adding back the explicit mapping of boot_params and the command line. Note: the changes also removed the explicit mapping of the main kernel, with the result that .bss and .brk may not be in the identity mapping, but those don't get accessed by the main kernel before it switches to its own page tables. [ bp: Pass boot_params with a MOV %rsp... instead of PUSH/POP. Use block formatting for the comment. ] Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Joerg Roedel <jroedel@suse.de> Link: https://lkml.kernel.org/r/20201016200404.1615994-1-nivedita@alum.mit.edu
1 parent 103a490 commit b17a45b

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

arch/x86/boot/compressed/head_64.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
544544
pushq %rsi
545545
call set_sev_encryption_mask
546546
call load_stage2_idt
547+
548+
/* Pass boot_params to initialize_identity_maps() */
549+
movq (%rsp), %rdi
547550
call initialize_identity_maps
548551
popq %rsi
549552

arch/x86/boot/compressed/ident_map_64.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#define __PAGE_OFFSET __PAGE_OFFSET_BASE
3434
#include "../../mm/ident_map.c"
3535

36+
#define _SETUP
37+
#include <asm/setup.h> /* For COMMAND_LINE_SIZE */
38+
#undef _SETUP
39+
40+
extern unsigned long get_cmd_line_ptr(void);
41+
3642
/* Used by PAGE_KERN* macros: */
3743
pteval_t __default_kernel_pte_mask __read_mostly = ~0;
3844

@@ -101,8 +107,10 @@ static void add_identity_map(unsigned long start, unsigned long end)
101107
}
102108

103109
/* Locates and clears a region for a new top level page table. */
104-
void initialize_identity_maps(void)
110+
void initialize_identity_maps(void *rmode)
105111
{
112+
unsigned long cmdline;
113+
106114
/* Exclude the encryption mask from __PHYSICAL_MASK */
107115
physical_mask &= ~sme_me_mask;
108116

@@ -143,10 +151,19 @@ void initialize_identity_maps(void)
143151
}
144152

145153
/*
146-
* New page-table is set up - map the kernel image and load it
147-
* into cr3.
154+
* New page-table is set up - map the kernel image, boot_params and the
155+
* command line. The uncompressed kernel requires boot_params and the
156+
* command line to be mapped in the identity mapping. Map them
157+
* explicitly here in case the compressed kernel does not touch them,
158+
* or does not touch all the pages covering them.
148159
*/
149160
add_identity_map((unsigned long)_head, (unsigned long)_end);
161+
boot_params = rmode;
162+
add_identity_map((unsigned long)boot_params, (unsigned long)(boot_params + 1));
163+
cmdline = get_cmd_line_ptr();
164+
add_identity_map(cmdline, cmdline + COMMAND_LINE_SIZE);
165+
166+
/* Load the new page-table. */
150167
write_cr3(top_level_pgt);
151168
}
152169

0 commit comments

Comments
 (0)