mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Arvind Sankar" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Arvind Sankar <nivedita@alum.mit.edu>,
	Borislav Petkov <bp@suse.de>, Joerg Roedel <jroedel@suse.de>,
	x86 <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>
Subject: [tip: x86/seves] x86/boot/64: Explicitly map boot_params and command line
Date: Mon, 19 Oct 2020 19:44:43 -0000	[thread overview]
Message-ID: <160313668395.7002.7778590955397923179.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20201016200404.1615994-1-nivedita@alum.mit.edu>

The following commit has been merged into the x86/seves branch of tip:

Commit-ID:     b17a45b6e53f6613118b2e5cfc4a992cc50deb2c
Gitweb:        https://git.kernel.org/tip/b17a45b6e53f6613118b2e5cfc4a992cc50deb2c
Author:        Arvind Sankar <nivedita@alum.mit.edu>
AuthorDate:    Fri, 16 Oct 2020 16:04:01 -04:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 19 Oct 2020 19:39:50 +02:00

x86/boot/64: Explicitly map boot_params and command line

Commits

  ca0e22d4f011 ("x86/boot/compressed/64: Always switch to own page table")
  8570978ea030 ("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
---
 arch/x86/boot/compressed/head_64.S      |  3 +++
 arch/x86/boot/compressed/ident_map_64.c | 23 ++++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 1c80f17..017de6c 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -544,6 +544,9 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
 	pushq	%rsi
 	call	set_sev_encryption_mask
 	call	load_stage2_idt
+
+	/* Pass boot_params to initialize_identity_maps() */
+	movq	(%rsp), %rdi
 	call	initialize_identity_maps
 	popq	%rsi
 
diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c
index c6f7aef..a5e5db6 100644
--- a/arch/x86/boot/compressed/ident_map_64.c
+++ b/arch/x86/boot/compressed/ident_map_64.c
@@ -33,6 +33,12 @@
 #define __PAGE_OFFSET __PAGE_OFFSET_BASE
 #include "../../mm/ident_map.c"
 
+#define _SETUP
+#include <asm/setup.h>	/* For COMMAND_LINE_SIZE */
+#undef _SETUP
+
+extern unsigned long get_cmd_line_ptr(void);
+
 /* Used by PAGE_KERN* macros: */
 pteval_t __default_kernel_pte_mask __read_mostly = ~0;
 
@@ -101,8 +107,10 @@ static void add_identity_map(unsigned long start, unsigned long end)
 }
 
 /* Locates and clears a region for a new top level page table. */
-void initialize_identity_maps(void)
+void initialize_identity_maps(void *rmode)
 {
+	unsigned long cmdline;
+
 	/* Exclude the encryption mask from __PHYSICAL_MASK */
 	physical_mask &= ~sme_me_mask;
 
@@ -143,10 +151,19 @@ void initialize_identity_maps(void)
 	}
 
 	/*
-	 * New page-table is set up - map the kernel image and load it
-	 * into cr3.
+	 * New page-table is set up - map the kernel image, boot_params and the
+	 * command line. The uncompressed kernel requires boot_params and the
+	 * command line to be mapped in the identity mapping. Map them
+	 * explicitly here in case the compressed kernel does not touch them,
+	 * or does not touch all the pages covering them.
 	 */
 	add_identity_map((unsigned long)_head, (unsigned long)_end);
+	boot_params = rmode;
+	add_identity_map((unsigned long)boot_params, (unsigned long)(boot_params + 1));
+	cmdline = get_cmd_line_ptr();
+	add_identity_map(cmdline, cmdline + COMMAND_LINE_SIZE);
+
+	/* Load the new page-table. */
 	write_cr3(top_level_pgt);
 }
 

  parent reply	other threads:[~2020-10-19 19:45 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 19:16 [PATCH v2 0/5] Couple of bugfixes to sev-es series Arvind Sankar
2020-10-08 19:16 ` [PATCH v2 1/5] x86/boot: Initialize boot_params in startup code Arvind Sankar
2020-10-08 19:16 ` [PATCH v2 2/5] x86/boot: Split out command-line related declarations Arvind Sankar
2020-10-08 19:16 ` [PATCH v2 3/5] x86/boot/64: Show original faulting address in case of error Arvind Sankar
2020-10-09 14:42   ` Joerg Roedel
2020-10-08 19:16 ` [PATCH v2 4/5] x86/boot/64: Explicitly map boot_params and command line Arvind Sankar
2020-10-09 14:49   ` Joerg Roedel
2020-10-16 16:27   ` Borislav Petkov
2020-10-16 16:47     ` Arvind Sankar
2020-10-16 17:07       ` Borislav Petkov
2020-10-16 17:20         ` Arvind Sankar
2020-10-16 17:32           ` Borislav Petkov
2020-10-16 20:04             ` [PATCH v3 1/4] " Arvind Sankar
2020-10-16 20:04               ` [PATCH v3 2/4] x86/boot: Initialize boot_params in startup code Arvind Sankar
2020-10-16 20:04               ` [PATCH v3 3/4] x86/boot: Split out command-line related declarations Arvind Sankar
2020-10-16 20:04               ` [PATCH v3 4/4] x86/boot/64: Show original faulting address in case of error Arvind Sankar
2020-10-19 14:51               ` [PATCH v3 1/4] x86/boot/64: Explicitly map boot_params and command line Borislav Petkov
2020-10-19 17:12                 ` Arvind Sankar
2020-10-19 17:31                   ` Borislav Petkov
2020-10-19 19:44               ` tip-bot2 for Arvind Sankar [this message]
2020-10-16 21:18             ` [PATCH v2 4/5] " Arvind Sankar
2020-10-16 21:23               ` Borislav Petkov
2020-10-08 19:16 ` [PATCH v2 5/5] x86/head/64: Disable stack protection for head$(BITS).o Arvind Sankar
2020-10-09 14:49   ` Joerg Roedel
2020-10-16 11:17   ` Borislav Petkov
2020-10-16 12:43     ` Arvind Sankar
2020-10-16 13:15       ` Borislav Petkov
2020-10-16 14:16         ` Arvind Sankar
2020-10-19 19:44   ` [tip: x86/seves] " tip-bot2 for Arvind Sankar
2020-10-10 19:11 ` [PATCH] x86/boot/64: Initialize 5-level paging variables earlier Arvind Sankar
2020-10-10 19:26   ` Arvind Sankar
2020-10-12 14:08     ` Kirill A. Shutemov
2020-10-12 15:35       ` Arvind Sankar
2020-10-13  8:11         ` Borislav Petkov
2020-10-13  8:20           ` Kirill A. Shutemov
2020-10-13  8:33             ` Borislav Petkov
2020-10-13  9:12               ` Kirill A. Shutemov
2020-10-13  9:46                 ` Borislav Petkov
2020-10-15 13:52               ` Kirill A. Shutemov
2020-10-16 10:21                 ` Borislav Petkov
2020-10-13  8:59   ` Joerg Roedel
2020-10-19 19:44   ` [tip: x86/seves] " tip-bot2 for Arvind Sankar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160313668395.7002.7778590955397923179.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=bp@suse.de \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=nivedita@alum.mit.edu \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®