Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oRR15-0004Xf-Mm for mharc-grub-devel@gnu.org; Fri, 26 Aug 2022 00:32:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRR14-0004WM-HV for grub-devel@gnu.org; Fri, 26 Aug 2022 00:32:22 -0400 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]:45796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oRR12-0000TY-Pp for grub-devel@gnu.org; Fri, 26 Aug 2022 00:32:22 -0400 Received: by mail-qv1-xf2d.google.com with SMTP id de16so247015qvb.12 for ; Thu, 25 Aug 2022 21:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=EYftn3/wwDZHRzYsvGGrj2OtGd9P/hhm01oBh2K5YP0=; b=h882D2L295dfdcYXG6K92BCbkf4tahl/gUxTqE2wdJO1asXranxsgoizXoPxFa7psB zHSz1jrCV3GXNAIphsUdigYj+EjaZj4Yryog1eNaZDfcogielH7kZEzZQaLBH6721e2H DfTntU+mgdbxmjnI9J6eAE+aE7SEoHJ0dfMNRC6jflblODzF/J4HTn09knY7qh3vZfrW Q3JhnYeXZEsPyhhVVbMj92H5xQjl53/ddGUPjhYHp/xe3otVIxbZxiZ7gMaoB6vFPhXr L6EQkO7CI6zol1DqVDwb0ASdKgw6IocpcgVBVND8xBAygE2Jv3B/xL/QKjKgTZBcrR4A hemg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=EYftn3/wwDZHRzYsvGGrj2OtGd9P/hhm01oBh2K5YP0=; b=CZv1RUnc2N4EC18WhQFvUFm27DabOcpb/Fl0YX0mvk0pz45kmf23tOdX414IO8A/IV 7hmF4zWL5kTzSQB8kzj94NEfx8L3TxvbfM+B+ep01qtMx3Tg8pNC9AmJejT/2+Ah7Otx +q4U9dGUk7jpXfyBEQrEHAmZ9zR6bTS5XiF6geBYKdN+zl5wRJ583507XwQZKh4wmvkq +Kgqk3fdK+OXQtrrcsPR6o1VYpa/NWpBdbxpIspOpXyblXFy/xUo23YE00R5PABDDEB1 3V9v1i4ChP+206H9GdNcHrzFTdjTIikuLzzGiUUS9sagHzm6CwgO9SVdYU0kQtIB7tby IDkQ== X-Gm-Message-State: ACgBeo1puEUrRuKW6Cuo8PVy/DSLEexggepMcDFB+/JMEt0Mw5/T0+L8 7rSLiE2j81XNdqNM3V4Jhnv0ud73rBCqBQ== X-Google-Smtp-Source: AA6agR7njv6ckIX6MWuGdZ8TsNuw4V2NAt3B7sMNxI5c7ycA2QH6+5T1yI74PCgG9cVjqqtPSXtlig== X-Received: by 2002:a05:6214:27cb:b0:497:e38:fa3d with SMTP id ge11-20020a05621427cb00b004970e38fa3dmr6494537qvb.34.1661488339724; Thu, 25 Aug 2022 21:32:19 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id j7-20020ac85c47000000b0031f0b43629dsm650086qtj.23.2022.08.25.21.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 21:32:19 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Ard Biesheuvel , Glenn Washburn Subject: [PATCH 1/2] efi/chainloader: Do not require a valid $root when chainloading Date: Thu, 25 Aug 2022 23:32:02 -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::f2d; envelope-from=development@efficientek.com; helo=mail-qv1-xf2d.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: Fri, 26 Aug 2022 04:32:22 -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 donig 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 | 31 +++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 7557eb269b..5aac3c59fd 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 @@ -239,11 +240,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (! file) goto fail; - /* Get the root device's device path. */ - dev = grub_device_open (0); - if (! dev) - goto fail; - + dev = file->device; if (dev->disk) dev_handle = grub_efidisk_get_device_handle (dev->disk); else if (dev->net && dev->net->server) @@ -267,18 +264,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 +281,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 = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, GRUB_EFI_LOADER_CODE, @@ -370,6 +364,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; @@ -400,7 +395,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } grub_file_close (file); - grub_device_close (dev); /* We're finished with the source image buffer and file path now. */ efi_call_2 (b->free_pages, address, pages); @@ -411,9 +405,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), fail: - if (dev) - grub_device_close (dev); - if (file) grub_file_close (file); -- 2.34.1