From patchwork Sun Apr 29 11:06:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134662 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2663700lji; Sun, 29 Apr 2018 04:06:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoLEjSJBp83olspbeScRlsoqjCJkEE6qXIWzBZMaSkMjxZOJ2gAp22ur4WZCnhcczcTc4wV X-Received: by 10.98.57.156 with SMTP id u28mr8522743pfj.95.1525000007392; Sun, 29 Apr 2018 04:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525000007; cv=none; d=google.com; s=arc-20160816; b=OcwOQYwj1ArZ6Frx3Le5kMBc68J+/Sbfcn8yKVKMLfhuTo5JBo22sGPIkgFuDOBZHr cDuekpO+UoAYICp8k11XRYWGF6Cl5aShLTQQRCVW9cFhE1qhoYX2MzEb/rXrjKkEbqH9 Kk25dIDgbq92WrZGn2oy2mKYgPqb5Nur9bIJ2UurpNKEc8H9l58qnGObIC9B3Wa9Z10e V5OLhDKf1yyRHdpnJ3VgnK/1LYD6RSQcLhU6ovRKR4iBgmICxkXP+FeOQHCib2l+arTl 2H2BmuxQiC0LomjZIEUTzHWm2jKiEMNKyZY/gR/OY3rEvs5lHj7bPDBR3keFyBLjZuAq /Rlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=NRBdI/TLBiUCtES3AhqlixTdIjE6BLtmoIRgeZIVkGY=; b=OkwVSYQUzhksk+pWCObn+qCB8tDdb62Pw87FLd8fujtO6F1bI6/hWfNwBrSgSoSP8G angZx2c7IN6k2UTQ83Qz9SELCkA40FJir2GlklVIPelo/kR6dan1HCzljBjpdsBPocar SwF1yDwL+xc9O35jYbS7zXbBthADoCInVOAZ5py8qa3FKoyr/leFd1er7q2IuZRqpoTy qtqV8VLOanM88/Y3cONkWcIrkLHUgFZQIwYXihy7OxQd3BAjE93yjN+8ZeR/mt9xle6I gKQiBiEFfVjipCIfBY+4X8tNRm7FlyqvEJ9GwvOrWubVS4gswaNuKTSpxKRGnQMTKL+P FUcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Mx20oTuQ; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si5369654plo.263.2018.04.29.04.06.47; Sun, 29 Apr 2018 04:06:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Mx20oTuQ; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752895AbeD2LGq (ORCPT + 2 others); Sun, 29 Apr 2018 07:06:46 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:40815 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752864AbeD2LGp (ORCPT ); Sun, 29 Apr 2018 07:06:45 -0400 Received: by mail-wr0-f193.google.com with SMTP id v60-v6so5527845wrc.7 for ; Sun, 29 Apr 2018 04:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wZm8+qDlhYAaGmAENHwDDzLI1CHyjII/6z4l9kThx7g=; b=Mx20oTuQxGvez2gnr6L2cjJjfoosRC3JHI+AVVng5yaiPx03k0zlsuzYTdQ1ovD3SG YI7mun71OcStuQaFUlT54ItXnwGbEUSvc/4phGLb7bqj1krNSonyE7OeYadGmXZJZfkn 1WL/B2dcfy9FI6Q3Nri1RxtHlre1EhIVzZ1Fg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wZm8+qDlhYAaGmAENHwDDzLI1CHyjII/6z4l9kThx7g=; b=EcM7EfStWONyAGHF0lQ4RPSgDMv7/0D6JIc4H/f5fOmbm3ReRMoyADkXLl9N6Z7Uol /9YsU3Q1IDBql5EIPQH0MC+09zCDFAqjchASnpLOciDkkMGHHDiMMuNwzo0kOnhNQfsA nqwRY+L3YqYiRCegU1KBipVJ9GS2LiYP3HnOkyubDW/Tmgwlny5BZVsPgI3bR6P7Gl3n LOvPiNF89xQ7B5K3bYCXmge+Hf8tZufyrDiAHnjv9qxdCfvP7dT+/zePiUDXYJGQAyUR c4n0OASNUwgrTT0ttla3xuN2qbT0fogUx1Z7x+NNPt/LX+IYtRAHPbHc0XUND/KA9JVU hrAw== X-Gm-Message-State: ALQs6tDvuWqs2/f91T9gzxSAcTzTVyo8hPhseDhXqAIA1HTQMqWAg6uj ZABa8xVapM7Gb54KBZ0Qi06AZg== X-Received: by 2002:adf:984c:: with SMTP id v70-v6mr6283562wrb.100.1525000004708; Sun, 29 Apr 2018 04:06:44 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id a13-v6sm4783275wrc.19.2018.04.29.04.06.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 04:06:43 -0700 (PDT) From: Ard Biesheuvel To: mingo@kernel.org, hdegoede@redhat.com, linux-efi@vger.kernel.org Cc: lukas@wunner.de, Ard Biesheuvel Subject: [PATCH v4 1/4] efi: fix efi_pci_io_protocol32 prototype for mixed mode Date: Sun, 29 Apr 2018 13:06:20 +0200 Message-Id: <20180429110623.13949-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180429110623.13949-1-ard.biesheuvel@linaro.org> References: <20180429110623.13949-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Mixed mode allows a kernel built for x86_64 to interact with 32-bit EFI firmware, but requires us to define all struct definitions carefully when it comes to pointer sizes. efi_pci_io_protocol32 currently uses a void* for the 'romimage' field, which will be interpreted as a 64-bit field on such kernels, potentially resulting in bogus memory references and subsequent crashes. Cc: Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 6 ++++-- include/linux/efi.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 47d3efff6805..09f36c0d9d4f 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -163,7 +163,8 @@ __setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom) if (status != EFI_SUCCESS) goto free_struct; - memcpy(rom->romdata, pci->romimage, pci->romsize); + memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, + pci->romsize); return status; free_struct: @@ -269,7 +270,8 @@ __setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom) if (status != EFI_SUCCESS) goto free_struct; - memcpy(rom->romdata, pci->romimage, pci->romsize); + memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, + pci->romsize); return status; free_struct: diff --git a/include/linux/efi.h b/include/linux/efi.h index f1b7d68ac460..3016d8c456bc 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -395,8 +395,8 @@ typedef struct { u32 attributes; u32 get_bar_attributes; u32 set_bar_attributes; - uint64_t romsize; - void *romimage; + u64 romsize; + u32 romimage; } efi_pci_io_protocol_32; typedef struct { @@ -415,8 +415,8 @@ typedef struct { u64 attributes; u64 get_bar_attributes; u64 set_bar_attributes; - uint64_t romsize; - void *romimage; + u64 romsize; + u64 romimage; } efi_pci_io_protocol_64; typedef struct { From patchwork Sun Apr 29 11:06:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134663 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2663718lji; Sun, 29 Apr 2018 04:06:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrOO+JzQgGuwkrQ+TjbHkkFg7tyMM4W7mv+9uZ9zTKap8P91cUFzwYYMRYnWAoG2C1IO7Bj X-Received: by 2002:a63:5f0d:: with SMTP id t13-v6mr7394361pgb.145.1525000008977; Sun, 29 Apr 2018 04:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525000008; cv=none; d=google.com; s=arc-20160816; b=s1A6HWhJOhQT7Vt/Sm7ohs3bhvqEF/KVa8M11UJmRTnII+UpR9xk4ZpoGyXpAA5fVT 9g+HQ9+vFj1xsNIcHl9hH+gysxhEoKl22GwqurjMB6/1zcMaPfBWoeIc5OurX6v8AQ9Y uxZwhl1vkvbJDdKLMLAgAxhQpxlr2iE68cSJYG4Axg9YmIAYw3dpw99VKB8Gp4g2BJlB QUuZEFh369NA4T2CfR1KFdC5MHIQVzP/83icRnzWHYSjpRemUvvsnXRbqmmgZM78f5OH w8W+ZUxgSkfkHaWZWkdGRVsfm9vOWA5XpDY0E0TTV6Pg8x+TkpgcWHc5N7Zu12Ti0Q72 mPSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=z6IgqYzHWl7sYWUT53ILpidxq2MOil5amSbNQZ2JAQA=; b=dN0zKtZK2ONPH0Vx+1W4v+a62sOt3HClmWOH/iREJpdAMwxSaMLt5+bSEDi6PA2mWb cfH9LigIl+TvoYbmn8jjfznnJLo1rJ2muypVOsF7Q25e0X57cxzo3pXJkCcRCp50AFf5 dhCXSUGCyeYQdbnyxcwPg4Sczutzc6qDxtMuNH0cBfoblmM0pPDMlqnwuIVkTFQxF8fG pPBA59gDWl5+hl5HsbvQ/VWlx2QkRQxc+cQOgimowOWpNPXYhAz84dfH8cRm2xynjMQ3 G47iCXEsxAVl663j5bP69ynIIO76jdUITTzROYn0R/carT+l1bJSPULN2J91o1Dt1nDg 8x5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hRmzXzTN; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si5369654plo.263.2018.04.29.04.06.48; Sun, 29 Apr 2018 04:06:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hRmzXzTN; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753033AbeD2LGs (ORCPT + 2 others); Sun, 29 Apr 2018 07:06:48 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54830 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752964AbeD2LGr (ORCPT ); Sun, 29 Apr 2018 07:06:47 -0400 Received: by mail-wm0-f66.google.com with SMTP id f6so8872989wmc.4 for ; Sun, 29 Apr 2018 04:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OvdDsSbv/V0fUxuKhbecNNPpIIGA1s86w1LgsmoagDs=; b=hRmzXzTNFxJ2ELJqsC2+zNMMnLGEW1ONA76DHppXSMeOoGIW7O247HVXr4YlJjjm8I A8XegSSrc1Gf23IOumnC3dJqjXpi0gZL9zmW1bLM9VM+u3UKmFo30zrcrPbUd1wFU+ou k7eahI0G8pefoY8jZ8HcKEwIe5fyLK5tAhMno= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OvdDsSbv/V0fUxuKhbecNNPpIIGA1s86w1LgsmoagDs=; b=bFgTtEp5MO1Aqg+K0+Tt9XIuhEVTaH44+qP2asxO3PzOjmLiq76XpM3RkdMUqoz5GH gRdH9LrW1RLLpdF7NhLtS237wLIZSN1ieWgBxyLSlzJ1CQZR6+iWUsE8b+0NdY9r2/0b uFBNSlhLMf3DLKPES+uaMce7hBQeabjr8O2paeNTlVryhghPBDzOSMxEqSgApCZUSaLH mtlq4qKcfnum/a+i+rWQW+EmXMggJzxGQJwwhylryigh1uLa0njHLsBcqh+CsqIxhRsB a94b3qPZb2YRA1Qo4QMZp/JiBLKXBXRqoK0AA01OJWqEeODtZzq32PCj5eFFuTaaAagC 0CWw== X-Gm-Message-State: ALQs6tDdRgpNsdM9cp5ynWHgc0zfMHcEVNoxoy0zJMrpiPiBPRp6hHH9 X6xJOTLyxbG8x6KzozWhl/VFeA== X-Received: by 10.28.110.30 with SMTP id j30mr4796519wmc.62.1525000006571; Sun, 29 Apr 2018 04:06:46 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id a13-v6sm4783275wrc.19.2018.04.29.04.06.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 04:06:45 -0700 (PDT) From: Ard Biesheuvel To: mingo@kernel.org, hdegoede@redhat.com, linux-efi@vger.kernel.org Cc: lukas@wunner.de, Ard Biesheuvel Subject: [PATCH v4 2/4] efi: align efi_pci_io_protocol typedefs to type naming convention Date: Sun, 29 Apr 2018 13:06:21 +0200 Message-Id: <20180429110623.13949-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180429110623.13949-1-ard.biesheuvel@linaro.org> References: <20180429110623.13949-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org In order to use the helper macros that perform type mangling with the EFI PCI I/O protocol struct typedefs, align their Linux typenames with the convention we use for definitionns that originate in the UEFI spec, and add the trailing _t to each. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 8 ++++---- include/linux/efi.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 09f36c0d9d4f..3994f48c4043 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -109,7 +109,7 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) } static efi_status_t -__setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom) +__setup_efi_pci32(efi_pci_io_protocol_32_t *pci, struct pci_setup_rom **__rom) { struct pci_setup_rom *rom = NULL; efi_status_t status; @@ -176,7 +176,7 @@ static void setup_efi_pci32(struct boot_params *params, void **pci_handle, unsigned long size) { - efi_pci_io_protocol_32 *pci = NULL; + efi_pci_io_protocol_32_t *pci = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; u32 *handles = (u32 *)(unsigned long)pci_handle; efi_status_t status; @@ -218,7 +218,7 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle, } static efi_status_t -__setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom) +__setup_efi_pci64(efi_pci_io_protocol_64_t *pci, struct pci_setup_rom **__rom) { struct pci_setup_rom *rom; efi_status_t status; @@ -284,7 +284,7 @@ static void setup_efi_pci64(struct boot_params *params, void **pci_handle, unsigned long size) { - efi_pci_io_protocol_64 *pci = NULL; + efi_pci_io_protocol_64_t *pci = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; u64 *handles = (u64 *)(unsigned long)pci_handle; efi_status_t status; diff --git a/include/linux/efi.h b/include/linux/efi.h index 3016d8c456bc..56add823f190 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -397,7 +397,7 @@ typedef struct { u32 set_bar_attributes; u64 romsize; u32 romimage; -} efi_pci_io_protocol_32; +} efi_pci_io_protocol_32_t; typedef struct { u64 poll_mem; @@ -417,7 +417,7 @@ typedef struct { u64 set_bar_attributes; u64 romsize; u64 romimage; -} efi_pci_io_protocol_64; +} efi_pci_io_protocol_64_t; typedef struct { void *poll_mem; @@ -437,7 +437,7 @@ typedef struct { void *set_bar_attributes; uint64_t romsize; void *romimage; -} efi_pci_io_protocol; +} efi_pci_io_protocol_t; #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002 From patchwork Sun Apr 29 11:06:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134664 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2663746lji; Sun, 29 Apr 2018 04:06:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrWw0na+S2GkP1wn09WMcQj+zpTRxKJ95oY31H7b7FT51pngk1xHJYg1n+3zEGUCLtylxTP X-Received: by 2002:a17:902:7406:: with SMTP id g6-v6mr8551457pll.237.1525000011301; Sun, 29 Apr 2018 04:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525000011; cv=none; d=google.com; s=arc-20160816; b=IGN2kBkCpISp/nfP9gAways7jhdy7lIhQtwfb6bFQ804cZQPl1fXehmIgY5mpOCU4U LCKqRwWuW9HdUJPXI89oYt3bX7Ymjr5XhHaq+EwPT3+ylZIme2zn9+UjYIFsSuT4J5xq 0bL/tbGb4DU7L3YRDoRoT1U0/Dfp/787P7YFRCgbKKbDIMihSl6A3t5e+mklr7HTk1pj NHnX0ZF7UgH6lHLuQBPruyo6vFC2ibAFt0raat3rRjyPonc9b7dZwpfV6NuuVnV8C1y7 V2JiZm2p0CBd53ov8kaEKXn/o/hYrt0dM/HgiVLeay1JaNjqSvtUJDmEjQTiRBUHlRw0 6zDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=567TfHnOExbPoGZrk9JB2pkPMODTTMSn/LaY+V8Y7dQ=; b=whLQMZPW16jbVSdNuJJr5wSsnsCb0hByydNEXcLzm/b7Sn9r1su4BD/cl++1Bbvirf hiXg2iKADhEPg+m8liUPmvOal5d+t2J6wDvveK3H/oERkrWGPLPLaFYSwboXTU9y5Ha0 ireointFAuA8js5KxeMSS07Eaz6hXo3iR5wrbUg85H4kFcJm9E2tmUsTBv7HJsJw7gKS rLMe1Za/L/rEaC2yuvGB184GnA3xBO2nYORyZIy2/yNBQ04GTbRJCss3RNegaycY8tCo EwcWVa0w3sn2yjkeZC8sjrdV4tMntyaFtHeSAFBfRDIWrsirRDSmAnwrmA/64LKIs9p+ ofbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aPMT2i0V; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si5369654plo.263.2018.04.29.04.06.51; Sun, 29 Apr 2018 04:06:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aPMT2i0V; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753054AbeD2LGu (ORCPT + 2 others); Sun, 29 Apr 2018 07:06:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:55960 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752977AbeD2LGt (ORCPT ); Sun, 29 Apr 2018 07:06:49 -0400 Received: by mail-wm0-f65.google.com with SMTP id a8so8867371wmg.5 for ; Sun, 29 Apr 2018 04:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fSbijCkk8hhRmdOnMzF9VUCG5wX+TYjZk9Gmdpbn0nw=; b=aPMT2i0VYHpxPkAsprNYpVPf7GkyH/ALNxCt/7oOknZcTMw480vctuQih7jW0qC7AQ pAl2yWmVkAYxhBBgc+OEQvfbz1gmBniVCtW6Wo41h7t5vUmKRXmmya37yzrytHWVtWZG rsAbyfQPK4H8bIpWpN9/JlEtA1I7kyIXBDGQg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fSbijCkk8hhRmdOnMzF9VUCG5wX+TYjZk9Gmdpbn0nw=; b=byBoIKNG27S7k5WSe3FV+4uPxwRnCykBXt53m56cpm24tc44iOb7oDhahMonUzra1s FfCBROBOrQviz5xRB2eojSxy5iV+LyaEkJj4Pf34Yqsi3NfyAxcPZfNVF5FZJxwyH8r0 T4H3YVUaPZ+0qZzZF40HHSvzs2aD/UAU0s6wyMHQSEGJrUMiQvR18YJoRZHFozQCYxak q7ycF1q9nc9MGAkGypbIq7S26JIX80M6HygBma0TOPmYl5YW5j+LHLf/KsHx+2g+rizG Jpqx1eI+xt2zT7DKxypzViyh5jZbJmewYt0OvrusbHpgGTPcNm7QLzgRRCtLWarkCien rY6A== X-Gm-Message-State: ALQs6tDxVBEklg7Te5YHQgjOH6LVjrR2kuONxZL/cPu9zhCCzbJrxFKp TA1YLbJDl4UAqsaR5WT2ldG4tA== X-Received: by 10.28.138.69 with SMTP id m66mr5754570wmd.117.1525000008599; Sun, 29 Apr 2018 04:06:48 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id a13-v6sm4783275wrc.19.2018.04.29.04.06.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 04:06:47 -0700 (PDT) From: Ard Biesheuvel To: mingo@kernel.org, hdegoede@redhat.com, linux-efi@vger.kernel.org Cc: lukas@wunner.de, Ard Biesheuvel Subject: [PATCH v4 3/4] efi/x86: fold __setup_efi_pci32 and __setup_efi_pci64 into one Date: Sun, 29 Apr 2018 13:06:22 +0200 Message-Id: <20180429110623.13949-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180429110623.13949-1-ard.biesheuvel@linaro.org> References: <20180429110623.13949-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org As suggested by Lukas, use his efi_call_proto() and efi_table_attr() macros to merge __setup_efi_pci32() and __setup_efi_pci64() into a single function, removing the need to duplicate changes made in subsequent patches across both. Cc: Lukas Wunner Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 107 +++++--------------- 1 file changed, 25 insertions(+), 82 deletions(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 3994f48c4043..dadf32312082 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -109,23 +109,27 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) } static efi_status_t -__setup_efi_pci32(efi_pci_io_protocol_32_t *pci, struct pci_setup_rom **__rom) +__setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) { struct pci_setup_rom *rom = NULL; efi_status_t status; unsigned long size; - uint64_t attributes; + uint64_t attributes, romsize; + void *romimage; - status = efi_early->call(pci->attributes, pci, - EfiPciIoAttributeOperationGet, 0, 0, - &attributes); + status = efi_call_proto(efi_pci_io_protocol, attributes, pci, + EfiPciIoAttributeOperationGet, 0, 0, + &attributes); if (status != EFI_SUCCESS) return status; - if (!pci->romimage || !pci->romsize) + romimage = (void *)(unsigned long)efi_table_attr(efi_pci_io_protocol, + romimage, pci); + romsize = efi_table_attr(efi_pci_io_protocol, romsize, pci); + if (!romimage || !romsize) return EFI_INVALID_PARAMETER; - size = pci->romsize + sizeof(*rom); + size = romsize + sizeof(*rom); status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); if (status != EFI_SUCCESS) { @@ -141,30 +145,32 @@ __setup_efi_pci32(efi_pci_io_protocol_32_t *pci, struct pci_setup_rom **__rom) rom->pcilen = pci->romsize; *__rom = rom; - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_VENDOR_ID, 1, &(rom->vendor)); + status = efi_call_proto(efi_pci_io_protocol, pci.read, pci, + EfiPciIoWidthUint16, PCI_VENDOR_ID, 1, + &rom->vendor); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to read rom->vendor\n"); goto free_struct; } - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_DEVICE_ID, 1, &(rom->devid)); + status = efi_call_proto(efi_pci_io_protocol, pci.read, pci, + EfiPciIoWidthUint16, PCI_DEVICE_ID, 1, + &rom->devid); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to read rom->devid\n"); goto free_struct; } - status = efi_early->call(pci->get_location, pci, &(rom->segment), - &(rom->bus), &(rom->device), &(rom->function)); + status = efi_call_proto(efi_pci_io_protocol, get_location, pci, + &rom->segment, &rom->bus, &rom->device, + &rom->function); if (status != EFI_SUCCESS) goto free_struct; - memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, - pci->romsize); + memcpy(rom->romdata, romimage, romsize); return status; free_struct: @@ -176,7 +182,7 @@ static void setup_efi_pci32(struct boot_params *params, void **pci_handle, unsigned long size) { - efi_pci_io_protocol_32_t *pci = NULL; + efi_pci_io_protocol_t *pci = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; u32 *handles = (u32 *)(unsigned long)pci_handle; efi_status_t status; @@ -203,7 +209,7 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle, if (!pci) continue; - status = __setup_efi_pci32(pci, &rom); + status = __setup_efi_pci(pci, &rom); if (status != EFI_SUCCESS) continue; @@ -217,74 +223,11 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle, } } -static efi_status_t -__setup_efi_pci64(efi_pci_io_protocol_64_t *pci, struct pci_setup_rom **__rom) -{ - struct pci_setup_rom *rom; - efi_status_t status; - unsigned long size; - uint64_t attributes; - - status = efi_early->call(pci->attributes, pci, - EfiPciIoAttributeOperationGet, 0, - &attributes); - if (status != EFI_SUCCESS) - return status; - - if (!pci->romimage || !pci->romsize) - return EFI_INVALID_PARAMETER; - - size = pci->romsize + sizeof(*rom); - - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); - if (status != EFI_SUCCESS) { - efi_printk(sys_table, "Failed to alloc mem for rom\n"); - return status; - } - - rom->data.type = SETUP_PCI; - rom->data.len = size - sizeof(struct setup_data); - rom->data.next = 0; - rom->pcilen = pci->romsize; - *__rom = rom; - - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_VENDOR_ID, 1, &(rom->vendor)); - - if (status != EFI_SUCCESS) { - efi_printk(sys_table, "Failed to read rom->vendor\n"); - goto free_struct; - } - - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_DEVICE_ID, 1, &(rom->devid)); - - if (status != EFI_SUCCESS) { - efi_printk(sys_table, "Failed to read rom->devid\n"); - goto free_struct; - } - - status = efi_early->call(pci->get_location, pci, &(rom->segment), - &(rom->bus), &(rom->device), &(rom->function)); - - if (status != EFI_SUCCESS) - goto free_struct; - - memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, - pci->romsize); - return status; - -free_struct: - efi_call_early(free_pool, rom); - return status; - -} - static void setup_efi_pci64(struct boot_params *params, void **pci_handle, unsigned long size) { - efi_pci_io_protocol_64_t *pci = NULL; + efi_pci_io_protocol_t *pci = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; u64 *handles = (u64 *)(unsigned long)pci_handle; efi_status_t status; @@ -311,7 +254,7 @@ setup_efi_pci64(struct boot_params *params, void **pci_handle, if (!pci) continue; - status = __setup_efi_pci64(pci, &rom); + status = __setup_efi_pci(pci, &rom); if (status != EFI_SUCCESS) continue; From patchwork Sun Apr 29 11:06:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134665 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2663771lji; Sun, 29 Apr 2018 04:06:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpd3StrXX37mVuFh5SRgEfSua3kPXgJpf/CAjQ4hFE/5zfvRXslR13ZXCKPAQFOT3Xy+VYp X-Received: by 2002:a17:902:5a46:: with SMTP id f6-v6mr8792517plm.85.1525000013157; Sun, 29 Apr 2018 04:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525000013; cv=none; d=google.com; s=arc-20160816; b=Uvyff6SBIes6hn8blCY+dpYXWeUUtGRKWcQ1e3LyWpXNs/cEkjw7j7/44uG1ryHS+d btgXfPDpVjW8gfxB7gXdauhhuusPKg/RUO2HNajgiH/qPbjAKST5KKtren2Lmve6LcHk nBroFPucxdc7obqLOTOa12ckdmU1zL9IkLGEt4gzPZG32IQpgOsLASzsTWmuCQBizdNq AL5S9DJOsNd5Z0sC5wVrVQ68QWRzofOmqCZr/LW627WGWt+fdeQYACqukJ1itfU2xU5e Nnh323Akw8v0+4evG/Hj3p0UaxOVJ43BReKuZ7wFE+yZuiML9tz2ZOUwdIrgJCJHYmzw 2Owg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=wHkdyRYNz1NT+sUJADVkn0TjvQXSx2dkhpECDaahmhg=; b=SHN4h8FFROAn1Rv5xxL1P9sYdfwoB57Kbm7iCRXV+sNqifAimrY0p6ksmqBK7w4/Cj EEzYZYRWU75+mJ9WdP7fOHKUDX0zmOdGcjtRsJJO0Ilgbf3U986U7gCDBax3dG5zaFBD lZhbLES6i1bmLh9wLasZtFMmbparab1bXVraY3zBv2f/MHaycz201yE1LBO7cxkTKm5d 6W/dYvfayazdmPvY9a2aSr4fgelbFPwyKU7Fv21zNISjWfw4A0K0E9Nl0I/wlsR2E46c d7oXJxPBWt9a65fnLfEqzumiOPnZuI4aczgwpSKz3HkKBBKe/UsCHqEXflYck/0NX7vb Mnvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D/6AXis2; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si5369654plo.263.2018.04.29.04.06.52; Sun, 29 Apr 2018 04:06:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D/6AXis2; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753087AbeD2LGw (ORCPT + 2 others); Sun, 29 Apr 2018 07:06:52 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:50868 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753041AbeD2LGv (ORCPT ); Sun, 29 Apr 2018 07:06:51 -0400 Received: by mail-wm0-f65.google.com with SMTP id t11so8902498wmt.0 for ; Sun, 29 Apr 2018 04:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ietiElKC1oTDjB9bKITo+nGAeqSiEt17+YjWEyOGGSM=; b=D/6AXis2pwv0G2k1UKij2MnzPTyQ+iM7NOcAuvcAUxWgeOFffJZnr7Eibqpgl5FkkK Wcznq3oWyj7ugmISlFU9GmpOqdZiSjYEh7wMwuV5MveNnR/ZbPeTZInhDO3xK4UVWh6t vit0cxj0twNXczCZ8tYruso+MUplS+XSJDtyo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ietiElKC1oTDjB9bKITo+nGAeqSiEt17+YjWEyOGGSM=; b=Nd+zoKJOylBXBIvmCqCFxdHXihg8Db5febELkOzYJI6AFZfU9ksTkiPp+z/X9Itu4a t8/A2ABfp3FwbsIeWKwOpN+0dtYoh+8BFtSoUsNKXuviFhLa0Holt2R9MNDo4DE+jY3q 7OvvxY7xSgGOelBkXmPN4Frgna0GXfI2IvCY7ejC+6C3C/zFPvjiz1XAqkZicd/uMR/5 pEJYU2dwX12LMZzR926frtvh5qAuJBa2Zd5E2bhZ+DtPlywjSX2+RAQJ2bDdY7TSYx9A JrCsnWkQm/u/WOrBmKn8/ppaPTMhSliKTlkSrxsVwiHOLLsLuB4uZ2N/0msZJJcxfZCO RU3A== X-Gm-Message-State: ALQs6tDejIBXLMUlqocd+ZTK2xvGz7ssj+Umh2K39dC5lFv9iOfOFmSR JhRywdu+pWswUebQnmiQH+hZp28GxUM= X-Received: by 10.28.190.15 with SMTP id o15mr5471824wmf.104.1525000010690; Sun, 29 Apr 2018 04:06:50 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id a13-v6sm4783275wrc.19.2018.04.29.04.06.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 04:06:49 -0700 (PDT) From: Ard Biesheuvel To: mingo@kernel.org, hdegoede@redhat.com, linux-efi@vger.kernel.org Cc: lukas@wunner.de, Ard Biesheuvel Subject: [PATCH v4 4/4] efi/x86: Ignore unrealistically large option roms Date: Sun, 29 Apr 2018 13:06:23 +0200 Message-Id: <20180429110623.13949-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180429110623.13949-1-ard.biesheuvel@linaro.org> References: <20180429110623.13949-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Hans de Goede setup_efi_pci() tries to save a copy of each PCI option ROM as this may be necessary for the device driver for the PCI device to have access too. On some systems the efi_pci_io_protocol's romimage and romsize fields contain invalid data, which looks a bit like pointers pointing back into other EFI code or data. Interpreting these pointers as romsize leads to a very large value and if we then try to alloc this amount of memory to save a copy the alloc call fails. This leads to a "Failed to alloc mem for rom" error being printed on the EFI console for each PCI device. This commit avoids the printing of these errors, by checking romsize before doing the alloc and if it is larger then the EFI spec limit of 16 MiB silently ignore the ROM fields instead of trying to alloc mem and fail. Signed-off-by: Hans de Goede [ardb: deduplicate 32/64 bit changes, use SZ_16M symbolic constant] Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index dadf32312082..720b06e86698 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -123,10 +123,17 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) if (status != EFI_SUCCESS) return status; + /* + * Some firmwares contain EFI function pointers at the place where the + * romimage and romsize fields are supposed to be. Typically the EFI + * code is mapped at high addresses, translating to an unrealistically + * large romsize. The UEFI spec limits the size of option ROMs to 16 + * MiB so we reject any roms over 16 MiB in size to catch this. + */ romimage = (void *)(unsigned long)efi_table_attr(efi_pci_io_protocol, romimage, pci); romsize = efi_table_attr(efi_pci_io_protocol, romsize, pci); - if (!romimage || !romsize) + if (!romimage || !romsize || romsize > SZ_16M) return EFI_INVALID_PARAMETER; size = romsize + sizeof(*rom);