All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: x86@kernel.org, Joerg Roedel <jroedel@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 4/5] x86/boot/64: Explicitly map boot_params and command line
Date: Wed,  7 Oct 2020 15:53:50 -0400	[thread overview]
Message-ID: <20201007195351.776555-5-nivedita@alum.mit.edu> (raw)
In-Reply-To: <20201007195351.776555-1-nivedita@alum.mit.edu>

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.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 arch/x86/boot/compressed/ident_map_64.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c
index 070cda70aef3..8edeff0d9324 100644
--- a/arch/x86/boot/compressed/ident_map_64.c
+++ b/arch/x86/boot/compressed/ident_map_64.c
@@ -150,10 +150,13 @@ 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, and load the new page-table into cr3.
 	 */
 	add_identity_map((unsigned long)_head, (unsigned long)_end - (unsigned long)_head);
+	add_identity_map((unsigned long)boot_params, sizeof(*boot_params));
+	add_identity_map(get_cmd_line_ptr(), COMMAND_LINE_SIZE);
+
 	write_cr3(top_level_pgt);
 }
 
-- 
2.26.2


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

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 19:53 [PATCH 0/5] Couple of bugfixes to sev-es series Arvind Sankar
2020-10-07 19:53 ` [PATCH 1/5] x86/boot: Initialize boot_params in startup code Arvind Sankar
2020-10-08  9:04   ` Joerg Roedel
2020-10-08 13:44     ` Arvind Sankar
2020-10-07 19:53 ` [PATCH 2/5] x86/boot: Move get_cmd_line_ptr() and COMMAND_LINE_SIZE into misc.h Arvind Sankar
2020-10-08  9:11   ` Joerg Roedel
2020-10-08  9:30   ` Borislav Petkov
2020-10-08 13:47     ` Arvind Sankar
2020-10-08 15:10       ` Borislav Petkov
2020-10-08 15:30         ` Arvind Sankar
2020-10-08 16:16           ` Borislav Petkov
2020-10-07 19:53 ` [PATCH 3/5] x86/boot/64: Change add_identity_map() to take size for ease of use Arvind Sankar
2020-10-08  9:14   ` Joerg Roedel
2020-10-08 13:49     ` Arvind Sankar
2020-10-07 19:53 ` Arvind Sankar [this message]
2020-10-08  9:17   ` [PATCH 4/5] x86/boot/64: Explicitly map boot_params and command line Joerg Roedel
2020-10-08  9:48   ` Joerg Roedel
2020-10-08 13:57     ` Arvind Sankar
2020-10-07 19:53 ` [PATCH 5/5] x86/head/64: Disable stack protection for head$(BITS).o Arvind Sankar
2020-10-08  8:42   ` Joerg Roedel
2020-10-08 14:52     ` 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=20201007195351.776555-5-nivedita@alum.mit.edu \
    --to=nivedita@alum.mit.edu \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.