public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Linn Crosetto <linn@hpe.com>
To: matt@codeblueprint.co.uk, ard.biesheuvel@linaro.org,
	roy.franz@linaro.org, mingo@kernel.org, mark.rutland@arm.com
Cc: linux-kernel@vger.kernel.org, Linn Crosetto <linn@hpe.com>
Subject: [PATCH v2 1/2] arm64/efi: report unexpected errors when determining Secure Boot status
Date: Thu, 25 Feb 2016 17:18:14 -0700	[thread overview]
Message-ID: <1456445895-97647-2-git-send-email-linn@hpe.com> (raw)
In-Reply-To: <1456445895-97647-1-git-send-email-linn@hpe.com>

Certain code in the boot path may require the ability to determine whether
UEFI Secure Boot is definitely enabled, for example printing status to the
console. Other code may need to know when UEFI Secure Boot is definitely
disabled, for example restricting use of kernel parameters.

If an unexpected error is returned from GetVariable when querying the
status of UEFI Secure Boot, return an error to the caller. This allows the
caller to determine the definite state, and to take appropriate action if
an expected error is returned.

Signed-off-by: Linn Crosetto <linn@hpe.com>
---
New patch in v2 based on feedback from v1:

 - Maintain existing behavior to allow 'dtb=' parameter only when UEFI
   Secure Boot is disabled and not in an unknown state. (Mark Rutland)

 drivers/firmware/efi/libstub/arm-stub.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
index 3397902..b1bb133 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -18,7 +18,7 @@
 
 #include "efistub.h"
 
-static int efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
+static int efi_get_secureboot(efi_system_table_t *sys_table_arg)
 {
 	static efi_guid_t const var_guid = EFI_GLOBAL_VARIABLE_GUID;
 	static efi_char16_t const var_name[] = {
@@ -37,8 +37,12 @@ static int efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
 		return val;
 	case EFI_NOT_FOUND:
 		return 0;
+	case EFI_DEVICE_ERROR:
+		return -EIO;
+	case EFI_SECURITY_VIOLATION:
+		return -EACCES;
 	default:
-		return 1;
+		return -EINVAL;
 	}
 }
 
@@ -183,6 +187,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
 	efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID;
 	unsigned long reserve_addr = 0;
 	unsigned long reserve_size = 0;
+	int secure_boot = 0;
 
 	/* Check if we were booted by the EFI firmware */
 	if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
@@ -231,13 +236,15 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
 	if (status != EFI_SUCCESS)
 		pr_efi_err(sys_table, "Failed to parse EFI cmdline options\n");
 
+	secure_boot = efi_get_secureboot(sys_table);
+	if (secure_boot > 0)
+		pr_efi(sys_table, "UEFI Secure Boot is enabled.\n");
+
 	/*
 	 * Unauthenticated device tree data is a security hazard, so
 	 * ignore 'dtb=' unless UEFI Secure Boot is disabled.
 	 */
-	if (efi_secureboot_enabled(sys_table)) {
-		pr_efi(sys_table, "UEFI Secure Boot is enabled.\n");
-	} else {
+	if (secure_boot == 0) {
 		status = handle_cmdline_files(sys_table, image, cmdline_ptr,
 					      "dtb=",
 					      ~0UL, &fdt_addr, &fdt_size);
-- 
2.1.4

  reply	other threads:[~2016-02-26  0:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-24  0:25 [PATCH] arm64/efi: check SetupMode when determining Secure Boot status Linn Crosetto
2016-02-24 11:23 ` Mark Rutland
2016-02-26  0:18 ` [PATCH v2 0/2] arm64/efi: query Secure Boot status according to UEFI spec Linn Crosetto
2016-02-26  0:18   ` Linn Crosetto [this message]
2016-03-03  8:03     ` [PATCH v2 1/2] arm64/efi: report unexpected errors when determining Secure Boot status Ard Biesheuvel
2016-02-26  0:18   ` [PATCH v2 2/2] arm64/efi: check SetupMode " Linn Crosetto
2016-03-02 13:38   ` [PATCH v2 0/2] arm64/efi: query Secure Boot status according to UEFI spec Matt Fleming
2016-03-03 21:45   ` [PATCH v3 " Linn Crosetto
2016-03-03 21:45     ` [PATCH v3 1/2] arm64/efi: report unexpected errors when determining Secure Boot status Linn Crosetto
2016-03-04  7:57       ` Ard Biesheuvel
2016-03-03 21:45     ` [PATCH v3 2/2] arm64/efi: check SetupMode " Linn Crosetto
2016-03-04  8:01       ` Ard Biesheuvel
2016-03-04 11:08     ` [PATCH v3 0/2] arm64/efi: query Secure Boot status according to UEFI spec Mark Rutland
2016-03-07 14:08     ` Matt Fleming

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=1456445895-97647-2-git-send-email-linn@hpe.com \
    --to=linn@hpe.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=roy.franz@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox