From: "Ard Biesheuvel" <ardb@kernel.org>
To: devel@edk2.groups.io, acdunlap@google.com
Subject: Re: [edk2-devel] [PATCH] OvmfPkg/PlatformPei: Validate SEC's GHCB page
Date: Fri, 9 Dec 2022 21:08:42 +0100 [thread overview]
Message-ID: <CAMj1kXHRzCiORqsNP-AYGc=3O28Hq7aw6bM-eRyDe1zjGgWCkQ@mail.gmail.com> (raw)
In-Reply-To: <e0cd049f583e73569acaad2508e7db70ef93fb82.1670542673.git.acdunlap@google.com>
On Fri, 9 Dec 2022 at 07:41, Adam Dunlap via groups.io
<acdunlap=google.com@groups.io> wrote:
>
> When running under SEV-ES, a page of shared memory is allocated for the
> GHCB during the SEC phase at address 0x809000. This page of memory is
> eventually passed to the OS as EfiConventionalMemory. When running
> SEV-SNP, this page is not PVALIDATE'd in the RMP table, meaning that if
> the guest OS tries to access the page, it will think that the host has
> voilated the security guarantees and will likely crash.
>
> This patch validates this page immediately after EDK2 switches to using
> the GHCB page allocated for the PEI phase.
>
> This was tested by writing a UEFI application that reads to and writes
> from one bytes of each page of memory and checks to see if a #VC
> exception is generated indicating that the page was not validated.
>
> Signed-off-by: Adam Dunlap <acdunlap@google.com>
> ---
> OvmfPkg/PlatformPei/AmdSev.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
> index e1b9fd9b7f..c465732068 100644
> --- a/OvmfPkg/PlatformPei/AmdSev.c
> +++ b/OvmfPkg/PlatformPei/AmdSev.c
> @@ -206,6 +206,7 @@ AmdSevEsInitialize (
> {
> UINT8 *GhcbBase;
> PHYSICAL_ADDRESS GhcbBasePa;
> + PHYSICAL_ADDRESS PrevGhcbPa;
> UINTN GhcbPageCount;
> UINT8 *GhcbBackupBase;
> UINT8 *GhcbBackupPages;
> @@ -293,8 +294,24 @@ AmdSevEsInitialize (
> GhcbRegister (GhcbBasePa);
> }
>
> + PrevGhcbPa = AsmReadMsr64 (MSR_SEV_ES_GHCB);
> +
> AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa);
>
> + //
> + // Now that the PEI GHCB is set up, the SEC GHCB page is no longer necessary
> + // to keep shared. Later, it is exposed to the OS as EfiConventionalMemory, so
> + // it needs to be marked private. The size of the region is hardcoded in
> + // OvmfPkg/ResetVector/ResetVector.nasmb in the definition of
> + // SNP_SEC_MEM_BASE_DESC_2.
> + //
> + ASSERT (PrevGhcbPa == FixedPcdGet32(PcdOvmfSecGhcbBase));
> +
> + ASSERT_RETURN_ERROR(MemEncryptSevSetPageEncMask(
> + 0 /*Cr3 -- use system Cr3*/,
> + PrevGhcbPa,
> + 1 /*Number of pages*/));
> +
What happens to this call when ASSERT()s are compiled out?
prev parent reply other threads:[~2022-12-09 20:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 23:43 [PATCH] OvmfPkg/PlatformPei: Validate SEC's GHCB page acdunlap
2022-12-09 16:41 ` [edk2-devel] " Lendacky, Thomas
2022-12-09 18:58 ` [PATCH v2] " Adam Dunlap
2022-12-09 20:06 ` Lendacky, Thomas
2022-12-12 6:51 ` [edk2-devel] " Gerd Hoffmann
2022-12-09 20:08 ` Ard Biesheuvel [this message]
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-list 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='CAMj1kXHRzCiORqsNP-AYGc=3O28Hq7aw6bM-eRyDe1zjGgWCkQ@mail.gmail.com' \
--to=devel@edk2.groups.io \
/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