From patchwork Sun Mar 8 08:08:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3997C18E7A for ; Sun, 8 Mar 2020 08:09:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E41121775 for ; Sun, 8 Mar 2020 08:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654951; bh=0L3JnpVh2/V/1uqvO5VAW63G8ir+cLFE9qbDxePw4yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gt2CQgnFhTN+XY2yADNE/x6pF7OjBtflRgFElwcjZXV8z5DyzeyC9ngSS7RUNqf8c U2bhrS9paEMAv1vZ08h5uNDupCxMiexFTIgQgkZNa8DCcfoAK/A2Fil41R2+qvcZGg T/SoF4SGG21AduxCOWMfdK/hwq6UYUbj7+0ckU3k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726202AbgCHIJK (ORCPT ); Sun, 8 Mar 2020 04:09:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:36128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgCHIJK (ORCPT ); Sun, 8 Mar 2020 04:09:10 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1545C20866; Sun, 8 Mar 2020 08:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654950; bh=0L3JnpVh2/V/1uqvO5VAW63G8ir+cLFE9qbDxePw4yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tOUxJ/cieC/Cjpan6NQ85Ks5fNxFZKhpmDPL3yE4pNxfTJFkBQVbMIWOjnUmDthiq yg1ocfkLKppZk4KBfYYG5wH7Ewo4NSqu2asw6RdMZJE3Qlv6MPprpBMQCV3/b/244G 4PRYA8UDR+WKB9IAJuCPLk1Xtjcyzn0p5lOGrLJs= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 01/28] efi/x86: Add TPM related EFI tables to unencrypted mapping checks Date: Sun, 8 Mar 2020 09:08:32 +0100 Message-Id: <20200308080859.21568-2-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Tom Lendacky When booting with SME active, EFI tables must be mapped unencrypted since they were built by UEFI in unencrypted memory. Update the list of tables to be checked during early_memremap() processing to account for the EFI TPM tables. This fixes a bug where an EFI TPM log table has been created by UEFI, but it lives in memory that has been marked as usable rather than reserved. Cc: # v5.4+ Signed-off-by: Tom Lendacky Link: https://lore.kernel.org/r/4144cd813f113c20cdfa511cf59500a64e6015be.1582662842.git.thomas.lendacky@amd.com Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index ebcec4bd273f..3ce695501681 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -88,6 +88,8 @@ static const unsigned long * const efi_tables[] = { #ifdef CONFIG_EFI_RCI2_TABLE &rci2_table_phys, #endif + &efi.tpm_log, + &efi.tpm_final_log, }; u64 efi_setup; /* efi setup_data physical address */ From patchwork Sun Mar 8 08:08:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC8D8C18E7A for ; Sun, 8 Mar 2020 08:09:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D2A8208CD for ; Sun, 8 Mar 2020 08:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654958; bh=uxxUuyobuFM1LmIEjIDa33YJQIHA/VSsyHgILYAFfl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UXVLyQrYTfOu7QT8vDvVw3vjbL6J7K1HX3ZlNBAK5AvyzdvHb4yUDdW9TLUPcFyLy RN/gA88SZua6B/Giqelh1JoOIm5QlGpPFJDRBQDOjlOZYBRyHe0jalstBFnlxV+3+l o1q8e0M6atgYlE1uc/t+INFRqEERr1CawUvM81ng= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbgCHIJR (ORCPT ); Sun, 8 Mar 2020 04:09:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:36354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgCHIJR (ORCPT ); Sun, 8 Mar 2020 04:09:17 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 115262084E; Sun, 8 Mar 2020 08:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654957; bh=uxxUuyobuFM1LmIEjIDa33YJQIHA/VSsyHgILYAFfl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nLcbgq0hgCgLUVYbe46uUB5726mHuJOh172HAxg5hucu2FdEwz4JD/+i+wW+UsSgw JUWnCVpyG4Q8KpwGaF3tKTFTP8iYd9x+kCjYI8UiY5pKjvoisRCf+Y/INxPm6alSXV P+GlPFveBvIEHEK1R8B8DuGaCybn+m9+KgOY24J4= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 03/28] efi: don't shadow i in efi_config_parse_tables() Date: Sun, 8 Mar 2020 09:08:34 +0100 Message-Id: <20200308080859.21568-4-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Heinrich Schuchardt Shadowing variables is generally frowned upon. Let's simply reuse the existing loop counter i instead of shadowing it. Signed-off-by: Heinrich Schuchardt Link: https://lore.kernel.org/r/20200223221324.156086-1-xypron.glpk@gmx.de Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 5f77cb8756ef..91f546dc13d4 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -611,7 +611,6 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, while (prsv) { struct linux_efi_memreserve *rsv; u8 *p; - int i; /* * Just map a full page: that is what we will get From patchwork Sun Mar 8 08:08:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BF95C2BB58 for ; Sun, 8 Mar 2020 08:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E861D2146E for ; Sun, 8 Mar 2020 08:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654967; bh=ZC3Ht6M1A+48LStSHQkp1WSEU79DLzGExzetr4ZF0/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uYtXExY5qCXZ4NVcsiLDvXzW6CCAosOiLOb18CY2PvQ8rSFoFrKxbraH2EH5D8wn1 evnROlFC64PnAsojNWpqEl6TMGScy4/8bXwkBUUWI3CS8i4jvKU06G3Zqf5stz19wE Rrs2SaRp9X8bLsCAawOwwE2aUhvFncWENwsziI/A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726363AbgCHIJ0 (ORCPT ); Sun, 8 Mar 2020 04:09:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:36512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgCHIJY (ORCPT ); Sun, 8 Mar 2020 04:09:24 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 085C921739; Sun, 8 Mar 2020 08:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654964; bh=ZC3Ht6M1A+48LStSHQkp1WSEU79DLzGExzetr4ZF0/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wlqYQQbJf49fo+tvqgZnzRXtZ+4PXamCyT3Ob1WyM/4LPYjRDDJSAWsoUJTE4RXdA DOM26GVL6jE7ZRJBfxzTu/nbMjG08PuURjECThsAsqHtDb6HxbiAps/grmjPew4/JA 2q6ow5vvHoI6WtZ9PJSk8hxmZ9an5a1wgAEG0JNQ= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 05/28] efi/arm64: clean EFI stub exit code from cache instead of avoiding it Date: Sun, 8 Mar 2020 09:08:36 +0100 Message-Id: <20200308080859.21568-6-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Commit 9f9223778 ("efi/libstub/arm: Make efi_entry() an ordinary PE/COFF entrypoint") modified the handover code written in assembler, and for maintainability, aligned the logic with the logic used in the 32-bit ARM version, which is to avoid cache maintenance on the remaining instructions in the subroutine that will be executed with the MMU and caches off, and instead, branch into the relocated copy of the kernel image. However, this assumes that this copy is executable, and this means we expect EFI_LOADER_DATA regions to be executable as well, which is not a reasonable assumption to make, even if this is true for most UEFI implementations today. So change this back, and add a __clean_dcache_area_poc() call to cover the remaining code in the subroutine. While at it, switch the other call site over to __clean_dcache_area_poc() as well, and clean up the terminology in comments to avoid using 'flush' in the context of cache maintenance. Also, let's switch to the new style asm annotations. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-entry.S | 26 +++++++++++++------------- arch/arm64/kernel/image-vars.h | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 4cfd03c35c49..1a03618df0df 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -12,32 +12,32 @@ __INIT -ENTRY(efi_enter_kernel) +SYM_CODE_START(efi_enter_kernel) /* * efi_entry() will have copied the kernel image if necessary and we * end up here with device tree address in x1 and the kernel entry * point stored in x0. Save those values in registers which are * callee preserved. */ - mov x19, x0 // relocated Image address + ldr w2, =stext_offset + add x19, x0, x2 // relocated Image entrypoint mov x20, x1 // DTB address /* - * Flush the copied Image to the PoC, and ensure it is not shadowed by + * Clean the copied Image to the PoC, and ensure it is not shadowed by * stale icache entries from before relocation. */ ldr w1, =kernel_size - bl __flush_dcache_area + bl __clean_dcache_area_poc ic ialluis - dsb sy /* - * Jump across, into the copy of the image that we just cleaned - * to the PoC, so that we can safely disable the MMU and caches. + * Clean the remainder of this routine to the PoC + * so that we can safely disable the MMU and caches. */ - ldr w0, .Ljmp - sub x0, x19, w0, sxtw - br x0 + adr x0, 0f + ldr w1, 3f + bl __clean_dcache_area_poc 0: /* Turn off Dcache and MMU */ mrs x0, CurrentEL @@ -63,6 +63,6 @@ ENTRY(efi_enter_kernel) mov x1, xzr mov x2, xzr mov x3, xzr - b stext -ENDPROC(efi_enter_kernel) -.Ljmp: .long _text - 0b + br x19 +SYM_CODE_END(efi_enter_kernel) +3: .long . - 0b diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index 9a7aef0d6f70..7f06ad93fc95 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -13,6 +13,7 @@ #ifdef CONFIG_EFI __efistub_kernel_size = _edata - _text; +__efistub_stext_offset = stext - _text; /* @@ -34,7 +35,7 @@ __efistub_strnlen = __pi_strnlen; __efistub_strcmp = __pi_strcmp; __efistub_strncmp = __pi_strncmp; __efistub_strrchr = __pi_strrchr; -__efistub___flush_dcache_area = __pi___flush_dcache_area; +__efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc; #ifdef CONFIG_KASAN __efistub___memcpy = __pi_memcpy; @@ -43,7 +44,6 @@ __efistub___memset = __pi_memset; #endif __efistub__text = _text; -__efistub_stext = stext; __efistub__end = _end; __efistub__edata = _edata; __efistub_screen_info = screen_info; From patchwork Sun Mar 8 08:08:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02860C3F2D1 for ; Sun, 8 Mar 2020 08:09:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF82D21741 for ; Sun, 8 Mar 2020 08:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654976; bh=v/U4OkqxqRWTdenDwIzfbVlCTaQKqrUR3iIvfWvw9xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=q8yt3uBdFB7L/rnfzOoifPhaOCy0hhbMSWH6RbsgAPu2wEy0qUQ1qs+XCv7vJKpUl IM9FJDHN18+CemIhR4TgBVjCbK8MHtGgrkCEo9BaBIbP7UtFK2JjjKOFrVJH0+bcQb 5f7gAMjbpw1Ji/Br8/6XbVhUuO8wXHnSeqe7G9kk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726461AbgCHIJg (ORCPT ); Sun, 8 Mar 2020 04:09:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726437AbgCHIJf (ORCPT ); Sun, 8 Mar 2020 04:09:35 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E1E220866; Sun, 8 Mar 2020 08:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654974; bh=v/U4OkqxqRWTdenDwIzfbVlCTaQKqrUR3iIvfWvw9xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILIPEOPW/3A2F7Xa/1PxE9iA76qsSGdayrtwU0wqAypZfJjT5zjayK/yp93AHoLWX okoYKGdlxprle4Fxm384zWqydDptxOjSvwGsc1OgHLVUywY6zK0Y+yXo2fZCKDzkEK cH4j1vtBwnUg11V9+DbHNDjWrg/KP+mYorE7Mj5s= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 08/28] efi/libstub: add libstub/mem.c to documentation tree Date: Sun, 8 Mar 2020 09:08:39 +0100 Message-Id: <20200308080859.21568-9-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Heinrich Schuchardt Let the description of the efi/libstub/mem.c functions appear in the Kernel API documentation in chapter The Linux driver implementer’s API guide Linux Firmware API UEFI Support UEFI stub library functions Signed-off-by: Heinrich Schuchardt Acked-by: Jonathan Corbet Link: https://lore.kernel.org/r/20200221035832.144960-1-xypron.glpk@gmx.de Signed-off-by: Ard Biesheuvel --- Documentation/driver-api/firmware/efi/index.rst | 11 +++++++++++ Documentation/driver-api/firmware/index.rst | 1 + 2 files changed, 12 insertions(+) create mode 100644 Documentation/driver-api/firmware/efi/index.rst diff --git a/Documentation/driver-api/firmware/efi/index.rst b/Documentation/driver-api/firmware/efi/index.rst new file mode 100644 index 000000000000..4fe8abba9fc6 --- /dev/null +++ b/Documentation/driver-api/firmware/efi/index.rst @@ -0,0 +1,11 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============ +UEFI Support +============ + +UEFI stub library functions +=========================== + +.. kernel-doc:: drivers/firmware/efi/libstub/mem.c + :internal: diff --git a/Documentation/driver-api/firmware/index.rst b/Documentation/driver-api/firmware/index.rst index 29da39ec4b8a..57415d657173 100644 --- a/Documentation/driver-api/firmware/index.rst +++ b/Documentation/driver-api/firmware/index.rst @@ -6,6 +6,7 @@ Linux Firmware API introduction core + efi/index request_firmware other_interfaces From patchwork Sun Mar 8 08:08:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7735CC18E5B for ; Sun, 8 Mar 2020 08:09:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43ED2217F4 for ; Sun, 8 Mar 2020 08:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654983; bh=N3ykKbjmMsOgUT9bUNFOnZD9DZ8jRnIwNCMFWKhA1+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tTHCyVeEO2WK2HqO7iDxIjgUXsmrE0IEHJhA0aG+fUrzvT4HGFEzMcEwBvVlqJiR1 v2M3NdzGuwiF7TK9Q0cqYbBjcgwAgWsXuiCnE2y38KmGw1biXWNfPRzpt+y5t89B3h G10E/iFaBKjmwDcvOXgPcH2AyVP9FLlWEVipk5DU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726482AbgCHIJj (ORCPT ); Sun, 8 Mar 2020 04:09:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:36954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726437AbgCHIJj (ORCPT ); Sun, 8 Mar 2020 04:09:39 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1451D2087F; Sun, 8 Mar 2020 08:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654978; bh=N3ykKbjmMsOgUT9bUNFOnZD9DZ8jRnIwNCMFWKhA1+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZ/OF78HpwSHJhCutWsZY9f4M1ABm3OaBGeDFRvFKRS4Tbb24LXxLYEGJufbZJwSv 98fTWUys7Ev4R7MgWwYtkn8QKW6ZpYp9miqFNjCq9DPoSLvxU9LYz5J7rCZq4N+Ypt dyosg9KrQF4SD3h0iZUx1GT9hJD3MA1p/JE2/JhY= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 09/28] efi/x86: Annotate the LOADED_IMAGE_PROTOCOL_GUID with SYM_DATA Date: Sun, 8 Mar 2020 09:08:40 +0100 Message-Id: <20200308080859.21568-10-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Arvind Sankar Use SYM_DATA* macro to annotate this constant, and explicitly align it to 4-byte boundary. Use lower-case for hexadecimal data. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200301230436.2246909-2-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index f7bacc4c1494..86c97797bf78 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -672,7 +672,7 @@ SYM_FUNC_START(efi32_pe_entry) /* Get the loaded image protocol pointer from the image handle */ subl $12, %esp // space for the loaded image pointer pushl %esp // pass its address - leal 4f(%ebp), %eax + leal loaded_image_proto(%ebp), %eax pushl %eax // pass the GUID address pushl 28(%esp) // pass the image handle @@ -695,9 +695,12 @@ SYM_FUNC_END(efi32_pe_entry) .section ".rodata" /* EFI loaded image protocol GUID */ -4: .long 0x5B1B31A1 + .balign 4 +SYM_DATA_START_LOCAL(loaded_image_proto) + .long 0x5b1b31a1 .word 0x9562, 0x11d2 - .byte 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B + .byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b +SYM_DATA_END(loaded_image_proto) #endif /* From patchwork Sun Mar 8 08:08:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CD86C10F28 for ; Sun, 8 Mar 2020 08:09:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F96021744 for ; Sun, 8 Mar 2020 08:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654987; bh=O0pfjgt8W4HZX12SXd+ODFIBPHBlX/yJxr6ENHQMr5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dzT7ycOJfK4DR39EnfTFMbZrJWRHKqCLFJklMtfTCW3up6b/TcnlYsf6n6zZERRkX Xjp6BUCEGHA09Il/NNJztNqutnYZNM020PsUzmloTwpthGUOlYju+FpzqCxSxB+lv1 g+te/kfsOf9n0/HCStMgqo8Gf3KwsgPGqXBGOh3s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbgCHIJq (ORCPT ); Sun, 8 Mar 2020 04:09:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:37152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726518AbgCHIJq (ORCPT ); Sun, 8 Mar 2020 04:09:46 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 45DE42146E; Sun, 8 Mar 2020 08:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654985; bh=O0pfjgt8W4HZX12SXd+ODFIBPHBlX/yJxr6ENHQMr5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bmDhZbTCJfYZY6c17Ag7oriGNsW0XK9PUr3xVN5x9hcy4G8Uwwk4OJIhXz2uEDG0B MIvjxYnXL+3lnGRqoWhs7f/IEb/V95TiwCGev9WSiKgT5sLC39v7Qf+FhWxGCFv8YD ZBYqfztREf30wZbHvarjYBUvlKcFMAdImyOjHs+A= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 11/28] efi/x86: Make efi32_pe_entry more readable Date: Sun, 8 Mar 2020 09:08:42 +0100 Message-Id: <20200308080859.21568-12-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Arvind Sankar Setup a proper frame pointer in efi32_pe_entry so that it's easier to calculate offsets for arguments. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200301230436.2246909-4-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 57 +++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 25fa763f4e83..b74a012a6fea 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -658,42 +658,65 @@ SYM_DATA(efi_is64, .byte 1) .text .code32 SYM_FUNC_START(efi32_pe_entry) +/* + * efi_status_t efi32_pe_entry(efi_handle_t image_handle, + * efi_system_table_32_t *sys_table) + */ + pushl %ebp + movl %esp, %ebp + pushl %eax // dummy push to allocate loaded_image - pushl %ebx + pushl %ebx // save callee-save registers pushl %edi + call verify_cpu // check for long mode support - popl %edi - popl %ebx testl %eax, %eax movl $0x80000003, %eax // EFI_UNSUPPORTED - jnz 3f + jnz 2f call 1f -1: pop %ebp - subl $1b, %ebp +1: pop %ebx + subl $1b, %ebx /* Get the loaded image protocol pointer from the image handle */ - subl $12, %esp // space for the loaded image pointer - pushl %esp // pass its address - leal loaded_image_proto(%ebp), %eax + leal -4(%ebp), %eax + pushl %eax // &loaded_image + leal loaded_image_proto(%ebx), %eax pushl %eax // pass the GUID address - pushl 28(%esp) // pass the image handle + pushl 8(%ebp) // pass the image handle - movl 36(%esp), %eax // sys_table + /* + * Note the alignment of the stack frame. + * sys_table + * handle <-- 16-byte aligned on entry by ABI + * return address + * frame pointer + * loaded_image <-- local variable + * saved %ebx <-- 16-byte aligned here + * saved %edi + * &loaded_image + * &loaded_image_proto + * handle <-- 16-byte aligned for call to handle_protocol + */ + + movl 12(%ebp), %eax // sys_table movl ST32_boottime(%eax), %eax // sys_table->boottime call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol - cmp $0, %eax + addl $12, %esp // restore argument space + testl %eax, %eax jnz 2f - movl 32(%esp), %ecx // image_handle - movl 36(%esp), %edx // sys_table - movl 12(%esp), %esi // loaded_image + movl 8(%ebp), %ecx // image_handle + movl 12(%ebp), %edx // sys_table + movl -4(%ebp), %esi // loaded_image movl LI32_image_base(%esi), %esi // loaded_image->image_base + movl %ebx, %ebp // startup_32 for efi32_pe_stub_entry jmp efi32_pe_stub_entry -2: addl $24, %esp -3: popl %ebp +2: popl %edi // restore callee-save registers + popl %ebx + leave ret SYM_FUNC_END(efi32_pe_entry) From patchwork Sun Mar 8 08:08:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62DF2C18E5B for ; Sun, 8 Mar 2020 08:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CE462084E for ; Sun, 8 Mar 2020 08:09:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654997; bh=+BIOo6Gvvso/C49TZvAFUtecF7m+6sMjMja0zZkaK8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1KITGx3RGhTlMUbpeYeBHKvuxU1TVn7kLW0mHf51rr4WqFVKWqyXR4S9xKPbly0NR ZI3HX8M/vxCTRjMXu3BFbLnCZyOUVRCd51PV7S7SQnliDMFB5AX71CutH0DqRwkfrq GEz2Dqjl9lf2OOrsSg6RQgnbT+hw7L1HJI7Nztuc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgCHIJx (ORCPT ); Sun, 8 Mar 2020 04:09:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:37392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbgCHIJx (ORCPT ); Sun, 8 Mar 2020 04:09:53 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 873B5217F4; Sun, 8 Mar 2020 08:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654992; bh=+BIOo6Gvvso/C49TZvAFUtecF7m+6sMjMja0zZkaK8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AEk6/p9h+5624RBvb/YhsAe7FYOammfe7cOdUQOe6Hi76WgrFuY2mSqst/3NfbbdN +vzwS+2E7Cbz24UOoWWKO0LBqebI9m6W5pPdihYucZwBZ8YxykTbNG3MQoj1mztgaC YLAOMfiUSjJL7E0DyKlEbDlvDfplZ+AydCSZH2J0= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 13/28] x86/boot: Use unsigned comparison for addresses Date: Sun, 8 Mar 2020 09:08:44 +0100 Message-Id: <20200308080859.21568-14-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Arvind Sankar The load address is compared with LOAD_PHYSICAL_ADDR using a signed comparison currently (using jge instruction). When loading a 64-bit kernel using the new efi32_pe_entry point added by commit 97aa276579b2 ("efi/x86: Add true mixed mode entry point into .compat section") using qemu with -m 3072, the firmware actually loads us above 2Gb, resulting in a very early crash. Use jae instruction to perform unsigned comparison instead, as physical addresses should be considered as unsigned. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200301230436.2246909-6-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_32.S | 2 +- arch/x86/boot/compressed/head_64.S | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 9ffc9454fd22..f250fc49cd61 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -105,7 +105,7 @@ SYM_FUNC_START(startup_32) notl %eax andl %eax, %ebx cmpl $LOAD_PHYSICAL_ADDR, %ebx - jge 1f + jae 1f #endif movl $LOAD_PHYSICAL_ADDR, %ebx 1: diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 08351d16ccc0..1199c4ef0c83 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -105,7 +105,7 @@ SYM_FUNC_START(startup_32) notl %eax andl %eax, %ebx cmpl $LOAD_PHYSICAL_ADDR, %ebx - jge 1f + jae 1f #endif movl $LOAD_PHYSICAL_ADDR, %ebx 1: @@ -305,7 +305,7 @@ SYM_CODE_START(startup_64) notq %rax andq %rax, %rbp cmpq $LOAD_PHYSICAL_ADDR, %rbp - jge 1f + jae 1f #endif movq $LOAD_PHYSICAL_ADDR, %rbp 1: From patchwork Sun Mar 8 08:08:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8F85C10F28 for ; Sun, 8 Mar 2020 08:10:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2CE021927 for ; Sun, 8 Mar 2020 08:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655005; bh=yzHPt2YhbeU/znqfMo6nGW1vySv6oU4FD8ygWXE8deY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hH3aD01N5YxPYgr62R9PxtTxoZg85AbzXV7HZTuQqfvAz6Hin5mve1+97TmTgN2lf FPV9pF/Dn+NsoLKiLkEKzg6n1a4BqFF6rYec/LGP6nchh/JLev/z98u/VJsNCSprig pCNvHkNQwCvOclnhbmzwdml6eKKPpLMPV75EDtBI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726647AbgCHIKB (ORCPT ); Sun, 8 Mar 2020 04:10:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:37582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbgCHIKA (ORCPT ); Sun, 8 Mar 2020 04:10:00 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4B1020838; Sun, 8 Mar 2020 08:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583654999; bh=yzHPt2YhbeU/znqfMo6nGW1vySv6oU4FD8ygWXE8deY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mYArbS58VqcVVv0vweSCSAHSCyyus3+fTBs0a14/RirmiH5aFmyJCzXaoweuDgDye MdlW6vIMNqELknh9Kmxu90vN0LbW0zHz7spHrKhJKJHkDMxMpLp7jXzIrGtPr/uq9r JnpcI3xEgkkNxeSm1SZL3TwIdxqf3ABAHIlB8hVE= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 15/28] x86/boot/compressed/32: Save the output address instead of recalculating it Date: Sun, 8 Mar 2020 09:08:46 +0100 Message-Id: <20200308080859.21568-16-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Arvind Sankar In preparation for being able to decompress into a buffer starting at a different address than startup_32, save the calculated output address instead of recalculating it later. We now keep track of three addresses: %edx: startup_32 as we were loaded by bootloader %ebx: new location of compressed kernel %ebp: start of decompression buffer Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200303221205.4048668-2-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_32.S | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index f250fc49cd61..2a8965aec234 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -75,11 +75,11 @@ SYM_FUNC_START(startup_32) */ leal (BP_scratch+4)(%esi), %esp call 1f -1: popl %ebp - subl $1b, %ebp +1: popl %edx + subl $1b, %edx /* Load new GDT */ - leal gdt(%ebp), %eax + leal gdt(%edx), %eax movl %eax, 2(%eax) lgdt (%eax) @@ -92,13 +92,14 @@ SYM_FUNC_START(startup_32) movl %eax, %ss /* - * %ebp contains the address we are loaded at by the boot loader and %ebx + * %edx contains the address we are loaded at by the boot loader and %ebx * contains the address where we should move the kernel image temporarily - * for safe in-place decompression. + * for safe in-place decompression. %ebp contains the address that the kernel + * will be decompressed to. */ #ifdef CONFIG_RELOCATABLE - movl %ebp, %ebx + movl %edx, %ebx movl BP_kernel_alignment(%esi), %eax decl %eax addl %eax, %ebx @@ -110,10 +111,10 @@ SYM_FUNC_START(startup_32) movl $LOAD_PHYSICAL_ADDR, %ebx 1: + movl %ebx, %ebp // Save the output address for later /* Target address to relocate to for decompression */ - movl BP_init_size(%esi), %eax - subl $_end, %eax - addl %eax, %ebx + addl BP_init_size(%esi), %ebx + subl $_end, %ebx /* Set up the stack */ leal boot_stack_end(%ebx), %esp @@ -127,7 +128,7 @@ SYM_FUNC_START(startup_32) * where decompression in place becomes safe. */ pushl %esi - leal (_bss-4)(%ebp), %esi + leal (_bss-4)(%edx), %esi leal (_bss-4)(%ebx), %edi movl $(_bss - startup_32), %ecx shrl $2, %ecx @@ -197,9 +198,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) /* push arguments for extract_kernel: */ pushl $z_output_len /* decompressed length, end of relocs */ - leal _end(%ebx), %eax - subl BP_init_size(%esi), %eax - pushl %eax /* output address */ + pushl %ebp /* output address */ pushl $z_input_len /* input_len */ leal input_data(%ebx), %eax From patchwork Sun Mar 8 08:08:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F85EC18E5F for ; Sun, 8 Mar 2020 08:10:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8F8820880 for ; Sun, 8 Mar 2020 08:10:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655009; bh=mjY+mhy5ip/EF4tM7wbe7FUn0QAZIdNhkYDMdzkX9vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xukiF9/L/ZXIIp05F498urL96i9KYAPXglQRWs5WpKQRVIoO+iahC3bPUq9j1KgMd +544tEzAUMP1DrW+Mv4oBWyE1ffvgmGW8CQcTOF0CeOfrT1s29wPHgAZhzcaolZlkU pC7FdR/egK91ZExdMG+8LWumWucVc5GZh3ftVULM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbgCHIKI (ORCPT ); Sun, 8 Mar 2020 04:10:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:37784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbgCHIKH (ORCPT ); Sun, 8 Mar 2020 04:10:07 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4BC42072A; Sun, 8 Mar 2020 08:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655007; bh=mjY+mhy5ip/EF4tM7wbe7FUn0QAZIdNhkYDMdzkX9vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gq597acox6U7vOw5T+6iC8AfeSGRpxkH1x83Hw0fotFT7AsBwqBGBiwv1nQUfA65N cvrNb+LejfR48KyCusNMpQggvNKsrfQpW+GybCPcl+Y4HjPn2NOmH4rMP2BJ1g9a8u IbHARRkEhrWgdtc56AMgavi5J9zjxMYNgC4F3UwY= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 17/28] efi/x86: Add kernel preferred address to PE header Date: Sun, 8 Mar 2020 09:08:48 +0100 Message-Id: <20200308080859.21568-18-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Arvind Sankar Store the kernel's link address as ImageBase in the PE header. Note that the PE specification requires the ImageBase to be 64k aligned. The preferred address should almost always satisfy that, except for 32-bit kernel if the configuration has been customized. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200303221205.4048668-4-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/header.S | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index 4ee25e28996f..736b3a0c9454 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -138,10 +138,12 @@ optional_header: #endif extra_header_fields: + # PE specification requires ImageBase to be 64k-aligned + .set image_base, (LOAD_PHYSICAL_ADDR + 0xffff) & ~0xffff #ifdef CONFIG_X86_32 - .long 0 # ImageBase + .long image_base # ImageBase #else - .quad 0 # ImageBase + .quad image_base # ImageBase #endif .long 0x20 # SectionAlignment .long 0x20 # FileAlignment From patchwork Sun Mar 8 08:08:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CE0CC18E5F for ; Sun, 8 Mar 2020 08:10:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B41722B48 for ; Sun, 8 Mar 2020 08:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655016; bh=t0zvztmSKZBoKnmOYnVnakURJ8XSfvQMNh6AI9EG5U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=RR10sxvpQuGEajHTy/8GaamPgYKJLJooB3OS5ythndFFU1PfI/3Wx1faCqpsTYXIx bv+hGNMMElPyH0evfQhyErvoZDuSODXZ+Ndn93hXuJ4w3xdXMOXyibfqfVIHq0nFAJ +za2ealQto9ibuc8OeBw/fAc+YEgog6UAkvyF4/Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbgCHIKM (ORCPT ); Sun, 8 Mar 2020 04:10:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:37878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbgCHIKL (ORCPT ); Sun, 8 Mar 2020 04:10:11 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 668F02084E; Sun, 8 Mar 2020 08:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655010; bh=t0zvztmSKZBoKnmOYnVnakURJ8XSfvQMNh6AI9EG5U4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTgQG5AXw5GRdnhwSuCXacqg1T8fwvrsfRvDN7h/XavfpT75YOP3jQUC8HXm3r8S1 syj1PmSvVHIhQvV1l9dcjcuEi/mpKvHCY1I1vmo0Hc8go6UbLTIlW0Nb72Og7kMlFy 3SuLGoaJHpGSO/MTR/gmgGARKeXDzGU2Ws74gWzM= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 18/28] efi/x86: Remove extra headroom for setup block Date: Sun, 8 Mar 2020 09:08:49 +0100 Message-Id: <20200308080859.21568-19-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Arvind Sankar commit 223e3ee56f77 ("efi/x86: add headroom to decompressor BSS to account for setup block") added headroom to the PE image to account for the setup block, which wasn't used for the decompression buffer. Now that the decompression buffer is located at the start of the image, and includes the setup block, this is no longer required. Add a check to make sure that the head section of the compressed kernel won't overwrite itself while relocating. This is only for future-proofing as with current limits on the setup and the actual size of the head section, this can never happen. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200303221205.4048668-5-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/tools/build.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 90d403dfec80..3d03ad753ed5 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -65,6 +65,8 @@ unsigned long efi_pe_entry; unsigned long efi32_pe_entry; unsigned long kernel_info; unsigned long startup_64; +unsigned long _ehead; +unsigned long _end; /*----------------------------------------------------------------------*/ @@ -232,7 +234,7 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz, { unsigned int pe_header; unsigned int text_sz = file_sz - text_start; - unsigned int bss_sz = init_sz + text_start - file_sz; + unsigned int bss_sz = init_sz - file_sz; pe_header = get_unaligned_le32(&buf[0x3c]); @@ -259,7 +261,7 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz, put_unaligned_le32(file_sz - 512 + bss_sz, &buf[pe_header + 0x1c]); /* Size of image */ - put_unaligned_le32(init_sz + text_start, &buf[pe_header + 0x50]); + put_unaligned_le32(init_sz, &buf[pe_header + 0x50]); /* * Address of entry point for PE/COFF executable @@ -360,6 +362,8 @@ static void parse_zoffset(char *fname) PARSE_ZOFS(p, efi32_pe_entry); PARSE_ZOFS(p, kernel_info); PARSE_ZOFS(p, startup_64); + PARSE_ZOFS(p, _ehead); + PARSE_ZOFS(p, _end); p = strchr(p, '\n'); while (p && (*p == '\r' || *p == '\n')) @@ -444,6 +448,26 @@ int main(int argc, char ** argv) put_unaligned_le32(sys_size, &buf[0x1f4]); init_sz = get_unaligned_le32(&buf[0x260]); +#ifdef CONFIG_EFI_STUB + /* + * The decompression buffer will start at ImageBase. When relocating + * the compressed kernel to its end, we must ensure that the head + * section does not get overwritten. The head section occupies + * [i, i + _ehead), and the destination is [init_sz - _end, init_sz). + * + * At present these should never overlap, because i is at most 32k + * because of SETUP_SECT_MAX, _ehead is less than 1k, and the + * calculation of INIT_SIZE in boot/header.S ensures that + * init_sz - _end is at least 64k. + * + * For future-proofing, increase init_sz if necessary. + */ + + if (init_sz - _end < i + _ehead) { + init_sz = (i + _ehead + _end + 4095) & ~4095; + put_unaligned_le32(init_sz, &buf[0x260]); + } +#endif update_pecoff_text(setup_sectors * 512, i + (sys_size * 16), init_sz); efi_stub_entry_update(); From patchwork Sun Mar 8 08:08:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23F08C18E7A for ; Sun, 8 Mar 2020 08:10:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1DDB20866 for ; Sun, 8 Mar 2020 08:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655027; bh=wsZayJivl+Akw8OakDrwAN3vwWAPvujymInCavCuQqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mH4KOs4itYid267ueJGWYc/2jdGlguG5jGTwMKMd7mbrZ1aCpyiI10ndpg33WKrhC /Ux1F8d1qxRH/ojc0EbDMRgUVxAOlZdRfnjBITzaMa987Gj1Ig0Ainrtb4z1bvr1oU fJSUi5nzh1H7m/oHJ6evn3IirrQHOmYE6ryoYDVE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726055AbgCHIKZ (ORCPT ); Sun, 8 Mar 2020 04:10:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:38306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726866AbgCHIKZ (ORCPT ); Sun, 8 Mar 2020 04:10:25 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EDC542187F; Sun, 8 Mar 2020 08:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655025; bh=wsZayJivl+Akw8OakDrwAN3vwWAPvujymInCavCuQqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mt5TpUcrHB1R5ntTmUdJIdouQL/WhWHlDI1TDuSSjpl2Y1Qoc75tnU6OE3d95R1J2 7Mapx9ZXM7jEptZRNkJemj/1AUHP0lLs62cFwQqiSKTAQVfcfJRrCo2xmFSIpj5ZST R9pVPFljjL02gPTyVXJOdUTVGKlFrInAOl9c7Ang= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 22/28] efi/libstub: avoid linking libstub/lib-ksyms.o into vmlinux Date: Sun, 8 Mar 2020 09:08:53 +0100 Message-Id: <20200308080859.21568-23-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Masahiro Yamada drivers/firmware/efi/libstub/Makefile builds a static library, which is not linked into the main vmlinux target in the ordinary way [arm64], or at all [ARM, x86]. Since commit 7f2084fa55e6 ("[kbuild] handle exports in lib-y objects reliably"), any Makefile using lib-y generates lib-ksyms.o which is linked into vmlinux. In this case, the following garbage object is linked into vmlinux. drivers/firmware/efi/libstub/lib-ksyms.o We do not want to follow the default linking rules for static libraries built under libstub/ so using subdir-y instead of obj-y is the correct way to descend into this directory. Signed-off-by: Masahiro Yamada Link: https://lore.kernel.org/r/20200305055047.6097-1-masahiroy@kernel.org [ardb: update commit log to clarify that arm64 deviates in this respect] Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index 317a05cd388b..7a216984552b 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -20,7 +20,7 @@ obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o obj-$(CONFIG_UEFI_CPER) += cper.o obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o -obj-$(CONFIG_EFI_STUB) += libstub/ +subdir-$(CONFIG_EFI_STUB) += libstub obj-$(CONFIG_EFI_FAKE_MEMMAP) += fake_map.o obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) += efibc.o obj-$(CONFIG_EFI_TEST) += test/ From patchwork Sun Mar 8 08:08:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56F28C10F29 for ; Sun, 8 Mar 2020 08:10:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D57E208C3 for ; Sun, 8 Mar 2020 08:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655031; bh=61zAIEug0G89junb5vkt8lgu+Si/8PoRj9JLz6YCKio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2hkyO3KM23wtpNyKfIjYHKdFq6/x/7J5oZ3HM9FAZKiCVV63MsxgpmIzDMuZrbPxR UT1HXfqCXgu6Yh1rp3TcGn0e/3KK+ByahPubQB5fFrsVZqQkAdB4xmNnV0oL4js6EC H0LQNnCDfb7M8a1q1I3pgR9uhjBHpwgwDv4xYqE8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbgCHIKa (ORCPT ); Sun, 8 Mar 2020 04:10:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:38414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726901AbgCHIK3 (ORCPT ); Sun, 8 Mar 2020 04:10:29 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7879A2087F; Sun, 8 Mar 2020 08:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655028; bh=61zAIEug0G89junb5vkt8lgu+Si/8PoRj9JLz6YCKio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRUlVpuYmm+12Sxumpx74WHm61HWxIHLnTT8eZHFc3ncSPgtePXw7nJdys3Wn28qH BW4V339mAe9/acs7sII4TMRvaYU5VD8VQb6KuaPCu1MMk2JOGtx/WBPj9G8BGBtTbg 8f8oS/k0wSbD1PsRPWCSz1EV2MCXW+b2gP+9FnUY= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 23/28] efi: fix a race and a buffer overflow while reading efivars via sysfs Date: Sun, 8 Mar 2020 09:08:54 +0100 Message-Id: <20200308080859.21568-24-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Vladis Dronov There is a race and a buffer overflow corrupting a kernel memory while reading an efi variable with a size more than 1024 bytes via the older sysfs method. This happens because accessing struct efi_variable in efivar_{attr,size,data}_read() and friends is not protected from a concurrent access leading to a kernel memory corruption and, at best, to a crash. The race scenario is the following: CPU0: CPU1: efivar_attr_read() var->DataSize = 1024; efivar_entry_get(... &var->DataSize) down_interruptible(&efivars_lock) efivar_attr_read() // same efi var var->DataSize = 1024; efivar_entry_get(... &var->DataSize) down_interruptible(&efivars_lock) virt_efi_get_variable() // returns EFI_BUFFER_TOO_SMALL but // var->DataSize is set to a real // var size more than 1024 bytes up(&efivars_lock) virt_efi_get_variable() // called with var->DataSize set // to a real var size, returns // successfully and overwrites // a 1024-bytes kernel buffer up(&efivars_lock) This can be reproduced by concurrent reading of an efi variable which size is more than 1024 bytes: ts# for cpu in $(seq 0 $(nproc --ignore=1)); do ( taskset -c $cpu \ cat /sys/firmware/efi/vars/KEKDefault*/size & ) ; done Fix this by using a local variable for a var's data buffer size so it does not get overwritten. Fixes: e14ab23dde12b80d ("efivars: efivar_entry API") Reported-by: Bob Sanders and the LTP testsuite Signed-off-by: Vladis Dronov Link: https://lore.kernel.org/r/20200305084041.24053-2-vdronov@redhat.com Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efivars.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c index d309abca5091..485c592d7990 100644 --- a/drivers/firmware/efi/efivars.c +++ b/drivers/firmware/efi/efivars.c @@ -83,13 +83,16 @@ static ssize_t efivar_attr_read(struct efivar_entry *entry, char *buf) { struct efi_variable *var = &entry->var; + unsigned long size = sizeof(var->Data); char *str = buf; + int ret; if (!entry || !buf) return -EINVAL; - var->DataSize = 1024; - if (efivar_entry_get(entry, &var->Attributes, &var->DataSize, var->Data)) + ret = efivar_entry_get(entry, &var->Attributes, &size, var->Data); + var->DataSize = size; + if (ret) return -EIO; if (var->Attributes & EFI_VARIABLE_NON_VOLATILE) @@ -116,13 +119,16 @@ static ssize_t efivar_size_read(struct efivar_entry *entry, char *buf) { struct efi_variable *var = &entry->var; + unsigned long size = sizeof(var->Data); char *str = buf; + int ret; if (!entry || !buf) return -EINVAL; - var->DataSize = 1024; - if (efivar_entry_get(entry, &var->Attributes, &var->DataSize, var->Data)) + ret = efivar_entry_get(entry, &var->Attributes, &size, var->Data); + var->DataSize = size; + if (ret) return -EIO; str += sprintf(str, "0x%lx\n", var->DataSize); @@ -133,12 +139,15 @@ static ssize_t efivar_data_read(struct efivar_entry *entry, char *buf) { struct efi_variable *var = &entry->var; + unsigned long size = sizeof(var->Data); + int ret; if (!entry || !buf) return -EINVAL; - var->DataSize = 1024; - if (efivar_entry_get(entry, &var->Attributes, &var->DataSize, var->Data)) + ret = efivar_entry_get(entry, &var->Attributes, &size, var->Data); + var->DataSize = size; + if (ret) return -EIO; memcpy(buf, var->Data, var->DataSize); @@ -250,14 +259,16 @@ efivar_show_raw(struct efivar_entry *entry, char *buf) { struct efi_variable *var = &entry->var; struct compat_efi_variable *compat; + unsigned long datasize = sizeof(var->Data); size_t size; + int ret; if (!entry || !buf) return 0; - var->DataSize = 1024; - if (efivar_entry_get(entry, &entry->var.Attributes, - &entry->var.DataSize, entry->var.Data)) + ret = efivar_entry_get(entry, &var->Attributes, &datasize, var->Data); + var->DataSize = datasize; + if (ret) return -EIO; if (in_compat_syscall()) { From patchwork Sun Mar 8 08:08:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA8EDC10F28 for ; Sun, 8 Mar 2020 08:10:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 90644208CD for ; Sun, 8 Mar 2020 08:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655041; bh=bzyWUzT+NhCF+bkKOqxl9ChyduAJx/5Wzt4n9ZAB888=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MgokvrkazVhPBd2g1d8BnN9JLP3eHD4nO6stoS0TTlQHsXHTiq7R7vjELYIXCAm+c qh/GgLFzlohSgWfM+P50R7DLLRygo5vGUpsetFMPzcP+bjLcIyj1linr/Qbcfb05H8 XubrExP+weDeOJnfaltoNLdw09caSdK7dEffdjzs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726695AbgCHIKk (ORCPT ); Sun, 8 Mar 2020 04:10:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:38728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbgCHIKj (ORCPT ); Sun, 8 Mar 2020 04:10:39 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F3B5208C3; Sun, 8 Mar 2020 08:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655039; bh=bzyWUzT+NhCF+bkKOqxl9ChyduAJx/5Wzt4n9ZAB888=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBmoj0G4tMEy9XZYE/D8Vs2w0yHvBLQf2yB3wg7kqf1LTCX4cIHPgpSg951WA89gz Gzfz8YjDEPyr4zOWEbvMDq833ojDFBKfrh4d0OdTgoLamsplwVXTVppEKVClPJUdtF 5iJJGQiCPevix2+Zm4IAdWO94QZ3RQj3Gg/6uZp8= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 26/28] efi/libstub/x86: use ULONG_MAX as upper bound for all allocations Date: Sun, 8 Mar 2020 09:08:57 +0100 Message-Id: <20200308080859.21568-27-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The header flag XLF_CAN_BE_LOADED_ABOVE_4G will inform us whether allocations above 4 GiB for kernel, command line, etc are permitted, so we take it into account when calling efi_allocate_pages() etc. However, CONFIG_EFI_STUB implies CONFIG_RELOCATABLE, and so the flag is guaranteed to be set on x86_64 builds, whereas i386 builds are guaranteed to run under firmware that will not allocate above 4 GB in the first place. So drop the check, and just pass ULONG_MAX as the upper bound for all allocations. Link: https://lore.kernel.org/r/20200303225054.28741-1-ardb@kernel.org Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/x86-stub.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 064941ecc36f..bf0c3f60762a 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -376,7 +376,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, char *cmdline_ptr; unsigned long ramdisk_addr; unsigned long ramdisk_size; - bool above4g; sys_table = sys_table_arg; @@ -394,10 +393,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, image_offset = (void *)startup_32 - image_base; hdr = &((struct boot_params *)image_base)->hdr; - above4g = hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G; - status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params, - above4g ? ULONG_MAX : UINT_MAX); + status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params, ULONG_MAX); if (status != EFI_SUCCESS) { efi_printk("Failed to allocate lowmem for boot params\n"); efi_exit(handle, status); @@ -421,8 +418,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, hdr->type_of_loader = 0x21; /* Convert unicode cmdline to ascii */ - cmdline_ptr = efi_convert_cmdline(image, &options_size, - above4g ? ULONG_MAX : UINT_MAX); + cmdline_ptr = efi_convert_cmdline(image, &options_size, ULONG_MAX); if (!cmdline_ptr) goto fail; @@ -442,8 +438,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, status = efi_load_initrd(image, &ramdisk_addr, &ramdisk_size, hdr->initrd_addr_max, - above4g ? ULONG_MAX - : hdr->initrd_addr_max); + ULONG_MAX); if (status != EFI_SUCCESS) goto fail2; hdr->ramdisk_image = ramdisk_addr & 0xffffffff; @@ -795,12 +790,8 @@ unsigned long efi_main(efi_handle_t handle, */ if (!noinitrd()) { unsigned long addr, size; - unsigned long max_addr = hdr->initrd_addr_max; - if (hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) - max_addr = ULONG_MAX; - - status = efi_load_initrd_dev_path(&addr, &size, max_addr); + status = efi_load_initrd_dev_path(&addr, &size, ULONG_MAX); if (status == EFI_SUCCESS) { hdr->ramdisk_image = (u32)addr; hdr->ramdisk_size = (u32)size; From patchwork Sun Mar 8 08:08:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FDDEC1975A for ; Sun, 8 Mar 2020 08:10:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED7102166E for ; Sun, 8 Mar 2020 08:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655052; bh=zKc2SulQs20Cun6h+8jWyRK6CogiZd5HYwoguulFBaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0jQg5sSyO+jFPwSDmb+q5RTOoPxAAFFyg8VyTYt3023GbQi0XOdKrHcsZXzh5Zi6p jTXQsCwUHb8hDttHELTd4Q9QnXNGGYY70vskBRznyZFPiZvV8ikVjvGTD/gbJfxnce bU0caWJhXrhDZtrH1IDxIaAL94eTmCQY4SylUnY0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727050AbgCHIKr (ORCPT ); Sun, 8 Mar 2020 04:10:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:38964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbgCHIKq (ORCPT ); Sun, 8 Mar 2020 04:10:46 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2B577208CD; Sun, 8 Mar 2020 08:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583655046; bh=zKc2SulQs20Cun6h+8jWyRK6CogiZd5HYwoguulFBaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fDCdSQlouPvsqVU7VFKJjgMIGTsuaITPxaujpKw9pl+YMQxBU4FHqvul2LGA4s3q1 R/zWLFuSHMtWyyBFL0frK0e87hiqS2+FDq7isOfgEhQPT0fUuQhnIq40ejkcp6MWgj sxrpdR1Eh4VwU6OBSltjKwpijeEB4n3es76Uqr8g= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Christoph Hellwig , David Hildenbrand , Davidlohr Bueso , Guenter Roeck , Heinrich Schuchardt , Jonathan Corbet , Lukas Bulwahn , Masahiro Yamada , Nikolai Merinov , Tom Lendacky , Vladis Dronov Subject: [PATCH 28/28] partitions/efi: Fix partition name parsing in GUID partition entry Date: Sun, 8 Mar 2020 09:08:59 +0100 Message-Id: <20200308080859.21568-29-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200308080859.21568-1-ardb@kernel.org> References: <20200308080859.21568-1-ardb@kernel.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Nikolai Merinov GUID partition entry defined to have a partition name as 36 UTF-16LE code units. This means that on big-endian platforms ASCII symbols would be read with 0xXX00 efi_char16_t character code. In order to correctly extract ASCII characters from a partition name field we should be converted from 16LE to CPU architecture. The problem exists on all big endian platforms. Cc: Davidlohr Bueso Signed-off-by: Nikolai Merinov Fixes: eec7ecfede74 ("genhd, efi: add efi partition metadata to hd_structs") Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/797777312.1324734.1582544319435.JavaMail.zimbra@inango-systems.com/ Signed-off-by: Ard Biesheuvel --- block/partitions/efi.c | 35 ++++++++++++++++++++++++++--------- block/partitions/efi.h | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index db2fef7dfc47..d26a0654d7ca 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -656,6 +656,30 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt, return 0; } +/** + * utf16_le_to_7bit(): Naively converts UTF-16LE string to 7bit characters + * @in: input UTF-16LE string + * @size: size of the input string + * @out: output string ptr, should be capable to store @size+1 characters + * + * Description: Converts @size UTF16-LE symbols from @in string to 7bit + * characters and store them to @out. Adds trailing zero to @out array. + */ +static void utf16_le_to_7bit(const __le16 *in, unsigned int size, u8 *out) +{ + unsigned int i = 0; + + out[size] = 0; + while (i < size) { + u8 c = le16_to_cpu(in[i]) & 0xff; + + if (c && !isprint(c)) + c = '!'; + out[i] = c; + i++; + } +} + /** * efi_partition(struct parsed_partitions *state) * @state: disk parsed partitions @@ -692,7 +716,6 @@ int efi_partition(struct parsed_partitions *state) for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) { struct partition_meta_info *info; - unsigned label_count = 0; unsigned label_max; u64 start = le64_to_cpu(ptes[i].starting_lba); u64 size = le64_to_cpu(ptes[i].ending_lba) - @@ -713,14 +736,8 @@ int efi_partition(struct parsed_partitions *state) /* Naively convert UTF16-LE to 7 bits. */ label_max = min(ARRAY_SIZE(info->volname) - 1, ARRAY_SIZE(ptes[i].partition_name)); - info->volname[label_max] = 0; - while (label_count < label_max) { - u8 c = ptes[i].partition_name[label_count] & 0xff; - if (c && !isprint(c)) - c = '!'; - info->volname[label_count] = c; - label_count++; - } + utf16_le_to_7bit(ptes[i].partition_name, label_max, + info->volname); state->parts[i + 1].has_info = true; } kfree(ptes); diff --git a/block/partitions/efi.h b/block/partitions/efi.h index 3e8576157575..0b6d5b7be111 100644 --- a/block/partitions/efi.h +++ b/block/partitions/efi.h @@ -88,7 +88,7 @@ typedef struct _gpt_entry { __le64 starting_lba; __le64 ending_lba; gpt_entry_attributes attributes; - efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; + __le16 partition_name[72 / sizeof (__le16)]; } __packed gpt_entry; typedef struct _gpt_mbr_record {