From patchwork Thu Feb 23 18:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1747063 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=roBvGY3y; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PN16H3Z7dz23yr for ; Fri, 24 Feb 2023 05:00:55 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7B5C2843B5; Thu, 23 Feb 2023 19:00:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="roBvGY3y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C06D780BAA; Thu, 23 Feb 2023 19:00:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1B1AA853AA for ; Thu, 23 Feb 2023 19:00:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from workstation5.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 0657D3F311; Thu, 23 Feb 2023 18:00:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1677175240; bh=sjcS1FlldlxUleE3ycdwpW4GcPREDKzzWiw5YyI/klg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=roBvGY3yngpMJFJlR0XiljvrZ1P2PCyXyNeytP7R0bAeP6UG976JxTPWU4z/iqb+V xUgD30d5+RteXwTj5GvgV1jag1bbEgtyIbXXFNH4euSPZEX6iS+7n6NWXbpCsDKYNb Uav0mvVjLtxW7IWCbRmeNP0GVWf7+Sz9H8dpiXYVpn28pkNfwqGk+Yt5MfUsdTGbZy FiuAEvvyhPMYYBE4Aley6WUSCCVFUZ7C0zkjHkjy02oGwnnzRr7MtIWTzTIay5W86g 3QGWnOlKxlZjZZRW8uXsmtfTwF41eMviK5klQuj+8L3rd4xNYHlzzjDZn/VTVT8D+k kWMccTCJnKE5Q== From: Heinrich Schuchardt To: Ilias Apalodimas Cc: Alexandre Ghiti , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] cmd: bootefi: allocate device-tree copy from high memory Date: Thu, 23 Feb 2023 19:00:29 +0100 Message-Id: <20230223180029.69447-1-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The bootefi command creates a copy of the device-tree within the first 127 MiB of memory. This may lead to overwriting previously loaded binaries (e.g. kernel, initrd). Linux EFI stub itself copies U-Boot's copy of the device-tree. This means there is not restriction for U-Boot to place the device-tree copy to any address. (Restrictions existed for 32bit ARM before Linux commit 7a1be318f579 ("ARM: 9012/1: move device tree mapping out of linear region") for legacy booting. Reported-by: Alexandre Ghiti Signed-off-by: Heinrich Schuchardt Tested-by: Alexandre Ghiti --- cmd/bootefi.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 6618335ddf..aca4e99930 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -208,21 +208,12 @@ static efi_status_t copy_fdt(void **fdtp) * Safe fdt location is at 127 MiB. * On the sandbox convert from the sandbox address space. */ - new_fdt_addr = (uintptr_t)map_sysmem(fdt_ram_start + 0x7f00000 + - fdt_size, 0); - ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, + ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, EFI_ACPI_RECLAIM_MEMORY, fdt_pages, &new_fdt_addr); if (ret != EFI_SUCCESS) { - /* If we can't put it there, put it somewhere */ - new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size); - ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_ACPI_RECLAIM_MEMORY, fdt_pages, - &new_fdt_addr); - if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to reserve space for FDT\n"); - goto done; - } + log_err("ERROR: Failed to reserve space for FDT\n"); + goto done; } new_fdt = (void *)(uintptr_t)new_fdt_addr; memcpy(new_fdt, fdt, fdt_totalsize(fdt));