From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Fri, 26 Apr 2019 17:54:11 -0700 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53215A049B; Sat, 27 Apr 2019 00:54:11 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-121-104.rdu2.redhat.com [10.10.121.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEE6D5D71B; Sat, 27 Apr 2019 00:54:09 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Anthony Perard , Ard Biesheuvel , Jordan Justen , Julien Grall Subject: [PATCH 13/16] OvmfPkg/EnrollDefaultKeys: document the steps of the entry point function Date: Sat, 27 Apr 2019 02:53:25 +0200 Message-Id: <20190427005328.27005-14-lersek@redhat.com> In-Reply-To: <20190427005328.27005-1-lersek@redhat.com> References: <20190427005328.27005-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 27 Apr 2019 00:54:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Julien Grall Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1747 Signed-off-by: Laszlo Ersek --- OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.c b/OvmfPkg/Enro= llDefaultKeys/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; =20 + // + // If we're not in Setup Mode, we can't do anything. + // Status =3D GetSettings (&Settings); if (EFI_ERROR (Status)) { return 1; } PrintSettings (&Settings); =20 if (Settings.SetupMode !=3D 1) { AsciiPrint ("error: already in User Mode\n"); return 1; } =20 + // + // Enter Custom Mode so we can enroll PK, KEK, db, and dbx without sig= nature + // checks on those variable writes. + // if (Settings.CustomMode !=3D CUSTOM_SECURE_BOOT_MODE) { Settings.CustomMode =3D CUSTOM_SECURE_BOOT_MODE; Status =3D gRT->SetVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEn= ableGuid, (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_MOD= E_NAME, &gEfiCustomModeEnableGuid, Status); return 1; } } =20 + // + // Enroll db. + // Status =3D EnrollListOfCerts ( EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid, &gEfiCertX509Guid, mMicrosoftPca, mSizeOfMicrosoftPca, &gMicrosoftVendor= Guid, mMicrosoftUefiCa, mSizeOfMicrosoftUefiCa, &gMicrosoftVendor= Guid, NULL); if (EFI_ERROR (Status)) { return 1; } =20 + // + // Enroll dbx. + // Status =3D EnrollListOfCerts ( EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid, &gEfiCertSha256Guid, mSha256OfDevNull, mSizeOfSha256OfDevNull, &gEfiCallerIdGuid= , NULL); if (EFI_ERROR (Status)) { return 1; } =20 + // + // Enroll KEK. + // Status =3D EnrollListOfCerts ( EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid, &gEfiCertX509Guid, mRedHatPkKek1, mSizeOfRedHatPkKek1, &gEfiCallerIdGuid, mMicrosoftKek, mSizeOfMicrosoftKek, &gMicrosoftVendorGuid, NULL); if (EFI_ERROR (Status)) { return 1; } =20 + // + // Enroll PK, leaving Setup Mode (entering User Mode) at once. + // Status =3D EnrollListOfCerts ( EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid, &gEfiCertX509Guid, mRedHatPkKek1, mSizeOfRedHatPkKek1, &gEfiGlobalVariableGuid= , NULL); if (EFI_ERROR (Status)) { return 1; } =20 + // + // Leave Custom Mode, so that updates to PK, KEK, db, and dbx require = valid + // signatures. + // Settings.CustomMode =3D STANDARD_SECURE_BOOT_MODE; Status =3D gRT->SetVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnab= leGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A= CCESS, sizeof Settings.CustomMode, &Settings.CustomMode); if (EFI_ERROR (Status)) { AsciiPrint ("error: SetVariable(\"%s\", %g): %r\n", EFI_CUSTOM_MODE_= NAME, &gEfiCustomModeEnableGuid, Status); return 1; } =20 + // + // Final sanity check: + // + // [SetupMode] + // (read-only, standardized by UEFI) + // / \_ + // 0 1, default + // / \_ + // PK enrolled no PK enrolled y= et, + // (this is called "User Mode") PK enrollment po= ssible + // | + // | + // [SecureBootEnable] + // (read-write, edk2-specific, boot service only) + // / \_ + // 0 1, default + // / \_ + // [SecureBoot]=3D0 [SecureBoot]=3D1 + // (read-only, standardized by UEFI) (read-only, standardized by UEFI= ) + // images are not verified images are verified, platform i= s + // operating in Secure Boot mode + // | + // | + // [CustomMode] + // (read-write, edk2-specific, boot service o= nly) + // / \_ + // 0, default 1 + // / \_ + // PK, KEK, db, dbx PK, KEK, db, d= bx + // updates are verified updates are not ve= rified + // Status =3D GetSettings (&Settings); if (EFI_ERROR (Status)) { return 1; } PrintSettings (&Settings); =20 if (Settings.SetupMode !=3D 0 || Settings.SecureBoot !=3D 1 || Settings.SecureBootEnable !=3D 1 || Settings.CustomMode !=3D 0 || --=20 2.19.1.3.g30247aa5d201