From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q4Zkc-0007el-5z for mharc-grub-devel@gnu.org; Thu, 01 Jun 2023 00:17:26 -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 1q4Zka-0007eO-DD for grub-devel@gnu.org; Thu, 01 Jun 2023 00:17:24 -0400 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4ZkY-0006Dy-5y for grub-devel@gnu.org; Thu, 01 Jun 2023 00:17:24 -0400 Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-3f8008cb772so2832491cf.3 for ; Wed, 31 May 2023 21:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20221208.gappssmtp.com; s=20221208; t=1685593040; x=1688185040; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ToTmKd4mZ0dv21AUDtkyaULL4mtNq1VttlRke7p+vCw=; b=p+RJ2/3ffRAZsAlvTZiuwdHsqkjFuuM0MLV+uCYqy0s4v3t/Uy8lwH/vYixX26Mcy8 JzHTNImabDCj8o8Ep4PpdkHJiOJPnAnZjA5w8WjZzpSciBkTeyxUl0nyYHsSFcWzO3Bc Qqn5gdYeeX3lEPi/2RiqZMhJ/Ktfcod2yclu9Sz5kpej8LMaLpHckQzU1tZqNonNtN1H qMrSyfETxmapJWMCRam2Yx6mt4KPiw4Fk5wrAuvZBiWucQ8GTfqquKTtxHR4g9VX6MvD EHq0vKZgY+o0TN37gHI5HMdxC95Z2eU2Aw8naoXMVgz1Oz+c6oXfgxNCQ1vASrdTWP40 GGJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685593040; x=1688185040; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ToTmKd4mZ0dv21AUDtkyaULL4mtNq1VttlRke7p+vCw=; b=MhYZSEjDSLYmR6AMDMapvoVJXFq8iygoDqczdHqkCCEtGBFsgfkmlHfE3z/maptJpx CNGa53UVvm2YsbfoN20KBX+AcWEUV0Fy5qDQjm2GGBnvPAiahLZk9dBJpnVwtM4RE9+e dcrfnDxAL4PT+P38VFF3Pl1QajKeLNGHuJIgds1w0qSVQKRYSENilaAJZKHy69oS7vNj 2U6kfrqIw955vqQB1v8Soomr2m7JW/47mrZLfIVrqfURCn7OmLvsVPmfsBnduapnRREH Ij0LKTXxRnF2CegXXyhf8AvDo7ZleM5q8bbdwzq68j42HQE81nkp0HEU3Ju+N1tjXPr2 uVqg== X-Gm-Message-State: AC+VfDzU1gZzNehsBmA8P26kHHrpaXGWS2LCtju+re+lq7id5yx8K74E kwZdbCzHvnF3O+BLv9oBperqnpCqbz9oX8biaQc= X-Google-Smtp-Source: ACHHUZ7BpHSzwWkEkzIEgIXQyXwlJBJPkdrSCNzhOHxzNg9VYZTswYtxtcfnlyx9gpOV4AInj3lRuA== X-Received: by 2002:a05:622a:1aa4:b0:3f6:a965:3359 with SMTP id s36-20020a05622a1aa400b003f6a9653359mr9602579qtc.47.1685593040305; Wed, 31 May 2023 21:17:20 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 21:17:19 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Ard Biesheuvel , Glenn Washburn Subject: [PATCH v2 0/2] EFI chainloader improvement Date: Wed, 31 May 2023 23:16:24 -0500 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::834; envelope-from=development@efficientek.com; helo=mail-qt1-x834.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:24 -0000 Changes since v1: * Rebase onto latest master * Change logic: The device path argument to image load changed back to the way it was originally where the argument is set to the device path that $root resolves to. If $root does not resolve or is not a device, the argument will be NULL as allowed for in the spec. By setting $root to the device of the chainloaded file, v1 behavior can be had. So this is more versatile behavior. * Minor rewording of metadata. This series improves the EFI chainloader. I've noticed for a while now that chainloading would fail when root=memdisk. It didn't really make sense because I was specifying the image to chainload as device+path, so why would it care about what my root was. But I noticed that if I changed the root to the device the image file was located on, then chainloading worked. The second patch fixes this by removing some previous assumptions that I don't believe are valid (eg. that LoadImage needs a valid device path). Glenn Glenn Washburn (2): docs: Document extra arguments to chainloader on EFI efi/chainloader: Do not require a $root visible to EFI firmware when chainloading docs/grub.texi | 7 +++++-- grub-core/loader/efi/chainloader.c | 28 +++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) Range-diff against v1: 2: 04edeb1d7fd0 ! 1: d1fc25518bfc docs: Document that extra arguments to chainloader on EFI @@ Metadata Author: Glenn Washburn ## Commit message ## - docs: Document that extra arguments to chainloader on EFI + docs: Document extra arguments to chainloader on EFI Extra arguments given to chainloader on EFI platforms will be sent to the chainloaded application. Also, minor edit in the chainloading section @@ Commit message necessarily in real mode (which does not exist on some achitectures). ## docs/grub.texi ## -@@ docs/grub.texi: information. +@@ docs/grub.texi: invoke shutdown machinery. Operating systems that do not support Multiboot and do not have specific support in GRUB (specific support is available for Linux, FreeBSD, NetBSD and OpenBSD) must be chain-loaded, which involves loading another boot 1: eed74ee4b128 ! 2: c17d3a8a0fe0 efi/chainloader: Do not require a valid $root when chainloading @@ Metadata Author: Glenn Washburn ## Commit message ## - efi/chainloader: Do not require a valid $root when chainloading + efi/chainloader: Do not require a $root visible to EFI firmware when chainloading 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 @@ Commit message 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. + 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. @@ grub-core/loader/efi/chainloader.c #include #include @@ grub-core/loader/efi/chainloader.c: 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); + /* Get the root device's device path. */ + dev = grub_device_open (0); - if (! dev) - goto fail; - -+ dev = file->device; - if (dev->disk) +- 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) + { @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (dev_handle) dp = grub_efi_get_device_path (dev_handle); @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader (grub_command_t cmd __a - 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, + status = b->allocate_pages (GRUB_EFI_ALLOCATE_ANY_PAGES, GRUB_EFI_LOADER_CODE, @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } @@ grub-core/loader/efi/chainloader.c: grub_cmd_chainloader (grub_command_t cmd __a if (argc > 1) { int i, len; -@@ grub-core/loader/efi/chainloader.c: 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); -@@ grub-core/loader/efi/chainloader.c: 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