From patchwork Sat Mar 28 20:58:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 206437 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 3C14DC43331 for ; Sat, 28 Mar 2020 20:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DC3E20716 for ; Sat, 28 Mar 2020 20:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585429097; bh=Wu4f1OnYj/QRZ0sdavFX0f/+cR088OEXn5AlxBMtMz8=; h=From:To:Cc:Subject:Date:List-ID:From; b=D34lwBprdTW9isQWK9XmqSb8Z7iX6GHbwsMxKbFAr5VzyxQ5a49USLbVAjSy4N36U o4bkgFbI+e6Fo8yumvUP1Ac9/sysfTNY59O903NLc6bnzHq6LJbb8t0EjvLow1ECbn AFXxP7eqoiSKST/l98bb0F47hsz45+NPPzXzaovA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbgC1U6Q (ORCPT ); Sat, 28 Mar 2020 16:58:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:38154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727009AbgC1U6Q (ORCPT ); Sat, 28 Mar 2020 16:58:16 -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 471B320714; Sat, 28 Mar 2020 20:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585429095; bh=Wu4f1OnYj/QRZ0sdavFX0f/+cR088OEXn5AlxBMtMz8=; h=From:To:Cc:Subject:Date:From; b=dh4KGrgzdL5yTx1XuHjUoCMQJFxrBr+KcCzkDPyt1vPlYL3M29TnFZ96Q5Sg/wVH5 LzPspshFNInQYvUsLZXjDVL5VQtZf+nVMMjd75m/vlL4xmSoo/C6xLwqbzHAUmGg1u dl14tB6hykH/VhACWO/nxOm9f3endQrrFQCFRXYo= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org, leif@nuviainc.com, mikelley@microsoft.com, Boqun.Feng@microsoft.com, Ard Biesheuvel Subject: [PATCH] efi/libstub/arm64: avoid image_base value from efi_loaded_image Date: Sat, 28 Mar 2020 21:58:09 +0100 Message-Id: <20200328205809.23825-1-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Commit 9f9223778ef3 ("efi/libstub/arm: Make efi_entry() an ordinary PE/COFF entrypoint") did some code refactoring to get rid of the EFI entry point assembler code, and in the process, it got rid of the assignment of image_addr to the value of _text. Instead, it switched to using the image_base field of the efi_loaded_image struct provided by UEFI, which should contain the same value. However, Michael reports that this is not the case: older GRUB builds corrupt this value in some way, and since we can easily switch back to referring to _text to discover this value, let's simply do that. While at it, fix another issue in commit 9f9223778ef3, which may result in the unassigned image_addr to be misidentified as the preferred load offset of the kernel, which is unlikely but will cause a boot crash if it does occur. Finally, let's add a warning if the _text vs. image_base discrepancy is detected, so we can tell more easily how widespread this issue actually is. Reported-by: Michael Kelley Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm64-stub.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c index 9254cd8ab2d3..db0c1a9c1699 100644 --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -116,6 +116,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, * Mustang), we can still place the kernel at the address * 'dram_base + TEXT_OFFSET'. */ + *image_addr = (unsigned long)_text; if (*image_addr == preferred_offset) return EFI_SUCCESS; @@ -140,7 +141,11 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, } *image_addr = *reserve_addr + TEXT_OFFSET; } - memcpy((void *)*image_addr, image->image_base, kernel_size); + + if (image->image_base != _text) + pr_efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n"); + + memcpy((void *)*image_addr, _text, kernel_size); return EFI_SUCCESS; }