From patchwork Mon Nov 30 14:58:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Alcantara X-Patchwork-Id: 1408340 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=cjr.nz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=cjr.nz header.i=@cjr.nz header.a=rsa-sha256 header.s=dkim header.b=qGeVZd4a; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cl7fv3FNLz9ryj for ; Tue, 1 Dec 2020 01:59:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D64E82638; Mon, 30 Nov 2020 15:58:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=cjr.nz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=cjr.nz header.i=@cjr.nz header.b="qGeVZd4a"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E51D82646; Mon, 30 Nov 2020 15:58:55 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx.cjr.nz (mx.cjr.nz [51.158.111.142]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4FB2382636 for ; Mon, 30 Nov 2020 15:58:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=cjr.nz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pc@cjr.nz Received: from authenticated-user (mx.cjr.nz [51.158.111.142]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pc) by mx.cjr.nz (Postfix) with ESMTPSA id B70417FD0A; Mon, 30 Nov 2020 14:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cjr.nz; s=dkim; t=1606748331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ERHcqdTS/lyoL2TqZxoSVLigkdxovUP7uaM/4RslSwY=; b=qGeVZd4aXhU26wDChuhv34MnOGyZpMeWsjTt2v7k2uSH/ueEfScZyGsmyR+U2HQhl7lchQ aCIiZMmQFsIAmTlsn8EEelKtHxHTIuIYAmxTyTtMbggNRuxNua1itRLDF6Wx/OociYVDME sBsi66nYyxDDLHfYB1h5ksVXzySGDQqMuZQUGpo0Grhsarp8vI2UFlwMgQFcIJ7L8IwjGG 2w+gVI8VxaOTTzNn+ocK5c2Y2ldl5iDlToTCpF6+cNfNy/NP+8J+9HjqKsCJS/5dMniFvl qSQzp1GX8bVK90/bj/UPm8napzgB2iq1kAoj8tHSuuNQC8WlTCy86rMpMUTPwA== From: Paulo Alcantara To: xypron.glpk@gmx.de, agraf@csgraf.de, u-boot@lists.denx.de Cc: Paulo Alcantara Subject: [PATCH] efi_loader: allow disabling EFI secure boot in User Mode Date: Mon, 30 Nov 2020 11:58:39 -0300 Message-Id: <20201130145839.31620-1-pc@cjr.nz> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Introduce a new config option CONFIG_EFI_SECURE_BOOT_VAR_DISABLE to allow disabling EFI secure boot when the platform is operating in User Mode and there is an NV+BS EFI variable called "SecureBootDisable". Otherwise, keep it enabled by default. Signed-off-by: Paulo Alcantara (SUSE) --- lib/efi_loader/Kconfig | 13 +++++++++ lib/efi_loader/efi_var_common.c | 48 ++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 29ea14b2ee2a..d453905c7666 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -224,5 +224,18 @@ config EFI_SECURE_BOOT Once SecureBoot mode is enforced, any EFI binary can run only if it is signed with a trusted key. To do that, you need to install, at least, PK, KEK and db. + Note that SecureBoot mode may no longer be enforced when + EFI_SECURE_BOOT_VAR_DISABLE option is enabled. + +config EFI_SECURE_BOOT_VAR_DISABLE + bool "Permit to disable EFI secure boot when in User Mode" + depends on EFI_SECURE_BOOT + default n + help + Select this option to allow disabling EFI secure boot when + the platform is operating in User Mode (e.g. PK is enrolled) + and there is an NV+BS EFI variable called + "SecureBootDisable". A platform reset is also required to + actually disable it. endif diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 1c7459266a38..89aa944180a4 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -241,6 +241,48 @@ err: return ret; } + +#ifdef CONFIG_EFI_SECURE_BOOT_VAR_DISABLE +/** + * efi_secure_boot_in_user_mode - check if secure boot enabled in User Mode + * + * @enabled: true if enabled, false if disabled + * + * Return: status code + */ +static efi_status_t efi_secure_boot_in_user_mode(u8 *enabled) +{ + efi_status_t ret; + efi_uintn_t size = 0; + u32 attributes; + u32 mask = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS; + + ret = efi_get_variable_int(L"SecureBootDisable", + &efi_global_variable_guid, + &attributes, &size, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + if (attributes ^ mask) { + log_err("Unable to disable secure boot. Required attributes for SecureBootDisable variable: NV+BS\n"); + *enabled = 1; + } else { + EFI_PRINT("Disabling secure boot due to existing SecureBootDisable variable\n"); + *enabled = 0; + } + ret = EFI_SUCCESS; + } else if (ret == EFI_NOT_FOUND) { + *enabled = 1; + ret = EFI_SUCCESS; + } + return ret; +} +#else +static efi_status_t efi_secure_boot_in_user_mode(u8 *enabled) +{ + *enabled = 1; + return EFI_SUCCESS; +} +#endif + /** * efi_transfer_secure_state - handle a secure boot state transition * @mode: new state @@ -274,7 +316,11 @@ static efi_status_t efi_transfer_secure_state(enum efi_secure_mode mode) if (ret != EFI_SUCCESS) goto err; } else if (mode == EFI_MODE_USER) { - ret = efi_set_secure_state(1, 0, 0, 0); + u8 secure_boot; + ret = efi_secure_boot_in_user_mode(&secure_boot); + if (ret != EFI_SUCCESS) + goto err; + ret = efi_set_secure_state(secure_boot, 0, 0, 0); if (ret != EFI_SUCCESS) goto err; } else if (mode == EFI_MODE_SETUP) {