All of lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v5 06/16] efi_loader: variable: add VendorKeys variable
Date: Tue, 28 Jan 2020 17:25:22 +0900	[thread overview]
Message-ID: <20200128082532.15943-7-takahiro.akashi@linaro.org> (raw)
In-Reply-To: <20200128082532.15943-1-takahiro.akashi@linaro.org>

The following variable is exported as UEFI specification defines:
VendorKeys: whether the system is configured to use only vendor-provided
	    keys or not
The value will have to be modified if a platform has its own way of
initializing signature database, in particular, PK.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 lib/efi_loader/efi_variable.c | 69 ++++++++++++++++++++++++++++++++---
 1 file changed, 63 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 17ea7d382d4b..05d8f2ad8123 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -26,6 +26,7 @@ enum efi_secure_mode {
 const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
 static bool efi_secure_boot;
 static int efi_secure_mode;
+static u8 efi_vendor_keys;
 
 #define READ_ONLY BIT(31)
 
@@ -343,6 +344,8 @@ static efi_status_t efi_transfer_secure_state(enum efi_secure_mode mode)
 		return EFI_INVALID_PARAMETER;
 	}
 
+	efi_secure_mode = mode;
+
 	return EFI_SUCCESS;
 
 err:
@@ -358,16 +361,46 @@ err:
  */
 static efi_status_t efi_init_secure_state(void)
 {
-	efi_uintn_t size = 0;
+	enum efi_secure_mode mode;
+	efi_uintn_t size;
 	efi_status_t ret;
 
+	/*
+	 * TODO:
+	 * Since there is currently no "platform-specific" installation
+	 * method of Platform Key, we can't say if VendorKeys is 0 or 1
+	 * precisely.
+	 */
+
+	size = 0;
 	ret = EFI_CALL(efi_get_variable(L"PK", &efi_global_variable_guid,
 					NULL, &size, NULL));
-	if (ret == EFI_BUFFER_TOO_SMALL && IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
-		ret = efi_transfer_secure_state(EFI_MODE_USER);
-	else
-		ret = efi_transfer_secure_state(EFI_MODE_SETUP);
+	if (ret == EFI_BUFFER_TOO_SMALL) {
+		if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
+			mode = EFI_MODE_USER;
+		else
+			mode = EFI_MODE_SETUP;
+
+		efi_vendor_keys = 0;
+	} else if (ret == EFI_NOT_FOUND) {
+		mode = EFI_MODE_SETUP;
+		efi_vendor_keys = 1;
+	} else {
+		goto err;
+	}
 
+	ret = efi_transfer_secure_state(mode);
+	if (ret == EFI_SUCCESS)
+		ret = efi_set_variable_internal(L"VendorKeys",
+						&efi_global_variable_guid,
+						EFI_VARIABLE_BOOTSERVICE_ACCESS
+						 | EFI_VARIABLE_RUNTIME_ACCESS
+						 | READ_ONLY,
+						sizeof(efi_vendor_keys),
+						&efi_vendor_keys,
+						false);
+
+err:
 	return ret;
 }
 
@@ -1123,6 +1156,8 @@ out:
 	if (env_set(native_name, val)) {
 		ret = EFI_DEVICE_ERROR;
 	} else {
+		bool vendor_keys_modified = false;
+
 		if ((u16_strcmp(variable_name, L"PK") == 0 &&
 		     guidcmp(vendor, &efi_global_variable_guid) == 0)) {
 			ret = efi_transfer_secure_state(
@@ -1130,8 +1165,30 @@ out:
 						  EFI_MODE_USER));
 			if (ret != EFI_SUCCESS)
 				goto err;
+
+			if (efi_secure_mode != EFI_MODE_SETUP)
+				vendor_keys_modified = true;
+		} else if ((u16_strcmp(variable_name, L"KEK") == 0 &&
+		     guidcmp(vendor, &efi_global_variable_guid) == 0)) {
+			if (efi_secure_mode != EFI_MODE_SETUP)
+				vendor_keys_modified = true;
+		}
+
+		/* update VendorKeys */
+		if (vendor_keys_modified & efi_vendor_keys) {
+			efi_vendor_keys = 0;
+			ret = efi_set_variable_internal(
+						L"VendorKeys",
+						&efi_global_variable_guid,
+						EFI_VARIABLE_BOOTSERVICE_ACCESS
+						 | EFI_VARIABLE_RUNTIME_ACCESS
+						 | READ_ONLY,
+						sizeof(efi_vendor_keys),
+						&efi_vendor_keys,
+						false);
+		} else {
+			ret = EFI_SUCCESS;
 		}
-		ret = EFI_SUCCESS;
 	}
 
 err:
-- 
2.24.0

  parent reply	other threads:[~2020-01-28  8:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28  8:25 [PATCH v5 00/16] efi_loader: add secure boot support AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 01/16] efi_loader: add CONFIG_EFI_SECURE_BOOT config option AKASHI Takahiro
2020-02-23 10:56   ` Heinrich Schuchardt
2020-02-25  5:02     ` AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 02/16] efi_loader: add signature verification functions AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 03/16] efi_loader: add signature database parser AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 04/16] efi_loader: variable: support variable authentication AKASHI Takahiro
2020-02-23 11:20   ` Heinrich Schuchardt
2020-02-25  5:10     ` AKASHI Takahiro
2020-02-25  6:46   ` Heinrich Schuchardt
2020-02-26  0:51     ` AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 05/16] efi_loader: variable: add secure boot state transition AKASHI Takahiro
2020-01-28  8:25 ` AKASHI Takahiro [this message]
2020-01-28  8:25 ` [PATCH v5 07/16] efi_loader: image_loader: support image authentication AKASHI Takahiro
2020-02-24 18:29   ` Heinrich Schuchardt
2020-02-25  5:25     ` AKASHI Takahiro
2020-02-25  6:40       ` Heinrich Schuchardt
2020-02-25  6:57         ` AKASHI Takahiro
2020-02-25  6:44   ` Heinrich Schuchardt
2020-02-26  0:50     ` AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 08/16] efi_loader: set up secure boot AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 09/16] cmd: env: use appropriate guid for authenticated UEFI variable AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 10/16] cmd: env: add "-at" option to "env set -e" command AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 11/16] cmd: efidebug: add "test bootmgr" sub-command AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 12/16] efi_loader, pytest: set up secure boot environment AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 13/16] efi_loader, pytest: add UEFI secure boot tests (authenticated variables) AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 14/16] efi_loader, pytest: add UEFI secure boot tests (image) AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 15/16] sandbox: add extra configurations for UEFI and related tests AKASHI Takahiro
2020-01-28  8:25 ` [PATCH v5 16/16] travis: add packages for UEFI secure boot test AKASHI Takahiro
2020-02-23 11:46   ` Heinrich Schuchardt
2020-02-25  5:16     ` AKASHI Takahiro
2020-02-23 11:53 ` [PATCH v5 00/16] efi_loader: add secure boot support Heinrich Schuchardt
2020-02-25  5:19   ` AKASHI Takahiro
2020-02-23 21:48 ` Heinrich Schuchardt

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=20200128082532.15943-7-takahiro.akashi@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /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.