From patchwork Thu Mar 13 22:47:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 3829511 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A10169F1CD for ; Thu, 13 Mar 2014 23:34:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B446A2017D for ; Thu, 13 Mar 2014 23:34:17 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AEFB52017B for ; Thu, 13 Mar 2014 23:34:16 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOETv-0002xR-F5; Thu, 13 Mar 2014 22:52:08 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOESp-0002OR-DO; Thu, 13 Mar 2014 22:50:59 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOEQh-00025P-Rb for linux-arm-kernel@lists.infradead.org; Thu, 13 Mar 2014 22:48:55 +0000 Received: by mail-wi0-f169.google.com with SMTP id hm4so4200460wib.2 for ; Thu, 13 Mar 2014 15:48:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hGsyIs8JCclCkJb9zHmFo29hG35WSugH+TGjh/+Ar04=; b=S/pXbl8lvoMPESy8He1AUEvPy1LDRZI9CUX9jOMa45P8LtL8MvidGBgvZKIllTWyjA 5XVFGesgSY8fwXcCOqQVGICTSLdg1TPpcHQpFq3Yd6hzaZWJTs0thCA6EMIEnqTINPSV bKt/WfPi8s3JfQU1MeoBVxnfVnzi6c+W4zNV9Z2q+Nv5Z/G46bLCCnbDyybF4quOSxYt Vq7MryzMHETqGKZ7hshAv4EJBpjxGrRbADjD5n1tTEbgueLguYMWnIc01Y9FqfTtF/5u EtTjgkslYQa0AHlX6sVWAJIaEHxiQPQS1Ijd7mbE3V3bJtTG5CR1Hg/5uwqcBGWJgJdy 014w== X-Gm-Message-State: ALoCoQm1zLW/lGisp8K/OKioH21AiuU80RJrP/Bxrf06+M4gOeT1Ac1p9BLz2U6VftNRWZJo1mmY X-Received: by 10.194.82.105 with SMTP id h9mr3750450wjy.52.1394750903721; Thu, 13 Mar 2014 15:48:23 -0700 (PDT) Received: from mohikan.mushroom.smurfnet.nu (cpc4-cmbg17-2-0-cust71.5-4.cable.virginm.net. [86.14.224.72]) by mx.google.com with ESMTPSA id dk9sm9072133wjb.4.2014.03.13.15.48.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Mar 2014 15:48:22 -0700 (PDT) From: Leif Lindholm To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, catalin.marinas@arm.com, matt.fleming@intel.com Subject: [PATCH v2 15/15] efi/arm64: ignore dtb= when UEFI SecureBoot is enabled Date: Thu, 13 Mar 2014 22:47:08 +0000 Message-Id: <1394750828-16351-16-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1394750828-16351-1-git-send-email-leif.lindholm@linaro.org> References: <1394750828-16351-1-git-send-email-leif.lindholm@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140313_184848_108082_182DE10C X-CRM114-Status: GOOD ( 13.78 ) X-Spam-Score: -2.6 (--) Cc: roy.franz@linaro.org, Ard Biesheuvel , Leif Lindholm , msalter@redhat.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ard Biesheuvel Loading unauthenticated FDT blobs directly from storage is a security hazard, so this should only be allowed when running with UEFI Secure Boot disabled. Signed-off-by: Ard Biesheuvel Signed-off-by: Leif Lindholm --- drivers/firmware/efi/arm-stub.c | 23 ++++++++++++++--------- drivers/firmware/efi/efi-stub-helper.c | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/arm-stub.c index b505fde..733723c 100644 --- a/drivers/firmware/efi/arm-stub.c +++ b/drivers/firmware/efi/arm-stub.c @@ -41,7 +41,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, /* addr/point and size pairs for memory management*/ unsigned long initrd_addr; u64 initrd_size = 0; - unsigned long fdt_addr; /* Original DTB */ + unsigned long fdt_addr = 0; /* Original DTB */ u64 fdt_size = 0; /* We don't get size from configuration table */ char *cmdline_ptr = NULL; int cmdline_size = 0; @@ -93,15 +93,20 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail_free_image; } - /* Load a device tree from the configuration table, if present. */ - fdt_addr = (uintptr_t)get_fdt(sys_table); + /* + * 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 + handle_cmdline_files(sys_table, image, cmdline_ptr, "dtb=", + ~0UL, (unsigned long *)&fdt_addr, + (unsigned long *)&fdt_size); if (!fdt_addr) { - status = handle_cmdline_files(sys_table, image, cmdline_ptr, - "dtb=", - ~0UL, (unsigned long *)&fdt_addr, - (unsigned long *)&fdt_size); - - if (status != EFI_SUCCESS) { + /* Look for a device tree configuration table entry. */ + fdt_addr = (uintptr_t)get_fdt(sys_table); + if (!fdt_addr) { pr_efi_err(sys_table, "Failed to load device tree!\n"); goto fail_free_cmdline; } diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c index 4a9986b..f2014f2 100644 --- a/drivers/firmware/efi/efi-stub-helper.c +++ b/drivers/firmware/efi/efi-stub-helper.c @@ -704,3 +704,27 @@ static char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, *cmd_line_len = options_bytes; return (char *)cmdline_addr; } + +static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg) +{ + static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID; + static efi_char16_t const var_name[] __initconst = { + 'S', 'e', 'c', 'u', 'r', 'e', 'B', 'o', 'o', 't', 0 }; + + efi_get_variable_t *f_getvar = sys_table_arg->runtime->get_variable; + unsigned long size = sizeof(u8); + efi_status_t status; + u8 val; + + status = efi_call_phys5(f_getvar, (efi_char16_t *)var_name, + (efi_guid_t *)&var_guid, NULL, &size, &val); + + switch (status) { + case EFI_SUCCESS: + return val; + case EFI_NOT_FOUND: + return 0; + default: + return 1; + } +}