From patchwork Fri Apr 25 16:09:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 29093 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5446C203AC for ; Fri, 25 Apr 2014 16:11:30 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id m5sf11821607qaj.1 for ; Fri, 25 Apr 2014 09:11:29 -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=7h3AfYgHkfN93OV0UDrMgCPnNHV1DYNrylCV6gOxZZo=; b=ZydbjmKDfMXlshmC8aILNyUIC1KeOiX4v0FdknJ4adwKRyQd9t3SjLbpqOwOpIEakI Q5zt1kKI+bYsxRFFv/Vm9bDlG+C0FeGWDg6pFr08zSEpJL2Y62os1iNMJo5wSnA2/ygN MGmpCBDBnksQ57TK6emCN6BzQbIcIjeb/8N0rI+Spi5IUmQ97w1hwH/Ka02IPYVtH41a iZ9YRUCQfxuG7BbQw4mGuEVwXg1d7UtT/H8arXhVuKi+M9ygrtE7zpE3e3U6KXEcN1gN qXdPH3ZF0Z9CZmeX8A1mz5FOBn8FOLrl+FU2TlxglR6RJonN/o+rg83L5EFeMBigjBts FrjA== X-Gm-Message-State: ALoCoQnZ77KjJ7liOqBomcAMG95lqL4TC6fR2A+Yin45ixIvtv66JZj0tFg+daEl1EuMr1H/ZZMO X-Received: by 10.236.141.11 with SMTP id f11mr4767279yhj.54.1398442289852; Fri, 25 Apr 2014 09:11:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.85.229 with SMTP id n92ls60282qgd.9.gmail; Fri, 25 Apr 2014 09:11:29 -0700 (PDT) X-Received: by 10.58.243.72 with SMTP id ww8mr412651vec.49.1398442289610; Fri, 25 Apr 2014 09:11:29 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id b2si1809121vcy.10.2014.04.25.09.11.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 09:11:29 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lh14so4988421vcb.6 for ; Fri, 25 Apr 2014 09:11:29 -0700 (PDT) X-Received: by 10.58.169.97 with SMTP id ad1mr600610vec.45.1398442289538; Fri, 25 Apr 2014 09:11:29 -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.221.72 with SMTP id ib8csp109704vcb; Fri, 25 Apr 2014 09:11:29 -0700 (PDT) X-Received: by 10.68.170.131 with SMTP id am3mr8636017pbc.97.1398442287738; Fri, 25 Apr 2014 09:11:27 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vv4si5165533pbc.150.2014.04.25.09.11.27 for ; Fri, 25 Apr 2014 09:11:27 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476AbaDYQKs (ORCPT + 28 others); Fri, 25 Apr 2014 12:10:48 -0400 Received: from mail-we0-f170.google.com ([74.125.82.170]:54977 "EHLO mail-we0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753430AbaDYQKn (ORCPT ); Fri, 25 Apr 2014 12:10:43 -0400 Received: by mail-we0-f170.google.com with SMTP id w61so3847660wes.15 for ; Fri, 25 Apr 2014 09:10:41 -0700 (PDT) X-Received: by 10.194.161.168 with SMTP id xt8mr7464164wjb.35.1398442241842; Fri, 25 Apr 2014 09:10:41 -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 uy4sm11813046wjc.8.2014.04.25.09.10.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Apr 2014 09:10:40 -0700 (PDT) From: Leif Lindholm To: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: matt.fleming@intel.com, catalin.marinas@arm.com, msalter@redhat.com, grant.likely@linaro.org, roy.franz@linaro.org, ard.biesheuvel@linaro.org, mark.rutland@arm.com, linux-doc@vger.kernel.org Subject: [PATCH v2 10/10] efi/arm64: ignore dtb= when UEFI SecureBoot is enabled Date: Fri, 25 Apr 2014 17:09:14 +0100 Message-Id: <1398442154-19974-11-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398442154-19974-1-git-send-email-leif.lindholm@linaro.org> References: <1398442154-19974-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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 Acked-by: Matt Fleming --- drivers/firmware/efi/arm-stub.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/arm-stub.c index 19239a9..41114ce 100644 --- a/drivers/firmware/efi/arm-stub.c +++ b/drivers/firmware/efi/arm-stub.c @@ -12,6 +12,30 @@ * */ +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 = 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; + } +} + static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, void **__fh) { @@ -144,7 +168,7 @@ unsigned long __init 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; @@ -196,9 +220,13 @@ unsigned long __init 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); - if (!fdt_addr) { + /* + * 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 { status = handle_cmdline_files(sys_table, image, cmdline_ptr, "dtb=", ~0UL, (unsigned long *)&fdt_addr, @@ -209,6 +237,9 @@ unsigned long __init efi_entry(void *handle, efi_system_table_t *sys_table, goto fail_free_cmdline; } } + if (!fdt_addr) + /* Look for a device tree configuration table entry. */ + fdt_addr = (uintptr_t)get_fdt(sys_table); status = handle_cmdline_files(sys_table, image, cmdline_ptr, "initrd=", dram_base + SZ_512M,