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: 26229 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B7156203AC for ; Thu, 13 Mar 2014 22:48:53 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf6210837obc.1 for ; Thu, 13 Mar 2014 15:48:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=GEYXi+bj0rPJBmVvOZ6rf/H72UK49T+LWdckIUuy3m0=; b=aMes0L820K75X/tpZO1NvwJdxLwq5LPuasr900KVLhuXOKukCPdQPcj6UaNUx3uROZ p8yVuqRp/33Lf0uYgUdNBcQx0m9ATfLtrga+yjbdpH/CscsjdT6Nww4/+ME96wdV3vn1 ziMuSK5GrsRWczJpXX6iMa5iEdLFWWDYBjlgs9dScV3vZUhxFd10FglkqpyI/VCyKhk0 I4msho5jEXi3L5EWPrL8UEdsbUcuVMNbgaz/3nAcTSbnYyRqp7UKo4tlsdksbK4Q6I1Y OyyUhIsCRj5vt6aHNGWSg9zebxAOAGhUyLAG0L5igOTAmzv26DiE+rXEQweB7fahnQs3 F3Hw== X-Gm-Message-State: ALoCoQnFeLUgDVXLAWWX+9aoYW6YreuuSjhFyfab3XBpElS2q7khDnVB7P2tBMK3NDwJHj8q55ee X-Received: by 10.182.104.70 with SMTP id gc6mr1737440obb.35.1394750933318; Thu, 13 Mar 2014 15:48:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.130 with SMTP id u2ls441790qga.34.gmail; Thu, 13 Mar 2014 15:48:53 -0700 (PDT) X-Received: by 10.52.189.33 with SMTP id gf1mr2997964vdc.26.1394750933218; Thu, 13 Mar 2014 15:48:53 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id tt2si1400222vdc.48.2014.03.13.15.48.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Mar 2014 15:48:53 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id cz12so1845932veb.2 for ; Thu, 13 Mar 2014 15:48:53 -0700 (PDT) X-Received: by 10.220.147.16 with SMTP id j16mr3131159vcv.28.1394750933104; Thu, 13 Mar 2014 15:48:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp10220vck; Thu, 13 Mar 2014 15:48:52 -0700 (PDT) X-Received: by 10.68.178.1 with SMTP id cu1mr5375995pbc.34.1394750932278; Thu, 13 Mar 2014 15:48:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wh10si2380748pab.140.2014.03.13.15.48.51; Thu, 13 Mar 2014 15:48:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755527AbaCMWsj (ORCPT + 26 others); Thu, 13 Mar 2014 18:48:39 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:51105 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755484AbaCMWsZ (ORCPT ); Thu, 13 Mar 2014 18:48:25 -0400 Received: by mail-wi0-f180.google.com with SMTP id hm4so1842040wib.7 for ; Thu, 13 Mar 2014 15:48:23 -0700 (PDT) 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 Cc: msalter@redhat.com, roy.franz@linaro.org, Ard Biesheuvel , Leif Lindholm 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: leif.lindholm@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; + } +}