Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q4Zkf-0007iU-Rt for mharc-grub-devel@gnu.org; Thu, 01 Jun 2023 00:17:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4Zkd-0007ha-Cs for grub-devel@gnu.org; Thu, 01 Jun 2023 00:17:27 -0400 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4Zkb-0006EH-LB for grub-devel@gnu.org; Thu, 01 Jun 2023 00:17:27 -0400 Received: by mail-qt1-x82a.google.com with SMTP id d75a77b69052e-3f6c014d33fso2533001cf.2 for ; Wed, 31 May 2023 21:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20221208.gappssmtp.com; s=20221208; t=1685593044; x=1688185044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MNQaHfn8nQ42DNTHyo3+dJP3AobwmWxTkwoYapNjFB0=; b=birT9edCNxWnTgSUM5vrBzXivwXSLp3K0cUXyBbljQU5EyY51Kt1cb+RISscIYjwNR 9+wg1KTSHfRg0EYVr+2SOHeYODk8akjAVYNbFt3wXr8rCx1wbDid2D9Eq2NAgwYG7Af4 F6M7f7yEzWcSKag8A/islI29SOoBXmEts7xNptjzg3C9H1Iwrqug6Ya3oPmX7/DFyvej LV7GN1bl7dzTju771pB4w9GIUr/3Njg/sH+kEV/sjvCn/DnmZBXXvPO0+YPc6Mqrn3ho QkxwIfyyABbfAjVqeWYBkHjeVz+xWHV4sKh4MMT7+7I6TKgvMPmbRU4gM8P/YGiuNCrQ WrMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685593044; x=1688185044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MNQaHfn8nQ42DNTHyo3+dJP3AobwmWxTkwoYapNjFB0=; b=M9WXVETTcy+4elquTjm45gHgHsx34trtQGBsVUQGE3bVo8loNgbXa5zbskuqdOTHWU +aByqMCrcAJ5RIoFrdrDMalMH4f9lTAM5wWSmAGqnCwD7+lUGBJ6uCL5gce2OVfhCCJc KSpHhdwgMmtjUod40PrHSrTKsAQe9hh/GOlS1MZfXIrsdNvQ8uogKYktdQKqkkIQBobH J4SCntzrLj8PWvD3crFCUPknP4vhAmuX0dWcGyRF1dGA+rAGiuSlTJ3+XYLuYXkAz7Fu ZZmTO8azWy4wCmjoW85Z3Bx6Ba921C20tn4p5QDb4lKdHXQ1rTOlbYhAY7DQb2S/7E6i mDLA== X-Gm-Message-State: AC+VfDzhlNGRGBDv/dlcdSM5igRbp6d+s2IXXSY8jNmj7gnwvLDg0LX9 knl+0yzZA/qS0jUBCMhR/mQggeHQanZ0DpJqeA0= X-Google-Smtp-Source: ACHHUZ6wXa5nuE7LnHycDDGLeToA6Dj6cLuP/2oUmp7WRdttX+f3E4GhEQgV9cp53QpG4SHe83jwaw== X-Received: by 2002:ac8:5f4d:0:b0:3f5:3f9e:ffce with SMTP id y13-20020ac85f4d000000b003f53f9effcemr7768237qta.43.1685593043763; Wed, 31 May 2023 21:17:23 -0700 (PDT) Received: from localhost.localdomain ([199.58.83.12]) by smtp.gmail.com with ESMTPSA id j29-20020ac84c9d000000b003f38aabb88asm6966908qtv.20.2023.05.31.21.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 21:17:23 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Ard Biesheuvel , Glenn Washburn Subject: [PATCH v2 2/2] efi/chainloader: Do not require a $root visible to EFI firmware when chainloading Date: Wed, 31 May 2023 23:16:26 -0500 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::82a; envelope-from=development@efficientek.com; helo=mail-qt1-x82a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jun 2023 04:17:27 -0000 The EFI chainloader checks that a device path can be created for the $root device before allowing chainloading to a given file. This is probably to ensure that the given file can be accessed and loaded by the firmware. However, since GRUB is loading the image itself, the firmware need not be able to access the file location of the image. So remove this check. Also, this fixes an issue where chainloading an image file on a location that is accessible by the firmware, eg. (hd0,1)/efi/boot.efi, would fail when root is a location inaccessible by the firmware, eg. memdisk. Use GRUB_EFI_BYTES_TO_PAGES() instead of doing the calculation explicitly. Add comment noting the section where the load options for the chainloaded EFI application is constructed. Signed-off-by: Glenn Washburn --- grub-core/loader/efi/chainloader.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 1759af632fe9..1de98f783136 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -241,10 +242,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), /* Get the root device's device path. */ dev = grub_device_open (0); - if (! dev) - goto fail; - - if (dev->disk) + if (dev == NULL) + ; + else if (dev->disk) dev_handle = grub_efidisk_get_device_handle (dev->disk); else if (dev->net && dev->net->server) { @@ -267,18 +267,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (dev_handle) dp = grub_efi_get_device_path (dev_handle); - if (! dp) + if (dp != NULL) { - grub_error (GRUB_ERR_BAD_DEVICE, "not a valid root device"); - goto fail; - } - - file_path = make_file_path (dp, filename); - if (! file_path) - goto fail; + file_path = make_file_path (dp, filename); + if (file_path == NULL) + goto fail; - grub_printf ("file path: "); - grub_efi_print_device_path (file_path); + grub_printf ("file path: "); + grub_efi_print_device_path (file_path); + } size = grub_file_size (file); if (!size) @@ -287,7 +284,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), filename); goto fail; } - pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12); + pages = (grub_efi_uintn_t) GRUB_EFI_BYTES_TO_PAGES (size); status = b->allocate_pages (GRUB_EFI_ALLOCATE_ANY_PAGES, GRUB_EFI_LOADER_CODE, @@ -370,6 +367,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } loaded_image->device_handle = dev_handle; + /* Build load options with arguments from chainloader command line. */ if (argc > 1) { int i, len; -- 2.34.1