From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: devel@edk2.groups.io, lersek@redhat.com
Cc: Anthony Perard <anthony.perard@citrix.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Jordan Justen <jordan.l.justen@intel.com>,
Julien Grall <julien.grall@arm.com>
Subject: Re: [edk2-devel] [PATCH 13/16] OvmfPkg/EnrollDefaultKeys: document the steps of the entry point function
Date: Mon, 29 Apr 2019 14:36:15 +0200 [thread overview]
Message-ID: <5231b832-9086-a4e5-7bb0-919f69eb4701@redhat.com> (raw)
In-Reply-To: <20190427005328.27005-14-lersek@redhat.com>
On 4/27/19 2:53 AM, Laszlo Ersek wrote:
> The entry point function of EnrollDefaultKeys finishes with a sanity
> check, verifying the values of the Secure Boot-related "control"
> variables. Add a diagram to explain why we expect the values we do.
>
> While at it, write comments on the rest of the entry point function.
>
> Cc: Anthony Perard <anthony.perard@citrix.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Julien Grall <julien.grall@arm.com>
> Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1747
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c | 54 ++++++++++++++++++++
> 1 file changed, 54 insertions(+)
>
> diff --git a/OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c b/OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c
> index 07297c631f38..9c4a0f06fb4d 100644
> --- a/OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c
> +++ b/OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c
> @@ -356,92 +356,146 @@ EFIAPI
> ShellAppMain (
> IN UINTN Argc,
> IN CHAR16 **Argv
> )
> {
> EFI_STATUS Status;
> SETTINGS Settings;
>
> + //
> + // If we're not in Setup Mode, we can't do anything.
> + //
> Status = GetSettings (&Settings);
> if (EFI_ERROR (Status)) {
> return 1;
> }
> PrintSettings (&Settings);
>
> if (Settings.SetupMode != 1) {
> AsciiPrint ("error: already in User Mode\n");
> return 1;
> }
>
> + //
> + // Enter Custom Mode so we can enroll PK, KEK, db, and dbx without signature
> + // checks on those variable writes.
> + //
> if (Settings.CustomMode != CUSTOM_SECURE_BOOT_MODE) {
> Settings.CustomMode = CUSTOM_SECURE_BOOT_MODE;
> Status = gRT->SetVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid,
> (EFI_VARIABLE_NON_VOLATILE |
> EFI_VARIABLE_BOOTSERVICE_ACCESS),
> sizeof Settings.CustomMode, &Settings.CustomMode);
> if (EFI_ERROR (Status)) {
> AsciiPrint ("error: SetVariable(\"%s\", %g): %r\n", EFI_CUSTOM_MODE_NAME,
> &gEfiCustomModeEnableGuid, Status);
> return 1;
> }
> }
>
> + //
> + // Enroll db.
> + //
> Status = EnrollListOfCerts (
> EFI_IMAGE_SECURITY_DATABASE,
> &gEfiImageSecurityDatabaseGuid,
> &gEfiCertX509Guid,
> mMicrosoftPca, mSizeOfMicrosoftPca, &gMicrosoftVendorGuid,
> mMicrosoftUefiCa, mSizeOfMicrosoftUefiCa, &gMicrosoftVendorGuid,
> NULL);
> if (EFI_ERROR (Status)) {
> return 1;
> }
>
> + //
> + // Enroll dbx.
> + //
> Status = EnrollListOfCerts (
> EFI_IMAGE_SECURITY_DATABASE1,
> &gEfiImageSecurityDatabaseGuid,
> &gEfiCertSha256Guid,
> mSha256OfDevNull, mSizeOfSha256OfDevNull, &gEfiCallerIdGuid,
> NULL);
> if (EFI_ERROR (Status)) {
> return 1;
> }
>
> + //
> + // Enroll KEK.
> + //
> Status = EnrollListOfCerts (
> EFI_KEY_EXCHANGE_KEY_NAME,
> &gEfiGlobalVariableGuid,
> &gEfiCertX509Guid,
> mRedHatPkKek1, mSizeOfRedHatPkKek1, &gEfiCallerIdGuid,
> mMicrosoftKek, mSizeOfMicrosoftKek, &gMicrosoftVendorGuid,
> NULL);
> if (EFI_ERROR (Status)) {
> return 1;
> }
>
> + //
> + // Enroll PK, leaving Setup Mode (entering User Mode) at once.
> + //
> Status = EnrollListOfCerts (
> EFI_PLATFORM_KEY_NAME,
> &gEfiGlobalVariableGuid,
> &gEfiCertX509Guid,
> mRedHatPkKek1, mSizeOfRedHatPkKek1, &gEfiGlobalVariableGuid,
> NULL);
> if (EFI_ERROR (Status)) {
> return 1;
> }
>
> + //
> + // Leave Custom Mode, so that updates to PK, KEK, db, and dbx require valid
> + // signatures.
> + //
> Settings.CustomMode = STANDARD_SECURE_BOOT_MODE;
> Status = gRT->SetVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid,
> EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
> sizeof Settings.CustomMode, &Settings.CustomMode);
> if (EFI_ERROR (Status)) {
> AsciiPrint ("error: SetVariable(\"%s\", %g): %r\n", EFI_CUSTOM_MODE_NAME,
> &gEfiCustomModeEnableGuid, Status);
> return 1;
> }
>
> + //
> + // Final sanity check:
> + //
> + // [SetupMode]
> + // (read-only, standardized by UEFI)
> + // / \_
> + // 0 1, default
> + // / \_
> + // PK enrolled no PK enrolled yet,
> + // (this is called "User Mode") PK enrollment possible
> + // |
> + // |
> + // [SecureBootEnable]
> + // (read-write, edk2-specific, boot service only)
> + // / \_
> + // 0 1, default
> + // / \_
> + // [SecureBoot]=0 [SecureBoot]=1
> + // (read-only, standardized by UEFI) (read-only, standardized by UEFI)
> + // images are not verified images are verified, platform is
> + // operating in Secure Boot mode
> + // |
> + // |
> + // [CustomMode]
> + // (read-write, edk2-specific, boot service only)
> + // / \_
> + // 0, default 1
> + // / \_
> + // PK, KEK, db, dbx PK, KEK, db, dbx
> + // updates are verified updates are not verified
> + //
Very helpful.
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
> Status = GetSettings (&Settings);
> if (EFI_ERROR (Status)) {
> return 1;
> }
> PrintSettings (&Settings);
>
> if (Settings.SetupMode != 0 || Settings.SecureBoot != 1 ||
> Settings.SecureBootEnable != 1 || Settings.CustomMode != 0 ||
>
next prev parent reply other threads:[~2019-04-29 12:36 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-27 0:53 [PATCH 00/16] OvmfPkg, ArmVirtPkg: upstream the EnrollDefaultKeys app Laszlo Ersek
2019-04-27 0:53 ` [PATCH 01/16] OvmfPkg: introduce EnrollDefaultKeys application Laszlo Ersek
2019-04-30 5:21 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 02/16] OvmfPkg/EnrollDefaultKeys: update @file comment blocks Laszlo Ersek
2019-04-30 5:13 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 03/16] OvmfPkg/EnrollDefaultKeys: refresh INF file Laszlo Ersek
2019-04-29 12:25 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 04/16] ArmVirtPkg: build EnrollDefaultKeys.efi Laszlo Ersek
2019-04-29 12:26 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 05/16] OvmfPkg/EnrollDefaultKeys: clean up minor whitespace wart Laszlo Ersek
2019-04-29 12:26 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 06/16] OvmfPkg/EnrollDefaultKeys: clean up global variable name prefixes Laszlo Ersek
2019-04-29 12:27 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 07/16] OvmfPkg/EnrollDefaultKeys: clean up acronym capitalization in identifiers Laszlo Ersek
2019-04-30 5:10 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 08/16] OvmfPkg/EnrollDefaultKeys: remove unneeded EFIAPI call. conv. specifiers Laszlo Ersek
2019-04-29 12:28 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 09/16] OvmfPkg/EnrollDefaultKeys: extract typedefs to a header file Laszlo Ersek
2019-04-29 12:30 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 10/16] OvmfPkg/EnrollDefaultKeys: split out certificate and signature constants Laszlo Ersek
2019-04-29 12:33 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 11/16] OvmfPkg/EnrollDefaultKeys: extract MICROSOFT_VENDOR_GUID Laszlo Ersek
2019-04-30 5:11 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 12/16] OvmfPkg/EnrollDefaultKeys: describe functions with leading comment blocks Laszlo Ersek
2019-04-30 5:12 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 13/16] OvmfPkg/EnrollDefaultKeys: document the steps of the entry point function Laszlo Ersek
2019-04-29 12:36 ` Philippe Mathieu-Daudé [this message]
2019-04-27 0:53 ` [PATCH 14/16] OvmfPkg: introduce OVMF_PK_KEK1_APP_PREFIX_GUID Laszlo Ersek
2019-04-30 5:24 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 15/16] OvmfPkg/EnrollDefaultKeys: enroll PK/KEK1 from the Type 11 SMBIOS table Laszlo Ersek
2019-04-30 5:34 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 0:53 ` [PATCH 16/16] OvmfPkg/EnrollDefaultKeys: remove Red Hat's hard-coded PK/KEK1 Laszlo Ersek
2019-04-30 5:35 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-04-27 1:07 ` [edk2-devel] [PATCH 00/16] OvmfPkg, ArmVirtPkg: upstream the EnrollDefaultKeys app Laszlo Ersek
2019-04-27 8:14 ` Ard Biesheuvel
2019-04-30 7:51 ` [edk2-devel] " Gary Lin
2019-04-30 12:32 ` Laszlo Ersek
2019-04-30 19:42 ` Ard Biesheuvel
2019-04-30 20:04 ` Laszlo Ersek
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=5231b832-9086-a4e5-7bb0-919f69eb4701@redhat.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