diff --git a/0471-x86-efi-Fallback-to-legacy-loader-for-old-kernels.patch b/0471-x86-efi-Fallback-to-legacy-loader-for-old-kernels.patch new file mode 100644 index 0000000000000000000000000000000000000000..013537292a618f76781c2d2cca60102fbfd6e76c --- /dev/null +++ b/0471-x86-efi-Fallback-to-legacy-loader-for-old-kernels.patch @@ -0,0 +1,119 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: wynnfeng +Date: Wed, 5 Aug 2026 14:50:00 +0800 +Subject: [PATCH] x86/efi: Fallback to legacy loader for old kernels + +Patch 0213 moved the x86_64-efi "linux" command to loader/i386/efi/linux.c +(EFI handover path). Kernels older than Linux v5.8 do not implement the +LoadFile2 initrd protocol and may reboot when booted via the handover +loader. Restore the same automatic fallback to grub_cmd_linux_x86_legacy() +that loader/efi/linux.c used before those code paths were disabled on x86. + +Also honor the linux_efi_legacy environment variable for manual override, +matching downstream practice (e.g. StarlingX). + +Signed-off-by: wynnfeng +--- + grub-core/loader/efi/linux.c | 6 ++++++ + grub-core/loader/i386/efi/linux.c | 35 +++++++++++++++++++++++++++++++++++ + include/grub/efi/linux.h | 3 +++ + 3 files changed, 45 insertions(+) + +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -419,6 +419,12 @@ + return GRUB_ERR_NONE; + } + ++bool ++grub_efi_linux_kernel_uses_loadfile2 (void) ++{ ++ return initrd_use_loadfile2; ++} ++ + #if !defined(__i386__) && !defined(__x86_64__) + static grub_err_t + finalize_params_linux (void) +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -34,6 +35,11 @@ + + GRUB_MOD_LICENSE ("GPLv3+"); + ++extern grub_err_t EXPORT_FUNC (grub_cmd_linux_x86_legacy) (grub_command_t cmd, ++ int argc, char *argv[]); ++extern grub_err_t EXPORT_FUNC (grub_cmd_initrd_x86_legacy) (grub_command_t cmd, ++ int argc, char *argv[]); ++ + static grub_dl_t my_mod; + + static grub_command_t cmd_linux, cmd_initrd; +@@ -216,6 +222,10 @@ + goto fail; + } + ++ if (grub_env_get ("linux_efi_legacy") || ++ !grub_efi_linux_kernel_uses_loadfile2 ()) ++ return grub_cmd_initrd_x86_legacy (cmd, argc, argv); ++ + if (!context) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first")); +@@ -289,6 +299,31 @@ + if (! file) + goto fail; + ++ { ++ struct linux_arch_kernel_header arch_lh; ++ int nx_required = 0; ++ ++ if (grub_env_get ("linux_efi_legacy") || ++ grub_arch_efi_linux_load_image_header (file, &arch_lh) != GRUB_ERR_NONE || ++ !grub_efi_linux_kernel_uses_loadfile2 ()) ++ { ++ if (grub_efi_check_nx_required (&nx_required)) ++ { ++ grub_error (GRUB_ERR_BAD_OS, ++ N_("cannot use legacy loader when NX is required")); ++ goto fail; ++ } ++ ++ grub_file_close (file); ++ grub_dprintf ("linux", ++ "falling back to legacy Linux kernel loader\n"); ++ return grub_cmd_linux_x86_legacy (cmd, argc, argv); ++ } ++ ++ if (grub_file_seek (file, 0) == (grub_off_t) -1) ++ goto fail; ++ } ++ + filelen = grub_file_size (file); + + kernel = grub_malloc(filelen); +--- a/include/grub/efi/linux.h ++++ b/include/grub/efi/linux.h +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + + #define GRUB_MOK_POLICY_NX_REQUIRED 0x1 + +@@ -44,4 +45,7 @@ + grub_size_t k_size, + grub_size_t k_start, int nx_supported); + ++ ++bool EXPORT_FUNC (grub_efi_linux_kernel_uses_loadfile2) (void); ++ + #endif /* ! GRUB_EFI_LINUX_HEADER */ diff --git a/0472-loongarch-Skip-NX-module-memory-attributes.patch b/0472-loongarch-Skip-NX-module-memory-attributes.patch new file mode 100644 index 0000000000000000000000000000000000000000..2be1f7fce636d8be4ad99b9d0ee7f97233d4e17a --- /dev/null +++ b/0472-loongarch-Skip-NX-module-memory-attributes.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: wynnfeng +Date: Wed, 5 Aug 2026 15:35:00 +0800 +Subject: [PATCH] loongarch: Skip NX module memory attributes + +2.12-20 rebased onto upstream introduced NX module loading (0171-0173, +0264) together with 0446 enabling 4 KiB section alignment on +loongarch64-efi. On LoongArch machines this can leave embedded modules +non-executable or otherwise broken, dropping GRUB into the rescue shell +with no working keyboard input after reboot. + +Restore the pre-2.12-20 module loading behaviour on LoongArch until NX +is validated on this platform: do not rewrite page permissions when +loading modules and do not force 4 KiB section alignment. + +Signed-off-by: wynnfeng +--- + grub-core/kern/dl.c | 10 ++++++++++ + grub-core/kern/loongarch64/dl.c | 6 +----- + 2 files changed, 11 insertions(+), 5 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index cb49bdc..a876d54 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -735,6 +735,16 @@ grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e) + static grub_err_t + grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) + { ++#if defined(__loongarch__) ++ /* ++ * LoongArch EFI firmware may not implement the Memory Attribute ++ * Protocol correctly. Applying NX permissions to dynamically loaded ++ * modules can leave code non-executable and strand GRUB at the rescue ++ * shell with no working console input. Keep the pre-2.12-20 behaviour ++ * until NX support is validated on this platform. ++ */ ++ return GRUB_ERR_NONE; ++#endif + unsigned i; + const Elf_Shdr *s; + const Elf_Ehdr *e = ehdr; +diff --git a/grub-core/kern/loongarch64/dl.c b/grub-core/kern/loongarch64/dl.c +index 9a9c883..02f3175 100644 +--- a/grub-core/kern/loongarch64/dl.c ++++ b/grub-core/kern/loongarch64/dl.c +@@ -155,9 +155,5 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + grub_size_t + grub_arch_dl_min_alignment (void) + { +-#ifdef GRUB_MACHINE_EFI +- return 4096; +-#else + return 1; +-#endif + } +\ No newline at end of file diff --git a/grub.macros b/grub.macros index cdfdf8e277ddc879cee85175fc8969528f6536aa..b752613142db2bb40e6769cd531641562f689f0d 100644 --- a/grub.macros +++ b/grub.macros @@ -411,7 +411,7 @@ install -m 644 %{1}.conf ${RPM_BUILD_ROOT}/etc/dnf/protected.d/ \ rm -f %{1}.conf \ %{nil} -%global grub_modules " all_video boot blscfg \\\ +%global grub_modules " all_video boot blscfg btrfs \\\ cat configfile cryptodisk \\\ echo ext2 f2fs fat font \\\ gcry_rijndael gcry_rsa gcry_serpent \\\ @@ -423,7 +423,7 @@ rm -f %{1}.conf \ memdisk \\\ mdraid09 mdraid1x minicmd net \\\ normal part_apple part_msdos part_gpt \\\ - password_pbkdf2 pgp png reboot regexp \\\ + password_pbkdf2 pgp png read reboot regexp \\\ search search_fs_uuid search_fs_file \\\ search_label serial sleep \\\ squash4 \\\ diff --git a/grub.patches b/grub.patches index 9228b78a551329bb0c62a970c159c32a92a1e7d0..3fffcbebca70aa0a6fd79b9ab994f85453d7f3b9 100644 --- a/grub.patches +++ b/grub.patches @@ -466,3 +466,5 @@ Patch0467: 0467-luks2-Use-grub-tpm2-token-for-TPM2-protected-volume.patch Patch0468: 0468-linuxefi-Use-common-grub_initrd_load.patch Patch0469: 0469-Add-crypttab-support-for-etc-crypttab-keyfile-import.patch Patch0470: 0470-appendedsig-Build-module-on-x86-and-loongarch64.patch +Patch0471: 0471-x86-efi-Fallback-to-legacy-loader-for-old-kernels.patch +Patch0472: 0472-loongarch-Skip-NX-module-memory-attributes.patch diff --git a/grub2.spec b/grub2.spec index c7d5c404caa8f3a2038b405a7e8c9e5851bc8f51..cf204558084e0cc57619539e66926dbcc777805a 100644 --- a/grub2.spec +++ b/grub2.spec @@ -17,7 +17,7 @@ Summary: Bootloader with support for Linux, Multiboot and more Name: grub2 Version: 2.12 -Release: 20%{?dist} +Release: 21%{?dist} License: GPL-3.0-or-later URL: http://www.gnu.org/software/grub/ Obsoletes: grub < 1:0.98 @@ -558,6 +558,15 @@ fi %endif %changelog +* Wed Aug 05 2026 wynnfeng - 2.12-21 +- [Type] bugfix +- [DESC] Patch 0471 (x86/efi): restore automatic fallback to the legacy Linux + loader for kernels without LoadFile2 initrd support, fixing PXE boot with + Linux 5.4 while keeping the 2.12-20 EFI handover path for newer kernels. + Patch 0472 (loongarch64): skip NX module memory attributes and 4 KiB section + alignment introduced by the 2.12-20 rebase, fixing reboot hang at the GRUB + rescue shell with no keyboard input on LoongArch64 + * Tue Dec 30 2025 wynnfeng - 2.12-20 - [Type] bugfix - [DESC] Refactor spec and patches to align with the upstream grub2 baseline