diff --git a/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch b/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch index fcc78251..51621653 100644 --- a/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch +++ b/0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch @@ -10,7 +10,7 @@ This reverts commit 722737630889607c3b5761f1f5a48f1674cd2821. 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 5984e92d291..94622481284 100644 +index 656301eaf22..376ca47efe4 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -36,7 +36,7 @@ if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/n diff --git a/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch b/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch index 4187765f..aa5a3263 100644 --- a/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch +++ b/0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch @@ -10,7 +10,7 @@ This reverts commit 54e0a1bbf1e9106901a557195bb35e5e20fb3925. 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index f8cbb8d7a2b..d3e879b8e5c 100644 +index 32c480daeb2..7516a015be0 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -140,9 +140,6 @@ GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2 @@ -31,7 +31,7 @@ index f8cbb8d7a2b..d3e879b8e5c 100644 GRUB_FS \ GRUB_FONT \ GRUB_PRELOAD_MODULES \ -@@ -246,6 +242,7 @@ export GRUB_DEFAULT \ +@@ -250,6 +246,7 @@ export GRUB_DEFAULT \ GRUB_BACKGROUND \ GRUB_THEME \ GRUB_GFXPAYLOAD_LINUX \ @@ -40,7 +40,7 @@ index f8cbb8d7a2b..d3e879b8e5c 100644 GRUB_SAVEDEFAULT \ GRUB_ENABLE_CRYPTODISK \ diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 94622481284..80685b15f4d 100644 +index 376ca47efe4..30f27f15b83 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -26,8 +26,8 @@ export TEXTDOMAINDIR="@localedir@" diff --git a/0003-Revert-templates-Disable-the-os-prober-by-default.patch b/0003-Revert-templates-Disable-the-os-prober-by-default.patch index 68cacfca..a51779d9 100644 --- a/0003-Revert-templates-Disable-the-os-prober-by-default.patch +++ b/0003-Revert-templates-Disable-the-os-prober-by-default.patch @@ -10,10 +10,10 @@ This reverts commit e346414725a70e5c74ee87ca14e580c66f517666. 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi -index f8b4b3b21a7..69f08d289f9 100644 +index a225f9a88d2..974bc0ddb07 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -1519,13 +1519,10 @@ boot sequence. If you have problems, set this option to @samp{text} and +@@ -1552,13 +1552,10 @@ boot sequence. If you have problems, set this option to @samp{text} and GRUB will tell Linux to boot in normal text mode. @item GRUB_DISABLE_OS_PROBER @@ -31,7 +31,7 @@ index f8b4b3b21a7..69f08d289f9 100644 @item GRUB_OS_PROBER_SKIP_LIST List of space-separated FS UUIDs of filesystems to be ignored from os-prober -@@ -1853,9 +1850,10 @@ than zero; otherwise 0. +@@ -1889,9 +1886,10 @@ than zero; otherwise 0. @section Multi-boot manual config Currently autogenerating config files for multi-boot environments depends on @@ -46,7 +46,7 @@ index f8b4b3b21a7..69f08d289f9 100644 First create a separate GRUB partition, big enough to hold GRUB. Some of the following entries show how to load OS installer images from this same partition, diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 80685b15f4d..1b91c102f35 100644 +index 30f27f15b83..f300e46fc6a 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -26,8 +26,7 @@ export TEXTDOMAINDIR="@localedir@" diff --git a/0005-Rework-linux-command.patch b/0004-Rework-linux-command.patch similarity index 86% rename from 0005-Rework-linux-command.patch rename to 0004-Rework-linux-command.patch index 9954dd0a..26d10ac8 100644 --- a/0005-Rework-linux-command.patch +++ b/0004-Rework-linux-command.patch @@ -13,10 +13,10 @@ Signed-off-by: Matthew Garrett 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 9f74a96b19a..dccf3bb3005 100644 +index 977757f2cc9..10f967f2563 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c -@@ -649,13 +649,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -661,13 +661,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { grub_file_t file = 0; struct linux_i386_kernel_header lh; @@ -33,7 +33,7 @@ index 9f74a96b19a..dccf3bb3005 100644 grub_dl_ref (my_mod); -@@ -669,7 +671,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -681,7 +683,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (! file) goto fail; @@ -50,7 +50,7 @@ index 9f74a96b19a..dccf3bb3005 100644 { if (!grub_errno) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -@@ -677,6 +687,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -689,6 +699,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } @@ -60,7 +60,7 @@ index 9f74a96b19a..dccf3bb3005 100644 if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) { grub_error (GRUB_ERR_BAD_OS, "invalid magic number"); -@@ -784,13 +797,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -796,13 +809,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* We've already read lh so there is no need to read it second time. */ len -= sizeof(lh); @@ -78,7 +78,7 @@ index 9f74a96b19a..dccf3bb3005 100644 } linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; -@@ -853,7 +864,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -865,7 +876,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* The other parameters are filled when booting. */ @@ -87,7 +87,7 @@ index 9f74a96b19a..dccf3bb3005 100644 grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n", (unsigned) real_size, (unsigned) prot_size); -@@ -1007,9 +1018,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -1019,9 +1030,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } len = prot_file_size; @@ -98,7 +98,7 @@ index 9f74a96b19a..dccf3bb3005 100644 if (grub_errno == GRUB_ERR_NONE) { -@@ -1020,6 +1029,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -1032,6 +1041,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), fail: diff --git a/0006-Rework-linux16-command.patch b/0005-Rework-linux16-command.patch similarity index 98% rename from 0006-Rework-linux16-command.patch rename to 0005-Rework-linux16-command.patch index 2c2d6f0b..50a648c8 100644 --- a/0006-Rework-linux16-command.patch +++ b/0005-Rework-linux16-command.patch @@ -13,7 +13,7 @@ Signed-off-by: Matthew Garrett 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 8be4c3b3f48..4b1750e360e 100644 +index 4adeee9ae00..600530a742b 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -124,13 +124,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), diff --git a/0010-re-write-.gitignore.patch b/0006-re-write-.gitignore.patch similarity index 95% rename from 0010-re-write-.gitignore.patch rename to 0006-re-write-.gitignore.patch index 74cb0dae..36b0efd8 100644 --- a/0010-re-write-.gitignore.patch +++ b/0006-re-write-.gitignore.patch @@ -4,14 +4,14 @@ Date: Mon, 8 Jul 2019 12:55:29 +0200 Subject: [PATCH] re-write .gitignore --- - .gitignore | 152 ++++++++++++++++++++++++++++++++++++++ + .gitignore | 150 ++++++++++++++++++++++++++++++++++++++ docs/.gitignore | 5 ++ grub-core/.gitignore | 16 ++++ grub-core/lib/.gitignore | 1 + include/grub/gcrypt/.gitignore | 2 + po/.gitignore | 5 ++ util/bash-completion.d/.gitignore | 2 + - 7 files changed, 183 insertions(+) + 7 files changed, 181 insertions(+) create mode 100644 docs/.gitignore create mode 100644 grub-core/.gitignore create mode 100644 grub-core/lib/.gitignore @@ -20,10 +20,10 @@ Subject: [PATCH] re-write .gitignore create mode 100644 util/bash-completion.d/.gitignore diff --git a/.gitignore b/.gitignore -index f6a1bd05175..594d0134d33 100644 +index 4d0dfb700e4..a18787dcfe6 100644 --- a/.gitignore +++ b/.gitignore -@@ -275,3 +275,155 @@ widthspec.bin +@@ -279,3 +279,153 @@ widthspec.bin /xfs_test /xzcompress_test /zfs_test @@ -152,8 +152,6 @@ index f6a1bd05175..594d0134d33 100644 +/grub*-reboot.8 +/grub*-render-label +/grub*-render-label.1 -+/grub*-rpm-sort -+/grub*-rpm-sort.8 +/grub*-script-check +/grub*-script-check.1 +/grub*-set-bootflag diff --git a/0011-IBM-client-architecture-CAS-reboot-support.patch b/0007-IBM-client-architecture-CAS-reboot-support.patch similarity index 91% rename from 0011-IBM-client-architecture-CAS-reboot-support.patch rename to 0007-IBM-client-architecture-CAS-reboot-support.patch index eaaf9a42..44755349 100644 --- a/0011-IBM-client-architecture-CAS-reboot-support.patch +++ b/0007-IBM-client-architecture-CAS-reboot-support.patch @@ -7,16 +7,20 @@ This is an implementation of IBM client architecture (CAS) reboot for GRUB. There are cases where the POWER firmware must reboot in order to support specific features requested by a kernel. The kernel calls -ibm,client-architecture-support and it may either return or reboot with the new -feature set. eg: +ibm,client-architecture-support and it may either return or reboot with +the new feature set. eg: Calling ibm,client-architecture-support.../ Elapsed time since release of system processors: 70959 mins 50 secs Welcome to GRUB! -Instead of return to the GRUB menu, it will check if the flag for CAS reboot is -set. If so, grub will automatically boot the last booted kernel using the same -parameters +Instead of return to the GRUB menu, it will check if the flag for CAS +reboot is set. If so, grub will automatically boot the last booted +kernel using the same parameters + +Signed-off-by: Paulo Flabiano Smorigo +[rharwood@redhat.com: commit message rewrap] +Signed-off-by: Robbie Harwood --- grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++++++++++ grub-core/normal/main.c | 19 ++++++++++++ @@ -25,7 +29,7 @@ parameters 4 files changed, 91 insertions(+) diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c -index 4d493ab7661..3a6689abb11 100644 +index 11b2beb2ff2..e2ecc65d2d8 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -591,3 +591,66 @@ grub_ieee1275_get_boot_dev (void) @@ -96,7 +100,7 @@ index 4d493ab7661..3a6689abb11 100644 + return 0; +} diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index c4ebe9e22ad..70614de1565 100644 +index bd44310005d..d3f53d93d87 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -34,6 +34,9 @@ @@ -133,7 +137,7 @@ index c4ebe9e22ad..70614de1565 100644 grub_errno = GRUB_ERR_NONE; } diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index 25158407dd8..ad80399246a 100644 +index 14ff09094f0..dab8fd2aeb0 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -28,6 +28,9 @@ @@ -158,10 +162,10 @@ index 25158407dd8..ad80399246a 100644 { char *line; diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h -index 73e2f464475..0a599607f31 100644 +index dddb385149e..4f6e6aaa098 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h -@@ -254,6 +254,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali +@@ -251,6 +251,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias); void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath, struct grub_ieee1275_devalias *alias); diff --git a/0012-for-ppc-reset-console-display-attr-when-clear-screen.patch b/0008-for-ppc-reset-console-display-attr-when-clear-screen.patch similarity index 89% rename from 0012-for-ppc-reset-console-display-attr-when-clear-screen.patch rename to 0008-for-ppc-reset-console-display-attr-when-clear-screen.patch index c8bb9d3c..63359395 100644 --- a/0012-for-ppc-reset-console-display-attr-when-clear-screen.patch +++ b/0008-for-ppc-reset-console-display-attr-when-clear-screen.patch @@ -10,12 +10,14 @@ This should fix this bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=908519 Signed-off-by: Peter Jones +Signed-off-by: Paulo Flabiano Smorigo +Signed-off-by: Robbie Harwood --- grub-core/term/terminfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c -index 85ecf06b4df..05c88dcf49e 100644 +index 4e534c683eb..3dbe88e8933 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output *term, diff --git a/0013-Disable-GRUB-video-support-for-IBM-power-machines.patch b/0009-Disable-GRUB-video-support-for-IBM-power-machines.patch similarity index 80% rename from 0013-Disable-GRUB-video-support-for-IBM-power-machines.patch rename to 0009-Disable-GRUB-video-support-for-IBM-power-machines.patch index 430f6002..d55e7d03 100644 --- a/0013-Disable-GRUB-video-support-for-IBM-power-machines.patch +++ b/0009-Disable-GRUB-video-support-for-IBM-power-machines.patch @@ -5,6 +5,9 @@ Subject: [PATCH] Disable GRUB video support for IBM power machines Should fix the problem in bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=973205 + +Signed-off-by: Paulo Flabiano Smorigo +Signed-off-by: Robbie Harwood --- grub-core/kern/ieee1275/cmain.c | 5 ++++- grub-core/video/ieee1275.c | 9 ++++++--- @@ -12,10 +15,10 @@ https://bugzilla.redhat.com/show_bug.cgi?id=973205 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c -index 20cbbd761ec..04df9d2c667 100644 +index e74de32483f..810a089a934 100644 --- a/grub-core/kern/ieee1275/cmain.c +++ b/grub-core/kern/ieee1275/cmain.c -@@ -90,7 +90,10 @@ grub_ieee1275_find_options (void) +@@ -89,7 +89,10 @@ grub_ieee1275_find_options (void) } if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0) @@ -28,10 +31,10 @@ index 20cbbd761ec..04df9d2c667 100644 /* Old Macs have no key repeat, newer ones have fully working one. The ones inbetween when repeated key generates an escaoe sequence diff --git a/grub-core/video/ieee1275.c b/grub-core/video/ieee1275.c -index 17a3dbbb575..b8e4b3feb32 100644 +index ca3d3c3b2c8..5592e4bb7c9 100644 --- a/grub-core/video/ieee1275.c +++ b/grub-core/video/ieee1275.c -@@ -352,9 +352,12 @@ static struct grub_video_adapter grub_video_ieee1275_adapter = +@@ -351,9 +351,12 @@ static struct grub_video_adapter grub_video_ieee1275_adapter = GRUB_MOD_INIT(ieee1275_fb) { @@ -48,14 +51,14 @@ index 17a3dbbb575..b8e4b3feb32 100644 GRUB_MOD_FINI(ieee1275_fb) diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h -index 0a599607f31..b5a1d49bbc3 100644 +index 4f6e6aaa098..db0ec5f4c68 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h -@@ -148,6 +148,8 @@ enum grub_ieee1275_flag - GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN, +@@ -145,6 +145,8 @@ enum grub_ieee1275_flag + GRUB_IEEE1275_FLAG_POWER_VM, - GRUB_IEEE1275_FLAG_RAW_DEVNAMES, -+ + GRUB_IEEE1275_FLAG_POWER_KVM, ++ + GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT }; diff --git a/0014-Move-bash-completion-script-922997.patch b/0010-Move-bash-completion-script-922997.patch similarity index 92% rename from 0014-Move-bash-completion-script-922997.patch rename to 0010-Move-bash-completion-script-922997.patch index 6bf0b4b9..113f8b08 100644 --- a/0014-Move-bash-completion-script-922997.patch +++ b/0010-Move-bash-completion-script-922997.patch @@ -10,10 +10,10 @@ Apparently these go in a new place now. 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac -index 7517fc49d98..8331f95b645 100644 +index cd667a2eb75..ae3a49321ad 100644 --- a/configure.ac +++ b/configure.ac -@@ -314,6 +314,14 @@ AC_SUBST(grubdirname) +@@ -319,6 +319,14 @@ AC_SUBST(grubdirname) AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname", [Default grub directory name]) @@ -28,7 +28,7 @@ index 7517fc49d98..8331f95b645 100644 # # Checks for build programs. # -@@ -525,6 +533,9 @@ HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags" +@@ -534,6 +542,9 @@ HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags" # Check for target programs. # diff --git a/0015-Allow-fallback-to-include-entries-by-title-not-just-.patch b/0011-Allow-fallback-to-include-entries-by-title-not-just-.patch similarity index 98% rename from 0015-Allow-fallback-to-include-entries-by-title-not-just-.patch rename to 0011-Allow-fallback-to-include-entries-by-title-not-just-.patch index f2a4a82c..b85e5e6e 100644 --- a/0015-Allow-fallback-to-include-entries-by-title-not-just-.patch +++ b/0011-Allow-fallback-to-include-entries-by-title-not-just-.patch @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 8397886fa05..d7a222e681b 100644 +index 6a90e091f22..6444ee6f969 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout) diff --git a/0016-Make-exit-take-a-return-code.patch b/0012-Make-exit-take-a-return-code.patch similarity index 84% rename from 0016-Make-exit-take-a-return-code.patch rename to 0012-Make-exit-take-a-return-code.patch index 39d70573..87e03ad8 100644 --- a/0016-Make-exit-take-a-return-code.patch +++ b/0012-Make-exit-take-a-return-code.patch @@ -13,7 +13,7 @@ Signed-off-by: Peter Jones grub-core/commands/minicmd.c | 20 ++++++++++++++++---- grub-core/kern/efi/efi.c | 9 +++++++-- grub-core/kern/emu/main.c | 2 +- - grub-core/kern/emu/misc.c | 5 +++-- + grub-core/kern/emu/misc.c | 9 +++++---- grub-core/kern/i386/coreboot/init.c | 2 +- grub-core/kern/i386/qemu/init.c | 2 +- grub-core/kern/ieee1275/init.c | 2 +- @@ -24,7 +24,7 @@ Signed-off-by: Peter Jones grub-core/kern/uboot/init.c | 6 +++--- grub-core/kern/xen/init.c | 2 +- include/grub/misc.h | 2 +- - 14 files changed, 48 insertions(+), 21 deletions(-) + 14 files changed, 50 insertions(+), 23 deletions(-) diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c index fa498931ed2..2bd3ac76f2d 100644 @@ -60,10 +60,10 @@ index fa498931ed2..2bd3ac76f2d 100644 } diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 8cff7be0289..05d8237a9b2 100644 +index b93ae3aba12..885d7c6420e 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -165,11 +165,16 @@ grub_reboot (void) +@@ -175,11 +175,16 @@ grub_reboot (void) } void @@ -76,14 +76,14 @@ index 8cff7be0289..05d8237a9b2 100644 + rc = GRUB_EFI_SUCCESS; + grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); - efi_call_4 (grub_efi_system_table->boot_services->exit, -- grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0); -+ grub_efi_image_handle, rc, 0, 0); + grub_efi_system_table->boot_services->exit (grub_efi_image_handle, +- GRUB_EFI_SUCCESS, 0, 0); ++ rc, 0, 0); for (;;) ; } diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c -index 425bb960347..55ea5a11ccd 100644 +index 855b11c3dec..38c1576a2ef 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -67,7 +67,7 @@ grub_reboot (void) @@ -96,10 +96,19 @@ index 425bb960347..55ea5a11ccd 100644 grub_reboot (); } diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index dfd8a8ec488..0ff13bcaf8c 100644 +index 521220b49d2..16c79bc9488 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c -@@ -151,9 +151,10 @@ xasprintf (const char *fmt, ...) +@@ -83,7 +83,7 @@ grub_util_error (const char *fmt, ...) + vfprintf (stderr, fmt, ap); + va_end (ap); + fprintf (stderr, ".\n"); +- grub_exit (); ++ grub_exit (1); + } + + void * +@@ -152,12 +152,13 @@ xasprintf (const char *fmt, ...) #if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) void @@ -107,13 +116,17 @@ index dfd8a8ec488..0ff13bcaf8c 100644 +__attribute__ ((noreturn)) +grub_exit (int rc) { +-#if defined (GRUB_KERNEL) ++#if defined (GRUB_KERNEL) && !defined (GRUB_MACHINE_EFI) + grub_reboot (); + #endif - exit (1); + exit (rc < 0 ? 1 : rc); } #endif diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c -index 3314f027fec..36f9134b7b7 100644 +index 4fae8b571f1..feaf9295e30 100644 --- a/grub-core/kern/i386/coreboot/init.c +++ b/grub-core/kern/i386/coreboot/init.c @@ -41,7 +41,7 @@ extern grub_uint8_t _end[]; @@ -126,7 +139,7 @@ index 3314f027fec..36f9134b7b7 100644 /* We can't use grub_fatal() in this function. This would create an infinite loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c -index 271b6fbfabd..9fafe98f015 100644 +index 08f81d25e68..604fc94b5a0 100644 --- a/grub-core/kern/i386/qemu/init.c +++ b/grub-core/kern/i386/qemu/init.c @@ -42,7 +42,7 @@ extern grub_uint8_t _end[]; @@ -139,11 +152,11 @@ index 271b6fbfabd..9fafe98f015 100644 /* We can't use grub_fatal() in this function. This would create an infinite loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index d483e35eed2..e71d1584164 100644 +index fb7d1a3bacf..50c65b2f6e5 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c -@@ -71,7 +71,7 @@ grub_addr_t grub_ieee1275_original_stack; - #endif +@@ -114,7 +114,7 @@ grub_addr_t grub_ieee1275_original_stack; + #define BYTE22 (DY_MEM_V2 | DRC_INFO) void -grub_exit (void) @@ -165,7 +178,7 @@ index 2ed3ff3191e..5c40c34078d 100644 GRUB_ARC_FIRMWARE_VECTOR->exit (); diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c -index 7b96531b983..dff598ca7b0 100644 +index 5bd721260f6..97b09b0eeea 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -304,7 +304,7 @@ grub_halt (void) @@ -178,7 +191,7 @@ index 7b96531b983..dff598ca7b0 100644 grub_halt (); } diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c -index be88b77d22d..8b6c55ffc01 100644 +index b5477b87ffa..69488a34e7c 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused))) @@ -191,10 +204,10 @@ index be88b77d22d..8b6c55ffc01 100644 grub_halt (); } diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 3af336ee227..63b586d09cb 100644 +index 7cee5d75c3c..11037dc0227 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -1209,9 +1209,18 @@ grub_abort (void) +@@ -1311,9 +1311,18 @@ grub_abort (void) grub_getkey (); } @@ -253,15 +266,15 @@ index 782ca72952a..708b060f324 100644 struct sched_shutdown arg; diff --git a/include/grub/misc.h b/include/grub/misc.h -index 7d2b5519690..fd18e6320b8 100644 +index 1b35a167fde..72aff15750d 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h -@@ -353,7 +353,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, - char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) +@@ -385,7 +385,7 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT; char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT; + -void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); +void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn)); + void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn)); grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint64_t d, - grub_uint64_t *r); diff --git a/0017-Make-efi-machines-load-an-env-block-from-a-variable.patch b/0013-Make-efi-machines-load-an-env-block-from-a-variable.patch similarity index 70% rename from 0017-Make-efi-machines-load-an-env-block-from-a-variable.patch rename to 0013-Make-efi-machines-load-an-env-block-from-a-variable.patch index d0614611..93552985 100644 --- a/0017-Make-efi-machines-load-an-env-block-from-a-variable.patch +++ b/0013-Make-efi-machines-load-an-env-block-from-a-variable.patch @@ -6,14 +6,14 @@ Subject: [PATCH] Make efi machines load an env block from a variable Signed-off-by: Peter Jones --- grub-core/Makefile.core.def | 1 + - grub-core/kern/efi/init.c | 36 +++++++++++++++++++++++++++++++++++- - 2 files changed, 36 insertions(+), 1 deletion(-) + grub-core/kern/efi/init.c | 34 ++++++++++++++++++++++++++++++++++ + 2 files changed, 35 insertions(+) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 45d3edaa4dc..c865a08b027 100644 +index 1571421d7e8..0bffbfea917 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -207,6 +207,7 @@ kernel = { +@@ -219,6 +219,7 @@ kernel = { efi = kern/efi/acpi.c; efi = kern/efi/sb.c; efi = kern/lockdown.c; @@ -22,10 +22,10 @@ index 45d3edaa4dc..c865a08b027 100644 i386_multiboot = kern/i386/pc/acpi.c; i386_coreboot = kern/acpi.c; diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 7facacf09c7..6d39bd3ad29 100644 +index 6c54af6e79e..b5201974a76 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c -@@ -27,8 +27,11 @@ +@@ -28,8 +28,11 @@ #include #include #include @@ -36,8 +36,8 @@ index 7facacf09c7..6d39bd3ad29 100644 + #ifdef GRUB_STACK_PROTECTOR - static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID; -@@ -82,6 +85,36 @@ stack_protector_init (void) + static grub_efi_char16_t stack_chk_fail_msg[] = +@@ -103,6 +106,36 @@ stack_protector_init (void) grub_addr_t grub_modbase; @@ -58,7 +58,7 @@ index 7facacf09c7..6d39bd3ad29 100644 +static void +grub_efi_env_init (void) +{ -+ grub_efi_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID; ++ grub_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID; + struct grub_envblk envblk_s = { NULL, 0 }; + grub_envblk_t envblk = &envblk_s; + @@ -71,19 +71,14 @@ index 7facacf09c7..6d39bd3ad29 100644 + grub_free (envblk_s.buf); +} + - void + __attribute__ ((__optimize__ ("-fno-stack-protector"))) void grub_efi_init (void) { -@@ -108,10 +141,11 @@ grub_efi_init (void) - efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer, - 0, 0, 0, NULL); +@@ -128,6 +161,7 @@ grub_efi_init (void) + + grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL); + grub_efi_env_init (); grub_efidisk_init (); - } - --void (*grub_efi_net_config) (grub_efi_handle_t hnd, -+void (*grub_efi_net_config) (grub_efi_handle_t hnd, - char **device, - char **path); + grub_efi_register_debug_commands (); diff --git a/0018-Migrate-PPC-from-Yaboot-to-Grub2.patch b/0014-Migrate-PPC-from-Yaboot-to-Grub2.patch similarity index 93% rename from 0018-Migrate-PPC-from-Yaboot-to-Grub2.patch rename to 0014-Migrate-PPC-from-Yaboot-to-Grub2.patch index ee8c7abf..1ff254cc 100644 --- a/0018-Migrate-PPC-from-Yaboot-to-Grub2.patch +++ b/0014-Migrate-PPC-from-Yaboot-to-Grub2.patch @@ -3,8 +3,11 @@ From: Mark Hamzy Date: Wed, 28 Mar 2012 14:46:41 -0500 Subject: [PATCH] Migrate PPC from Yaboot to Grub2 -Add configuration support for serial terminal consoles. This will set the -maximum screen size so that text is not overwritten. +Add configuration support for serial terminal consoles. This will set +the maximum screen size so that text is not overwritten. + +Signed-off-by: Mark Hamzy +Signed-off-by: Robbie Harwood --- Makefile.util.def | 7 +++ util/grub.d/20_ppc_terminfo.in | 114 +++++++++++++++++++++++++++++++++++++++++ @@ -12,11 +15,11 @@ maximum screen size so that text is not overwritten. create mode 100644 util/grub.d/20_ppc_terminfo.in diff --git a/Makefile.util.def b/Makefile.util.def -index f8b356cc1fa..2c9b283a230 100644 +index 9432365a9df..09bfcadd976 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -508,6 +508,13 @@ script = { - condition = COND_HOST_LINUX; +@@ -517,6 +517,13 @@ script = { + installdir = grubconf; }; +script = { diff --git a/0019-Add-fw_path-variable-revised.patch b/0015-Add-fw_path-variable-revised.patch similarity index 92% rename from 0019-Add-fw_path-variable-revised.patch rename to 0015-Add-fw_path-variable-revised.patch index df9ef830..4012f3fe 100644 --- a/0019-Add-fw_path-variable-revised.patch +++ b/0015-Add-fw_path-variable-revised.patch @@ -8,13 +8,16 @@ found. It was originally written by Matthew Garrett, and adapted to fix the "No modules are loaded on grub2 network boot" issue: https://bugzilla.redhat.com/show_bug.cgi?id=857936 + +Signed-off-by: Paulo Flabiano Smorigo +Signed-off-by: Robbie Harwood --- grub-core/kern/main.c | 13 ++++++------- grub-core/normal/main.c | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index 73967e2f5b0..d1de9fa6873 100644 +index 731c07c2901..463dafdba02 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -128,16 +128,15 @@ grub_set_prefix_and_root (void) @@ -41,7 +44,7 @@ index 73967e2f5b0..d1de9fa6873 100644 } diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 70614de1565..62571e6dfcc 100644 +index d3f53d93d87..08f48c71df1 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), diff --git a/0020-Pass-x-hex-hex-straight-through-unmolested.patch b/0016-Pass-x-hex-hex-straight-through-unmolested.patch similarity index 98% rename from 0020-Pass-x-hex-hex-straight-through-unmolested.patch rename to 0016-Pass-x-hex-hex-straight-through-unmolested.patch index b81abb54..e1aa1aff 100644 --- a/0020-Pass-x-hex-hex-straight-through-unmolested.patch +++ b/0016-Pass-x-hex-hex-straight-through-unmolested.patch @@ -13,7 +13,7 @@ Signed-off-by: Peter Jones 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c -index cc3290311f0..8f67a4be7f0 100644 +index ed65865050a..5455242c352 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c @@ -488,6 +488,12 @@ check_file (const char *dir, const char *basename) @@ -97,7 +97,7 @@ index ed0b149dca5..8e2294d8ff6 100644 *buf++ = *c; diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index ad80399246a..0c6dd9c5201 100644 +index dab8fd2aeb0..c19b4bf700e 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -56,6 +56,12 @@ static struct grub_script_scope *scope = 0; diff --git a/0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch b/0017-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch similarity index 99% rename from 0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch rename to 0017-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch index da65e187..56582e58 100644 --- a/0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch +++ b/0017-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch @@ -28,10 +28,10 @@ Signed-off-by: Will Thompson create mode 100644 grub-core/commands/loadenv.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index c865a08b027..c15e91943b9 100644 +index 0bffbfea917..47c0fc755a2 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -814,6 +814,16 @@ module = { +@@ -842,6 +842,16 @@ module = { common = commands/blocklist.c; }; @@ -48,7 +48,7 @@ index c865a08b027..c15e91943b9 100644 module = { name = boot; common = commands/boot.c; -@@ -980,6 +990,7 @@ module = { +@@ -1009,6 +1019,7 @@ module = { module = { name = loadenv; common = commands/loadenv.c; @@ -1240,7 +1240,7 @@ index 00000000000..e907a6a5d28 + grub_unregister_extcmd (oldcmd); +} diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c -index cc5971f4dbd..782761c31aa 100644 +index e9e9d94eff5..2c5d1a0ef9a 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -143,7 +143,7 @@ legacy_file (const char *filename) @@ -1263,7 +1263,7 @@ index cc5971f4dbd..782761c31aa 100644 } diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c -index 3fd664aac33..163b9a09042 100644 +index 16644584978..dfcb19e0ff8 100644 --- a/grub-core/commands/loadenv.c +++ b/grub-core/commands/loadenv.c @@ -28,6 +28,8 @@ @@ -1430,7 +1430,7 @@ index 720e6d8ea3b..b194123eb67 100644 src[len - 1] = ch; args[argc - 1] = src; diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 62571e6dfcc..7ca2e5400b1 100644 +index 08f48c71df1..1317279c081 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -21,6 +21,7 @@ @@ -1553,7 +1553,7 @@ index 00000000000..952f46121bd + return 0; +} diff --git a/include/grub/compiler.h b/include/grub/compiler.h -index 8f3be3ae706..ebafec68957 100644 +index 0c5519387b2..441a9eca07c 100644 --- a/include/grub/compiler.h +++ b/include/grub/compiler.h @@ -56,4 +56,6 @@ diff --git a/0022-Add-devicetree-loading.patch b/0018-Add-devicetree-loading.patch similarity index 90% rename from 0022-Add-devicetree-loading.patch rename to 0018-Add-devicetree-loading.patch index c0728a98..3897a2a6 100644 --- a/0022-Add-devicetree-loading.patch +++ b/0018-Add-devicetree-loading.patch @@ -20,10 +20,10 @@ Signed-off-by: David A. Marlin 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index d3e879b8e5c..8ea2315ebc2 100644 +index 7516a015be0..7b355115dd4 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -248,7 +248,8 @@ export GRUB_DEFAULT \ +@@ -252,7 +252,8 @@ export GRUB_DEFAULT \ GRUB_ENABLE_CRYPTODISK \ GRUB_BADRAM \ GRUB_OS_PROBER_SKIP_LIST \ @@ -34,10 +34,10 @@ index d3e879b8e5c..8ea2315ebc2 100644 if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index e8b01c0d0c7..dc75a1c30bf 100644 +index cc393be7eda..00d4b220ccb 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -153,6 +153,13 @@ EOF +@@ -155,6 +155,13 @@ EOF sed "s/^/$submenu_indentation/" << EOF echo '$(echo "$message" | grub_quote)' initrd $(echo $initrd_path) @@ -51,7 +51,7 @@ index e8b01c0d0c7..dc75a1c30bf 100644 EOF fi sed "s/^/$submenu_indentation/" << EOF -@@ -236,6 +243,14 @@ while [ "x$list" != "x" ] ; do +@@ -250,6 +257,14 @@ for linux in ${reverse_sorted_list}; do gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 fi diff --git a/0032-Enable-pager-by-default.-985860.patch b/0019-Enable-pager-by-default.-985860.patch similarity index 94% rename from 0032-Enable-pager-by-default.-985860.patch rename to 0019-Enable-pager-by-default.-985860.patch index d92fbcc7..8f38cc2b 100644 --- a/0032-Enable-pager-by-default.-985860.patch +++ b/0019-Enable-pager-by-default.-985860.patch @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+) diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in -index 93a90233ead..858b526c925 100644 +index 6a316a5ba77..c2d8b093762 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -43,6 +43,8 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_ diff --git a/0020-Don-t-say-GNU-Linux-in-generated-menus.patch b/0020-Don-t-say-GNU-Linux-in-generated-menus.patch new file mode 100644 index 00000000..a299f052 --- /dev/null +++ b/0020-Don-t-say-GNU-Linux-in-generated-menus.patch @@ -0,0 +1,85 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 14 Mar 2011 14:27:42 -0400 +Subject: [PATCH] Don't say "GNU/Linux" in generated menus. + +[rharwood: say it even less] +--- + grub-core/normal/main.c | 2 +- + tests/util/grub-shell-tester.in | 2 +- + tests/util/grub-shell.in | 2 +- + util/grub.d/10_linux.in | 4 ++-- + util/grub.d/20_linux_xen.in | 4 ++-- + 5 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 1317279c081..568c2adfa16 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -218,7 +218,7 @@ grub_normal_init_page (struct grub_term_output *term, + + grub_term_cls (term); + +- msg_formatted = grub_xasprintf (_("GNU GRUB version %s"), PACKAGE_VERSION); ++ msg_formatted = grub_xasprintf (_("GRUB version %s"), PACKAGE_VERSION); + if (!msg_formatted) + return; + +diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in +index 8a87109b152..9a4319d4f4f 100644 +--- a/tests/util/grub-shell-tester.in ++++ b/tests/util/grub-shell-tester.in +@@ -56,7 +56,7 @@ for option in "$@"; do + usage + exit 0 ;; + -v | --version) +- echo "$0 (GNU GRUB ${PACKAGE_VERSION})" ++ echo "$0 (GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//'` +diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in +index 496e1bab33c..e0570c88e15 100644 +--- a/tests/util/grub-shell.in ++++ b/tests/util/grub-shell.in +@@ -243,7 +243,7 @@ for option in "$@"; do + usage + exit 0 ;; + -v | --version) +- echo "$0 (GNU GRUB ${PACKAGE_VERSION})" ++ echo "$0 (GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --trim) + trim=1 ;; +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 00d4b220ccb..901745707f1 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" + CLASS="--class gnu-linux --class gnu --class os" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then +- OS=GNU/Linux ++ OS="$(sed 's, release .*$,,g' /etc/system-release)" + else +- OS="${GRUB_DISTRIBUTOR} GNU/Linux" ++ OS="${GRUB_DISTRIBUTOR}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" + fi + +diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in +index 94dd8be1342..98ee5bc58dc 100644 +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" + CLASS="--class gnu-linux --class gnu --class os --class xen" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then +- OS=GNU/Linux ++ OS="$(sed 's, release .*$,,g' /etc/system-release)" + else +- OS="${GRUB_DISTRIBUTOR} GNU/Linux" ++ OS="${GRUB_DISTRIBUTOR}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" + fi + diff --git a/0037-Add-.eh_frame-to-list-of-relocations-stripped.patch b/0021-Add-.eh_frame-to-list-of-relocations-stripped.patch similarity index 76% rename from 0037-Add-.eh_frame-to-list-of-relocations-stripped.patch rename to 0021-Add-.eh_frame-to-list-of-relocations-stripped.patch index ed48c5c7..9344171f 100644 --- a/0037-Add-.eh_frame-to-list-of-relocations-stripped.patch +++ b/0021-Add-.eh_frame-to-list-of-relocations-stripped.patch @@ -3,20 +3,21 @@ From: Fedora Ninjas Date: Mon, 13 Jan 2014 21:50:59 -0500 Subject: [PATCH] Add .eh_frame to list of relocations stripped +Signed-off-by: Peter Jones --- conf/Makefile.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/Makefile.common b/conf/Makefile.common -index 2a1a886f6d5..191b1a70c6b 100644 +index b8f216f6cd3..ece9ed8a1bf 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common -@@ -38,7 +38,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding +@@ -41,7 +41,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) -STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx +STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx - - CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding - LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d + if !COND_emu + if COND_HAVE_ASM_USCORE + LDFLAGS_KERNEL += -Wl,--defsym=_malloc=_grub_malloc -Wl,--defsym=_free=_grub_free diff --git a/0038-Don-t-require-a-password-to-boot-entries-generated-b.patch b/0022-Don-t-require-a-password-to-boot-entries-generated-b.patch similarity index 96% rename from 0038-Don-t-require-a-password-to-boot-entries-generated-b.patch rename to 0022-Don-t-require-a-password-to-boot-entries-generated-b.patch index fb0e1976..b2806860 100644 --- a/0038-Don-t-require-a-password-to-boot-entries-generated-b.patch +++ b/0022-Don-t-require-a-password-to-boot-entries-generated-b.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 4fc58c83304..635d2fe0cd3 100644 +index 901745707f1..9c31a94decb 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -26,7 +26,7 @@ datarootdir="@datarootdir@" diff --git a/0023-Don-t-write-messages-to-the-screen.patch b/0023-Don-t-write-messages-to-the-screen.patch deleted file mode 100644 index 01d0264b..00000000 --- a/0023-Don-t-write-messages-to-the-screen.patch +++ /dev/null @@ -1,176 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 13:30:20 -0400 -Subject: [PATCH] Don't write messages to the screen - -Writing messages to the screen before the menus or boot splash -happens so quickly it looks like something is wrong and isn't -very appealing. ---- - grub-core/gettext/gettext.c | 25 +++++-------------------- - grub-core/kern/main.c | 5 ----- - grub-core/boot/i386/pc/boot.S | 3 --- - grub-core/boot/i386/pc/diskboot.S | 5 ----- - util/grub.d/10_linux.in | 7 ------- - 5 files changed, 5 insertions(+), 40 deletions(-) - -diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c -index 4d02e62c109..84d520cd494 100644 ---- a/grub-core/gettext/gettext.c -+++ b/grub-core/gettext/gettext.c -@@ -434,16 +434,12 @@ static char * - grub_gettext_env_write_lang (struct grub_env_var *var - __attribute__ ((unused)), const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&main_context, val, grub_env_get ("locale_dir"), - grub_env_get ("prefix")); -- if (err) -- grub_print_error (); - - err = grub_gettext_init_ext (&secondary_context, val, - grub_env_get ("secondary_locale_dir"), 0); -- if (err) -- grub_print_error (); - - return grub_strdup (val); - } -@@ -451,23 +447,19 @@ grub_gettext_env_write_lang (struct grub_env_var *var - void - grub_gettext_reread_prefix (const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&main_context, grub_env_get ("lang"), - grub_env_get ("locale_dir"), - val); -- if (err) -- grub_print_error (); - } - - static char * - read_main (struct grub_env_var *var - __attribute__ ((unused)), const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&main_context, grub_env_get ("lang"), val, - grub_env_get ("prefix")); -- if (err) -- grub_print_error (); - return grub_strdup (val); - } - -@@ -475,12 +467,9 @@ static char * - read_secondary (struct grub_env_var *var - __attribute__ ((unused)), const char *val) - { -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - err = grub_gettext_init_ext (&secondary_context, grub_env_get ("lang"), val, - 0); -- if (err) -- grub_print_error (); -- - return grub_strdup (val); - } - -@@ -500,18 +489,14 @@ grub_cmd_translate (grub_command_t cmd __attribute__ ((unused)), - GRUB_MOD_INIT (gettext) - { - const char *lang; -- grub_err_t err; -+ grub_err_t __attribute__((__unused__)) err; - - lang = grub_env_get ("lang"); - - err = grub_gettext_init_ext (&main_context, lang, grub_env_get ("locale_dir"), - grub_env_get ("prefix")); -- if (err) -- grub_print_error (); - err = grub_gettext_init_ext (&secondary_context, lang, - grub_env_get ("secondary_locale_dir"), 0); -- if (err) -- grub_print_error (); - - grub_register_variable_hook ("locale_dir", NULL, read_main); - grub_register_variable_hook ("secondary_locale_dir", NULL, read_secondary); -diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index d1de9fa6873..48058d983ce 100644 ---- a/grub-core/kern/main.c -+++ b/grub-core/kern/main.c -@@ -269,11 +269,6 @@ grub_main (void) - - grub_boot_time ("After machine init."); - -- /* Hello. */ -- grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); -- grub_printf ("Welcome to GRUB!\n\n"); -- grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); -- - /* Init verifiers API. */ - grub_verifiers_init (); - -diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S -index 2bd0b2d2866..ea167fe1206 100644 ---- a/grub-core/boot/i386/pc/boot.S -+++ b/grub-core/boot/i386/pc/boot.S -@@ -249,9 +249,6 @@ real_start: - /* save drive reference first thing! */ - pushw %dx - -- /* print a notification message on the screen */ -- MSG(notification_string) -- - /* set %si to the disk address packet */ - movw $disk_address_packet, %si - -diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S -index c1addc0df29..68d31de0c4c 100644 ---- a/grub-core/boot/i386/pc/diskboot.S -+++ b/grub-core/boot/i386/pc/diskboot.S -@@ -50,11 +50,6 @@ _start: - /* save drive reference first thing! */ - pushw %dx - -- /* print a notification message on the screen */ -- pushw %si -- MSG(notification_string) -- popw %si -- - /* this sets up for the first run through "bootloop" */ - movw $LOCAL(firstlist), %di - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index dc75a1c30bf..ad2ac4b078d 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -138,27 +138,20 @@ linux_entry () - fi - printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" - fi -- message="$(gettext_printf "Loading Linux %s ..." ${version})" - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} - EOF - if test -n "${initrd}" ; then -- # TRANSLATORS: ramdisk isn't identifier. Should be translated. -- message="$(gettext_printf "Loading initial ramdisk ...")" - initrd_path= - for i in ${initrd}; do - initrd_path="${initrd_path} ${rel_dirname}/${i}" - done - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - initrd $(echo $initrd_path) - EOF - fi - if test -n "${fdt}" ; then -- message="$(gettext_printf "Loading fdt ...")" - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - devicetree ${rel_dirname}/${fdt} - EOF - fi diff --git a/0041-use-fw_path-prefix-when-fallback-searching-for-grub-.patch b/0023-use-fw_path-prefix-when-fallback-searching-for-grub-.patch similarity index 89% rename from 0041-use-fw_path-prefix-when-fallback-searching-for-grub-.patch rename to 0023-use-fw_path-prefix-when-fallback-searching-for-grub-.patch index 985205c1..40f598dd 100644 --- a/0041-use-fw_path-prefix-when-fallback-searching-for-grub-.patch +++ b/0023-use-fw_path-prefix-when-fallback-searching-for-grub-.patch @@ -17,10 +17,10 @@ Signed-off-by: Mark Salter 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index ec1cd257397..d85f7598d23 100644 +index 568c2adfa16..0b2bbee19c3 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -349,7 +349,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -347,7 +347,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), char *config; const char *prefix, *fw_path; @@ -29,7 +29,7 @@ index ec1cd257397..d85f7598d23 100644 if (fw_path) { config = grub_xasprintf ("%s/grub.cfg", fw_path); -@@ -372,7 +372,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -370,7 +370,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), } } diff --git a/0024-Don-t-print-GNU-GRUB-header.patch b/0024-Don-t-print-GNU-GRUB-header.patch deleted file mode 100644 index c903fd48..00000000 --- a/0024-Don-t-print-GNU-GRUB-header.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 13:53:48 -0400 -Subject: [PATCH] Don't print GNU GRUB header - -No one cares. ---- - grub-core/normal/main.c | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) - -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 7ca2e5400b1..5d5f7b539f5 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -208,15 +208,16 @@ read_config_file (const char *config) - /* Initialize the screen. */ - void - grub_normal_init_page (struct grub_term_output *term, -- int y) -+ int y __attribute__((__unused__))) - { -+ grub_term_cls (term); -+ -+#if 0 - grub_ssize_t msg_len; - int posx; - char *msg_formatted; - grub_uint32_t *unicode_msg; - grub_uint32_t *last_position; -- -- grub_term_cls (term); - - msg_formatted = grub_xasprintf (_("GNU GRUB version %s"), PACKAGE_VERSION); - if (!msg_formatted) -@@ -241,6 +242,7 @@ grub_normal_init_page (struct grub_term_output *term, - grub_putcode ('\n', term); - grub_putcode ('\n', term); - grub_free (unicode_msg); -+#endif - } - - static void diff --git a/0042-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch b/0024-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch similarity index 97% rename from 0042-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch rename to 0024-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch index 61dd5caa..be44d1a5 100644 --- a/0042-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch +++ b/0024-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch @@ -9,10 +9,10 @@ Signed-off-by: Peter Jones 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index d85f7598d23..1e509fceb91 100644 +index 0b2bbee19c3..4c89892fa70 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -347,61 +347,66 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -345,61 +345,66 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), /* Guess the config filename. It is necessary to make CONFIG static, so that it won't get broken by longjmp. */ char *config; diff --git a/0025-Don-t-add-to-highlighted-row.patch b/0025-Don-t-add-to-highlighted-row.patch deleted file mode 100644 index b83f543e..00000000 --- a/0025-Don-t-add-to-highlighted-row.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 17:49:45 -0400 -Subject: [PATCH] Don't add '*' to highlighted row - -It is already highlighted. ---- - grub-core/normal/menu_text.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 18240e76cea..65deafda531 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -242,7 +242,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, - unicode_title[i] = ' '; - - if (data->geo.num_entries > 1) -- grub_putcode (highlight ? '*' : ' ', data->term); -+ grub_putcode (' ', data->term); - - grub_print_ucs4_menu (unicode_title, - unicode_title + len, diff --git a/0043-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch b/0025-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch similarity index 96% rename from 0043-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch rename to 0025-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch index ef0b0f4b..d29c0aff 100644 --- a/0043-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch +++ b/0025-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 635d2fe0cd3..fed73271478 100644 +index 9c31a94decb..b7809091b36 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -29,7 +29,8 @@ export TEXTDOMAINDIR="@localedir@" diff --git a/0026-Message-string-cleanups.patch b/0026-Message-string-cleanups.patch deleted file mode 100644 index e23ee1ad..00000000 --- a/0026-Message-string-cleanups.patch +++ /dev/null @@ -1,68 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 11:09:04 -0400 -Subject: [PATCH] Message string cleanups - -Make use of terminology consistent. Remove jargon. ---- - grub-core/normal/menu_text.c | 21 +++++++++------------ - 1 file changed, 9 insertions(+), 12 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 65deafda531..cc5837ed2b8 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -157,9 +157,8 @@ print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - - if (edit) - { -- ret += grub_print_message_indented_real (_("Minimum Emacs-like screen editing is \ --supported. TAB lists completions. Press Ctrl-x or F10 to boot, Ctrl-c or F2 for a \ --command-line or ESC to discard edits and return to the GRUB menu."), -+ ret += grub_print_message_indented_real (_("Press Ctrl-x or F10 to start, Ctrl-c or F2 for a \ -+command prompt or Escape to discard edits and return to the menu. Pressing Tab lists possible completions."), - STANDARD_MARGIN, STANDARD_MARGIN, - term, dry_run); - } -@@ -167,8 +166,8 @@ command-line or ESC to discard edits and return to the GRUB menu."), - { - char *msg_translated; - -- msg_translated = grub_xasprintf (_("Use the %C and %C keys to select which " -- "entry is highlighted."), -+ msg_translated = grub_xasprintf (_("Use the %C and %C keys to change the " -+ "selection."), - GRUB_UNICODE_UPARROW, - GRUB_UNICODE_DOWNARROW); - if (!msg_translated) -@@ -181,17 +180,15 @@ command-line or ESC to discard edits and return to the GRUB menu."), - if (nested) - { - ret += grub_print_message_indented_real -- (_("Press enter to boot the selected OS, " -- "`e' to edit the commands before booting " -- "or `c' for a command-line. ESC to return previous menu."), -+ (_("Press 'e' to edit the selected item, " -+ "or 'c' for a command prompt. Press Escape to return to the previous menu."), - STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); - } - else - { - ret += grub_print_message_indented_real -- (_("Press enter to boot the selected OS, " -- "`e' to edit the commands before booting " -- "or `c' for a command-line."), -+ (_("Press 'e' to edit the selected item, " -+ "or 'c' for a command prompt."), - STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); - } - } -@@ -443,7 +440,7 @@ menu_text_print_timeout (int timeout, void *dataptr) - || data->timeout_msg == TIMEOUT_TERSE_NO_MARGIN) - msg_translated = grub_xasprintf (_("%ds"), timeout); - else -- msg_translated = grub_xasprintf (_("The highlighted entry will be executed automatically in %ds."), timeout); -+ msg_translated = grub_xasprintf (_("The selected entry will be started automatically in %ds."), timeout); - if (!msg_translated) - { - grub_print_error (); diff --git a/0045-Try-prefix-if-fw_path-doesn-t-work.patch b/0026-Try-prefix-if-fw_path-doesn-t-work.patch similarity index 92% rename from 0045-Try-prefix-if-fw_path-doesn-t-work.patch rename to 0026-Try-prefix-if-fw_path-doesn-t-work.patch index 59489bd9..effa3510 100644 --- a/0045-Try-prefix-if-fw_path-doesn-t-work.patch +++ b/0026-Try-prefix-if-fw_path-doesn-t-work.patch @@ -7,38 +7,26 @@ Related: rhbz#1148652 Signed-off-by: Peter Jones --- - grub-core/kern/ieee1275/init.c | 28 +++++---- + grub-core/kern/ieee1275/init.c | 34 ++++++----- grub-core/net/net.c | 2 +- grub-core/normal/main.c | 134 ++++++++++++++++++++--------------------- - 3 files changed, 82 insertions(+), 82 deletions(-) + 3 files changed, 85 insertions(+), 85 deletions(-) diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index e71d1584164..0cd2a627231 100644 +index 50c65b2f6e5..51c1e1c9d9f 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c -@@ -127,23 +127,25 @@ grub_machine_get_bootlocation (char **device, char **path) +@@ -170,23 +170,25 @@ grub_machine_get_bootlocation (char **device, char **path) grub_free (canon); } else - *device = grub_ieee1275_encode_devname (bootpath); -- grub_free (type); -- -- filename = grub_ieee1275_get_filename (bootpath); -- if (filename) - { -- char *lastslash = grub_strrchr (filename, '\\'); -- -- /* Truncate at last directory. */ -- if (lastslash) ++ { + filename = grub_ieee1275_get_filename (bootpath); + if (filename) - { -- *lastslash = '\0'; -- grub_translate_ieee1275_path (filename); ++ { + char *lastslash = grub_strrchr (filename, '\\'); - -- *path = filename; -- } ++ + /* Truncate at last directory. */ + if (lastslash) + { @@ -49,17 +37,32 @@ index e71d1584164..0cd2a627231 100644 + } + } + *device = grub_ieee1275_encode_devname (bootpath); - } ++ } + -+ grub_free (type); + grub_free (type); +- +- filename = grub_ieee1275_get_filename (bootpath); +- if (filename) +- { +- char *lastslash = grub_strrchr (filename, '\\'); +- +- /* Truncate at last directory. */ +- if (lastslash) +- { +- *lastslash = '\0'; +- grub_translate_ieee1275_path (filename); +- +- *path = filename; +- } +- } grub_free (bootpath); } diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 4d3eb5c1a52..0ef148f4adc 100644 +index 8cad4fb6d4d..54451cea2a7 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c -@@ -1869,7 +1869,7 @@ grub_net_search_config_file (char *config) +@@ -2005,7 +2005,7 @@ grub_net_search_config_file (char *config) /* Remove the remaining minus sign at the end. */ config[config_len] = '\0'; @@ -69,10 +72,10 @@ index 4d3eb5c1a52..0ef148f4adc 100644 static struct grub_preboot *fini_hnd; diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 1e509fceb91..d5968797f4f 100644 +index 4c89892fa70..3463f444f74 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -337,81 +337,79 @@ grub_enter_normal_mode (const char *config) +@@ -335,81 +335,79 @@ grub_enter_normal_mode (const char *config) grub_boot_time ("Exiting normal mode"); } diff --git a/0027-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch b/0027-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch deleted file mode 100644 index 920ef797..00000000 --- a/0027-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:08:23 -0400 -Subject: [PATCH] Fix border spacing now that we aren't displaying it - ---- - grub-core/normal/menu_text.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index cc5837ed2b8..b49835a9af7 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -331,12 +331,12 @@ grub_menu_init_page (int nested, int edit, - int empty_lines = 1; - int version_msg = 1; - -- geo->border = 1; -- geo->first_entry_x = 1 /* margin */ + 1 /* border */; -+ geo->border = 0; -+ geo->first_entry_x = 0 /* margin */ + 0 /* border */; - geo->entry_width = grub_term_width (term) - 5; - - geo->first_entry_y = 2 /* two empty lines*/ -- + 1 /* GNU GRUB version text */ + 1 /* top border */; -+ + 0 /* GNU GRUB version text */ + 1 /* top border */; - - geo->timeout_lines = 2; - diff --git a/0047-Make-grub2-mkconfig-construct-titles-that-look-like-.patch b/0027-Make-grub2-mkconfig-construct-titles-that-look-like-.patch similarity index 95% rename from 0047-Make-grub2-mkconfig-construct-titles-that-look-like-.patch rename to 0027-Make-grub2-mkconfig-construct-titles-that-look-like-.patch index 4c474e4b..1fb624e3 100644 --- a/0047-Make-grub2-mkconfig-construct-titles-that-look-like-.patch +++ b/0027-Make-grub2-mkconfig-construct-titles-that-look-like-.patch @@ -12,10 +12,10 @@ Signed-off-by: Peter Jones 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index fed73271478..2e59f3b4197 100644 +index b7809091b36..993c53ad92e 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -78,6 +78,32 @@ case x"$GRUB_FS" in +@@ -80,6 +80,32 @@ case x"$GRUB_FS" in ;; esac @@ -48,7 +48,7 @@ index fed73271478..2e59f3b4197 100644 title_correction_code= linux_entry () -@@ -91,17 +117,11 @@ linux_entry () +@@ -93,17 +119,11 @@ linux_entry () boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" fi if [ x$type != xsimple ] ; then diff --git a/0048-Add-friendly-grub2-password-config-tool-985962.patch b/0028-Add-friendly-grub2-password-config-tool-985962.patch similarity index 78% rename from 0048-Add-friendly-grub2-password-config-tool-985962.patch rename to 0028-Add-friendly-grub2-password-config-tool-985962.patch index 9807d0ea..2e1ba2cd 100644 --- a/0048-Add-friendly-grub2-password-config-tool-985962.patch +++ b/0028-Add-friendly-grub2-password-config-tool-985962.patch @@ -13,36 +13,38 @@ Signed-off-by: Robert Marshall [pjones: fix the efidir in grub-setpassword and rename tool] Signed-off-by: Peter Jones [luto: fix grub-setpassword -o's output path] -Andy Lutomirski +Signed-off-by: Andy Lutomirski +[rharwood: migrate man page to h2m, context] +Signed-off-by: Robbie Harwood --- - configure.ac | 1 + - Makefile.util.def | 13 +++++ - util/grub-mkconfig.in | 2 + - util/grub-set-password.8 | 28 ++++++++++ - util/grub-set-password.in | 128 ++++++++++++++++++++++++++++++++++++++++++++++ - util/grub.d/01_users.in | 11 ++++ - 6 files changed, 183 insertions(+) - create mode 100644 util/grub-set-password.8 + configure.ac | 1 + + Makefile.util.def | 13 +++++ + docs/man/grub-set-password.h2m | 2 + + util/grub-mkconfig.in | 2 + + util/grub-set-password.in | 128 +++++++++++++++++++++++++++++++++++++++++ + util/grub.d/01_users.in | 11 ++++ + 6 files changed, 157 insertions(+) + create mode 100644 docs/man/grub-set-password.h2m create mode 100644 util/grub-set-password.in create mode 100644 util/grub.d/01_users.in diff --git a/configure.ac b/configure.ac -index fdcb452581c..30fd84d8067 100644 +index ae3a49321ad..493e336ec6c 100644 --- a/configure.ac +++ b/configure.ac -@@ -72,6 +72,7 @@ grub_TRANSFORM([grub-mkrelpath]) +@@ -77,6 +77,7 @@ grub_TRANSFORM([grub-mkrelpath]) grub_TRANSFORM([grub-mkrescue]) grub_TRANSFORM([grub-probe]) grub_TRANSFORM([grub-reboot]) +grub_TRANSFORM([grub-set-password]) - grub_TRANSFORM([grub-rpm-sort]) grub_TRANSFORM([grub-script-check]) grub_TRANSFORM([grub-set-default]) + grub_TRANSFORM([grub-sparc64-setup]) diff --git a/Makefile.util.def b/Makefile.util.def -index ba4cf4b29b0..1a7dd433e33 100644 +index 09bfcadd976..95884956a68 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -452,6 +452,12 @@ script = { +@@ -455,6 +455,12 @@ script = { installdir = grubconf; }; @@ -55,7 +57,7 @@ index ba4cf4b29b0..1a7dd433e33 100644 script = { name = '10_windows'; common = util/grub.d/10_windows.in; -@@ -740,6 +746,13 @@ script = { +@@ -733,6 +739,13 @@ script = { installdir = sbin; }; @@ -69,11 +71,19 @@ index ba4cf4b29b0..1a7dd433e33 100644 script = { name = grub-mkconfig_lib; common = util/grub-mkconfig_lib.in; +diff --git a/docs/man/grub-set-password.h2m b/docs/man/grub-set-password.h2m +new file mode 100644 +index 00000000000..10ee82f4d52 +--- /dev/null ++++ b/docs/man/grub-set-password.h2m +@@ -0,0 +1,2 @@ ++[NAME] ++grub-set-password \- generate the user.cfg file containing the hashed grub bootloader password diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 8ea2315ebc2..ba14cf6261c 100644 +index 7b355115dd4..5f2824d4f58 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -276,6 +276,8 @@ for i in "${grub_mkconfig_dir}"/* ; do +@@ -280,6 +280,8 @@ for i in "${grub_mkconfig_dir}"/* ; do *~) ;; # emacsen autosave files. FIXME: support other editors */\#*\#) ;; @@ -82,40 +92,6 @@ index 8ea2315ebc2..ba14cf6261c 100644 *) if grub_file_is_not_garbage "$i" && test -x "$i" ; then echo -diff --git a/util/grub-set-password.8 b/util/grub-set-password.8 -new file mode 100644 -index 00000000000..9646546e43d ---- /dev/null -+++ b/util/grub-set-password.8 -@@ -0,0 +1,28 @@ -+.TH GRUB-SET-PASSWORD 3 "Thu Jun 25 2015" -+.SH NAME -+\fBgrub-set-password\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. -+ -+.SH SYNOPSIS -+\fBgrub-set-password\fR [OPTION] -+ -+.SH DESCRIPTION -+\fBgrub-set-password\fR outputs the user.cfg file which contains the hashed GRUB bootloader password. This utility only supports configurations where there is a single root user. -+ -+The file has the format: -+GRUB2_PASSWORD=<\fIhashed password\fR>. -+ -+.SH OPTIONS -+.TP -+-h, --help -+Display program usage and exit. -+.TP -+-v, --version -+Display the current version. -+.TP -+-o, --output=<\fIDIRECTORY\fR> -+Choose the file path to which user.cfg will be written. -+ -+.SH SEE ALSO -+.BR "info grub" -+ -+.BR "info grub2-mkpasswd-pbkdf2" diff --git a/util/grub-set-password.in b/util/grub-set-password.in new file mode 100644 index 00000000000..5ebf50576d6 diff --git a/0028-Use-the-correct-indentation-for-the-term-help-text.patch b/0028-Use-the-correct-indentation-for-the-term-help-text.patch deleted file mode 100644 index 0ce3b048..00000000 --- a/0028-Use-the-correct-indentation-for-the-term-help-text.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:08:49 -0400 -Subject: [PATCH] Use the correct indentation for the term help text - -That is consistent with the menu help text ---- - grub-core/normal/main.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index 5d5f7b539f5..ec1cd257397 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -440,8 +440,8 @@ grub_normal_reader_init (int nested) - grub_normal_init_page (term, 1); - grub_term_setcursor (term, 1); - -- if (grub_term_width (term) > 3 + STANDARD_MARGIN + 20) -- grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); -+ if (grub_term_width (term) > 2 * STANDARD_MARGIN + 20) -+ grub_print_message_indented (msg_formatted, STANDARD_MARGIN, STANDARD_MARGIN, term); - else - grub_print_message_indented (msg_formatted, 0, 0, term); - grub_putcode ('\n', term); diff --git a/0029-Indent-menu-entries.patch b/0029-Indent-menu-entries.patch deleted file mode 100644 index 7e588fd0..00000000 --- a/0029-Indent-menu-entries.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:30:55 -0400 -Subject: [PATCH] Indent menu entries - ---- - grub-core/normal/menu_text.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index b49835a9af7..6a57376fa80 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -239,7 +239,8 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, - unicode_title[i] = ' '; - - if (data->geo.num_entries > 1) -- grub_putcode (' ', data->term); -+ for (i = 0; i < STANDARD_MARGIN; i++) -+ grub_putcode (' ', data->term); - - grub_print_ucs4_menu (unicode_title, - unicode_title + len, diff --git a/0049-tcp-add-window-scaling-support.patch b/0029-tcp-add-window-scaling-support.patch similarity index 95% rename from 0049-tcp-add-window-scaling-support.patch rename to 0029-tcp-add-window-scaling-support.patch index 7d1996c8..ef3a81ee 100644 --- a/0049-tcp-add-window-scaling-support.patch +++ b/0029-tcp-add-window-scaling-support.patch @@ -17,7 +17,7 @@ Signed-off-by: Josef Bacik 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c -index e8ad34b84d4..7d4b822626d 100644 +index 93dee0caa1b..902ab7e8ae6 100644 --- a/grub-core/net/tcp.c +++ b/grub-core/net/tcp.c @@ -106,6 +106,18 @@ struct tcphdr @@ -39,7 +39,7 @@ index e8ad34b84d4..7d4b822626d 100644 struct tcp_pseudohdr { grub_uint32_t src; -@@ -566,7 +578,7 @@ grub_net_tcp_open (char *server, +@@ -571,7 +583,7 @@ grub_net_tcp_open (char *server, grub_net_tcp_socket_t socket; static grub_uint16_t in_port = 21550; struct grub_net_buff *nb; @@ -48,7 +48,7 @@ index e8ad34b84d4..7d4b822626d 100644 int i; grub_uint8_t *nbd; grub_net_link_level_address_t ll_target_addr; -@@ -635,20 +647,24 @@ grub_net_tcp_open (char *server, +@@ -640,20 +652,24 @@ grub_net_tcp_open (char *server, } tcph = (void *) nb->data; diff --git a/0030-Fix-margins.patch b/0030-Fix-margins.patch deleted file mode 100644 index baa10edf..00000000 --- a/0030-Fix-margins.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 14:59:36 -0400 -Subject: [PATCH] Fix margins - ---- - grub-core/normal/menu_text.c | 8 +++----- - 1 file changed, 3 insertions(+), 5 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 6a57376fa80..cbd62f714cb 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -333,17 +333,15 @@ grub_menu_init_page (int nested, int edit, - int version_msg = 1; - - geo->border = 0; -- geo->first_entry_x = 0 /* margin */ + 0 /* border */; -- geo->entry_width = grub_term_width (term) - 5; -+ geo->first_entry_x = 0; /* no margin */ -+ geo->entry_width = grub_term_width (term) - 1; - -- geo->first_entry_y = 2 /* two empty lines*/ -- + 0 /* GNU GRUB version text */ + 1 /* top border */; -+ geo->first_entry_y = 3; /* three empty lines*/ - - geo->timeout_lines = 2; - - /* 3 lines for timeout message and bottom margin. 2 lines for the border. */ - geo->num_entries = grub_term_height (term) - geo->first_entry_y -- - 1 /* bottom border */ - - 1 /* empty line before info message*/ - - geo->timeout_lines /* timeout */ - - 1 /* empty final line */; diff --git a/0050-efinet-and-bootp-add-support-for-dhcpv6.patch b/0030-efinet-and-bootp-add-support-for-dhcpv6.patch similarity index 84% rename from 0050-efinet-and-bootp-add-support-for-dhcpv6.patch rename to 0030-efinet-and-bootp-add-support-for-dhcpv6.patch index a9844b89..19a63c5b 100644 --- a/0050-efinet-and-bootp-add-support-for-dhcpv6.patch +++ b/0030-efinet-and-bootp-add-support-for-dhcpv6.patch @@ -6,18 +6,18 @@ Subject: [PATCH] efinet and bootp: add support for dhcpv6 Signed-off-by: Peter Jones --- grub-core/net/bootp.c | 173 +++++++++++++++++++++++++++++++++++++ - grub-core/net/drivers/efi/efinet.c | 53 ++++++++++-- + grub-core/net/drivers/efi/efinet.c | 84 +++++++++++++----- grub-core/net/net.c | 72 +++++++++++++++ - grub-core/net/tftp.c | 4 + + grub-core/net/tftp.c | 3 + include/grub/efi/api.h | 129 +++++++++++++++++++++++++-- include/grub/net.h | 60 +++++++++++++ - 6 files changed, 477 insertions(+), 14 deletions(-) + 6 files changed, 491 insertions(+), 30 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 6fb5627025d..e28fb6a09f9 100644 +index abe45ef7bf6..02d2c2614cb 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c -@@ -902,6 +902,179 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), +@@ -905,6 +905,179 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp; @@ -198,7 +198,7 @@ index 6fb5627025d..e28fb6a09f9 100644 grub_bootp_init (void) { diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 5388f952ba9..173fb63153c 100644 +index 3ea25cf9894..2af8742f904 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -18,11 +18,14 @@ @@ -216,16 +216,16 @@ index 5388f952ba9..173fb63153c 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -329,7 +332,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -346,7 +349,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, char **path) { struct grub_net_card *card; - grub_efi_device_path_t *dp; + grub_efi_device_path_t *dp, *ldp = NULL; - - dp = grub_efi_get_device_path (hnd); - if (! dp) -@@ -340,14 +343,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + struct grub_net_network_level_interface *inter; + grub_efi_device_path_t *vlan_dp; + grub_efi_uint16_t vlan_dp_len; +@@ -361,14 +364,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, grub_efi_device_path_t *cdp; struct grub_efi_pxe *pxe; struct grub_efi_pxe_mode *pxe_mode; @@ -246,7 +246,7 @@ index 5388f952ba9..173fb63153c 100644 int match; /* EDK2 UEFI PXE driver creates pseudo devices with type IPv4/IPv6 -@@ -356,7 +364,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -377,7 +385,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, devices. We skip them when enumerating cards, so here we need to find matching MAC device. */ @@ -254,7 +254,7 @@ index 5388f952ba9..173fb63153c 100644 if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) -@@ -373,16 +380,46 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -394,41 +401,70 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (!match) continue; } @@ -265,11 +265,6 @@ index 5388f952ba9..173fb63153c 100644 continue; + pxe_mode = pxe->mode; -- grub_net_configure_by_dhcp_ack (card->name, card, 0, -- (struct grub_net_bootp_packet *) -- &pxe_mode->dhcp_ack, -- sizeof (pxe_mode->dhcp_ack), -- 1, device, path); + if (pxe_mode->using_ipv6) + { + grub_net_link_level_address_t hwaddr; @@ -281,41 +276,86 @@ index 5388f952ba9..173fb63153c 100644 + pxe_mode->dhcp_ack_received ? "" : " cannot continue"); + if (!pxe_mode->dhcp_ack_received) + continue; -+ + +- inter = grub_net_configure_by_dhcp_ack (card->name, card, 0, +- (struct grub_net_bootp_packet *) +- &pxe_mode->dhcp_ack, +- sizeof (pxe_mode->dhcp_ack), +- 1, device, path); + hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + grub_memcpy (hwaddr.mac, + card->efi_net->mode->current_address, + sizeof (hwaddr.mac)); -+ -+ intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr, + +- if (inter != NULL) ++ inter = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr, + (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6, + 1, device, path); -+ if (intf && device && path) ++ if (inter && device && path) + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); + } + else -+ { + { +- /* +- * Search the device path for any VLAN subtype and use it +- * to configure the interface. +- */ +- vlan_dp = dp; + grub_dprintf ("efinet", "using ipv4 and dhcp\n"); -+ grub_net_configure_by_dhcp_ack (card->name, card, 0, -+ (struct grub_net_bootp_packet *) -+ &pxe_mode->dhcp_ack, -+ sizeof (pxe_mode->dhcp_ack), -+ 1, device, path); ++ inter = grub_net_configure_by_dhcp_ack (card->name, card, 0, ++ (struct grub_net_bootp_packet *) ++ &pxe_mode->dhcp_ack, ++ sizeof (pxe_mode->dhcp_ack), ++ 1, device, path); + +- while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (vlan_dp)) + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); -+ } - return; ++ if (inter != NULL) + { +- if (GRUB_EFI_DEVICE_PATH_TYPE (vlan_dp) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE && +- GRUB_EFI_DEVICE_PATH_SUBTYPE (vlan_dp) == GRUB_EFI_VLAN_DEVICE_PATH_SUBTYPE) ++ /* ++ * Search the device path for any VLAN subtype and use it ++ * to configure the interface. ++ */ ++ vlan_dp = dp; ++ ++ while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (vlan_dp)) + { +- vlan = (grub_efi_vlan_device_path_t *) vlan_dp; +- inter->vlantag = vlan->vlan_id; +- break; ++ if (GRUB_EFI_DEVICE_PATH_TYPE (vlan_dp) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE && ++ GRUB_EFI_DEVICE_PATH_SUBTYPE (vlan_dp) == GRUB_EFI_VLAN_DEVICE_PATH_SUBTYPE) ++ { ++ vlan = (grub_efi_vlan_device_path_t *) vlan_dp; ++ inter->vlantag = vlan->vlan_id; ++ break; ++ } ++ ++ vlan_dp_len = GRUB_EFI_DEVICE_PATH_LENGTH (vlan_dp); ++ vlan_dp = (grub_efi_device_path_t *) ((grub_efi_uint8_t *) vlan_dp + vlan_dp_len); + } +- +- vlan_dp_len = GRUB_EFI_DEVICE_PATH_LENGTH (vlan_dp); +- vlan_dp = (grub_efi_device_path_t *) ((grub_efi_uint8_t *) vlan_dp + vlan_dp_len); + } ++ return; + } +- return; } } + diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 0ef148f4adc..22f2689aaeb 100644 +index 54451cea2a7..20c55257647 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c -@@ -960,6 +960,78 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa +@@ -984,6 +984,78 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa grub_net_network_level_interfaces = inter; } +int -+grub_ipv6_get_masksize (grub_uint16_t be_mask[8]) ++grub_ipv6_get_masksize (grub_uint16_t *be_mask) +{ + grub_uint8_t *mask; + grub_uint16_t mask16[8]; @@ -390,10 +430,10 @@ index 0ef148f4adc..22f2689aaeb 100644 grub_err_t grub_net_add_ipv4_local (struct grub_net_network_level_interface *inter, diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index 7f44b30f521..4ab2f5c7357 100644 +index 409b1d09bcd..f300a9d4007 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c -@@ -358,18 +358,22 @@ tftp_open (struct grub_file *file, const char *filename) +@@ -359,6 +359,7 @@ tftp_open (struct grub_file *file, const char *filename) file->not_easily_seekable = 1; file->data = data; @@ -401,14 +441,13 @@ index 7f44b30f521..4ab2f5c7357 100644 err = grub_net_resolve_address (file->device->net->server, &addr); if (err) { -+ grub_dprintf("tftp", "Address resolution failed: %d\n", err); - grub_free (data); +@@ -369,11 +370,13 @@ tftp_open (struct grub_file *file, const char *filename) return err; } + grub_dprintf("tftp", "opening connection\n"); data->sock = grub_net_udp_open (addr, - TFTP_SERVER_PORT, tftp_receive, + port ? port : TFTP_SERVER_PORT, tftp_receive, file); if (!data->sock) { @@ -417,10 +456,10 @@ index 7f44b30f521..4ab2f5c7357 100644 return grub_errno; } diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index f1a52210c0c..117469450d3 100644 +index d44d00ad7d5..c6d702831f7 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -592,10 +592,16 @@ typedef void *grub_efi_handle_t; +@@ -637,10 +637,16 @@ typedef void *grub_efi_handle_t; typedef void *grub_efi_event_t; typedef grub_efi_uint64_t grub_efi_lba_t; typedef grub_efi_uintn_t grub_efi_tpl_t; @@ -441,7 +480,7 @@ index f1a52210c0c..117469450d3 100644 typedef grub_efi_uint64_t grub_efi_physical_address_t; typedef grub_efi_uint64_t grub_efi_virtual_address_t; -@@ -1474,16 +1480,127 @@ struct grub_efi_simple_text_output_interface +@@ -1521,16 +1527,127 @@ struct grub_efi_simple_text_output_interface }; typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t; @@ -572,10 +611,10 @@ index f1a52210c0c..117469450d3 100644 typedef struct grub_efi_pxe diff --git a/include/grub/net.h b/include/grub/net.h -index 7ae4b6bd805..8a05ec4fe7a 100644 +index 844e501c128..bf8430a6364 100644 --- a/include/grub/net.h +++ b/include/grub/net.h -@@ -447,6 +447,51 @@ struct grub_net_bootp_packet +@@ -450,6 +450,51 @@ struct grub_net_bootp_packet grub_uint8_t vendor[0]; } GRUB_PACKED; @@ -627,7 +666,7 @@ index 7ae4b6bd805..8a05ec4fe7a 100644 #define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63 #define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82 #define GRUB_NET_BOOTP_RFC1048_MAGIC_2 0x53 -@@ -482,6 +527,21 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -485,6 +530,21 @@ grub_net_configure_by_dhcp_ack (const char *name, grub_size_t size, int is_def, char **device, char **path); diff --git a/0031-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch b/0031-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch deleted file mode 100644 index 79321807..00000000 --- a/0031-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 21 Jun 2013 14:44:08 -0400 -Subject: [PATCH] Use -2 instead of -1 for our right-hand margin, so - linewrapping works (#976643). - -Signed-off-by: Peter Jones ---- - grub-core/normal/menu_text.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index cbd62f714cb..26e9e82042a 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -334,7 +334,7 @@ grub_menu_init_page (int nested, int edit, - - geo->border = 0; - geo->first_entry_x = 0; /* no margin */ -- geo->entry_width = grub_term_width (term) - 1; -+ geo->entry_width = grub_term_width (term) - 2; - - geo->first_entry_y = 3; /* three empty lines*/ - diff --git a/0089-bootp-New-net_bootp6-command.patch b/0031-bootp-New-net_bootp6-command.patch similarity index 96% rename from 0089-bootp-New-net_bootp6-command.patch rename to 0031-bootp-New-net_bootp6-command.patch index 21b3871b..91e58f29 100644 --- a/0089-bootp-New-net_bootp6-command.patch +++ b/0031-bootp-New-net_bootp6-command.patch @@ -12,14 +12,14 @@ Signed-off-by: Ken Lin Signed-off-by: Peter Jones --- grub-core/net/bootp.c | 1059 ++++++++++++++++++++++++++++++------ - grub-core/net/drivers/efi/efinet.c | 20 +- + grub-core/net/drivers/efi/efinet.c | 18 +- grub-core/net/ip.c | 39 ++ include/grub/efi/api.h | 2 +- include/grub/net.h | 91 ++-- - 5 files changed, 1002 insertions(+), 209 deletions(-) + 5 files changed, 1001 insertions(+), 208 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 08b6b2b5d6c..fe93b80f1cf 100644 +index 02d2c2614cb..e0aec25233d 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -24,6 +24,98 @@ @@ -121,7 +121,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644 struct grub_dhcp_discover_options { -@@ -604,6 +696,584 @@ out: +@@ -610,6 +702,584 @@ out: return err; } @@ -427,7 +427,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644 + grub_dhcp6_session_t se; + struct grub_datetime date; + grub_err_t err; -+ grub_int32_t t = 0; ++ grub_int64_t t = 0; + + se = grub_malloc (sizeof (*se)); + @@ -706,7 +706,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644 /* * This is called directly from net/ip.c:handle_dgram(), because those * BOOTP/DHCP packets are a bit special due to their improper -@@ -672,6 +1342,77 @@ grub_net_process_dhcp (struct grub_net_buff *nb, +@@ -678,6 +1348,77 @@ grub_net_process_dhcp (struct grub_net_buff *nb, } } @@ -784,7 +784,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644 static grub_err_t grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) -@@ -897,180 +1638,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), +@@ -903,180 +1644,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), return err; } @@ -1119,7 +1119,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644 void grub_bootp_init (void) -@@ -1084,11 +1819,15 @@ grub_bootp_init (void) +@@ -1090,11 +1825,15 @@ grub_bootp_init (void) cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); @@ -1136,10 +1136,10 @@ index 08b6b2b5d6c..fe93b80f1cf 100644 grub_unregister_command (cmd_bootp); grub_unregister_command (cmd_dhcp); diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index a673bea807a..8e25680db0c 100644 +index 2af8742f904..3e2432fb61c 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -393,9 +393,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -410,9 +410,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, pxe_mode = pxe->mode; if (pxe_mode->using_ipv6) { @@ -1149,7 +1149,7 @@ index a673bea807a..8e25680db0c 100644 grub_dprintf ("efinet", "using ipv6 and dhcpv6\n"); grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n", pxe_mode->dhcp_ack_received ? "yes" : "no", -@@ -403,15 +400,14 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -420,14 +417,13 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (!pxe_mode->dhcp_ack_received) continue; @@ -1158,26 +1158,24 @@ index a673bea807a..8e25680db0c 100644 - card->efi_net->mode->current_address, - sizeof (hwaddr.mac)); - -- intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr, +- inter = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr, - (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6, - 1, device, path); -- if (intf && device && path) -+ grub_net_configure_by_dhcpv6_reply (card->name, card, 0, -+ (struct grub_net_dhcp6_packet *) -+ &pxe_mode->dhcp_ack, -+ sizeof (pxe_mode->dhcp_ack), -+ 1, device, path); ++ inter = grub_net_configure_by_dhcpv6_reply (card->name, card, 0, ++ (struct grub_net_dhcp6_packet *) ++ &pxe_mode->dhcp_ack, ++ sizeof (pxe_mode->dhcp_ack), ++ 1, device, path); + if (grub_errno) + grub_print_error (); -+ if (device && path) + if (inter && device && path) grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); } - else diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c -index a5896f6dc26..ce6bdc75c6d 100644 +index 3c3d0be0e57..f967618e53f 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c -@@ -239,6 +239,45 @@ handle_dgram (struct grub_net_buff *nb, +@@ -240,6 +240,45 @@ handle_dgram (struct grub_net_buff *nb, { struct udphdr *udph; udph = (struct udphdr *) nb->data; @@ -1224,10 +1222,10 @@ index a5896f6dc26..ce6bdc75c6d 100644 { const struct grub_net_bootp_packet *bootp; diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 99628801478..7614b58dca8 100644 +index c6d702831f7..c1b869db520 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -1532,7 +1532,7 @@ typedef struct grub_efi_pxe_ip_filter +@@ -1570,7 +1570,7 @@ typedef struct grub_efi_pxe_ip_filter { grub_efi_uint8_t filters; grub_efi_uint8_t ip_count; @@ -1237,10 +1235,10 @@ index 99628801478..7614b58dca8 100644 } grub_efi_pxe_ip_filter_t; diff --git a/include/grub/net.h b/include/grub/net.h -index d55d505a03a..543251f7273 100644 +index bf8430a6364..ff901b96e22 100644 --- a/include/grub/net.h +++ b/include/grub/net.h -@@ -451,50 +451,65 @@ struct grub_net_bootp_packet +@@ -450,50 +450,65 @@ struct grub_net_bootp_packet grub_uint8_t vendor[0]; } GRUB_PACKED; @@ -1336,7 +1334,7 @@ index d55d505a03a..543251f7273 100644 #define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63 #define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82 -@@ -532,12 +547,12 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -531,12 +546,12 @@ grub_net_configure_by_dhcp_ack (const char *name, int is_def, char **device, char **path); struct grub_net_network_level_interface * @@ -1355,7 +1353,7 @@ index d55d505a03a..543251f7273 100644 int grub_ipv6_get_masksize(grub_uint16_t *mask); -@@ -554,6 +569,10 @@ void +@@ -553,6 +568,10 @@ void grub_net_process_dhcp (struct grub_net_buff *nb, struct grub_net_network_level_interface *iface); diff --git a/0051-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch b/0032-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch similarity index 81% rename from 0051-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch rename to 0032-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch index e799ac1a..8890e10d 100644 --- a/0051-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch +++ b/0032-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch @@ -10,23 +10,24 @@ variables are then used by 10_linux to choose whether or not to create debug stanzas. Resolves: rhbz#1226325 +[rharwood: migrate man page to h2m] --- - configure.ac | 2 + + configure.ac | 1 + Makefile.util.def | 7 ++ + docs/man/grub-get-kernel-settings.h2m | 2 + util/bash-completion.d/grub-completion.bash.in | 22 +++++++ - util/grub-get-kernel-settings.3 | 20 ++++++ util/grub-get-kernel-settings.in | 88 ++++++++++++++++++++++++++ util/grub-mkconfig.in | 3 + util/grub.d/10_linux.in | 23 +++++-- - 7 files changed, 160 insertions(+), 5 deletions(-) - create mode 100644 util/grub-get-kernel-settings.3 + 7 files changed, 141 insertions(+), 5 deletions(-) + create mode 100644 docs/man/grub-get-kernel-settings.h2m create mode 100644 util/grub-get-kernel-settings.in diff --git a/configure.ac b/configure.ac -index 30fd84d8067..ed31ea457d2 100644 +index 493e336ec6c..3602b4ab62b 100644 --- a/configure.ac +++ b/configure.ac -@@ -65,6 +65,7 @@ grub_TRANSFORM([grub-install]) +@@ -70,6 +70,7 @@ grub_TRANSFORM([grub-install]) grub_TRANSFORM([grub-mkconfig]) grub_TRANSFORM([grub-mkfont]) grub_TRANSFORM([grub-mkimage]) @@ -34,19 +35,11 @@ index 30fd84d8067..ed31ea457d2 100644 grub_TRANSFORM([grub-glue-efi]) grub_TRANSFORM([grub-mklayout]) grub_TRANSFORM([grub-mkpasswd-pbkdf2]) -@@ -82,6 +83,7 @@ grub_TRANSFORM([grub-file]) - grub_TRANSFORM([grub-bios-setup.3]) - grub_TRANSFORM([grub-editenv.1]) - grub_TRANSFORM([grub-fstest.3]) -+grub_TRANSFORM([grub-get-kernel-settings.3]) - grub_TRANSFORM([grub-glue-efi.3]) - grub_TRANSFORM([grub-install.1]) - grub_TRANSFORM([grub-kbdcomp.3]) diff --git a/Makefile.util.def b/Makefile.util.def -index 1a7dd433e33..cdd2f51fe4b 100644 +index 95884956a68..84a17ef5cfa 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -732,6 +732,13 @@ script = { +@@ -725,6 +725,13 @@ script = { installdir = sbin; }; @@ -60,11 +53,19 @@ index 1a7dd433e33..cdd2f51fe4b 100644 script = { name = grub-set-default; common = util/grub-set-default.in; +diff --git a/docs/man/grub-get-kernel-settings.h2m b/docs/man/grub-get-kernel-settings.h2m +new file mode 100644 +index 00000000000..b8051f01f3a +--- /dev/null ++++ b/docs/man/grub-get-kernel-settings.h2m +@@ -0,0 +1,2 @@ ++[NAME] ++grub-get-kernel-settings \- Evaluate the system's kernel installation settings for use while making a grub configuration file diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in -index 44bf135b9f8..5c4acd496d4 100644 +index 213ce1e57cf..da7fca5efac 100644 --- a/util/bash-completion.d/grub-completion.bash.in +++ b/util/bash-completion.d/grub-completion.bash.in -@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \ +@@ -275,6 +275,28 @@ have ${__grub_sparc64_setup_program} && \ unset __grub_sparc64_setup_program @@ -93,32 +94,6 @@ index 44bf135b9f8..5c4acd496d4 100644 # # grub-install # -diff --git a/util/grub-get-kernel-settings.3 b/util/grub-get-kernel-settings.3 -new file mode 100644 -index 00000000000..ba33330e28d ---- /dev/null -+++ b/util/grub-get-kernel-settings.3 -@@ -0,0 +1,20 @@ -+.TH GRUB-GET-KERNEL-SETTINGS 3 "Thu Jun 25 2015" -+.SH NAME -+\fBgrub-get-kernel-settings\fR \(em Evaluate the system's kernel installation settings for use while making a grub configuration file. -+ -+.SH SYNOPSIS -+\fBgrub-get-kernel-settings\fR [OPTION] -+ -+.SH DESCRIPTION -+\fBgrub-get-kernel-settings\fR reads the kernel installation settings on the host system, and emits a set of grub settings suitable for use when creating a grub configuration file. -+ -+.SH OPTIONS -+.TP -+-h, --help -+Display program usage and exit. -+.TP -+-v, --version -+Display the current version. -+ -+.SH SEE ALSO -+.BR "info grub" diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in new file mode 100644 index 00000000000..7e87dfccc0e @@ -214,7 +189,7 @@ index 00000000000..7e87dfccc0e + echo export GRUB_UPDATE_DEFAULT_KERNEL +fi diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index ba14cf6261c..005f093809b 100644 +index 5f2824d4f58..28e92515795 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -45,6 +45,7 @@ grub_probe="${sbindir}/@grub_probe@" @@ -235,10 +210,10 @@ index ba14cf6261c..005f093809b 100644 if [ -z "${GRUB_DISABLE_LINUX_UUID}" ]; then GRUB_DISABLE_LINUX_UUID="true" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 2e59f3b4197..0f3c19e30cc 100644 +index 993c53ad92e..e8ab4082f87 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -111,7 +111,8 @@ linux_entry () +@@ -113,7 +113,8 @@ linux_entry () os="$1" version="$2" type="$3" @@ -248,7 +223,7 @@ index 2e59f3b4197..0f3c19e30cc 100644 if [ -z "$boot_device_id" ]; then boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" -@@ -123,6 +124,9 @@ linux_entry () +@@ -125,6 +126,9 @@ linux_entry () quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" fi @@ -258,7 +233,7 @@ index 2e59f3b4197..0f3c19e30cc 100644 echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" else echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" -@@ -299,11 +303,15 @@ while [ "x$list" != "x" ] ; do +@@ -320,11 +324,15 @@ for linux in ${reverse_sorted_list}; do fi if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then @@ -276,7 +251,7 @@ index 2e59f3b4197..0f3c19e30cc 100644 if [ -z "$boot_device_id" ]; then boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" fi -@@ -312,10 +320,15 @@ while [ "x$list" != "x" ] ; do +@@ -333,10 +341,15 @@ for linux in ${reverse_sorted_list}; do is_top_level=false fi @@ -291,6 +266,6 @@ index 2e59f3b4197..0f3c19e30cc 100644 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then - linux_entry "${OS}" "${version}" recovery \ + linux_entry "${OS}" "${version}" recovery standard \ - "single ${GRUB_CMDLINE_LINUX}" + "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}" fi - + done diff --git a/0033-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch b/0033-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch deleted file mode 100644 index 7e9e8294..00000000 --- a/0033-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 28 Oct 2013 10:13:27 -0400 -Subject: [PATCH] F10 doesn't work on serial, so don't tell the user to hit it - (#987443) - -Signed-off-by: Peter Jones ---- - grub-core/normal/menu_text.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 26e9e82042a..4895ffe7d1d 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -157,7 +157,7 @@ print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - - if (edit) - { -- ret += grub_print_message_indented_real (_("Press Ctrl-x or F10 to start, Ctrl-c or F2 for a \ -+ ret += grub_print_message_indented_real (_("Press Ctrl-x to start, Ctrl-c for a \ - command prompt or Escape to discard edits and return to the menu. Pressing Tab lists possible completions."), - STANDARD_MARGIN, STANDARD_MARGIN, - term, dry_run); diff --git a/0053-Make-grub_fatal-also-backtrace.patch b/0033-Make-grub_fatal-also-backtrace.patch similarity index 91% rename from 0053-Make-grub_fatal-also-backtrace.patch rename to 0033-Make-grub_fatal-also-backtrace.patch index 3534b05a..1cfe7639 100644 --- a/0053-Make-grub_fatal-also-backtrace.patch +++ b/0033-Make-grub_fatal-also-backtrace.patch @@ -5,18 +5,18 @@ Subject: [PATCH] Make grub_fatal() also backtrace. --- grub-core/Makefile.core.def | 3 ++ - grub-core/kern/misc.c | 8 +++++- + grub-core/kern/misc.c | 6 ++++ grub-core/lib/arm64/backtrace.c | 62 +++++++++++++++++++++++++++++++++++++++++ grub-core/lib/backtrace.c | 2 ++ grub-core/lib/i386/backtrace.c | 14 +++++++++- - 5 files changed, 87 insertions(+), 2 deletions(-) + 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 grub-core/lib/arm64/backtrace.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index c15e91943b9..058c88ac3af 100644 +index 47c0fc755a2..63f053b3add 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -188,6 +188,9 @@ kernel = { +@@ -199,6 +199,9 @@ kernel = { softdiv = lib/division.c; @@ -27,19 +27,19 @@ index c15e91943b9..058c88ac3af 100644 i386_xen = kern/i386/dl.c; i386_xen_pvh = kern/i386/dl.c; diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 63b586d09cb..a3e215155bd 100644 +index 11037dc0227..465a8e74ea7 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -24,6 +24,7 @@ - #include - #include +@@ -26,6 +26,7 @@ #include + #include + #include +#include union printf_arg { -@@ -1199,8 +1200,13 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) - static void __attribute__ ((noreturn)) +@@ -1301,6 +1302,11 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) + void __attribute__ ((noreturn)) grub_abort (void) { +#ifndef GRUB_UTIL @@ -48,11 +48,8 @@ index 63b586d09cb..a3e215155bd 100644 +#endif +#endif grub_printf ("\nAborted."); -- -+ + #ifndef GRUB_UTIL - if (grub_term_inputs) - #endif diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c new file mode 100644 index 00000000000..1079b5380e1 diff --git a/0034-Don-t-say-GNU-Linux-in-generated-menus.patch b/0034-Don-t-say-GNU-Linux-in-generated-menus.patch deleted file mode 100644 index db2a8b5b..00000000 --- a/0034-Don-t-say-GNU-Linux-in-generated-menus.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 14 Mar 2011 14:27:42 -0400 -Subject: [PATCH] Don't say "GNU/Linux" in generated menus. - ---- - util/grub.d/10_linux.in | 4 ++-- - util/grub.d/20_linux_xen.in | 4 ++-- - 2 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index ad2ac4b078d..4fc58c83304 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" - CLASS="--class gnu-linux --class gnu --class os" - - if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then -- OS=GNU/Linux -+ OS="$(sed 's, release .*$,,g' /etc/system-release)" - else -- OS="${GRUB_DISTRIBUTOR} GNU/Linux" -+ OS="${GRUB_DISTRIBUTOR}" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" - fi - -diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in -index 3b1f4704921..ada20775a14 100644 ---- a/util/grub.d/20_linux_xen.in -+++ b/util/grub.d/20_linux_xen.in -@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" - CLASS="--class gnu-linux --class gnu --class os --class xen" - - if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then -- OS=GNU/Linux -+ OS="$(sed 's, release .*$,,g' /etc/system-release)" - else -- OS="${GRUB_DISTRIBUTOR} GNU/Linux" -+ OS="${GRUB_DISTRIBUTOR}" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" - fi - diff --git a/0055-Make-our-info-pages-say-grub2-where-appropriate.patch b/0034-Make-our-info-pages-say-grub2-where-appropriate.patch similarity index 80% rename from 0055-Make-our-info-pages-say-grub2-where-appropriate.patch rename to 0034-Make-our-info-pages-say-grub2-where-appropriate.patch index be28efd5..992bb439 100644 --- a/0055-Make-our-info-pages-say-grub2-where-appropriate.patch +++ b/0034-Make-our-info-pages-say-grub2-where-appropriate.patch @@ -9,11 +9,11 @@ time. Signed-off-by: Peter Jones --- docs/grub-dev.texi | 4 +- - docs/grub.texi | 321 ++++++++++++++++++++++++++++------------------------- - 2 files changed, 171 insertions(+), 154 deletions(-) + docs/grub.texi | 357 ++++++++++++++++++++++++++++------------------------- + 2 files changed, 189 insertions(+), 172 deletions(-) diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi -index 6c629a23e2d..19f708ee662 100644 +index 1276c59302a..04c6678cb6b 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -1,7 +1,7 @@ @@ -35,7 +35,7 @@ index 6c629a23e2d..19f708ee662 100644 @setchapternewpage odd diff --git a/docs/grub.texi b/docs/grub.texi -index 69f08d289f9..0615d0ed97e 100644 +index 974bc0ddb07..c30701b4e1f 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1,7 +1,7 @@ @@ -72,31 +72,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end direntry @setchapternewpage odd -@@ -103,15 +103,15 @@ This edition documents version @value{VERSION}. - * Platform-specific operations:: Platform-specific operations - * Supported kernels:: The list of supported kernels - * Troubleshooting:: Error messages produced by GRUB --* Invoking grub-install:: How to use the GRUB installer --* Invoking grub-mkconfig:: Generate a GRUB configuration file --* Invoking grub-mkpasswd-pbkdf2:: -+* Invoking grub2-install:: How to use the GRUB installer -+* Invoking grub2-mkconfig:: Generate a GRUB configuration file -+* Invoking grub2-mkpasswd-pbkdf2:: - Generate GRUB password hashes --* Invoking grub-mkrelpath:: Make system path relative to its root --* Invoking grub-mkrescue:: Make a GRUB rescue image --* Invoking grub-mount:: Mount a file system using GRUB --* Invoking grub-probe:: Probe device information for GRUB --* Invoking grub-script-check:: Check GRUB script file for syntax errors -+* Invoking grub2-mkrelpath:: Make system path relative to its root -+* Invoking grub2-mkrescue:: Make a GRUB rescue image -+* Invoking grub2-mount:: Mount a file system using GRUB -+* Invoking grub2-probe:: Probe device information for GRUB -+* Invoking grub2-script-check:: Check GRUB script file for syntax errors - * Obtaining and Building GRUB:: How to obtain and build GRUB - * Reporting bugs:: Where you should send a bug report - * Future:: Some future plans on GRUB -@@ -230,7 +230,7 @@ surprising. +@@ -223,7 +223,7 @@ surprising. @item @file{grub.cfg} is typically automatically generated by @@ -105,7 +81,7 @@ index 69f08d289f9..0615d0ed97e 100644 easier to handle versioned kernel upgrades. @item -@@ -244,7 +244,7 @@ scripting language: variables, conditionals, and loops are available. +@@ -237,7 +237,7 @@ scripting language: variables, conditionals, and loops are available. @item A small amount of persistent storage is available across reboots, using the @command{save_env} and @command{load_env} commands in GRUB and the @@ -114,7 +90,7 @@ index 69f08d289f9..0615d0ed97e 100644 (@pxref{Environment block}). @item -@@ -549,7 +549,7 @@ On OS which have device nodes similar to Unix-like OS GRUB tools use the +@@ -542,7 +542,7 @@ On OS which have device nodes similar to Unix-like OS GRUB tools use the OS name. E.g. for GNU/Linux: @example @@ -123,7 +99,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example On AROS we use another syntax. For volumes: -@@ -572,7 +572,7 @@ For disks we use syntax: +@@ -565,7 +565,7 @@ For disks we use syntax: E.g. @example @@ -132,7 +108,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example On Windows we use UNC path. For volumes it's typically -@@ -599,7 +599,7 @@ For disks it's +@@ -592,7 +592,7 @@ For disks it's E.g. @example @@ -141,7 +117,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example Beware that you may need to further escape the backslashes depending on your -@@ -609,7 +609,7 @@ When compiled with cygwin support then cygwin drive names are automatically +@@ -602,7 +602,7 @@ When compiled with cygwin support then cygwin drive names are automatically when needed. E.g. @example @@ -150,7 +126,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example @node Installation -@@ -622,7 +622,7 @@ from the source tarball, or as a package for your OS. +@@ -615,7 +615,7 @@ from the source tarball, or as a package for your OS. After you have done that, you need to install the boot loader on a drive (floppy or hard disk) by using the utility @@ -159,7 +135,7 @@ index 69f08d289f9..0615d0ed97e 100644 GRUB comes with boot images, which are normally put in the directory @file{/usr/lib/grub/-} (for BIOS-based machines -@@ -633,22 +633,22 @@ loader needs to find them (usually @file{/boot}) will be called +@@ -626,22 +626,22 @@ loader needs to find them (usually @file{/boot}) will be called the @dfn{boot directory}. @menu @@ -187,7 +163,7 @@ index 69f08d289f9..0615d0ed97e 100644 The usage is basically very simple. You only need to specify one argument to the program, namely, where to install the boot loader. The -@@ -657,13 +657,13 @@ For example, under Linux the following will install GRUB into the MBR +@@ -650,13 +650,13 @@ For example, under Linux the following will install GRUB into the MBR of the first IDE disk: @example @@ -203,7 +179,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example But all the above examples assume that GRUB should put images under -@@ -677,7 +677,7 @@ boot floppy with a filesystem. Here is an example: +@@ -670,7 +670,7 @@ boot floppy with a filesystem. Here is an example: # @kbd{mke2fs /dev/fd0} # @kbd{mount -t ext2 /dev/fd0 /mnt} # @kbd{mkdir /mnt/boot} @@ -212,7 +188,7 @@ index 69f08d289f9..0615d0ed97e 100644 # @kbd{umount /mnt} @end group @end example -@@ -689,30 +689,37 @@ floppy instead of exposing the USB drive as a hard disk (they call it +@@ -682,30 +682,37 @@ floppy instead of exposing the USB drive as a hard disk (they call it @example # @kbd{losetup /dev/loop0 /dev/sdb1} # @kbd{mount /dev/loop0 /mnt/usb} @@ -254,7 +230,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example @node Making a GRUB bootable CD-ROM -@@ -732,10 +739,10 @@ usually also need to include a configuration file @file{grub.cfg} and some +@@ -725,10 +732,10 @@ usually also need to include a configuration file @file{grub.cfg} and some other GRUB modules. To make a simple generic GRUB rescue CD, you can use the @@ -267,7 +243,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example You will often need to include other files in your image. To do this, first -@@ -758,7 +765,7 @@ directory @file{iso/}. +@@ -751,7 +758,7 @@ directory @file{iso/}. Finally, make the image: @example @@ -276,7 +252,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example This produces a file named @file{grub.iso}, which then can be burned -@@ -774,7 +781,7 @@ storage devices. +@@ -767,7 +774,7 @@ storage devices. @node Device map @section The map between BIOS drives and OS devices @@ -285,7 +261,7 @@ index 69f08d289f9..0615d0ed97e 100644 etc.) read it to map BIOS drives to OS devices. This file consists of lines like this: -@@ -1254,23 +1261,23 @@ need to write the whole thing by hand. +@@ -1269,23 +1276,23 @@ need to write the whole thing by hand. @node Simple configuration @section Simple configuration handling @@ -314,7 +290,7 @@ index 69f08d289f9..0615d0ed97e 100644 valid POSIX shell input; normally, it will just be a sequence of @samp{KEY=value} lines, but if the value contains spaces or other special characters then it must be quoted. For example: -@@ -1308,7 +1315,7 @@ works it's not recommended since titles often contain unstable device names +@@ -1323,7 +1330,7 @@ works it's not recommended since titles often contain unstable device names and may be translated If you set this to @samp{saved}, then the default menu entry will be that @@ -323,7 +299,7 @@ index 69f08d289f9..0615d0ed97e 100644 the environment block, which may not be available in all situations (@pxref{Environment block}). -@@ -1319,7 +1326,7 @@ If this option is set to @samp{true}, then, when an entry is selected, save +@@ -1334,7 +1341,7 @@ If this option is set to @samp{true}, then, when an entry is selected, save it as a new default entry for use by future runs of GRUB. This is only useful if @samp{GRUB_DEFAULT=saved}; it is a separate option because @samp{GRUB_DEFAULT=saved} is useful without this option, in conjunction with @@ -332,7 +308,7 @@ index 69f08d289f9..0615d0ed97e 100644 This option relies on the environment block, which may not be available in all situations (@pxref{Environment block}). -@@ -1449,7 +1456,7 @@ intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode +@@ -1481,15 +1488,15 @@ intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode @end example @item GRUB_DISABLE_LINUX_UUID @@ -341,7 +317,17 @@ index 69f08d289f9..0615d0ed97e 100644 universally-unique identifiers (UUIDs) to identify the root filesystem to the Linux kernel, using a @samp{root=UUID=...} kernel parameter. This is usually more reliable, but in some cases it may not be appropriate. To -@@ -1471,7 +1478,7 @@ If this option is set to @samp{true}, disable the generation of recovery + disable the use of UUIDs, set this option to @samp{true}. + + @item GRUB_DISABLE_LINUX_PARTUUID +-If @command{grub-mkconfig} cannot identify the root filesystem via its +-universally-unique indentifier (UUID), @command{grub-mkconfig} can use the UUID ++If @command{grub2-mkconfig} cannot identify the root filesystem via its ++universally-unique indentifier (UUID), @command{grub2-mkconfig} can use the UUID + of the partition containing the filesystem to identify the root filesystem to + the Linux kernel via a @samp{root=PARTUUID=...} kernel parameter. This is not + as reliable as using the filesystem UUID, but is more reliable than using the +@@ -1503,7 +1510,7 @@ If this option is set to @samp{true}, disable the generation of recovery mode menu entries. @item GRUB_DISABLE_UUID @@ -350,7 +336,7 @@ index 69f08d289f9..0615d0ed97e 100644 universally-unique identifiers (UUIDs) to identify various filesystems to search for files. This is usually more reliable, but in some cases it may not be appropriate. To disable this use of UUIDs, set this option to -@@ -1482,12 +1489,12 @@ not be appropriate. To disable this use of UUIDs, set this option to +@@ -1514,12 +1521,12 @@ not be appropriate. To disable this use of UUIDs, set this option to @item GRUB_VIDEO_BACKEND If graphical video support is required, either because the @samp{gfxterm} graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, @@ -366,7 +352,7 @@ index 69f08d289f9..0615d0ed97e 100644 @item GRUB_GFXMODE Set the resolution used on the @samp{gfxterm} graphical terminal. Note that -@@ -1519,7 +1526,7 @@ boot sequence. If you have problems, set this option to @samp{text} and +@@ -1552,7 +1559,7 @@ boot sequence. If you have problems, set this option to @samp{text} and GRUB will tell Linux to boot in normal text mode. @item GRUB_DISABLE_OS_PROBER @@ -375,7 +361,7 @@ index 69f08d289f9..0615d0ed97e 100644 @command{os-prober} program, if installed, to discover other operating systems installed on the same system and generate appropriate menu entries for them. Set this option to @samp{true} to disable this. -@@ -1529,7 +1536,7 @@ List of space-separated FS UUIDs of filesystems to be ignored from os-prober +@@ -1562,7 +1569,7 @@ List of space-separated FS UUIDs of filesystems to be ignored from os-prober output. For efi chainloaders it's @@ @item GRUB_DISABLE_SUBMENU @@ -384,7 +370,7 @@ index 69f08d289f9..0615d0ed97e 100644 the kernel with highest version number and put all other found kernels or alternative menu entries for recovery mode in submenu. For entries returned by @command{os-prober} first entry will be put on top level and all others -@@ -1537,11 +1544,11 @@ in submenu. If this option is set to @samp{true}, flat menu with all entries +@@ -1570,11 +1577,11 @@ in submenu. If this option is set to @samp{true}, flat menu with all entries on top level will be generated instead. Changing this option will require changing existing values of @samp{GRUB_DEFAULT}, @samp{fallback} (@pxref{fallback}) and @samp{default} (@pxref{default}) environment variables as well as saved @@ -399,7 +385,7 @@ index 69f08d289f9..0615d0ed97e 100644 check for encrypted disks and generate additional commands needed to access them during boot. Note that in this case unattended boot is not possible because GRUB will wait for passphrase to unlock encrypted container. -@@ -1600,7 +1607,7 @@ confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or +@@ -1633,7 +1640,7 @@ confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or @end table @@ -408,7 +394,48 @@ index 69f08d289f9..0615d0ed97e 100644 edit the scripts in @file{/etc/grub.d} directly. @file{/etc/grub.d/40_custom} is particularly useful for adding entire custom menu entries; simply type the menu entries you want to add at the end of -@@ -1862,7 +1869,7 @@ images as well. +@@ -1641,14 +1648,14 @@ that file, making sure to leave at least the first two lines intact. + + @node Root Identifcation Heuristics + @section Root Identifcation Heuristics +-If the target operating system uses the Linux kernel, @command{grub-mkconfig} ++If the target operating system uses the Linux kernel, @command{grub2-mkconfig} + attempts to identify the root file system via a heuristic algoirthm. This + algorithm selects the identification method of the root file system by + considering three factors. The first is if an initrd for the target operating + system is also present. The second is @samp{GRUB_DISABLE_LINUX_UUID} and if set +-to @samp{true}, prevents @command{grub-mkconfig} from identifying the root file ++to @samp{true}, prevents @command{grub2-mkconfig} from identifying the root file + system by its UUID. The third is @samp{GRUB_DISABLE_LINUX_PARTUUID} and if set +-to @samp{true}, prevents @command{grub-mkconfig} from identifying the root file ++to @samp{true}, prevents @command{grub2-mkconfig} from identifying the root file + system via the UUID of its enclosing partition. If the variables are assigned + any other value, that value is considered equivalent to @samp{false}. The + variables are also considered to be set to @samp{false} if they are not set. +@@ -1658,18 +1665,18 @@ filesystem to the initrd. Most initrd images determine the root file system by + checking the Linux kernel's command-line for the @samp{root} key and use its + value as the identification method of the root file system. To improve the + reliability of booting, most initrd images also allow the root file system to be +-identified by its UUID. Because of this behavior, the @command{grub-mkconfig} ++identified by its UUID. Because of this behavior, the @command{grub2-mkconfig} + command will set @samp{root} to @samp{root=UUID=...} to provide the initrd with + the filesystem UUID of the root file system. + + If no initrd is detected or @samp{GRUB_DISABLE_LINUX_UUID} is set to @samp{true} +-then @command{grub-command} will identify the root filesystem by setting the ++then @command{grub2-command} will identify the root filesystem by setting the + kernel command-line variable @samp{root} to @samp{root=PARTUUID=...} unless + @samp{GRUB_DISABLE_LINUX_PARTUUID} is also set to @samp{true}. If + @samp{GRUB_DISABLE_LINUX_PARTUUID} is also set to @samp{true}, +-@command{grub-command} will identify by its Linux device name. ++@command{grub2-command} will identify by its Linux device name. + +-The following table summarizes the behavior of the @command{grub-mkconfig} ++The following table summarizes the behavior of the @command{grub2-mkconfig} + command. + + @multitable {detected} {GRUB_DISABLE_LINUX_PARTUUID} {GRUB_DISABLE_LINUX_UUID} {Linux Root} +@@ -1898,7 +1905,7 @@ images as well. Mount this partition on/mnt/boot and disable GRUB in all OSes and manually install self-compiled latest GRUB with: @@ -417,7 +444,7 @@ index 69f08d289f9..0615d0ed97e 100644 In all the OSes install GRUB tools but disable installing GRUB in bootsector, so you'll have menu.lst and grub.cfg available for use. Also disable os-prober -@@ -1872,20 +1879,20 @@ use by setting: +@@ -1908,20 +1915,20 @@ use by setting: in /etc/default/grub @@ -441,7 +468,7 @@ index 69f08d289f9..0615d0ed97e 100644 @} menuentry "Windows XP" @{ -@@ -1948,15 +1955,15 @@ GRUB supports embedding a configuration file directly into the core image, +@@ -1984,15 +1991,15 @@ GRUB supports embedding a configuration file directly into the core image, so that it is loaded before entering normal mode. This is useful, for example, when it is not straightforward to find the real configuration file, or when you need to debug problems with loading that file. @@ -460,7 +487,7 @@ index 69f08d289f9..0615d0ed97e 100644 After the embedded configuration file (if any) is executed, GRUB will load the @samp{normal} module (@pxref{normal}), which will then read the real -@@ -1991,13 +1998,13 @@ included in the core image: +@@ -2027,13 +2034,13 @@ included in the core image: @example @group search.fs_label grub root @@ -478,7 +505,7 @@ index 69f08d289f9..0615d0ed97e 100644 else echo "Could not find an example configuration file!" fi -@@ -2521,7 +2528,7 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 +@@ -2557,7 +2564,7 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 @end group @end example @@ -487,7 +514,7 @@ index 69f08d289f9..0615d0ed97e 100644 server. The grub.cfg file is placed in the same directory as the path output by -@@ -2715,7 +2722,7 @@ team are: +@@ -2760,7 +2767,7 @@ team are: @end table To take full advantage of this function, install GRUB into the MBR @@ -496,7 +523,7 @@ index 69f08d289f9..0615d0ed97e 100644 If you have a laptop which has a similar feature and not in the above list could you figure your address and contribute? -@@ -2776,7 +2783,7 @@ bytes. +@@ -2821,7 +2828,7 @@ bytes. The sole function of @file{boot.img} is to read the first sector of the core image from a local disk and jump to it. Because of the size restriction, @file{boot.img} cannot understand any file system structure, so @@ -505,7 +532,7 @@ index 69f08d289f9..0615d0ed97e 100644 core image into @file{boot.img} when installing GRUB. @item diskboot.img -@@ -2806,7 +2813,7 @@ images. +@@ -2851,7 +2858,7 @@ images. @item core.img This is the core image of GRUB. It is built dynamically from the kernel @@ -514,7 +541,7 @@ index 69f08d289f9..0615d0ed97e 100644 program. Usually, it contains enough modules to access @file{/boot/grub}, and loads everything else (including menu handling, the ability to load target operating systems, and so on) from the file system at run-time. The -@@ -2858,7 +2865,7 @@ GRUB 2 has no single Stage 2 image. Instead, it loads modules from +@@ -2903,7 +2910,7 @@ GRUB 2 has no single Stage 2 image. Instead, it loads modules from In GRUB 2, images for booting from CD-ROM drives are now constructed using @file{cdboot.img} and @file{core.img}, making sure that the core image contains the @samp{iso9660} module. It is usually best to use the @@ -523,7 +550,7 @@ index 69f08d289f9..0615d0ed97e 100644 @item nbgrub There is as yet no equivalent for @file{nbgrub} in GRUB 2; it was used by -@@ -3014,8 +3021,8 @@ There are two ways to specify files, by @dfn{absolute file name} and by +@@ -3071,8 +3078,8 @@ There are two ways to specify files, by @dfn{absolute file name} and by An absolute file name resembles a Unix absolute file name, using @samp{/} for the directory separator (not @samp{\} as in DOS). One @@ -534,7 +561,7 @@ index 69f08d289f9..0615d0ed97e 100644 disk. If you omit the device name in an absolute file name, GRUB uses GRUB's @dfn{root device} implicitly. So if you set the root device to, say, @samp{(hd1,1)} by the command @samp{set root=(hd1,1)} (@pxref{set}), -@@ -3023,8 +3030,8 @@ then @code{/boot/kernel} is the same as @code{(hd1,1)/boot/kernel}. +@@ -3080,8 +3087,8 @@ then @code{/boot/kernel} is the same as @code{(hd1,1)/boot/kernel}. On ZFS filesystem the first path component must be @var{volume}@samp{@@}[@var{snapshot}]. @@ -545,7 +572,7 @@ index 69f08d289f9..0615d0ed97e 100644 @samp{snap-129}. Trailing @samp{@@} after volume name is mandatory even if snapshot name is omitted. -@@ -3427,7 +3434,7 @@ The more recent release of Minix would then be identified as +@@ -3500,7 +3507,7 @@ The more recent release of Minix would then be identified as @samp{other>minix>minix-3.4.0}. This variable is often set by @samp{GRUB_DEFAULT} (@pxref{Simple @@ -554,7 +581,7 @@ index 69f08d289f9..0615d0ed97e 100644 @node fallback -@@ -3517,7 +3524,7 @@ If this variable is set, it names the language code that the +@@ -3590,7 +3597,7 @@ If this variable is set, it names the language code that the example, French would be named as @samp{fr}, and Simplified Chinese as @samp{zh_CN}. @@ -563,7 +590,7 @@ index 69f08d289f9..0615d0ed97e 100644 reasonable default for this variable based on the system locale. -@@ -3525,10 +3532,10 @@ reasonable default for this variable based on the system locale. +@@ -3598,10 +3605,10 @@ reasonable default for this variable based on the system locale. @subsection locale_dir If this variable is set, it names the directory where translation files may @@ -576,7 +603,7 @@ index 69f08d289f9..0615d0ed97e 100644 default for this variable if internationalization is needed and any translation files are available. -@@ -3646,7 +3653,7 @@ input. The default is not to pause output. +@@ -3738,7 +3745,7 @@ input. The default is not to pause output. The location of the @samp{/boot/grub} directory as an absolute file name (@pxref{File name syntax}). This is normally set by GRUB at startup based @@ -585,7 +612,7 @@ index 69f08d289f9..0615d0ed97e 100644 dynamically loaded from this directory, so it must be set correctly in order for many parts of GRUB to work. -@@ -3737,17 +3744,17 @@ GRUB provides an ``environment block'' which can be used to save a small +@@ -3850,17 +3857,17 @@ GRUB provides an ``environment block'' which can be used to save a small amount of state. The environment block is a preallocated 1024-byte file, which normally lives @@ -605,8 +632,8 @@ index 69f08d289f9..0615d0ed97e 100644 +@command{grub2-mkconfig} uses this facility to implement @samp{GRUB_SAVEDEFAULT} (@pxref{Simple configuration}). - -@@ -4476,7 +4483,7 @@ Translate @var{string} into the current language. + @node Modules +@@ -4922,7 +4929,7 @@ Translate @var{string} into the current language. The current language code is stored in the @samp{lang} variable in GRUB's environment (@pxref{lang}). Translation files in MO format are read from @@ -615,7 +642,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end deffn -@@ -4871,7 +4878,7 @@ Define a user named @var{user} with password @var{clear-password}. +@@ -5274,7 +5281,7 @@ Define a user named @var{user} with password @var{clear-password}. @deffn Command password_pbkdf2 user hashed-password Define a user named @var{user} with password hash @var{hashed-password}. @@ -624,7 +651,7 @@ index 69f08d289f9..0615d0ed97e 100644 to generate password hashes. @xref{Security}. @end deffn -@@ -5814,8 +5821,8 @@ The @samp{password} (@pxref{password}) and @samp{password_pbkdf2} +@@ -6400,8 +6407,8 @@ The @samp{password} (@pxref{password}) and @samp{password_pbkdf2} which has an associated password. @samp{password} sets the password in plain text, requiring @file{grub.cfg} to be secure; @samp{password_pbkdf2} sets the password hashed using the Password-Based Key Derivation Function @@ -635,7 +662,7 @@ index 69f08d289f9..0615d0ed97e 100644 In order to enable authentication support, the @samp{superusers} environment variable must be set to a list of usernames, separated by any of spaces, -@@ -5860,7 +5867,7 @@ menuentry "May be run by user1 or a superuser" --users user1 @{ +@@ -6446,7 +6453,7 @@ menuentry "May be run by user1 or a superuser" --users user1 @{ @end group @end example @@ -644,11 +671,13 @@ index 69f08d289f9..0615d0ed97e 100644 generating configuration files with authentication. You can use @file{/etc/grub.d/40_custom} to add simple superuser authentication, by adding @kbd{set superusers=} and @kbd{password} or @kbd{password_pbkdf2} -@@ -5887,7 +5894,17 @@ may halt or otherwise impact the boot process. +@@ -6472,8 +6479,18 @@ validation fails, then file @file{foo} cannot be opened. This failure + may halt or otherwise impact the boot process. An initial trusted public key can be embedded within the GRUB @file{core.img} - using the @code{--pubkey} option to @command{grub-install} +-using the @code{--pubkey} option to @command{grub-install} -(@pxref{Invoking grub-install}). ++using the @code{--pubkey} option to @command{grub2-install} +(@pxref{Invoking grub2-install}). + +@comment Unfortunately --pubkey is not yet supported by grub2-install, @@ -663,7 +692,7 @@ index 69f08d289f9..0615d0ed97e 100644 GRUB uses GPG-style detached signatures (meaning that a file @file{foo.sig} will be produced when file @file{foo} is signed), and -@@ -5907,8 +5924,8 @@ gpg --detach-sign /path/to/file +@@ -6493,8 +6510,8 @@ gpg --detach-sign /path/to/file For successful validation of all of GRUB's subcomponents and the loaded OS kernel, they must all be signed. One way to accomplish this is the following (after having already produced the desired @@ -674,7 +703,7 @@ index 69f08d289f9..0615d0ed97e 100644 @example @group -@@ -5930,7 +5947,7 @@ See also: @ref{check_signatures}, @ref{verify_detached}, @ref{trust}, +@@ -6516,7 +6533,7 @@ See also: @ref{check_signatures}, @ref{verify_detached}, @ref{trust}, Note that internally signature enforcement is controlled by setting the environment variable @code{check_signatures} equal to @code{enforce}. Passing one or more @code{--pubkey} options to @@ -683,7 +712,16 @@ index 69f08d289f9..0615d0ed97e 100644 equal to @code{enforce} in @file{core.img} prior to processing any configuration files. -@@ -6388,10 +6405,10 @@ Required files are: +@@ -6564,7 +6581,7 @@ UTF-8 strings as comma-separated values (CSV). See + @uref{https://github.com/rhboot/shim/blob/main/SBAT.md} for more details. + + To add a data section containing the SBAT information into the binary, the +-@option{--sbat} option of @command{grub-mkimage} command should be used. The content ++@option{--sbat} option of @command{grub2-mkimage} command should be used. The content + of a CSV file, encoded with UTF-8, is copied as is to the .sbat data section into + the generated EFI binary. The CSV file can be stored anywhere on the file system. + +@@ -6975,10 +6992,10 @@ Required files are: GRUB's normal start-up procedure involves setting the @samp{prefix} environment variable to a value set in the core image by @@ -696,7 +734,7 @@ index 69f08d289f9..0615d0ed97e 100644 things GRUB is supposed to do. If, instead, you only get a rescue shell, this usually means that GRUB -@@ -6417,8 +6434,8 @@ normal +@@ -7004,8 +7021,8 @@ normal However, any problem that leaves you in the rescue shell probably means that GRUB was not correctly installed. It may be more useful to try to reinstall @@ -707,7 +745,7 @@ index 69f08d289f9..0615d0ed97e 100644 @itemize @bullet{} @item -@@ -6430,7 +6447,7 @@ is usually better to use UUIDs or file system labels and avoid depending on +@@ -7017,7 +7034,7 @@ is usually better to use UUIDs or file system labels and avoid depending on drive ordering entirely. @item @@ -716,14 +754,34 @@ index 69f08d289f9..0615d0ed97e 100644 to a partition but GRUB has already been installed in the master boot record, then the GRUB installation in the partition will be ignored. -@@ -6461,21 +6478,21 @@ entry which claims partition start at block 0. This change will not hamper - bootability on other machines. +@@ -7052,33 +7069,33 @@ bootability on other machines. + @chapter User-space utilities + + @menu +-* Invoking grub-install:: How to use the GRUB installer +-* Invoking grub-mkconfig:: Generate a GRUB configuration file +-* Invoking grub-mkpasswd-pbkdf2:: ++* Invoking grub2-install:: How to use the GRUB installer ++* Invoking grub2-mkconfig:: Generate a GRUB configuration file ++* Invoking grub2-mkpasswd-pbkdf2:: + Generate GRUB password hashes +-* Invoking grub-mkrelpath:: Make system path relative to its root +-* Invoking grub-mkrescue:: Make a GRUB rescue image +-* Invoking grub-mount:: Mount a file system using GRUB +-* Invoking grub-probe:: Probe device information for GRUB +-* Invoking grub-script-check:: Check GRUB script file for syntax errors ++* Invoking grub2-mkrelpath:: Make system path relative to its root ++* Invoking grub2-mkrescue:: Make a GRUB rescue image ++* Invoking grub2-mount:: Mount a file system using GRUB ++* Invoking grub2-probe:: Probe device information for GRUB ++* Invoking grub2-script-check:: Check GRUB script file for syntax errors + @end menu -@node Invoking grub-install --@chapter Invoking grub-install +-@section Invoking grub-install +@node Invoking grub2-install -+@chapter Invoking grub2-install ++@section Invoking grub2-install -The program @command{grub-install} generates a GRUB core image using -@command{grub-mkimage} and installs it on your system. You must specify the @@ -744,7 +802,7 @@ index 69f08d289f9..0615d0ed97e 100644 @table @option @item --help -@@ -6491,13 +6508,13 @@ separate partition or a removable disk. +@@ -7094,13 +7111,13 @@ separate partition or a removable disk. If this option is not specified then it defaults to @file{/boot}, so @example @@ -760,7 +818,7 @@ index 69f08d289f9..0615d0ed97e 100644 @end example Here is an example in which you have a separate @dfn{boot} partition which is -@@ -6505,16 +6522,16 @@ mounted on +@@ -7108,16 +7125,16 @@ mounted on @file{/mnt/boot}: @example @@ -780,14 +838,14 @@ index 69f08d289f9..0615d0ed97e 100644 extra space in the bootloader embedding area for Reed-Solomon error-correcting codes. This enables GRUB to still boot successfully if some blocks are corrupted. The exact amount of protection offered -@@ -6527,17 +6544,17 @@ installation}) where GRUB does not reside in any unpartitioned space +@@ -7130,17 +7147,17 @@ installation}) where GRUB does not reside in any unpartitioned space outside of the MBR. Disable the Reed-Solomon codes with this option. @end table -@node Invoking grub-mkconfig --@chapter Invoking grub-mkconfig +-@section Invoking grub-mkconfig +@node Invoking grub2-mkconfig -+@chapter Invoking grub2-mkconfig ++@section Invoking grub2-mkconfig -The program @command{grub-mkconfig} generates a configuration file for GRUB +The program @command{grub2-mkconfig} generates a configuration file for GRUB @@ -795,7 +853,7 @@ index 69f08d289f9..0615d0ed97e 100644 @example -grub-mkconfig -o /boot/grub/grub.cfg -+grub-mkconfig -o /boot/grub2/grub.cfg ++grub2-mkconfig -o /boot/grub2/grub.cfg @end example -@command{grub-mkconfig} accepts the following options: @@ -803,21 +861,22 @@ index 69f08d289f9..0615d0ed97e 100644 @table @option @item --help -@@ -6553,17 +6570,17 @@ it to standard output. +@@ -7156,17 +7173,17 @@ it to standard output. @end table -@node Invoking grub-mkpasswd-pbkdf2 --@chapter Invoking grub-mkpasswd-pbkdf2 +-@section Invoking grub-mkpasswd-pbkdf2 +@node Invoking grub2-mkpasswd-pbkdf2 -+@chapter Invoking grub2-mkpasswd-pbkdf2 ++@section Invoking grub2-mkpasswd-pbkdf2 -The program @command{grub-mkpasswd-pbkdf2} generates password hashes for +The program @command{grub2-mkpasswd-pbkdf2} generates password hashes for GRUB (@pxref{Security}). @example - grub-mkpasswd-pbkdf2 +-grub-mkpasswd-pbkdf2 ++grub2-mkpasswd-pbkdf2 @end example -@command{grub-mkpasswd-pbkdf2} accepts the following options: @@ -825,14 +884,14 @@ index 69f08d289f9..0615d0ed97e 100644 @table @option @item -c @var{number} -@@ -6581,23 +6598,23 @@ Length of the salt. Defaults to 64. +@@ -7184,23 +7201,23 @@ Length of the salt. Defaults to 64. @end table -@node Invoking grub-mkrelpath --@chapter Invoking grub-mkrelpath +-@section Invoking grub-mkrelpath +@node Invoking grub2-mkrelpath -+@chapter Invoking grub2-mkrelpath ++@section Invoking grub2-mkrelpath -The program @command{grub-mkrelpath} makes a file system path relative to +The program @command{grub2-mkrelpath} makes a file system path relative to @@ -855,21 +914,22 @@ index 69f08d289f9..0615d0ed97e 100644 @table @option @item --help -@@ -6608,17 +6625,17 @@ Print the version number of GRUB and exit. +@@ -7211,17 +7228,17 @@ Print the version number of GRUB and exit. @end table -@node Invoking grub-mkrescue --@chapter Invoking grub-mkrescue +-@section Invoking grub-mkrescue +@node Invoking grub2-mkrescue -+@chapter Invoking grub2-mkrescue ++@section Invoking grub2-mkrescue -The program @command{grub-mkrescue} generates a bootable GRUB rescue image +The program @command{grub2-mkrescue} generates a bootable GRUB rescue image (@pxref{Making a GRUB bootable CD-ROM}). @example - grub-mkrescue -o grub.iso +-grub-mkrescue -o grub.iso ++grub2-mkrescue -o grub.iso @end example -All arguments not explicitly listed as @command{grub-mkrescue} options are @@ -877,8 +937,12 @@ index 69f08d289f9..0615d0ed97e 100644 passed on directly to @command{xorriso} in @command{mkisofs} emulation mode. Options passed to @command{xorriso} will normally be interpreted as @command{mkisofs} options; if the option @samp{--} is used, then anything -@@ -6633,7 +6650,7 @@ mkdir -p disk/boot/grub - grub-mkrescue -o grub.iso disk +@@ -7233,10 +7250,10 @@ commonly used to add extra files to the image: + @example + mkdir -p disk/boot/grub + @r{(add extra files to @file{disk/boot/grub})} +-grub-mkrescue -o grub.iso disk ++grub2-mkrescue -o grub.iso disk @end example -@command{grub-mkrescue} accepts the following options: @@ -886,7 +950,7 @@ index 69f08d289f9..0615d0ed97e 100644 @table @option @item --help -@@ -6661,15 +6678,15 @@ Use @var{file} as the @command{xorriso} program, rather than the built-in +@@ -7264,15 +7281,15 @@ Use @var{file} as the @command{xorriso} program, rather than the built-in default. @item --grub-mkimage=@var{file} @@ -897,16 +961,16 @@ index 69f08d289f9..0615d0ed97e 100644 -@node Invoking grub-mount --@chapter Invoking grub-mount +-@section Invoking grub-mount +@node Invoking grub2-mount -+@chapter Invoking grub2-mount ++@section Invoking grub2-mount -The program @command{grub-mount} performs a read-only mount of any file +The program @command{grub2-mount} performs a read-only mount of any file system or file system image that GRUB understands, using GRUB's file system drivers via FUSE. (It is only available if FUSE development files were present when GRUB was built.) This has a number of uses: -@@ -6701,13 +6718,13 @@ even if nobody has yet written a FUSE module specifically for that file +@@ -7304,13 +7321,13 @@ even if nobody has yet written a FUSE module specifically for that file system type. @end itemize @@ -914,7 +978,8 @@ index 69f08d289f9..0615d0ed97e 100644 +Using @command{grub2-mount} is normally as simple as: @example - grub-mount /dev/sda1 /mnt +-grub-mount /dev/sda1 /mnt ++grub2-mount /dev/sda1 /mnt @end example -@command{grub-mount} must be given one or more images and a mount point as @@ -922,7 +987,7 @@ index 69f08d289f9..0615d0ed97e 100644 non-option arguments (if it is given more than one image, it will treat them as a RAID set), and also accepts the following options: -@@ -6729,13 +6746,13 @@ Show debugging output for conditions matching @var{string}. +@@ -7332,13 +7349,13 @@ Show debugging output for conditions matching @var{string}. @item -K prompt|@var{file} @itemx --zfs-key=prompt|@var{file} Load a ZFS encryption key. If you use @samp{prompt} as the argument, @@ -938,22 +1003,33 @@ index 69f08d289f9..0615d0ed97e 100644 root of the supplied file system. If @var{device} is just a number, then it will be treated as a partition -@@ -6753,10 +6770,10 @@ Print verbose messages. +@@ -7347,7 +7364,7 @@ an entire disk in @file{disk.img}, then you can use this command to mount + its second partition: + + @example +-grub-mount -r 2 disk.img mount-point ++grub2-mount -r 2 disk.img mount-point + @end example + + @item -v +@@ -7356,18 +7373,18 @@ Print verbose messages. @end table -@node Invoking grub-probe --@chapter Invoking grub-probe +-@section Invoking grub-probe +@node Invoking grub2-probe -+@chapter Invoking grub2-probe ++@section Invoking grub2-probe -The program @command{grub-probe} probes device information for a given path +The program @command{grub2-probe} probes device information for a given path or device. @example -@@ -6764,7 +6781,7 @@ grub-probe --target=fs /boot/grub - grub-probe --target=drive --device /dev/sda1 +-grub-probe --target=fs /boot/grub +-grub-probe --target=drive --device /dev/sda1 ++grub2-probe --target=fs /boot/grub ++grub2-probe --target=drive --device /dev/sda1 @end example -@command{grub-probe} must be given a path or device as a non-option @@ -961,7 +1037,7 @@ index 69f08d289f9..0615d0ed97e 100644 argument, and also accepts the following options: @table @option -@@ -6777,16 +6794,16 @@ Print the version number of GRUB and exit. +@@ -7380,16 +7397,16 @@ Print the version number of GRUB and exit. @item -d @itemx --device If this option is given, then the non-option argument is a system device @@ -981,14 +1057,14 @@ index 69f08d289f9..0615d0ed97e 100644 @item -t @var{target} @itemx --target=@var{target} -@@ -6839,19 +6856,19 @@ Print verbose messages. +@@ -7442,19 +7459,19 @@ Print verbose messages. @end table -@node Invoking grub-script-check --@chapter Invoking grub-script-check +-@section Invoking grub-script-check +@node Invoking grub2-script-check -+@chapter Invoking grub2-script-check ++@section Invoking grub2-script-check -The program @command{grub-script-check} takes a GRUB script file +The program @command{grub2-script-check} takes a GRUB script file @@ -998,7 +1074,7 @@ index 69f08d289f9..0615d0ed97e 100644 @example -grub-script-check /boot/grub/grub.cfg -+grub-script-check /boot/grub2/grub.cfg ++grub2-script-check /boot/grub2/grub.cfg @end example -@command{grub-script-check} accepts the following options: diff --git a/0035-Don-t-draw-a-border-around-the-menu.patch b/0035-Don-t-draw-a-border-around-the-menu.patch deleted file mode 100644 index 31a973ea..00000000 --- a/0035-Don-t-draw-a-border-around-the-menu.patch +++ /dev/null @@ -1,71 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Wed, 15 May 2013 16:47:33 -0400 -Subject: [PATCH] Don't draw a border around the menu - -It looks cleaner without it. ---- - grub-core/normal/menu_text.c | 43 ------------------------------------------- - 1 file changed, 43 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 4895ffe7d1d..e72ed438ba3 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -108,47 +108,6 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right, - grub_print_message_indented_real (msg, margin_left, margin_right, term, 0); - } - --static void --draw_border (struct grub_term_output *term, const struct grub_term_screen_geometry *geo) --{ -- int i; -- -- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); -- -- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y - 1 }); -- grub_putcode (GRUB_UNICODE_CORNER_UL, term); -- for (i = 0; i < geo->entry_width + 1; i++) -- grub_putcode (GRUB_UNICODE_HLINE, term); -- grub_putcode (GRUB_UNICODE_CORNER_UR, term); -- -- for (i = 0; i < geo->num_entries; i++) -- { -- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y + i }); -- grub_putcode (GRUB_UNICODE_VLINE, term); -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x + geo->entry_width + 1, -- geo->first_entry_y + i }); -- grub_putcode (GRUB_UNICODE_VLINE, term); -- } -- -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y - 1 + geo->num_entries + 1 }); -- grub_putcode (GRUB_UNICODE_CORNER_LL, term); -- for (i = 0; i < geo->entry_width + 1; i++) -- grub_putcode (GRUB_UNICODE_HLINE, term); -- grub_putcode (GRUB_UNICODE_CORNER_LR, term); -- -- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); -- -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x - 1, -- (geo->first_entry_y - 1 + geo->num_entries -- + GRUB_TERM_MARGIN + 1) }); --} -- - static int - print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - { -@@ -406,8 +365,6 @@ grub_menu_init_page (int nested, int edit, - - grub_term_normal_color = grub_color_menu_normal; - grub_term_highlight_color = grub_color_menu_highlight; -- if (geo->border) -- draw_border (term, geo); - grub_term_normal_color = old_color_normal; - grub_term_highlight_color = old_color_highlight; - geo->timeout_y = geo->first_entry_y + geo->num_entries diff --git a/0056-macos-just-build-chainloader-entries-don-t-try-any-x.patch b/0035-macos-just-build-chainloader-entries-don-t-try-any-x.patch similarity index 98% rename from 0056-macos-just-build-chainloader-entries-don-t-try-any-x.patch rename to 0035-macos-just-build-chainloader-entries-don-t-try-any-x.patch index 574d1173..3246b116 100644 --- a/0056-macos-just-build-chainloader-entries-don-t-try-any-x.patch +++ b/0035-macos-just-build-chainloader-entries-don-t-try-any-x.patch @@ -20,7 +20,7 @@ Signed-off-by: Peter Jones 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 1b91c102f35..4b27bd20153 100644 +index f300e46fc6a..d7d423b2eaf 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -42,68 +42,25 @@ if [ -z "${OSPROBED}" ] ; then @@ -104,7 +104,7 @@ index 1b91c102f35..4b27bd20153 100644 } EOF } -@@ -292,11 +249,12 @@ EOF +@@ -296,11 +253,12 @@ EOF echo "$title_correction_code" ;; macosx) diff --git a/0036-Use-the-standard-margin-for-the-timeout-string.patch b/0036-Use-the-standard-margin-for-the-timeout-string.patch deleted file mode 100644 index 49a382d8..00000000 --- a/0036-Use-the-standard-margin-for-the-timeout-string.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Jon McCann -Date: Fri, 7 Jun 2013 10:52:32 -0400 -Subject: [PATCH] Use the standard margin for the timeout string - -So that it aligns with the other messages ---- - grub-core/normal/menu_text.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index e72ed438ba3..ca135624356 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -372,7 +372,7 @@ grub_menu_init_page (int nested, int edit, - if (bottom_message) - { - grub_term_gotoxy (term, -- (struct grub_term_coordinate) { GRUB_TERM_MARGIN, -+ (struct grub_term_coordinate) { STANDARD_MARGIN, - geo->timeout_y }); - - print_message (nested, edit, term, 0); -@@ -407,14 +407,14 @@ menu_text_print_timeout (int timeout, void *dataptr) - if (data->timeout_msg == TIMEOUT_UNKNOWN) - { - data->timeout_msg = grub_print_message_indented_real (msg_translated, -- 3, 1, data->term, 1) -+ STANDARD_MARGIN, 1, data->term, 1) - <= data->geo.timeout_lines ? TIMEOUT_NORMAL : TIMEOUT_TERSE; - if (data->timeout_msg == TIMEOUT_TERSE) - { - grub_free (msg_translated); - msg_translated = grub_xasprintf (_("%ds"), timeout); - if (grub_term_width (data->term) < 10) -- data->timeout_msg = TIMEOUT_TERSE_NO_MARGIN; -+ data->timeout_msg = STANDARD_MARGIN; - } - } - diff --git a/0057-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch b/0036-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch similarity index 94% rename from 0057-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch rename to 0036-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch index 68dfc1dc..ad004426 100644 --- a/0057-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch +++ b/0036-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch @@ -19,12 +19,12 @@ variable and loading the config file from the subvolume. Signed-off-by: Jeff Mahoney --- - grub-core/fs/btrfs.c | 552 +++++++++++++++++++++++++++++++++++++++++++++++++-- + grub-core/fs/btrfs.c | 558 ++++++++++++++++++++++++++++++++++++++++++++++++--- include/grub/btrfs.h | 1 + - 2 files changed, 533 insertions(+), 20 deletions(-) + 2 files changed, 536 insertions(+), 23 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 63203034dfc..f1fff7385b5 100644 +index ba0c583526d..f14fe9c1bda 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -38,6 +38,9 @@ @@ -89,7 +89,7 @@ index 63203034dfc..f1fff7385b5 100644 static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, 256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 }; -@@ -1173,6 +1195,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, +@@ -1252,6 +1274,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, return GRUB_ERR_NONE; } @@ -152,7 +152,7 @@ index 63203034dfc..f1fff7385b5 100644 static struct grub_btrfs_data * grub_btrfs_mount (grub_device_t dev) { -@@ -1208,6 +1286,13 @@ grub_btrfs_mount (grub_device_t dev) +@@ -1287,6 +1365,13 @@ grub_btrfs_mount (grub_device_t dev) data->devices_attached[0].dev = dev; data->devices_attached[0].id = data->sblock.this_device.device_id; @@ -166,7 +166,7 @@ index 63203034dfc..f1fff7385b5 100644 return data; } -@@ -1673,6 +1758,91 @@ get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key, +@@ -1784,6 +1869,91 @@ get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key, return GRUB_ERR_NONE; } @@ -258,7 +258,7 @@ index 63203034dfc..f1fff7385b5 100644 static grub_err_t find_path (struct grub_btrfs_data *data, const char *path, struct grub_btrfs_key *key, -@@ -1691,14 +1861,26 @@ find_path (struct grub_btrfs_data *data, +@@ -1802,14 +1972,26 @@ find_path (struct grub_btrfs_data *data, char *origpath = NULL; unsigned symlinks_max = 32; @@ -289,15 +289,18 @@ index 63203034dfc..f1fff7385b5 100644 while (1) { while (path[0] == '/') -@@ -1871,9 +2053,21 @@ find_path (struct grub_btrfs_data *data, +@@ -1982,13 +2164,25 @@ find_path (struct grub_btrfs_data *data, path = path_alloc = tmp; if (path[0] == '/') { - err = get_root (data, key, tree, type); - if (err) -- return err; + if (data->fs_tree) -+ { + { +- grub_free (direl); +- grub_free (path_alloc); +- grub_free (origpath); +- return err; + *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; + *tree = data->fs_tree; + /* This is a tree root, so everything starts at objectid 256 */ @@ -309,12 +312,16 @@ index 63203034dfc..f1fff7385b5 100644 + { + err = get_root (data, key, tree, type); + if (err) -+ return err; -+ } ++ { ++ grub_free (direl); ++ grub_free (path_alloc); ++ grub_free (origpath); ++ return err; ++ } + } } continue; - } -@@ -2114,18 +2308,10 @@ grub_btrfs_read (grub_file_t file, char *buf, grub_size_t len) +@@ -2256,18 +2450,10 @@ grub_btrfs_read (grub_file_t file, char *buf, grub_size_t len) data->tree, file->offset, buf, len); } @@ -336,7 +343,7 @@ index 63203034dfc..f1fff7385b5 100644 grub_be_to_cpu16 (data->sblock.uuid[0]), grub_be_to_cpu16 (data->sblock.uuid[1]), grub_be_to_cpu16 (data->sblock.uuid[2]), -@@ -2134,6 +2320,20 @@ grub_btrfs_uuid (grub_device_t device, char **uuid) +@@ -2276,6 +2462,20 @@ grub_btrfs_uuid (grub_device_t device, char **uuid) grub_be_to_cpu16 (data->sblock.uuid[5]), grub_be_to_cpu16 (data->sblock.uuid[6]), grub_be_to_cpu16 (data->sblock.uuid[7])); @@ -357,7 +364,7 @@ index 63203034dfc..f1fff7385b5 100644 grub_btrfs_unmount (data); -@@ -2190,6 +2390,242 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), +@@ -2396,6 +2596,242 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), } #endif @@ -600,7 +607,7 @@ index 63203034dfc..f1fff7385b5 100644 static struct grub_fs grub_btrfs_fs = { .name = "btrfs", .fs_dir = grub_btrfs_dir, -@@ -2205,12 +2641,88 @@ static struct grub_fs grub_btrfs_fs = { +@@ -2411,12 +2847,88 @@ static struct grub_fs grub_btrfs_fs = { #endif }; diff --git a/0037-btrfs-fix-a-bad-null-check.patch b/0037-btrfs-fix-a-bad-null-check.patch new file mode 100644 index 00000000..093ca650 --- /dev/null +++ b/0037-btrfs-fix-a-bad-null-check.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 15:41:52 -0500 +Subject: [PATCH] btrfs: fix a bad null check +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +current gcc complains: + + grub-core/fs/btrfs.c: In function ‘grub_cmd_btrfs_info’: + grub-core/fs/btrfs.c:2745:7: error: the comparison will always evaluate as ‘true’ for the address of ‘label’ will never be NULL [-Werror=address] + 2745 | if (data->sblock.label) + | ^~~~ + grub-core/fs/btrfs.c:92:8: note: ‘label’ declared here + 92 | char label[0x100]; + | ^~~~~ + cc1: all warnings being treated as errors + +Obviously this check should be on the first data byte instead of the +symbol itself. + +Signed-off-by: Peter Jones +--- + grub-core/fs/btrfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index f14fe9c1bda..8e2b1e9f7bc 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2625,7 +2625,7 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, + return grub_error (GRUB_ERR_BAD_ARGUMENT, "failed to open fs"); + } + +- if (data->sblock.label) ++ if (data->sblock.label[0]) + grub_printf("Label: '%s' ", data->sblock.label); + else + grub_printf("Label: none "); diff --git a/0058-export-btrfs_subvol-and-btrfs_subvolid.patch b/0038-export-btrfs_subvol-and-btrfs_subvolid.patch similarity index 91% rename from 0058-export-btrfs_subvol-and-btrfs_subvolid.patch rename to 0038-export-btrfs_subvol-and-btrfs_subvolid.patch index d38a6b87..d35f598e 100644 --- a/0058-export-btrfs_subvol-and-btrfs_subvolid.patch +++ b/0038-export-btrfs_subvol-and-btrfs_subvolid.patch @@ -12,10 +12,10 @@ Signed-off-by: Michael Chang 1 file changed, 2 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index f1fff7385b5..ad1b56b716d 100644 +index 8e2b1e9f7bc..14e38a4df02 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -2714,6 +2714,8 @@ GRUB_MOD_INIT (btrfs) +@@ -2920,6 +2920,8 @@ GRUB_MOD_INIT (btrfs) subvol_set_env); grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, subvolid_set_env); diff --git a/0039-Don-t-emit-Booting-.-message.patch b/0039-Don-t-emit-Booting-.-message.patch deleted file mode 100644 index 4133b526..00000000 --- a/0039-Don-t-emit-Booting-.-message.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 18 Feb 2014 09:37:49 -0500 -Subject: [PATCH] Don't emit "Booting ..." message. - -UI team still hates this stuff, so we're disabling it for RHEL 7. - -Resolves: rhbz#1023142 - -Signed-off-by: Peter Jones ---- - grub-core/normal/menu.c | 4 +++- - grub-core/normal/menu_entry.c | 3 --- - 2 files changed, 3 insertions(+), 4 deletions(-) - -diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index d7a222e681b..37d753d8081 100644 ---- a/grub-core/normal/menu.c -+++ b/grub-core/normal/menu.c -@@ -838,12 +838,14 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) - - /* Callback invoked immediately before a menu entry is executed. */ - static void --notify_booting (grub_menu_entry_t entry, -+notify_booting (grub_menu_entry_t __attribute__((unused)) entry, - void *userdata __attribute__((unused))) - { -+#if 0 - grub_printf (" "); - grub_printf_ (N_("Booting `%s'"), entry->title); - grub_printf ("\n\n"); -+#endif - } - - /* Callback invoked when a default menu entry executed because of a timeout -diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c -index 50eef918cf6..de64a367c4e 100644 ---- a/grub-core/normal/menu_entry.c -+++ b/grub-core/normal/menu_entry.c -@@ -1176,9 +1176,6 @@ run (struct screen *screen) - char *dummy[1] = { NULL }; - - grub_cls (); -- grub_printf (" "); -- grub_printf_ (N_("Booting a command list")); -- grub_printf ("\n\n"); - - errs_before = grub_err_printed_errors; - diff --git a/0059-grub2-btrfs-03-follow_default.patch b/0039-grub2-btrfs-03-follow_default.patch similarity index 88% rename from 0059-grub2-btrfs-03-follow_default.patch rename to 0039-grub2-btrfs-03-follow_default.patch index 2b9a1364..bbe2fbc0 100644 --- a/0059-grub2-btrfs-03-follow_default.patch +++ b/0039-grub2-btrfs-03-follow_default.patch @@ -3,15 +3,17 @@ From: Michael Chang Date: Thu, 21 Aug 2014 03:39:11 +0000 Subject: [PATCH] grub2-btrfs-03-follow_default +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/fs/btrfs.c | 107 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 31 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index ad1b56b716d..113c1f746c9 100644 +index 14e38a4df02..d47f9ab0352 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -1256,6 +1256,7 @@ grub_btrfs_mount (grub_device_t dev) +@@ -1335,6 +1335,7 @@ grub_btrfs_mount (grub_device_t dev) { struct grub_btrfs_data *data; grub_err_t err; @@ -19,7 +21,7 @@ index ad1b56b716d..113c1f746c9 100644 if (!dev->disk) { -@@ -1286,11 +1287,14 @@ grub_btrfs_mount (grub_device_t dev) +@@ -1365,11 +1366,14 @@ grub_btrfs_mount (grub_device_t dev) data->devices_attached[0].dev = dev; data->devices_attached[0].id = data->sblock.this_device.device_id; @@ -38,7 +40,7 @@ index ad1b56b716d..113c1f746c9 100644 } return data; -@@ -1855,24 +1859,39 @@ find_path (struct grub_btrfs_data *data, +@@ -1966,24 +1970,39 @@ find_path (struct grub_btrfs_data *data, grub_size_t allocated = 0; struct grub_btrfs_dir_item *direl = NULL; struct grub_btrfs_key key_out; @@ -85,7 +87,7 @@ index ad1b56b716d..113c1f746c9 100644 } else { -@@ -1883,15 +1902,23 @@ find_path (struct grub_btrfs_data *data, +@@ -1994,15 +2013,23 @@ find_path (struct grub_btrfs_data *data, while (1) { @@ -118,7 +120,7 @@ index ad1b56b716d..113c1f746c9 100644 if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) { -@@ -1902,7 +1929,9 @@ find_path (struct grub_btrfs_data *data, +@@ -2013,7 +2040,9 @@ find_path (struct grub_btrfs_data *data, if (ctokenlen == 1 && ctoken[0] == '.') { @@ -129,7 +131,7 @@ index ad1b56b716d..113c1f746c9 100644 continue; } if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.') -@@ -1933,8 +1962,9 @@ find_path (struct grub_btrfs_data *data, +@@ -2044,8 +2073,9 @@ find_path (struct grub_btrfs_data *data, *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; key->object_id = key_out.offset; @@ -141,7 +143,7 @@ index ad1b56b716d..113c1f746c9 100644 continue; } -@@ -2003,7 +2033,9 @@ find_path (struct grub_btrfs_data *data, +@@ -2114,7 +2144,9 @@ find_path (struct grub_btrfs_data *data, return err; } @@ -152,7 +154,7 @@ index ad1b56b716d..113c1f746c9 100644 if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK) { struct grub_btrfs_inode inode; -@@ -2053,14 +2085,26 @@ find_path (struct grub_btrfs_data *data, +@@ -2164,14 +2196,26 @@ find_path (struct grub_btrfs_data *data, path = path_alloc = tmp; if (path[0] == '/') { @@ -186,7 +188,7 @@ index ad1b56b716d..113c1f746c9 100644 } else { -@@ -2716,6 +2760,7 @@ GRUB_MOD_INIT (btrfs) +@@ -2922,6 +2966,7 @@ GRUB_MOD_INIT (btrfs) subvolid_set_env); grub_env_export ("btrfs_subvol"); grub_env_export ("btrfs_subvolid"); diff --git a/0040-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch b/0040-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch deleted file mode 100644 index daa6fae0..00000000 --- a/0040-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch +++ /dev/null @@ -1,1959 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 4 Mar 2014 11:00:23 -0500 -Subject: [PATCH] Replace a lot of man pages with slightly nicer ones. - -Replace a bunch of machine generated ones with ones that look nicer. ---- - configure.ac | 23 ++++++ - conf/Makefile.extra-dist | 1 - - docs/Makefile.am | 2 - - docs/man/grub-bios-setup.h2m | 6 -- - docs/man/grub-editenv.h2m | 5 -- - docs/man/grub-emu.h2m | 6 -- - docs/man/grub-file.h2m | 2 - - docs/man/grub-fstest.h2m | 4 - - docs/man/grub-glue-efi.h2m | 4 - - docs/man/grub-install.h2m | 6 -- - docs/man/grub-kbdcomp.h2m | 10 --- - docs/man/grub-macbless.h2m | 4 - - docs/man/grub-macho2img.h2m | 4 - - docs/man/grub-menulst2cfg.h2m | 4 - - docs/man/grub-mkconfig.h2m | 4 - - docs/man/grub-mkfont.h2m | 4 - - docs/man/grub-mkimage.h2m | 6 -- - docs/man/grub-mklayout.h2m | 10 --- - docs/man/grub-mknetdir.h2m | 4 - - docs/man/grub-mkpasswd-pbkdf2.h2m | 4 - - docs/man/grub-mkrelpath.h2m | 4 - - docs/man/grub-mkrescue.h2m | 4 - - docs/man/grub-mkstandalone.h2m | 4 - - docs/man/grub-mount.h2m | 2 - - docs/man/grub-ofpathname.h2m | 4 - - docs/man/grub-pe2elf.h2m | 4 - - docs/man/grub-probe.h2m | 4 - - docs/man/grub-reboot.h2m | 5 -- - docs/man/grub-render-label.h2m | 3 - - docs/man/grub-script-check.h2m | 4 - - docs/man/grub-set-default.h2m | 5 -- - docs/man/grub-sparc64-setup.h2m | 6 -- - docs/man/grub-syslinux2cfg.h2m | 4 - - gentpl.py | 5 +- - util/grub-bios-setup.8 | 54 +++++++++++++ - util/grub-editenv.1 | 46 +++++++++++ - util/grub-file.1 | 165 ++++++++++++++++++++++++++++++++++++++ - util/grub-fstest.1 | 99 +++++++++++++++++++++++ - util/grub-glue-efi.1 | 31 +++++++ - util/grub-install.8 | 128 +++++++++++++++++++++++++++++ - util/grub-kbdcomp.1 | 19 +++++ - util/grub-macbless.1 | 22 +++++ - util/grub-menulst2cfg.1 | 12 +++ - util/grub-mkconfig.8 | 17 ++++ - util/grub-mkfont.1 | 87 ++++++++++++++++++++ - util/grub-mkimage.1 | 95 ++++++++++++++++++++++ - util/grub-mklayout.1 | 27 +++++++ - util/grub-mknetdir.1 | 12 +++ - util/grub-mkpasswd-pbkdf2.1 | 27 +++++++ - util/grub-mkrelpath.1 | 12 +++ - util/grub-mkrescue.1 | 123 ++++++++++++++++++++++++++++ - util/grub-mkstandalone.1 | 100 +++++++++++++++++++++++ - util/grub-ofpathname.8 | 12 +++ - util/grub-probe.8 | 80 ++++++++++++++++++ - util/grub-reboot.8 | 21 +++++ - util/grub-render-label.1 | 51 ++++++++++++ - util/grub-script-check.1 | 21 +++++ - util/grub-set-default.8 | 21 +++++ - util/grub-sparc64-setup.8 | 12 +++ - 59 files changed, 1318 insertions(+), 147 deletions(-) - delete mode 100644 docs/man/grub-bios-setup.h2m - delete mode 100644 docs/man/grub-editenv.h2m - delete mode 100644 docs/man/grub-emu.h2m - delete mode 100644 docs/man/grub-file.h2m - delete mode 100644 docs/man/grub-fstest.h2m - delete mode 100644 docs/man/grub-glue-efi.h2m - delete mode 100644 docs/man/grub-install.h2m - delete mode 100644 docs/man/grub-kbdcomp.h2m - delete mode 100644 docs/man/grub-macbless.h2m - delete mode 100644 docs/man/grub-macho2img.h2m - delete mode 100644 docs/man/grub-menulst2cfg.h2m - delete mode 100644 docs/man/grub-mkconfig.h2m - delete mode 100644 docs/man/grub-mkfont.h2m - delete mode 100644 docs/man/grub-mkimage.h2m - delete mode 100644 docs/man/grub-mklayout.h2m - delete mode 100644 docs/man/grub-mknetdir.h2m - delete mode 100644 docs/man/grub-mkpasswd-pbkdf2.h2m - delete mode 100644 docs/man/grub-mkrelpath.h2m - delete mode 100644 docs/man/grub-mkrescue.h2m - delete mode 100644 docs/man/grub-mkstandalone.h2m - delete mode 100644 docs/man/grub-mount.h2m - delete mode 100644 docs/man/grub-ofpathname.h2m - delete mode 100644 docs/man/grub-pe2elf.h2m - delete mode 100644 docs/man/grub-probe.h2m - delete mode 100644 docs/man/grub-reboot.h2m - delete mode 100644 docs/man/grub-render-label.h2m - delete mode 100644 docs/man/grub-script-check.h2m - delete mode 100644 docs/man/grub-set-default.h2m - delete mode 100644 docs/man/grub-sparc64-setup.h2m - delete mode 100644 docs/man/grub-syslinux2cfg.h2m - create mode 100644 util/grub-bios-setup.8 - create mode 100644 util/grub-editenv.1 - create mode 100644 util/grub-file.1 - create mode 100644 util/grub-fstest.1 - create mode 100644 util/grub-glue-efi.1 - create mode 100644 util/grub-install.8 - create mode 100644 util/grub-kbdcomp.1 - create mode 100644 util/grub-macbless.1 - create mode 100644 util/grub-menulst2cfg.1 - create mode 100644 util/grub-mkconfig.8 - create mode 100644 util/grub-mkfont.1 - create mode 100644 util/grub-mkimage.1 - create mode 100644 util/grub-mklayout.1 - create mode 100644 util/grub-mknetdir.1 - create mode 100644 util/grub-mkpasswd-pbkdf2.1 - create mode 100644 util/grub-mkrelpath.1 - create mode 100644 util/grub-mkrescue.1 - create mode 100644 util/grub-mkstandalone.1 - create mode 100644 util/grub-ofpathname.8 - create mode 100644 util/grub-probe.8 - create mode 100644 util/grub-reboot.8 - create mode 100644 util/grub-render-label.1 - create mode 100644 util/grub-script-check.1 - create mode 100644 util/grub-set-default.8 - create mode 100644 util/grub-sparc64-setup.8 - -diff --git a/configure.ac b/configure.ac -index 8331f95b645..bec8535af70 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -77,6 +77,29 @@ grub_TRANSFORM([grub-set-default]) - grub_TRANSFORM([grub-sparc64-setup]) - grub_TRANSFORM([grub-render-label]) - grub_TRANSFORM([grub-file]) -+grub_TRANSFORM([grub-bios-setup.3]) -+grub_TRANSFORM([grub-editenv.1]) -+grub_TRANSFORM([grub-fstest.3]) -+grub_TRANSFORM([grub-glue-efi.3]) -+grub_TRANSFORM([grub-install.1]) -+grub_TRANSFORM([grub-kbdcomp.3]) -+grub_TRANSFORM([grub-menulst2cfg.1]) -+grub_TRANSFORM([grub-mkconfig.1]) -+grub_TRANSFORM([grub-mkfont.3]) -+grub_TRANSFORM([grub-mkimage.1]) -+grub_TRANSFORM([grub-mklayout.3]) -+grub_TRANSFORM([grub-mknetdir.3]) -+grub_TRANSFORM([grub-mkpasswd-pbkdf2.3]) -+grub_TRANSFORM([grub-mkrelpath.3]) -+grub_TRANSFORM([grub-mkrescue.1]) -+grub_TRANSFORM([grub-mkstandalone.3]) -+grub_TRANSFORM([grub-ofpathname.3]) -+grub_TRANSFORM([grub-probe.3]) -+grub_TRANSFORM([grub-reboot.3]) -+grub_TRANSFORM([grub-render-label.3]) -+grub_TRANSFORM([grub-script-check.3]) -+grub_TRANSFORM([grub-set-default.1]) -+grub_TRANSFORM([grub-sparc64-setup.3]) - - # Optimization flag. Allow user to override. - if test "x$TARGET_CFLAGS" = x; then -diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist -index 8f1485d52a5..b909f2c073a 100644 ---- a/conf/Makefile.extra-dist -+++ b/conf/Makefile.extra-dist -@@ -11,7 +11,6 @@ EXTRA_DIST += unicode - EXTRA_DIST += util/import_gcry.py - EXTRA_DIST += util/import_unicode.py - --EXTRA_DIST += docs/man - EXTRA_DIST += docs/autoiso.cfg - EXTRA_DIST += docs/grub.cfg - EXTRA_DIST += docs/osdetect.cfg -diff --git a/docs/Makefile.am b/docs/Makefile.am -index 93eb3962765..ab28f199694 100644 ---- a/docs/Makefile.am -+++ b/docs/Makefile.am -@@ -5,5 +5,3 @@ info_TEXINFOS = grub.texi grub-dev.texi - grub_TEXINFOS = fdl.texi - - EXTRA_DIST = font_char_metrics.png font_char_metrics.txt -- -- -diff --git a/docs/man/grub-bios-setup.h2m b/docs/man/grub-bios-setup.h2m -deleted file mode 100644 -index ac6ede36296..00000000000 ---- a/docs/man/grub-bios-setup.h2m -+++ /dev/null -@@ -1,6 +0,0 @@ --[NAME] --grub-bios-setup \- set up a device to boot using GRUB --[SEE ALSO] --.BR grub-install (8), --.BR grub-mkimage (1), --.BR grub-mkrescue (1) -diff --git a/docs/man/grub-editenv.h2m b/docs/man/grub-editenv.h2m -deleted file mode 100644 -index 3859d3d4c4f..00000000000 ---- a/docs/man/grub-editenv.h2m -+++ /dev/null -@@ -1,5 +0,0 @@ --[NAME] --grub-editenv \- edit GRUB environment block --[SEE ALSO] --.BR grub-reboot (8), --.BR grub-set-default (8) -diff --git a/docs/man/grub-emu.h2m b/docs/man/grub-emu.h2m -deleted file mode 100644 -index ef1c000656a..00000000000 ---- a/docs/man/grub-emu.h2m -+++ /dev/null -@@ -1,6 +0,0 @@ --[NAME] --grub-emu \- GRUB emulator --[SEE ALSO] --If you are trying to install GRUB, then you should use --.BR grub-install (8) --rather than this program. -diff --git a/docs/man/grub-file.h2m b/docs/man/grub-file.h2m -deleted file mode 100644 -index e09bb4d3101..00000000000 ---- a/docs/man/grub-file.h2m -+++ /dev/null -@@ -1,2 +0,0 @@ --[NAME] --grub-file \- check file type -diff --git a/docs/man/grub-fstest.h2m b/docs/man/grub-fstest.h2m -deleted file mode 100644 -index 9676b159afd..00000000000 ---- a/docs/man/grub-fstest.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-fstest \- debug tool for GRUB filesystem drivers --[SEE ALSO] --.BR grub-probe (8) -diff --git a/docs/man/grub-glue-efi.h2m b/docs/man/grub-glue-efi.h2m -deleted file mode 100644 -index c1c6ded49ff..00000000000 ---- a/docs/man/grub-glue-efi.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-glue-efi \- generate a fat binary for EFI --[DESCRIPTION] --grub-glue-efi processes ia32 and amd64 EFI images and glues them according to Apple format. -diff --git a/docs/man/grub-install.h2m b/docs/man/grub-install.h2m -deleted file mode 100644 -index 8cbbc87a0f2..00000000000 ---- a/docs/man/grub-install.h2m -+++ /dev/null -@@ -1,6 +0,0 @@ --[NAME] --grub-install \- install GRUB to a device --[SEE ALSO] --.BR grub-mkconfig (8), --.BR grub-mkimage (1), --.BR grub-mkrescue (1) -diff --git a/docs/man/grub-kbdcomp.h2m b/docs/man/grub-kbdcomp.h2m -deleted file mode 100644 -index d81f9157e01..00000000000 ---- a/docs/man/grub-kbdcomp.h2m -+++ /dev/null -@@ -1,10 +0,0 @@ --[NAME] --grub-kbdcomp \- generate a GRUB keyboard layout file --[DESCRIPTION] --grub-kbdcomp processes a X keyboard layout description in --.BR keymaps (5) --format into a format that can be used by GRUB's --.B keymap --command. --[SEE ALSO] --.BR grub-mklayout (8) -diff --git a/docs/man/grub-macbless.h2m b/docs/man/grub-macbless.h2m -deleted file mode 100644 -index 0197c0087d7..00000000000 ---- a/docs/man/grub-macbless.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-macbless \- bless a mac file/directory --[SEE ALSO] --.BR grub-install (1) -diff --git a/docs/man/grub-macho2img.h2m b/docs/man/grub-macho2img.h2m -deleted file mode 100644 -index d79aaeed8f9..00000000000 ---- a/docs/man/grub-macho2img.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-macho2img \- convert Mach-O to raw image --[SEE ALSO] --.BR grub-mkimage (1) -diff --git a/docs/man/grub-menulst2cfg.h2m b/docs/man/grub-menulst2cfg.h2m -deleted file mode 100644 -index c2e0055ed7e..00000000000 ---- a/docs/man/grub-menulst2cfg.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-menulst2cfg \- transform legacy menu.lst into grub.cfg --[SEE ALSO] --.BR grub-mkconfig (8) -diff --git a/docs/man/grub-mkconfig.h2m b/docs/man/grub-mkconfig.h2m -deleted file mode 100644 -index 9b42f813010..00000000000 ---- a/docs/man/grub-mkconfig.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mkconfig \- generate a GRUB configuration file --[SEE ALSO] --.BR grub-install (8) -diff --git a/docs/man/grub-mkfont.h2m b/docs/man/grub-mkfont.h2m -deleted file mode 100644 -index d46fe600eca..00000000000 ---- a/docs/man/grub-mkfont.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mkfont \- make GRUB font files --[SEE ALSO] --.BR grub-mkconfig (8) -diff --git a/docs/man/grub-mkimage.h2m b/docs/man/grub-mkimage.h2m -deleted file mode 100644 -index f0fbc2bb197..00000000000 ---- a/docs/man/grub-mkimage.h2m -+++ /dev/null -@@ -1,6 +0,0 @@ --[NAME] --grub-mkimage \- make a bootable image of GRUB --[SEE ALSO] --.BR grub-install (8), --.BR grub-mkrescue (1), --.BR grub-mknetdir (8) -diff --git a/docs/man/grub-mklayout.h2m b/docs/man/grub-mklayout.h2m -deleted file mode 100644 -index 1e43409c0ab..00000000000 ---- a/docs/man/grub-mklayout.h2m -+++ /dev/null -@@ -1,10 +0,0 @@ --[NAME] --grub-mklayout \- generate a GRUB keyboard layout file --[DESCRIPTION] --grub-mklayout processes a keyboard layout description in --.BR keymaps (5) --format into a format that can be used by GRUB's --.B keymap --command. --[SEE ALSO] --.BR grub-mkconfig (8) -diff --git a/docs/man/grub-mknetdir.h2m b/docs/man/grub-mknetdir.h2m -deleted file mode 100644 -index a2ef13ec111..00000000000 ---- a/docs/man/grub-mknetdir.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mknetdir \- prepare a GRUB netboot directory. --[SEE ALSO] --.BR grub-mkimage (1) -diff --git a/docs/man/grub-mkpasswd-pbkdf2.h2m b/docs/man/grub-mkpasswd-pbkdf2.h2m -deleted file mode 100644 -index 4d202f3da7e..00000000000 ---- a/docs/man/grub-mkpasswd-pbkdf2.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mkpasswd-pbkdf2 \- generate hashed password for GRUB --[SEE ALSO] --.BR grub-mkconfig (8) -diff --git a/docs/man/grub-mkrelpath.h2m b/docs/man/grub-mkrelpath.h2m -deleted file mode 100644 -index d01f3961e3f..00000000000 ---- a/docs/man/grub-mkrelpath.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mkrelpath \- make a system path relative to its root --[SEE ALSO] --.BR grub-probe (8) -diff --git a/docs/man/grub-mkrescue.h2m b/docs/man/grub-mkrescue.h2m -deleted file mode 100644 -index a427f02e3c6..00000000000 ---- a/docs/man/grub-mkrescue.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mkrescue \- make a GRUB rescue image --[SEE ALSO] --.BR grub-mkimage (1) -diff --git a/docs/man/grub-mkstandalone.h2m b/docs/man/grub-mkstandalone.h2m -deleted file mode 100644 -index c77313978ad..00000000000 ---- a/docs/man/grub-mkstandalone.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-mkstandalone \- make a memdisk-based GRUB image --[SEE ALSO] --.BR grub-mkimage (1) -diff --git a/docs/man/grub-mount.h2m b/docs/man/grub-mount.h2m -deleted file mode 100644 -index 8d168982d72..00000000000 ---- a/docs/man/grub-mount.h2m -+++ /dev/null -@@ -1,2 +0,0 @@ --[NAME] --grub-mount \- export GRUB filesystem with FUSE -diff --git a/docs/man/grub-ofpathname.h2m b/docs/man/grub-ofpathname.h2m -deleted file mode 100644 -index 74b43eea039..00000000000 ---- a/docs/man/grub-ofpathname.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-ofpathname \- find OpenBOOT path for a device --[SEE ALSO] --.BR grub-probe (8) -diff --git a/docs/man/grub-pe2elf.h2m b/docs/man/grub-pe2elf.h2m -deleted file mode 100644 -index 7ca29bd703c..00000000000 ---- a/docs/man/grub-pe2elf.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-pe2elf \- convert PE image to ELF --[SEE ALSO] --.BR grub-mkimage (1) -diff --git a/docs/man/grub-probe.h2m b/docs/man/grub-probe.h2m -deleted file mode 100644 -index 6e1ffdcf937..00000000000 ---- a/docs/man/grub-probe.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-probe \- probe device information for GRUB --[SEE ALSO] --.BR grub-fstest (1) -diff --git a/docs/man/grub-reboot.h2m b/docs/man/grub-reboot.h2m -deleted file mode 100644 -index e4acace65ce..00000000000 ---- a/docs/man/grub-reboot.h2m -+++ /dev/null -@@ -1,5 +0,0 @@ --[NAME] --grub-reboot \- set the default boot entry for GRUB, for the next boot only --[SEE ALSO] --.BR grub-set-default (8), --.BR grub-editenv (1) -diff --git a/docs/man/grub-render-label.h2m b/docs/man/grub-render-label.h2m -deleted file mode 100644 -index 50ae5247c05..00000000000 ---- a/docs/man/grub-render-label.h2m -+++ /dev/null -@@ -1,3 +0,0 @@ --[NAME] --grub-render-label \- generate a .disk_label for Apple Macs. -- -diff --git a/docs/man/grub-script-check.h2m b/docs/man/grub-script-check.h2m -deleted file mode 100644 -index 3653682671a..00000000000 ---- a/docs/man/grub-script-check.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-script-check \- check grub.cfg for syntax errors --[SEE ALSO] --.BR grub-mkconfig (8) -diff --git a/docs/man/grub-set-default.h2m b/docs/man/grub-set-default.h2m -deleted file mode 100644 -index 7945001c154..00000000000 ---- a/docs/man/grub-set-default.h2m -+++ /dev/null -@@ -1,5 +0,0 @@ --[NAME] --grub-set-default \- set the saved default boot entry for GRUB --[SEE ALSO] --.BR grub-reboot (8), --.BR grub-editenv (1) -diff --git a/docs/man/grub-sparc64-setup.h2m b/docs/man/grub-sparc64-setup.h2m -deleted file mode 100644 -index 18f803a50db..00000000000 ---- a/docs/man/grub-sparc64-setup.h2m -+++ /dev/null -@@ -1,6 +0,0 @@ --[NAME] --grub-sparc64-setup \- set up a device to boot using GRUB --[SEE ALSO] --.BR grub-install (8), --.BR grub-mkimage (1), --.BR grub-mkrescue (1) -diff --git a/docs/man/grub-syslinux2cfg.h2m b/docs/man/grub-syslinux2cfg.h2m -deleted file mode 100644 -index ad25c8ab753..00000000000 ---- a/docs/man/grub-syslinux2cfg.h2m -+++ /dev/null -@@ -1,4 +0,0 @@ --[NAME] --grub-syslinux2cfg \- transform syslinux config into grub.cfg --[SEE ALSO] --.BR grub-menulst2cfg (8) -diff --git a/gentpl.py b/gentpl.py -index c86550d4f9e..2cba0bbbd6f 100644 ---- a/gentpl.py -+++ b/gentpl.py -@@ -805,10 +805,7 @@ def manpage(defn, adddeps): - - output("if COND_MAN_PAGES\n") - gvar_add("man_MANS", name + "." + mansection) -- rule(name + "." + mansection, name + " " + adddeps, """ --chmod a+x """ + name + """ --PATH=$(builddir):$$PATH pkgdatadir=$(builddir) $(HELP2MAN) --section=""" + mansection + """ -i $(top_srcdir)/docs/man/""" + name + """.h2m -o $@ """ + name + """ --""") -+ rule(name + "." + mansection, name + " " + adddeps, "cat $(top_srcdir)/util/" + name + "." + mansection + " | $(top_builddir)/config.status --file=$@:-") - gvar_add("CLEANFILES", name + "." + mansection) - output("endif\n") - -diff --git a/util/grub-bios-setup.8 b/util/grub-bios-setup.8 -new file mode 100644 -index 00000000000..56f582b3d75 ---- /dev/null -+++ b/util/grub-bios-setup.8 -@@ -0,0 +1,54 @@ -+.TH GRUB-BIOS-SETUP 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-bios-setup\fR \(em Set up images to boot from a device. -+ -+.SH SYNOPSIS -+\fBgrub-bios-setup\fR [-a | --allow-floppy] [-b | --boot-image=\fIFILE\fR] -+.RS 17 -+[-c | --core-image=\fIFILE\fR] [-d | --directory=\fIDIR\fR] -+.RE -+.RS 17 -+[-f | --force] [-m | --device-map=\fIFILE\fR] -+.RE -+.RS 17 -+[-s | --skip-fs-probe] [-v | --verbose] \fIDEVICE\fR -+ -+.SH DESCRIPTION -+You should not normally run this program directly. Use grub-install instead. -+ -+.SH OPTIONS -+.TP -+\fB--allow-floppy\fR -+Make the device also bootable as a floppy. This option is the default for -+/dev/fdX devices. Some BIOSes will not boot images created with this option. -+ -+.TP -+\fB--boot-image\fR=\fIFILE\fR -+Use FILE as the boot image. The default value is \fBboot.img\fR. -+ -+.TP -+\fB--core-image\fR=\fIFILE\fR -+Use FILE as ther core image. The default value is \fBcore.img\fR. -+ -+.TP -+\fB--directory\fR=\fIDIR\fR -+Use GRUB files in the directory DIR. The default value is \fB/boot/grub\fR. -+ -+.TP -+\fB--force\fR -+Install even if problems are detected. -+ -+.TP -+\fB--device-map\fR=\fIFILE\fR -+Use FILE as the device map. The default value is /boot/grub/device.map . -+ -+.TP -+\fB--skip-fs-probe\fR -+Do not probe DEVICE for filesystems. -+ -+.TP -+\fB--verbose\fR -+Print verbose messages. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-editenv.1 b/util/grub-editenv.1 -new file mode 100644 -index 00000000000..d28ba03ba42 ---- /dev/null -+++ b/util/grub-editenv.1 -@@ -0,0 +1,46 @@ -+.TH GRUB-EDITENV 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-editenv\fR \(em Manage the GRUB environment block. -+ -+.SH SYNOPSIS -+\fBgrub-editenv\fR [-v | --verbose] [\fIFILE\fR] -+.RS 14 -+ -+ -+.SH DESCRIPTION -+\fBgrub-editenv\fR is a command line tool to manage GRUB's stored environment. -+ -+.SH OPTIONS -+.TP -+\fB--verbose\fR -+Print verbose messages. -+ -+.TP -+\fBFILE\fR -+.RS 7 -+File name to use for grub environment. Default is /boot/grub/grubenv . -+.RE -+ -+.SH COMMANDS -+.TP -+\fBcreate\fR -+.RS 7 -+Create a blank environment block file. -+.RE -+ -+.TP -+\fBlist\fR -+.RS 7 -+List the current variables. -+.RE -+ -+.TP -+\fBset\fR [\fINAME\fR=\fIVALUE\fR ...] -+Set variables. -+ -+.TP -+\fBunset [\fINAME\fR ...] -+Delete variables. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-file.1 b/util/grub-file.1 -new file mode 100644 -index 00000000000..b29cb327889 ---- /dev/null -+++ b/util/grub-file.1 -@@ -0,0 +1,165 @@ -+.TH GRUB-FILE 1 "Web Feb 26 2014" -+.SH NAME -+\fBgrub-file\fR \(em Check if FILE is of specified type. -+ -+.SH SYNOPSIS -+\fBgrub-file\fR (--is-i386-xen-pae-domu | --is-x86_64-xen-domu | -+.RS 11 -+--is-x86-xen-dom0 | --is-x86-multiboot | -+.RE -+.RS 11 -+--is-x86-multiboot2 | --is-arm-linux | --is-arm64-linux | -+.RE -+.RS 11 -+--is-ia64-linux | --is-mips-linux | --is-mipsel-linux | -+.RE -+.RS 11 -+--is-sparc64-linux | --is-powerpc-linux | --is-x86-linux | -+.RE -+.RS 11 -+--is-x86-linux32 | --is-x86-kfreebsd | --is-i386-kfreebsd | -+.RE -+.RS 11 -+--is-x86_64-kfreebsd | --is-x86-knetbsd | -+.RE -+.RS 11 -+--is-i386-knetbsd | --is-x86_64-knetbsd | --is-i386-efi | -+.RE -+.RS 11 -+--is-x86_64-efi | --is-ia64-efi | --is-arm64-efi | -+.RE -+.RS 11 -+--is-arm-efi | --is-hibernated-hiberfil | --is-x86_64-xnu | -+.RE -+.RS 11 -+--is-i386-xnu | --is-xnu-hibr | --is-x86-bios-bootsector) -+.RE -+.RS 11 -+\fIFILE\fR -+ -+.SH DESCRIPTION -+\fBgrub-file\fR is used to check if \fIFILE\fR is of a specified type. -+ -+.SH OPTIONS -+.TP -+--is-i386-xen-pae-domu -+Check if FILE can be booted as i386 PAE Xen unprivileged guest kernel -+ -+.TP -+--is-x86_64-xen-domu -+Check if FILE can be booted as x86_64 Xen unprivileged guest kernel -+ -+.TP -+--is-x86-xen-dom0 -+Check if FILE can be used as Xen x86 privileged guest kernel -+ -+.TP -+--is-x86-multiboot -+Check if FILE can be used as x86 multiboot kernel -+ -+.TP -+--is-x86-multiboot2 -+Check if FILE can be used as x86 multiboot2 kernel -+ -+.TP -+--is-arm-linux -+Check if FILE is ARM Linux -+ -+.TP -+--is-arm64-linux -+Check if FILE is ARM64 Linux -+ -+.TP -+--is-ia64-linux -+Check if FILE is IA64 Linux -+ -+.TP -+--is-mips-linux -+Check if FILE is MIPS Linux -+ -+.TP -+--is-mipsel-linux -+Check if FILE is MIPSEL Linux -+ -+.TP -+--is-sparc64-linux -+Check if FILE is SPARC64 Linux -+ -+.TP -+--is-powerpc-linux -+Check if FILE is POWERPC Linux -+ -+.TP -+--is-x86-linux -+Check if FILE is x86 Linux -+ -+.TP -+--is-x86-linux32 -+Check if FILE is x86 Linux supporting 32-bit protocol -+ -+.TP -+--is-x86-kfreebsd -+Check if FILE is x86 kFreeBSD -+ -+.TP -+--is-i386-kfreebsd -+Check if FILE is i386 kFreeBSD -+ -+.TP -+--is-x86_64-kfreebsd -+Check if FILE is x86_64 kFreeBSD -+ -+.TP -+--is-x86-knetbsd -+Check if FILE is x86 kNetBSD -+ -+.TP -+--is-i386-knetbsd -+Check if FILE is i386 kNetBSD -+ -+.TP -+--is-x86_64-knetbsd -+Check if FILE is x86_64 kNetBSD -+ -+.TP -+--is-i386-efi -+Check if FILE is i386 EFI file -+ -+.TP -+--is-x86_64-efi -+Check if FILE is x86_64 EFI file -+ -+.TP -+--is-ia64-efi -+Check if FILE is IA64 EFI file -+ -+.TP -+--is-arm64-efi -+Check if FILE is ARM64 EFI file -+ -+.TP -+--is-arm-efi -+Check if FILE is ARM EFI file -+ -+.TP -+--is-hibernated-hiberfil -+Check if FILE is hiberfil.sys in hibernated state -+ -+.TP -+--is-x86_64-xnu -+Check if FILE is x86_64 XNU (Mac OS X kernel) -+ -+.TP -+--is-i386-xnu -+Check if FILE is i386 XNU (Mac OS X kernel) -+ -+.TP -+--is-xnu-hibr -+Check if FILE is XNU (Mac OS X kernel) hibernated image -+ -+.TP -+--is-x86-bios-bootsector -+Check if FILE is BIOS bootsector -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-fstest.1 b/util/grub-fstest.1 -new file mode 100644 -index 00000000000..792fa78634c ---- /dev/null -+++ b/util/grub-fstest.1 -@@ -0,0 +1,99 @@ -+.TH GRUB-FSTEST 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-fstest\fR — Debug tool for GRUB's filesystem driver. -+ -+.SH SYNOPSIS -+\fBgrub-fstest\fR [-c | --diskcount=\fINUM\fR] [-C | --crypto] -+.RS 13 -+[-d | --debug=\fISTRING\fR] [-K | --zfs-key=\fIFILE\fR|\fIprompt\fR] -+.RE -+.RS 13 -+[-n | --length=\fINUM\fR] [-r | --root=\fIDEVICE_NAME\fR] -+.RE -+.RS 13 -+[-s | --skip=\fINUM\fR] [-u | --uncompress] [-v | --verbose] -+.RE -+.RS 13 -+\fIIMAGE_PATH\fR -+ -+.SH DESCRIPTION -+\fBgrub-fstest\fR is a tool for testing GRUB's filesystem drivers. You should not normally need to run this program. -+ -+.SH OPTIONS -+.TP -+\fB--diskcount\fR=\fINUM\fR -+Specify the number of input files. -+ -+.TP -+\fB--crypto\fR -+Mount cryptographic devices. -+ -+.TP -+\fB--debug\fR=\fISTRING\fR -+Set debug environment variable. -+ -+.TP -+\fB--zfs-key\fR=\fIFILE\fR|\fIprompt\fR -+Load ZFS cryptographic key. -+ -+.TP -+\fB--length\fR=\fINUM\fR -+Handle NUM bytes in output file. -+ -+.TP -+\fB--root\fR=\fIDEVICE_NAME\fR -+Set root device. -+ -+.TP -+\fB--skip\fR=\fINUM\fR -+Skip NUM bytes from output file. -+ -+.TP -+\fB--uncompress\fR -+Uncompress data. -+ -+.TP -+\fB--verbose\fR -+Print verbose messages. -+ -+.SH COMMANDS -+.TP -+\fBblocklist\fR \fIFILE\fR -+Display block list of \fIFILE\fR. -+ -+.TP -+\fBcat\fR \fIFILE\fR -+Display \fIFILE\fR on standard output. -+ -+.TP -+\fBcmp\fR \fIFILE\fR \fILOCAL\fR -+Compare \fIFILE\fR with local file \fILOCAL\fR. -+ -+.TP -+\fBcp\fR \fIFILE\fR \fILOCAL\fR -+Copy \fIFILE\fR to local file \fILOCAL\fR. -+ -+.TP -+\fBcrc\fR \fIFILE\fR -+Display the CRC-32 checksum of \fIFILE\fR. -+ -+.TP -+\fBhex\fR \fIFILE\fR -+Display contents of \fIFILE\fR in hexidecimal. -+ -+.TP -+\fBls\fR \fIPATH\fR -+List files at \fIPATH\fR. -+ -+.TP -+\fBxnu_uuid\fR \fIDEVICE\fR -+Display the XNU UUID of \fIDEVICE\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-glue-efi.1 b/util/grub-glue-efi.1 -new file mode 100644 -index 00000000000..72bd555d577 ---- /dev/null -+++ b/util/grub-glue-efi.1 -@@ -0,0 +1,31 @@ -+.TH GRUB-GLUE-EFI 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-glue-efi\fR \(em Create an Apple fat EFI binary. -+ -+.SH SYNOPSIS -+\fBgrub-glue-efi\fR <-3 | --input32=\fIFILE\fR> <-6 | --input64=\fIFILE\fR> -+.RS 15 -+<-o | --output=\fIFILE\fR> [-v | --verbose] -+ -+.SH DESCRIPTION -+\fBgrub-glue-efi\fR creates an Apple fat EFI binary from two EFI binaries. -+ -+.SH OPTIONS -+.TP -+\fB--input32\fR=\fIFILE\fR -+Read 32-bit binary from \fIFILE\fR. -+ -+.TP -+\fB--input64\fR=\fIFILE\fR -+Read 64-bit binary from \fIFILE\fR. -+ -+.TP -+\fB--output\fR=\fIFILE\fR -+Write resulting fat binary to \fIFILE\fR. -+ -+.TP -+\fB--verbose\fR -+Print verbose messages. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-install.8 b/util/grub-install.8 -new file mode 100644 -index 00000000000..1db89e94b3b ---- /dev/null -+++ b/util/grub-install.8 -@@ -0,0 +1,128 @@ -+.TH GRUB-INSTALL 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-install\fR \(em Install GRUB on a device. -+ -+.SH SYNOPSIS -+\fBgrub-install\fR [--modules=\fIMODULES\fR] [--install-modules=\fIMODULES\fR] -+.RS 14 -+[--themes=\fITHEMES\fR] [--fonts=\fIFONTS\fR] [--locales=\fILOCALES\fR] -+.RE -+.RS 14 -+[--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR]] [-d | --directory=\fIDIR\fR] -+.RE -+.RS 14 -+[--grub-mkimage=\fIFILE\fR] [--boot-directory=\fIDIR\fR] -+.RE -+.RS 14 -+[--target=\fITARGET\fR] [--grub-setup=\fIFILE\fR] -+.RE -+.RS 14 -+[--grub-mkrelpath=\fIFILE\fR] [--grub-probe=\fIFILE\fR] -+.RE -+.RS 14 -+[--allow-floppy] [--recheck] [--force] [--force-file-id] -+.RE -+.RS 14 -+[--disk-module=\fIMODULE\fR] [--no-nvram] [--removable] -+.RE -+.RS 14 -+[--bootloader-id=\fIID\fR] [--efi-directory=\fIDIR\fR] \fIINSTALL_DEVICE\fR -+ -+.SH DESCRIPTION -+\fBgrub-install\fR installs GRUB onto a device. This includes copying GRUB images into the target directory (generally \fI/boot/grub\fR), and on some platforms may also include installing GRUB onto a boot sector. -+ -+.SH OPTIONS -+.TP -+\fB--modules\fR=\fIMODULES\fR\! -+Pre-load modules specified by \fIMODULES\fR. -+ -+.TP -+\fB--install-modules\fR=\fIMODULES\fR -+Install only \fIMODULES\fR and their dependencies. The default is to install all available modules. -+ -+.TP -+\fB--themes\fR=\fITHEMES\fR -+Install \fITHEMES\fR. The default is to install the \fIstarfield\fR theme, if available. -+ -+.TP -+\fB--fonts\fR=\fIFONTS\fR -+Install \fIFONTS\fR. The default is to install the \fIunicode\fR font. -+ -+.TP -+\fB--locales\fR=\fILOCALES\fR -+Install only locales listed in \fILOCALES\fR. The default is to install all available locales. -+ -+.TP -+\fB--compress\fR=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR -+Compress GRUB files using the specified compression algorithm. -+ -+.TP -+\fB--directory\fR=\fIDIR\fR -+Use images and modules in \fIDIR\fR. -+ -+.TP -+\fB--grub-mkimage\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-mkimage\fR. The default is \fI/usr/bin/grub-mkimage\fR. -+ -+.TP -+\fB--boot-directory\fR=\fIDIR\fR -+Use \fIDIR\fR as the boot directory. The default is \fI/boot\fR. GRUB will put its files in a subdirectory of this directory named \fIgrub\fR. -+ -+.TP -+\fB--target\fR=\fITARGET\fR -+Install GRUB for \fITARGET\fR platform. The default is the platform \fBgrub-install\fR is running on. -+ -+.TP -+\fB--grub-setup\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-setup\fR. The default is \fI/usr/bin/grub-setup\fR. -+ -+.TP -+\fB--grub-mkrelpath\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-mkrelpath\fR. The default is \fI/usr/bin/grub-mkrelpath\fR. -+ -+.TP -+\fB--grub-probe\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-probe\fR. The default is \fI/usr/bin/grub-mkrelpath\fR. -+ -+.TP -+\fB--allow-floppy -+Make the device also bootable as a floppy. This option is the default for /dev/fdX devices. Some BIOSes will not boot images created with this option. -+ -+.TP -+\fB--recheck -+Delete any existing device map and create a new one if necessary. -+ -+.TP -+\fB--force -+Install even if problems are detected. -+ -+.TP -+\fB--force-file-id -+Use identifier file even if UUID is available. -+ -+.TP -+\fB--disk-module\fR=\fIMODULE\fR -+Use \fIMODULE\fR for disk access. This allows you to manually specify either \fIbiosdisk\fR or \fInative\fR disk access. This option is only available on the BIOS target platform. -+ -+.TP -+\fB--no-nvram -+Do not update the \fIboot-device\fR NVRAM variable. This option is only available on IEEE1275 target platforms. -+ -+.TP -+\fB--removable -+Treat the target device as if it is removeable. This option is only available on the EFI target platform. -+ -+.TP -+\fB--bootloader-id\fR=\fIID\fR -+Use \fIID\fR as the bootloader ID. This option is only available on the EFI target platform. -+ -+.TP -+\fB--efi-directory\fR=\fIDIR\fR -+Use \fIDIR\fR as the EFI System Partition root. This option is only available on the EFI target platform. -+ -+.TP -+\fIINSTALL_DEVICE\fR -+Install GRUB to the block device \fIINSTALL_DEVICE\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-kbdcomp.1 b/util/grub-kbdcomp.1 -new file mode 100644 -index 00000000000..0bb969a5b43 ---- /dev/null -+++ b/util/grub-kbdcomp.1 -@@ -0,0 +1,19 @@ -+.TH GRUB-KBDCOMP 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-kbdcomp\fR \(em Generate a GRUB keyboard layout file. -+ -+.SH SYNOPSIS -+\fBgrub-kbdcomp\fR <-o | --output=\fIFILE\fR> \fICKBMAP_ARGUMENTS\fR -+ -+.SH DESCRIPTION -+\fBgrub-kbdcomp\fR processes an X keyboard layout description in -+\fBkeymaps\fR(5) format into a format that can be used by GRUB's \fBkeymap\fR -+command. -+ -+.SH OPTIONS -+.TP -+\fB--output\fR=\fIFILE\fR -+Write output to \fIFILE\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-macbless.1 b/util/grub-macbless.1 -new file mode 100644 -index 00000000000..41a96186f70 ---- /dev/null -+++ b/util/grub-macbless.1 -@@ -0,0 +1,22 @@ -+.TH GRUB-MACBLESS 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-macbless\fR \(em Mac-style bless on HFS or HFS+ -+ -+.SH SYNOPSIS -+\fBgrub-macbless\fR [-v | --verbose] [-p | --ppc] \fIFILE\fR | [-x | --x86] \fIFILE\fR -+ -+.SH OPTIONS -+.TP -+--x86 -+Bless for x86 based Macs. -+ -+.TP -+--ppc -+Bless for PPC based Macs. -+ -+.TP -+--verbose -+Print verbose messages. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-menulst2cfg.1 b/util/grub-menulst2cfg.1 -new file mode 100644 -index 00000000000..91e2ef87113 ---- /dev/null -+++ b/util/grub-menulst2cfg.1 -@@ -0,0 +1,12 @@ -+.TH GRUB-MENULST2CFG 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-menulst2cfg\fR \(em Convert a configuration file from GRUB 0.xx to GRUB 2.xx format. -+ -+.SH SYNOPSIS -+\fBgrub-menulst2cfg\fR [\fIINFILE\fR [\fIOUTFILE\fR]] -+ -+.SH DESCRIPTION -+\fBgrub-menulst2cfg\fR converts a configuration file from GRUB 0.xx to the current format. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8 -new file mode 100644 -index 00000000000..a2d1f577b9b ---- /dev/null -+++ b/util/grub-mkconfig.8 -@@ -0,0 +1,17 @@ -+.TH GRUB-MKCONFIG 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mkconfig\fR \(em Generate a GRUB configuration file. -+ -+.SH SYNOPSIS -+\fBgrub-mkconfig\fR [-o | --output=\fIFILE\fR] -+ -+.SH DESCRIPTION -+\fBgrub-mkconfig\fR generates a configuration file for GRUB. -+ -+.SH OPTIONS -+.TP -+\fB--output\fR=\fIFILE\fR -+Write generated output to \fIFILE\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkfont.1 b/util/grub-mkfont.1 -new file mode 100644 -index 00000000000..3494857987d ---- /dev/null -+++ b/util/grub-mkfont.1 -@@ -0,0 +1,87 @@ -+.TH GRUB-MKFONT 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mkfont\fR \(em Convert common font file formats into the PF2 format. -+ -+.SH SYNOPSIS -+\fBgrub-mkfont\fR [--ascii-bitmaps] [-a | --force-autohint] -+.RS 13 -+[-b | --bold] [-c | --asce=\fINUM\fR] [-d | --desc=\fINUM\fR] -+.RE -+.RS 13 -+[-i | --index=\fINUM\fR] [-n | --name=\fINAME\fR] [--no-bitmap] -+.RE -+.RS 13 -+[--no-hinting] <-o | --output=\fIFILE\fR> -+.RE -+.RS 13 -+[-r | --range=\fIFROM-TO\fR[\fI,FROM-TO\fR]] [-s | --size=\fISIZE\fR] -+.RE -+.RS 13 -+[-v | --verbose] [--width-spec] \fIFONT_FILES\fR -+ -+.SH DESCRIPTION -+\fBgrub-mkfont\fR converts font files from common formats into the PF2 format used by GRUB. -+ -+.SH OPTIONS -+.TP -+--ascii-bitmaps -+Save only bitmaps for ASCII characters. -+ -+.TP -+--force-autohint -+Force generation of automatic hinting. -+ -+.TP -+--bold -+Convert font to bold. -+ -+.TP -+--asce=\fINUM\fR -+Set font ascent to \fINUM\fR. -+ -+.TP -+--desc=\fINUM\fR -+Set font descent to \fINUM\fR. -+ -+.TP -+--index=\fINUM\fR -+Select face index \fINUM\fR. -+ -+.TP -+--name=\fINAME\fR -+Set font family to \fINAME\fR. -+ -+.TP -+--no-bitmap -+Ignore bitmap strikes when loading. -+ -+.TP -+--no-hinting -+Disable hinting. -+ -+.TP -+--output=\fIFILE\fR -+Save ouptut to \fIFILE\fR. This argument is required. -+ -+.TP -+--range=\fIFROM-TO\fR\fI,FROM-TO\fR -+Set the font ranges to each pair of \fIFROM\fR,\fITO\fR. -+ -+.TP -+--size=\fISIZE\fR -+Set font size to \fISIZE\fR. -+ -+.TP -+--verbose -+Print verbose messages. -+ -+.TP -+--width-spec -+Create a width summary file. -+ -+.TP -+\fIFONT_FILES\fR -+The input files to be converted. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkimage.1 b/util/grub-mkimage.1 -new file mode 100644 -index 00000000000..4dea4f54597 ---- /dev/null -+++ b/util/grub-mkimage.1 -@@ -0,0 +1,95 @@ -+.TH GRUB-MKIMAGE 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mkimage\fR \(em Make a bootable GRUB image. -+ -+.SH SYNOPSIS -+\fBgrub-mkimage\fR [-c | --config=\fRFILE\fI] [-C | --compression=(\fIxz\fR,\fInone\fR,\fIauto\fR)] -+.RS 14 -+[-d | --directory=\fRDIR\fR] [-k | --pubkey=\fIFILE\fR] -+.RE -+.RS 14 -+[-m | --memdisk=\fIFILE\fR] [-n | --note] [-o | --output=\fIFILE\fR] -+.RE -+.RS 14 -+[-O | --format=\fIFORMAT\fR] [-p | --prefix=\fIDIR\fR] -+.RE -+.RS 14 -+[-v | --verbose] \fIMODULES\fR -+ -+.SH DESCRIPTION -+\fBgrub-mkimage\fI builds a bootable image of GRUB. -+ -+.SH OPTIONS -+.TP -+--config=\fIFILE\fR -+Embed \fIFILE\fR as the image's initial configuration file. -+ -+.TP -+--compression=(\fIxz\fR,\fInone\fR,\fIauto\fR) -+Use one of \fIxz\fR, \fInone\fR, or \fIauto\fR as the compression method for the core image. -+ -+.TP -+--directory=\fIDIR\fR -+Use images and modules from \fIDIR\fR. The default value is \fB/usr/lib/grub/\fR. -+ -+.TP -+--pubkey=\fIFILE\fR -+Embed the public key \fIFILE\fR for signature checking. -+ -+.TP -+--memdisk=\fIFILE\fR -+Embed the memdisk image \fIFILE\fR. If no \fB-p\fR option is also specified, this implies \fI-p (memdisk)/boot/grub\fR. -+ -+.TP -+--note -+Add a CHRP \fINOTE\fR section. This option is only valid on IEEE1275 platforms. -+ -+.TP -+--output=\fIFILE\fR -+Write the generated file to \fIFILE\fR. The default is to write to standard output. -+ -+.TP -+--format=\fIFORMAT\fR -+Generate an image in the specified \fIFORMAT\fR. Valid values are: -+.RS -+.RS 4 -+.P -+i386-coreboot, -+i386-multiboot, -+i386-pc, -+i386-pc-pxe, -+i386-efi, -+i386-ieee1275, -+i386-qemu, -+x86_64-efi, -+mipsel-yeeloong-flash, -+mipsel-fuloong2f-flash, -+mipself-loongson-elf, -+powerpc-ieee1275, -+sparc64-ieee1275-raw, -+sparc64-ieee1275-cdcore, -+sparc64-ieee1275-aout, -+ia64-efi, -+mips-arc, -+mipsel-arc, -+mipsel-qemu_mips-elf, -+mips-qemu_mips-flash, -+mipsel-qemu_mips-flash, -+mips-qemu_mips-elf -+.RE -+.RE -+ -+.TP -+--prefix=\fIDIR\fR -+Set prefix directory. The default value is \fI/boot/grub\fR. -+ -+.TP -+--verbose -+Print verbose messages. -+ -+.TP -+\fIMODULES\fR -+Include \fIMODULES\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mklayout.1 b/util/grub-mklayout.1 -new file mode 100644 -index 00000000000..d1bbc2ec515 ---- /dev/null -+++ b/util/grub-mklayout.1 -@@ -0,0 +1,27 @@ -+.TH GRUB-MKLAYOUT 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mklayout\fR \(em Generate a GRUB keyboard layout file. -+ -+.SH SYNOPSIS -+\fBgrub-mklayout\fR [-i | --input=\fIFILE\fR] [-o | --output=\fIFILE\fR] -+.RS 15 -+[-v | --verbose] -+ -+.SH DESCRIPTION -+\fBgrub-mklayout\fR generates a GRUB keyboard layout description which corresponds with the Linux console layout description given as input. -+ -+.SH OPTIONS -+.TP -+--input=\fIFILE\fR -+Use \fIFILE\fR as the input. The default value is the standard input device. -+ -+.TP -+--output=\fIFILE\fR -+Use \fIFILE\fR as the output. The default value is the standard output device. -+ -+.TP -+--verbose -+Print verbose messages. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mknetdir.1 b/util/grub-mknetdir.1 -new file mode 100644 -index 00000000000..fa7e8d4ef0d ---- /dev/null -+++ b/util/grub-mknetdir.1 -@@ -0,0 +1,12 @@ -+.TH GRUB-MKNETDIR 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mknetdir\fR \(em Prepare a GRUB netboot directory. -+ -+.SH SYNOPSIS -+\fBgrub-mknetdir\fR -+ -+.SH DESCRIPTION -+\fBgrub-mknetdir\fR prepares a directory for GRUB to be netbooted from. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkpasswd-pbkdf2.1 b/util/grub-mkpasswd-pbkdf2.1 -new file mode 100644 -index 00000000000..73c437c15d8 ---- /dev/null -+++ b/util/grub-mkpasswd-pbkdf2.1 -@@ -0,0 +1,27 @@ -+.TH GRUB-MKPASSWD-PBKDF2 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mkpasswd-pbkdf2\fR \(em Generate a PBKDF2 password hash. -+ -+.SH SYNOPSIS -+\fBgrub-mkpasswd-pbkdf2\fR [-c | --iteration-count=\fINUM\fR] [-l | --buflen=\fINUM\fR] -+.RS 22 -+[-s | --salt=\fINUM\fR] -+ -+.SH DESCRIPTION -+\fBgrub-mkpasswd-pbkdf2\fR generates a PBKDF2 password string suitable for use in a GRUB configuration file. -+ -+.SH OPTIONS -+.TP -+--iteration-count=\fINUM\fR -+Number of PBKDF2 iterations. -+ -+.TP -+--buflen=\fINUM\fR -+Length of generated hash. -+ -+.TP -+--salt=\fINUM\fR -+Length of salt to use. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkrelpath.1 b/util/grub-mkrelpath.1 -new file mode 100644 -index 00000000000..85f1113621d ---- /dev/null -+++ b/util/grub-mkrelpath.1 -@@ -0,0 +1,12 @@ -+.TH GRUB-MKRELPATH 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mkrelpath\fR \(em Generate a relative GRUB path given an OS path. -+ -+.SH SYNOPSIS -+\fBgrub-mkrelpath\fR \fIFILE\fR -+ -+.SH DESCRIPTION -+\fBgrub-mkrelpath\fR takes an OS filesystem path for \fIFILE\fR and returns a relative path suitable for use in a GRUB configuration file. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkrescue.1 b/util/grub-mkrescue.1 -new file mode 100644 -index 00000000000..4ed9fc723fd ---- /dev/null -+++ b/util/grub-mkrescue.1 -@@ -0,0 +1,123 @@ -+.TH GRUB-MKRESCUE 3 "Wed Feb 26 2014" -+.SH NAME -+grub-mkrescue \(em Generate a GRUB rescue image using GNU Xorriso. -+ -+.SH SYNOPSIS -+\fBgrub-mkrescue\fR [-o | --output=\fIFILE\fR] [--modules=\fIMODULES\fR] -+.RS 15 -+[--install-modules=\fIMODULES\fR] [--themes=\fITHEMES\fR] -+.RE -+.RS 15 -+[--fonts=\fIFONTS\fR] [--locales=\fILOCALES\fR] -+.RE -+.RS 15 -+[--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR]] [-d | --directory=\fIDIR\fR] -+.RE -+.RS 15 -+[--grub-mkimage=\fIFILE\fR] [--rom-directory=\fIDIR\fR] -+.RE -+.RS 15 -+[--xorriso=\fIFILE\fR] [--grub-glue-efi=\fIFILE\fR] -+.RE -+.RS 15 -+[--grub-render-label=\fIFILE\fR] [--label-font=\fIFILE\fR] -+.RE -+.RS 15 -+[--label-color=\fICOLOR\fR] [--label-bgcolor=\fIFILE\fR] -+.RE -+.RS 15 -+[--product-name=\fISTRING\fR] [--product-version=\fISTRING\fR] -+.RE -+.RS 15 -+[--sparc-boot] [--arcs-boot] -+ -+.SH DESCRIPTION -+\fBgrub-mkrescue\fR can be used to generate a rescue image with the GRUB bootloader. -+ -+.SH OPTIONS -+.TP -+\fB--output\fR=\fIFILE\fR -+Write the generated file to \fIFILE\fR. The default is to write to standard output. -+ -+.TP -+\fB--modules\fR=\fIMODULES\fR -+Pre-load modules specified by \fIMODULES\fR. -+ -+.TP -+\fB--install-modules\fR=\fIMODULES\fR -+Install only \fIMODULES\fR and their dependencies. The default is to install all available modules. -+ -+.TP -+\fB--themes\fR=\fITHEMES\fR -+Install \fITHEMES\fR. The default is to install the \fIstarfield\fR theme, if available. -+ -+.TP -+\fB--fonts\fR=\fIFONTS\fR -+Install \fIFONTS\fR. The default is to install the \fIunicode\fR font. -+ -+.TP -+\fB--locales\fR=\fILOCALES\fR -+Install only locales listed in \fILOCALES\fR. The default is to install all available locales. -+ -+.TP -+\fB--compress\fR[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR] -+Compress GRUB files using the specified compression algorithm. -+ -+.TP -+\fB--directory\fR=\fIDIR\fR -+Use images and modules in \fIDIR\fR. -+ -+.TP -+\fB--grub-mkimage\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-mkimage\fR(1). The default is \fI/usr/bin/grub-mkimage\fR. -+ -+.TP -+\fB--rom-directory\fR=\fIDIR\fR -+Save ROM images in \fIDIR\fR. -+ -+.TP -+\fB--xorriso\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBxorriso\fI. -+ -+.TP -+\fB--grub-glue-efi\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-glue-efi\fR(3). -+ -+.TP -+\fB--grub-render-label\fR=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-render-label\fR(3). -+ -+.TP -+\fB--label-font\fR=\fIFILE\fR -+Use \fIFILE\fR as the font file for generated labels. -+ -+.TP -+\fB--label-color\fR=\fICOLOR\fR -+Use \fICOLOR\fI as the color for generated labels. -+ -+.TP -+\fB--label-bgcolor\fR=\fICOLOR\fR -+Use \fICOLOR\fR as the background color for generated labels. -+ -+.TP -+\fB--product-name\fR=\fISTRING\fR -+Use \fISTRING\fR as the product name in generated labels. -+ -+.TP -+\fB--product-version\fR=\fISTRING\fR -+Use \fISTRING\fR as the product version in generated labels. -+ -+.TP -+\fB--sparc-boot\fR -+Enable booting the SPARC platform. This disables HFS+, APM, ARCS, and "boot as disk image" on the \fIi386-pc\fR target platform. -+ -+.TP -+\fB--arcs-boot\fR -+Enable ARCS booting. This is typically for big-endian MIPS machines, and disables HFS+, APM, sparc64, and "boot as disk image" on the \fIi386-pc\fR target platform. -+ -+.TP -+\fB--\fR -+All options after a \fB--\fR will be passed directly to xorriso's command line when generating the image. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkstandalone.1 b/util/grub-mkstandalone.1 -new file mode 100644 -index 00000000000..ba2d2bdf279 ---- /dev/null -+++ b/util/grub-mkstandalone.1 -@@ -0,0 +1,100 @@ -+.TH GRUB-MKSTANDALONE 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-mkstandalone\fR \(em Generate a standalone image in the selected format. -+ -+.SH SYNOPSIS -+\fBgrub-mkstandalone\fR [-o | --output=\fIFILE\fR] [-O | --format=\fIFORMAT\fR] -+.RS 19 -+[-C | --compression=(\fIxz\fR|\fInone\fR|\fIauto\fR)] -+.RE -+.RS 19 -+[--modules=\fIMODULES\fR] [--install-modules=\fIMODULES\fR] -+.RE -+.RS 19 -+[--themes=\fITHEMES\fR] [--fonts=\fIFONTS\fR] -+.RE -+.RS 19 -+[--locales=\fILOCALES\fR] [--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR]] -+.RE -+.RS 19 -+[-d | --directory=\fIDIR\fR] [--grub-mkimage=\fIFILE\fR] -+.RE -+.RS 19 -+\fISOURCE...\fR -+ -+.SH DESCRIPTION -+ -+.SH OPTIONS -+.TP -+--output=\fIFILE\fR -+Write the generated file to \fIFILE\fR. The default is to write to standard output. -+ -+.TP -+--format=\fIFORMAT\fR -+Generate an image in the specified \fIFORMAT\fR. Valid values are: -+.RS -+.RS 4 -+.P -+i386-coreboot, -+i386-multiboot, -+i386-pc, -+i386-pc-pxe, -+i386-efi, -+i386-ieee1275, -+i386-qemu, -+x86_64-efi, -+mipsel-yeeloong-flash, -+mipsel-fuloong2f-flash, -+mipself-loongson-elf, -+powerpc-ieee1275, -+sparc64-ieee1275-raw, -+sparc64-ieee1275-cdcore, -+sparc64-ieee1275-aout, -+ia64-efi, -+mips-arc, -+mipsel-arc, -+mipsel-qemu_mips-elf, -+mips-qemu_mips-flash, -+mipsel-qemu_mips-flash, -+mips-qemu_mips-elf -+.RE -+.RE -+ -+.TP -+--compression=(\fIxz\fR|\fInone\fR|\fIauto\fR) -+Use one of \fIxz\fR, \fInone\fR, or \fIauto\fR as the compression method for the core image. -+ -+.TP -+--modules=\fIMODULES\fR -+Pre-load modules specified by \fIMODULES\fR. -+ -+.TP -+--install-modules=\fIMODULES\fR -+Install only \fIMODULES\fR and their dependencies. The default is to install all available modules. -+ -+.TP -+--themes=\fITHEMES\fR -+Install \fITHEMES\fR. The default is to install the \fIstarfield\fR theme, if available. -+ -+.TP -+--fonts=\fIFONTS\fR -+Install \fIFONTS\fR. The default is to install the \fIunicode\fR font. -+ -+.TP -+--locales=\fILOCALES\fR -+Install only locales listed in \fILOCALES\fR. The default is to install all available locales. -+ -+.TP -+--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR] -+Compress GRUB files using the specified compression algorithm. -+ -+.TP -+--directory=\fIDIR\fR -+Use images and modules in \fIDIR\fR. -+ -+.TP -+--grub-mkimage=\fIFILE\fR -+Use \fIFILE\fR as \fBgrub-mkimage\fR. The default is \fI/usr/bin/grub-mkimage\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-ofpathname.8 b/util/grub-ofpathname.8 -new file mode 100644 -index 00000000000..bf3743aeba1 ---- /dev/null -+++ b/util/grub-ofpathname.8 -@@ -0,0 +1,12 @@ -+.TH GRUB-OFPATHNAME 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-ofpathname\fR \(em Generate an IEEE-1275 device path for a specified device. -+ -+.SH SYNOPSIS -+\fBgrub-ofpathname\fR \fIDEVICE\fR -+ -+.SH DESCRIPTION -+\fBgrub-ofpathname\fR generates an IEEE-1275 device path for the specified \fIDEVICE\fR. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-probe.8 b/util/grub-probe.8 -new file mode 100644 -index 00000000000..04e26c832bb ---- /dev/null -+++ b/util/grub-probe.8 -@@ -0,0 +1,80 @@ -+.TH GRUB-PROBE 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-probe\fR \(em Probe device information for a given path. -+ -+.SH SYNOPSIS -+\fBgrub-probe\fR \[-d | --device] [-m | --device-map=\fIFILE\fR] -+.RS 12 -+[-t | --target=(fs|fs_uuid|fs_label|drive|device|partmap| -+.RE -+.RS 28 -+abstraction|cryptodisk_uuid| -+.RE -+.RS 28 -+msdos_parttype)] -+.RE -+.RS 12 -+[-v | --verbose] (PATH|DEVICE) -+ -+.SH DESCRIPTION -+\fBgrub-probe\fR probes a path or device for filesystem and related information. -+ -+.SH OPTIONS -+.TP -+--device -+Final option represents a \fIDEVICE\fR, rather than a filesystem \fIPATH\fR. -+.TP -+--device-map=\fIFILE\fR -+Use \fIFILE\fR as the device map. The default value is \fI/boot/grub/device.map\fR. -+ -+.TP -+--target=(fs|fs_uuid|fs_label|drive|device|partmap|msdos_parttype) -+Select among various output definitions. The default is \fIfs\fR. -+.RS -+.TP -+\fIfs\fR -+filesystem module -+ -+.TP -+\fIfs_uuid\fR -+filesystem UUID -+ -+.TP -+\fIfs_label\fR -+filesystem label -+ -+.TP -+\fIdrive\fR -+GRUB drive name -+ -+.TP -+\fIdevice\fR -+System device -+ -+.TP -+\fIpartmap\fR -+partition map module -+ -+.TP -+\fIabstraction\fR -+abstraction module -+ -+.TP -+\fIcryptodisk_uuid\fR -+cryptographic container -+ -+.TP -+\fImsdos_partmap\fR -+MS-DOS partition map -+.RE -+ -+.TP -+--verbose -+Print verbose output. -+ -+.TP -+(\fIPATH\fR|\fIDEVICE\fR) -+If --device is passed, a block \fIDEVICE\fR. Otherwise, the \fIPATH\fR of a file on the filesystem. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-reboot.8 b/util/grub-reboot.8 -new file mode 100644 -index 00000000000..faa5e4eece2 ---- /dev/null -+++ b/util/grub-reboot.8 -@@ -0,0 +1,21 @@ -+.TH GRUB-REBOOT 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-reboot\fR \(em Set the default boot menu entry for the next boot only. -+ -+.SH SYNOPSIS -+\fBgrub-reboot\fR [--boot-directory=\fIDIR\fR] \fIMENU_ENTRY\fR -+ -+.SH DESCRIPTION -+\fBgrub-reboot\fR sets the default boot menu entry for the next boot, but not further boots after that. This command only works for GRUB configuration files created with \fIGRUB_DEFAULT=saved\fR in \fI/etc/default/grub\fR. -+ -+.SH OPTIONS -+.TP -+--boot-directory=\fIDIR\fR -+Find GRUB images under \fIDIR/grub\fR. The default value is \fI/boot\fR, resulting in grub images being search for at \fI/boot/grub\fR. -+ -+.TP -+\fIMENU_ENTRY\fR -+A number, a menu item title or a menu item identifier. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-render-label.1 b/util/grub-render-label.1 -new file mode 100644 -index 00000000000..4d51c8abf01 ---- /dev/null -+++ b/util/grub-render-label.1 -@@ -0,0 +1,51 @@ -+.TH GRUB-RENDER-LABEL 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-render-label\fR \(em Render an Apple disk label. -+ -+.SH SYNOPSIS -+\fBgrub-render-label\fR [-b | --bgcolor=\fICOLOR\fR] [-c | --color=\fICOLOR\fR] -+.RS 19 -+[-f | --font=\fIFILE\fR] [-i | --input=\fIFILE\fR] -+.RE -+.RS 19 -+[-o | --output=\fIFILE\fR] [-t | --text=\fISTRING\fR] -+.RE -+.RS 19 -+[-v | --verbose] -+ -+.SH DESCRIPTION -+\fBgrub-render-label\fR renders an Apple disk label (.disk_label) file. -+ -+ -+.SH OPTIONS -+.TP -+\fB--color\fR=\fICOLOR\fR -+Use \fICOLOR\fI as the color for generated labels. -+ -+.TP -+\fB--bgcolor\fR=\fICOLOR\fR -+Use \fICOLOR\fR as the background color for generated labels. -+ -+.TP -+\fB--font\fR=\fIFILE\fR -+Use \fIFILE\fR as the font file for generated labels. -+ -+.TP -+--input=\fIFILE\fR -+Read input text from \fIFILE\fR. -+ -+.TP -+--output=\fIFILE\fR -+Render output to \fIFILE\fR. -+ -+.TP -+--text=\fISTRING\fR -+Use \fISTRING\fR as input text. -+ -+.TP -+--verbose -+Print verbose output. -+ -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-script-check.1 b/util/grub-script-check.1 -new file mode 100644 -index 00000000000..0f1f625b05d ---- /dev/null -+++ b/util/grub-script-check.1 -@@ -0,0 +1,21 @@ -+.TH GRUB-SCRIPT-CHECK 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-script-check\fR \(em Check GRUB configuration file for syntax errors. -+ -+.SH SYNOPSIS -+\fBgrub-script-check\fR [-v | --verbose] \fIPATH\fR -+ -+.SH DESCRIPTION -+\fBgrub-script-check\fR verifies that a specified GRUB configuration file does not contain syntax errors. -+ -+.SH OPTIONS -+.TP -+--verbose -+Print verbose output. -+ -+.TP -+\fIPATH\fR -+Path of the file to use as input. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-set-default.8 b/util/grub-set-default.8 -new file mode 100644 -index 00000000000..a96265a1509 ---- /dev/null -+++ b/util/grub-set-default.8 -@@ -0,0 +1,21 @@ -+.TH GRUB-SET-DEFAULT 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-set-default\fR \(em Set the default boot menu entry for GRUB. -+ -+.SH SYNOPSIS -+\fBgrub-set-default\fR [--boot-directory=\fIDIR\fR] \fIMENU_ENTRY\fR -+ -+.SH DESCRIPTION -+\fBgrub-set-default\fR sets the default boot menu entry for all subsequent boots. This command only works for GRUB configuration files created with \fIGRUB_DEFAULT=saved\fR in \fI/etc/default/grub\fR. -+ -+.SH OPTIONS -+.TP -+--boot-directory=\fIDIR\fR -+Find GRUB images under \fIDIR/grub\fR. The default value is \fI/boot\fR, resulting in grub images being search for at \fI/boot/grub\fR. -+ -+.TP -+\fIMENU_ENTRY\fR -+A number, a menu item title or a menu item identifier. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-sparc64-setup.8 b/util/grub-sparc64-setup.8 -new file mode 100644 -index 00000000000..37ea2dd5eaa ---- /dev/null -+++ b/util/grub-sparc64-setup.8 -@@ -0,0 +1,12 @@ -+.TH GRUB-SPARC64-SETUP 3 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-sparc64-setup\fR \(em Set up a device to boot a sparc64 GRUB image. -+ -+.SH SYNOPSIS -+\fBgrub-sparc64-setup\fR [OPTIONS]. -+ -+.SH DESCRIPTION -+You should not normally run this program directly. Use grub-install instead. -+ -+.SH SEE ALSO -+.BR "info grub" diff --git a/0060-grub2-btrfs-04-grub2-install.patch b/0040-grub2-btrfs-04-grub2-install.patch similarity index 88% rename from 0060-grub2-btrfs-04-grub2-install.patch rename to 0040-grub2-btrfs-04-grub2-install.patch index f91c31a8..c7b56564 100644 --- a/0060-grub2-btrfs-04-grub2-install.patch +++ b/0040-grub2-btrfs-04-grub2-install.patch @@ -3,20 +3,22 @@ From: Michael Chang Date: Thu, 21 Aug 2014 03:39:11 +0000 Subject: [PATCH] grub2-btrfs-04-grub2-install +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/osdep/linux/getroot.c | 7 +++++++ grub-core/osdep/unix/config.c | 17 +++++++++++++++-- util/config.c | 10 ++++++++++ - util/grub-install.c | 15 +++++++++++++++ + util/grub-install.c | 14 ++++++++++++++ util/grub-mkrelpath.c | 6 ++++++ include/grub/emu/config.h | 1 + - 6 files changed, 54 insertions(+), 2 deletions(-) + 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 001b818fe58..caf9b1ccd3f 100644 +index 7dd775d2ad9..7c29b3523b4 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c -@@ -376,6 +376,7 @@ get_btrfs_fs_prefix (const char *mount_path) +@@ -373,6 +373,7 @@ get_btrfs_fs_prefix (const char *mount_path) return NULL; } @@ -24,7 +26,7 @@ index 001b818fe58..caf9b1ccd3f 100644 char ** grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) -@@ -519,6 +520,12 @@ again: +@@ -516,6 +517,12 @@ again: { ret = grub_find_root_devices_from_btrfs (dir); fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path); @@ -38,7 +40,7 @@ index 001b818fe58..caf9b1ccd3f 100644 else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) { diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c -index 7d6325138ce..46a881530c0 100644 +index 0b1f7618d21..0ce0e309ac0 100644 --- a/grub-core/osdep/unix/config.c +++ b/grub-core/osdep/unix/config.c @@ -82,6 +82,19 @@ grub_util_load_config (struct grub_util_config *cfg) @@ -94,19 +96,19 @@ index ebcdd8f5e22..f044a880a76 100644 sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0) { diff --git a/util/grub-install.c b/util/grub-install.c -index 0fbe7f78c6d..0f66f36d23a 100644 +index 7dc5657bb67..ec3ed49674b 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -827,6 +827,8 @@ fill_core_services (const char *core_services) - free (sysv_plist); +@@ -843,6 +843,8 @@ try_open (const char *path) } + #endif +extern int use_relative_path_on_btrfs; + int main (int argc, char *argv[]) { -@@ -860,6 +862,9 @@ main (int argc, char *argv[]) +@@ -876,6 +878,9 @@ main (int argc, char *argv[]) grub_util_load_config (&config); @@ -116,11 +118,10 @@ index 0fbe7f78c6d..0f66f36d23a 100644 if (!bootloader_id && config.grub_distributor) { char *ptr; -@@ -1352,6 +1357,16 @@ main (int argc, char *argv[]) - fprintf (load_cfg_f, "set debug='%s'\n", - debug_image); +@@ -1366,6 +1371,15 @@ main (int argc, char *argv[]) + relative_grubdir = xstrdup ("/"); } -+ + + if (config.is_suse_btrfs_snapshot_enabled + && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0) + { diff --git a/0061-grub2-btrfs-05-grub2-mkconfig.patch b/0041-grub2-btrfs-05-grub2-mkconfig.patch similarity index 92% rename from 0061-grub2-btrfs-05-grub2-mkconfig.patch rename to 0041-grub2-btrfs-05-grub2-mkconfig.patch index 8270505d..f1187fdc 100644 --- a/0061-grub2-btrfs-05-grub2-mkconfig.patch +++ b/0041-grub2-btrfs-05-grub2-mkconfig.patch @@ -13,10 +13,10 @@ Signed-off-by: Michael Chang 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 005f093809b..535c0f02499 100644 +index 28e92515795..884e4d363ca 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in -@@ -252,7 +252,8 @@ export GRUB_DEFAULT \ +@@ -256,7 +256,8 @@ export GRUB_DEFAULT \ GRUB_BADRAM \ GRUB_OS_PROBER_SKIP_LIST \ GRUB_DISABLE_SUBMENU \ @@ -27,10 +27,10 @@ index 005f093809b..535c0f02499 100644 if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 42c2ea9ba50..fafeac95061 100644 +index 33e1750aebb..0ba0e0e1c65 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in -@@ -52,7 +52,11 @@ grub_warn () +@@ -49,7 +49,11 @@ grub_warn () make_system_path_relative_to_its_root () { @@ -43,7 +43,7 @@ index 42c2ea9ba50..fafeac95061 100644 is_path_readable_by_grub () diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in -index 858b526c925..de727e6ee6b 100644 +index c2d8b093762..3e1b77265db 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@" @@ -90,10 +90,10 @@ index 858b526c925..de727e6ee6b 100644 +EOF +fi diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 0f3c19e30cc..cbfaca34cc7 100644 +index e8ab4082f87..48ff32c1da4 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -66,10 +66,14 @@ fi +@@ -68,10 +68,14 @@ fi case x"$GRUB_FS" in xbtrfs) @@ -109,10 +109,10 @@ index 0f3c19e30cc..cbfaca34cc7 100644 xzfs) rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in -index ada20775a14..e9e73b815fb 100644 +index 98ee5bc58dc..efcded0fbb4 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in -@@ -73,10 +73,14 @@ fi +@@ -75,10 +75,14 @@ fi case x"$GRUB_FS" in xbtrfs) diff --git a/0062-grub2-btrfs-06-subvol-mount.patch b/0042-grub2-btrfs-06-subvol-mount.patch similarity index 93% rename from 0062-grub2-btrfs-06-subvol-mount.patch rename to 0042-grub2-btrfs-06-subvol-mount.patch index 9a511759..7ddae569 100644 --- a/0062-grub2-btrfs-06-subvol-mount.patch +++ b/0042-grub2-btrfs-06-subvol-mount.patch @@ -3,6 +3,8 @@ From: Michael Chang Date: Tue, 9 Jul 2019 13:56:16 +0200 Subject: [PATCH] grub2-btrfs-06-subvol-mount +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/fs/btrfs.c | 195 +++++++++++++++++++++++++++++++++++++++- grub-core/osdep/linux/getroot.c | 148 +++++++++++++++++++++++++++++- @@ -11,7 +13,7 @@ Subject: [PATCH] grub2-btrfs-06-subvol-mount 4 files changed, 392 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 113c1f746c9..d323746ecfa 100644 +index d47f9ab0352..d44a1c73b8a 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -41,6 +41,7 @@ @@ -35,7 +37,7 @@ index 113c1f746c9..d323746ecfa 100644 static grub_err_t read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb) -@@ -1223,9 +1230,26 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) +@@ -1302,9 +1309,26 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) grub_err_t err; grub_uint64_t tree = 0; grub_uint8_t type; @@ -62,10 +64,10 @@ index 113c1f746c9..d323746ecfa 100644 if (err) return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path); -@@ -2199,11 +2223,20 @@ grub_btrfs_dir (grub_device_t device, const char *path, - int r = 0; +@@ -2316,11 +2340,20 @@ grub_btrfs_dir (grub_device_t device, const char *path, grub_uint64_t tree; grub_uint8_t type; + grub_size_t est_size = 0; + char *new_path = NULL; if (!data) @@ -84,7 +86,7 @@ index 113c1f746c9..d323746ecfa 100644 if (err) { grub_btrfs_unmount (data); -@@ -2305,11 +2338,21 @@ grub_btrfs_open (struct grub_file *file, const char *name) +@@ -2447,11 +2480,21 @@ grub_btrfs_open (struct grub_file *file, const char *name) struct grub_btrfs_inode inode; grub_uint8_t type; struct grub_btrfs_key key_in; @@ -107,7 +109,7 @@ index 113c1f746c9..d323746ecfa 100644 if (err) { grub_btrfs_unmount (data); -@@ -2480,6 +2523,150 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, +@@ -2686,6 +2729,150 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, return 0; } @@ -258,7 +260,7 @@ index 113c1f746c9..d323746ecfa 100644 static grub_err_t get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, grub_uint64_t objectid, grub_uint64_t offset, -@@ -2686,6 +2873,7 @@ static struct grub_fs grub_btrfs_fs = { +@@ -2892,6 +3079,7 @@ static struct grub_fs grub_btrfs_fs = { }; static grub_command_t cmd_info; @@ -266,7 +268,7 @@ index 113c1f746c9..d323746ecfa 100644 static grub_extcmd_t cmd_list_subvols; static char * -@@ -2749,6 +2937,9 @@ GRUB_MOD_INIT (btrfs) +@@ -2955,6 +3143,9 @@ GRUB_MOD_INIT (btrfs) cmd_info = grub_register_command("btrfs-info", grub_cmd_btrfs_info, "DEVICE", "Print BtrFS info about DEVICE."); @@ -277,10 +279,10 @@ index 113c1f746c9..d323746ecfa 100644 grub_cmd_btrfs_list_subvols, 0, "[-p|-n] [-o var] DEVICE", diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index caf9b1ccd3f..28790307e00 100644 +index 7c29b3523b4..74a48c03026 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c -@@ -107,6 +107,14 @@ struct btrfs_ioctl_search_key +@@ -103,6 +103,14 @@ struct btrfs_ioctl_search_key grub_uint32_t unused[9]; }; @@ -295,7 +297,7 @@ index caf9b1ccd3f..28790307e00 100644 struct btrfs_ioctl_search_args { struct btrfs_ioctl_search_key key; grub_uint64_t buf[(4096 - sizeof(struct btrfs_ioctl_search_key)) -@@ -378,6 +386,109 @@ get_btrfs_fs_prefix (const char *mount_path) +@@ -375,6 +383,109 @@ get_btrfs_fs_prefix (const char *mount_path) int use_relative_path_on_btrfs = 0; @@ -405,7 +407,7 @@ index caf9b1ccd3f..28790307e00 100644 char ** grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) { -@@ -519,12 +630,15 @@ again: +@@ -516,12 +627,15 @@ again: else if (grub_strcmp (entries[i].fstype, "btrfs") == 0) { ret = grub_find_root_devices_from_btrfs (dir); @@ -424,7 +426,7 @@ index caf9b1ccd3f..28790307e00 100644 } } else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) -@@ -1150,6 +1264,34 @@ grub_util_get_grub_dev_os (const char *os_dev) +@@ -1147,6 +1261,34 @@ grub_util_get_grub_dev_os (const char *os_dev) return grub_dev; } @@ -460,10 +462,10 @@ index caf9b1ccd3f..28790307e00 100644 grub_make_system_path_relative_to_its_root_os (const char *path) { diff --git a/util/grub-install.c b/util/grub-install.c -index 0f66f36d23a..84ed6e88ecb 100644 +index ec3ed49674b..d3ec2570d1d 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -1569,6 +1569,55 @@ main (int argc, char *argv[]) +@@ -1615,6 +1615,55 @@ main (int argc, char *argv[]) prefix_drive = xasprintf ("(%s)", grub_drives[0]); } diff --git a/0063-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch b/0043-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch similarity index 94% rename from 0063-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch rename to 0043-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch index b02ab53f..1b3a969a 100644 --- a/0063-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch +++ b/0043-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch @@ -10,10 +10,10 @@ Ref: bsc#953538 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index d323746ecfa..673ded03522 100644 +index d44a1c73b8a..dba86d19b1a 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -1260,11 +1260,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) +@@ -1339,11 +1339,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) return GRUB_ERR_NONE; } diff --git a/0064-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch b/0044-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch similarity index 96% rename from 0064-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch rename to 0044-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch index d4e20cd5..add5764e 100644 --- a/0064-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch +++ b/0044-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch @@ -3,15 +3,17 @@ From: Michael Chang Date: Thu, 11 May 2017 08:56:57 +0000 Subject: [PATCH] Grub not working correctly with btrfs snapshots (bsc#1026511) +Signed-off-by: Michael Chang +Signed-off-by: Robbie Harwood --- grub-core/fs/btrfs.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 673ded03522..2b21cbaa67e 100644 +index dba86d19b1a..87e4dd1a07a 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c -@@ -2887,6 +2887,238 @@ out: +@@ -3093,6 +3093,238 @@ out: return 0; } @@ -250,7 +252,7 @@ index 673ded03522..2b21cbaa67e 100644 static struct grub_fs grub_btrfs_fs = { .name = "btrfs", .fs_dir = grub_btrfs_dir, -@@ -2905,6 +3137,7 @@ static struct grub_fs grub_btrfs_fs = { +@@ -3111,6 +3343,7 @@ static struct grub_fs grub_btrfs_fs = { static grub_command_t cmd_info; static grub_command_t cmd_mount_subvol; static grub_extcmd_t cmd_list_subvols; @@ -258,7 +260,7 @@ index 673ded03522..2b21cbaa67e 100644 static char * subvolid_set_env (struct grub_env_var *var __attribute__ ((unused)), -@@ -2975,6 +3208,11 @@ GRUB_MOD_INIT (btrfs) +@@ -3181,6 +3414,11 @@ GRUB_MOD_INIT (btrfs) "[-p|-n] [-o var] DEVICE", "Print list of BtrFS subvolumes on " "DEVICE.", options); diff --git a/0065-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch b/0045-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch similarity index 82% rename from 0065-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch rename to 0045-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch index bde70969..b88fbab7 100644 --- a/0065-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch +++ b/0045-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch @@ -10,21 +10,21 @@ Signed-off-by: Peter Jones 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 585fa6662b6..03f9a9d0118 100644 +index a5cd99e5afa..8d98203a784 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h -@@ -24,6 +24,10 @@ - #include - #include +@@ -36,6 +36,10 @@ struct linux_arch_kernel_header { + struct grub_pe_image_header pe_image_header; + }; +/* Variables. */ +extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table); +extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle); + /* Functions. */ - void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol, + void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol, void *registration); -@@ -60,6 +64,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, +@@ -71,6 +75,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_uintn_t *descriptor_size, grub_efi_uint32_t *descriptor_version); void grub_efi_memory_fini (void); @@ -39,7 +39,7 @@ index 585fa6662b6..03f9a9d0118 100644 + grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; -+ status = efi_call_3 (b->allocate_pool, pool_type, buffer_size, buffer); ++ status = b->allocate_pool(pool_type, buffer_size, buffer); + return status; +} + @@ -51,14 +51,14 @@ index 585fa6662b6..03f9a9d0118 100644 + grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; -+ status = efi_call_1 (b->free_pool, buffer); ++ status = b->free_pool(buffer); + return status; +} + grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle); void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp); char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp); -@@ -115,10 +146,7 @@ void grub_efi_init (void); +@@ -140,10 +171,7 @@ void grub_efi_init (void); void grub_efi_fini (void); void grub_efi_set_prefix (void); diff --git a/0046-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch b/0046-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch deleted file mode 100644 index 78a6fa1b..00000000 --- a/0046-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch +++ /dev/null @@ -1,458 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Robert Marshall -Date: Mon, 16 Mar 2015 14:14:19 -0400 -Subject: [PATCH] Use Distribution Package Sort for grub2-mkconfig (#1124074) - -Users reported that newly installed kernels on their systems installed -with grub-mkconfig would not appear on the grub boot list in order -starting with the most recent. Added an option for rpm-based systems to -use the rpm-sort library to sort kernels instead. - -Resolves rhbz#1124074 - -Signed-off-by: Robert Marshall -[pjones: fix --enable-rpm-sort configure option] -Signed-off-by: Peter Jones -[thierry.vignaud: fix build with rpm-4.16] -Signed-off-by: Thierry Vignaud ---- - configure.ac | 38 +++++++ - Makefile.util.def | 16 +++ - util/grub-rpm-sort.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ - util/grub-mkconfig_lib.in | 11 +- - util/grub-rpm-sort.8 | 12 ++ - 5 files changed, 357 insertions(+), 1 deletion(-) - create mode 100644 util/grub-rpm-sort.c - create mode 100644 util/grub-rpm-sort.8 - -diff --git a/configure.ac b/configure.ac -index bec8535af70..fdcb452581c 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -72,6 +72,7 @@ grub_TRANSFORM([grub-mkrelpath]) - grub_TRANSFORM([grub-mkrescue]) - grub_TRANSFORM([grub-probe]) - grub_TRANSFORM([grub-reboot]) -+grub_TRANSFORM([grub-rpm-sort]) - grub_TRANSFORM([grub-script-check]) - grub_TRANSFORM([grub-set-default]) - grub_TRANSFORM([grub-sparc64-setup]) -@@ -95,6 +96,7 @@ grub_TRANSFORM([grub-mkrescue.1]) - grub_TRANSFORM([grub-mkstandalone.3]) - grub_TRANSFORM([grub-ofpathname.3]) - grub_TRANSFORM([grub-probe.3]) -+grub_TRANSFORM([grub-rpm-sort.8]) - grub_TRANSFORM([grub-reboot.3]) - grub_TRANSFORM([grub-render-label.3]) - grub_TRANSFORM([grub-script-check.3]) -@@ -1860,6 +1862,42 @@ fi - - AC_SUBST([LIBDEVMAPPER]) - -+AC_ARG_ENABLE([rpm-sort], -+ [AS_HELP_STRING([--enable-rpm-sort], -+ [enable native rpm sorting of kernels in grub (default=guessed)])]) -+if test x"$enable_rpm_sort" = xno ; then -+ rpm_sort_excuse="explicitly disabled" -+fi -+ -+if test x"$rpm_sort_excuse" = x ; then -+ # Check for rpmlib header. -+ AC_CHECK_HEADER([rpm/rpmlib.h], [], -+ [rpm_sort_excuse="need rpm/rpmlib header"]) -+fi -+ -+if test x"$rpm_sort_excuse" = x ; then -+ # Check for rpm library. -+ AC_CHECK_LIB([rpm], [rpmvercmp], [], -+ [rpm_sort_excuse="rpmlib missing rpmvercmp"]) -+fi -+ -+if test x"$rpm_sort_excuse" = x ; then -+ LIBRPM="-lrpm"; -+ AC_DEFINE([HAVE_RPM], [1], -+ [Define to 1 if you have the rpm library.]) -+fi -+ -+if test x"$LIBRPM" = x ; then -+ # Check for rpm library. -+ AC_CHECK_LIB([rpmio], [rpmvercmp], [], -+ [rpm_sort_excuse="rpmio missing rpmvercmp"]) -+ LIBRPM="-lrpmio"; -+ AC_DEFINE([HAVE_RPMIO], [1], -+ [Define to 1 if you have the rpm library.]) -+fi -+ -+AC_SUBST([LIBRPM]) -+ - LIBGEOM= - if test x$host_kernel = xkfreebsd; then - AC_CHECK_LIB([geom], [geom_gettree], [], -diff --git a/Makefile.util.def b/Makefile.util.def -index 2c9b283a230..ba4cf4b29b0 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -703,6 +703,22 @@ program = { - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; - }; - -+program = { -+ name = grub-rpm-sort; -+ mansection = 8; -+ installdir = sbin; -+ -+ common = grub-core/kern/emu/misc.c; -+ common = grub-core/kern/emu/argp_common.c; -+ common = grub-core/osdep/init.c; -+ common = util/misc.c; -+ common = util/grub-rpm-sort.c; -+ -+ ldadd = libgrubkern.a; -+ ldadd = grub-core/lib/gnulib/libgnu.a; -+ ldadd = '$(LIBDEVMAPPER) $(LIBRPM)'; -+}; -+ - script = { - name = grub-mkconfig; - common = util/grub-mkconfig.in; -diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c -new file mode 100644 -index 00000000000..f33bd1ed568 ---- /dev/null -+++ b/util/grub-rpm-sort.c -@@ -0,0 +1,281 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+static size_t -+read_file (const char *input, char **ret) -+{ -+ FILE *in; -+ size_t s; -+ size_t sz = 2048; -+ size_t offset = 0; -+ char *text; -+ -+ if (!strcmp(input, "-")) -+ in = stdin; -+ else -+ in = grub_util_fopen(input, "r"); -+ -+ text = xmalloc (sz); -+ -+ if (!in) -+ grub_util_error (_("cannot open `%s': %s"), input, strerror (errno)); -+ -+ while ((s = fread (text + offset, 1, sz - offset, in)) != 0) -+ { -+ offset += s; -+ if (sz - offset == 0) -+ { -+ sz += 2048; -+ text = xrealloc (text, sz); -+ } -+ } -+ -+ text[offset] = '\0'; -+ *ret = text; -+ -+ if (in != stdin) -+ fclose(in); -+ -+ return offset + 1; -+} -+ -+/* returns name/version/release */ -+/* NULL string pointer returned if nothing found */ -+static void -+split_package_string (char *package_string, char **name, -+ char **version, char **release) -+{ -+ char *package_version, *package_release; -+ -+ /* Release */ -+ package_release = strrchr (package_string, '-'); -+ -+ if (package_release != NULL) -+ *package_release++ = '\0'; -+ -+ *release = package_release; -+ -+ /* Version */ -+ package_version = strrchr(package_string, '-'); -+ -+ if (package_version != NULL) -+ *package_version++ = '\0'; -+ -+ *version = package_version; -+ /* Name */ -+ *name = package_string; -+ -+ /* Bubble up non-null values from release to name */ -+ if (*name == NULL) -+ { -+ *name = (*version == NULL ? *release : *version); -+ *version = *release; -+ *release = NULL; -+ } -+ if (*version == NULL) -+ { -+ *version = *release; -+ *release = NULL; -+ } -+} -+ -+/* -+ * package name-version-release comparator for qsort -+ * expects p, q which are pointers to character strings (char *) -+ * which will not be altered in this function -+ */ -+static int -+package_version_compare (const void *p, const void *q) -+{ -+ char *local_p, *local_q; -+ char *lhs_name, *lhs_version, *lhs_release; -+ char *rhs_name, *rhs_version, *rhs_release; -+ int vercmpflag = 0; -+ -+ local_p = alloca (strlen (*(char * const *)p) + 1); -+ local_q = alloca (strlen (*(char * const *)q) + 1); -+ -+ /* make sure these allocated */ -+ assert (local_p); -+ assert (local_q); -+ -+ strcpy (local_p, *(char * const *)p); -+ strcpy (local_q, *(char * const *)q); -+ -+ split_package_string (local_p, &lhs_name, &lhs_version, &lhs_release); -+ split_package_string (local_q, &rhs_name, &rhs_version, &rhs_release); -+ -+ /* Check Name and return if unequal */ -+ vercmpflag = rpmvercmp ((lhs_name == NULL ? "" : lhs_name), -+ (rhs_name == NULL ? "" : rhs_name)); -+ if (vercmpflag != 0) -+ return vercmpflag; -+ -+ /* Check version and return if unequal */ -+ vercmpflag = rpmvercmp ((lhs_version == NULL ? "" : lhs_version), -+ (rhs_version == NULL ? "" : rhs_version)); -+ if (vercmpflag != 0) -+ return vercmpflag; -+ -+ /* Check release and return the version compare value */ -+ vercmpflag = rpmvercmp ((lhs_release == NULL ? "" : lhs_release), -+ (rhs_release == NULL ? "" : rhs_release)); -+ -+ return vercmpflag; -+} -+ -+static void -+add_input (const char *filename, char ***package_names, size_t *n_package_names) -+{ -+ char *orig_input_buffer = NULL; -+ char *input_buffer; -+ char *position_of_newline; -+ char **names = *package_names; -+ char **new_names = NULL; -+ size_t n_names = *n_package_names; -+ -+ if (!*package_names) -+ new_names = names = xmalloc (sizeof (char *) * 2); -+ -+ if (read_file (filename, &orig_input_buffer) < 2) -+ { -+ if (new_names) -+ free (new_names); -+ if (orig_input_buffer) -+ free (orig_input_buffer); -+ return; -+ } -+ -+ input_buffer = orig_input_buffer; -+ while (input_buffer && *input_buffer && -+ (position_of_newline = strchrnul (input_buffer, '\n'))) -+ { -+ size_t sz = position_of_newline - input_buffer; -+ char *new; -+ -+ if (sz == 0) -+ { -+ input_buffer = position_of_newline + 1; -+ continue; -+ } -+ -+ new = xmalloc (sz+1); -+ strncpy (new, input_buffer, sz); -+ new[sz] = '\0'; -+ -+ names = xrealloc (names, sizeof (char *) * (n_names + 1)); -+ names[n_names] = new; -+ n_names++; -+ -+ /* move buffer ahead to next line */ -+ input_buffer = position_of_newline + 1; -+ if (*position_of_newline == '\0') -+ input_buffer = NULL; -+ } -+ -+ free (orig_input_buffer); -+ -+ *package_names = names; -+ *n_package_names = n_names; -+} -+ -+static char * -+help_filter (int key, const char *text, void *input __attribute__ ((unused))) -+{ -+ return (char *)text; -+} -+ -+static struct argp_option options[] = { -+ { 0, } -+}; -+ -+struct arguments -+{ -+ size_t ninputs; -+ size_t input_max; -+ char **inputs; -+}; -+ -+static error_t -+argp_parser (int key, char *arg, struct argp_state *state) -+{ -+ struct arguments *arguments = state->input; -+ switch (key) -+ { -+ case ARGP_KEY_ARG: -+ assert (arguments->ninputs < arguments->input_max); -+ arguments->inputs[arguments->ninputs++] = xstrdup (arg); -+ break; -+ default: -+ return ARGP_ERR_UNKNOWN; -+ } -+ return 0; -+} -+ -+static struct argp argp = { -+ options, argp_parser, N_("[INPUT_FILES]"), -+ N_("Sort a list of strings in RPM version sort order."), -+ NULL, help_filter, NULL -+}; -+ -+int -+main (int argc, char *argv[]) -+{ -+ struct arguments arguments; -+ char **package_names = NULL; -+ size_t n_package_names = 0; -+ int i; -+ -+ grub_util_host_init (&argc, &argv); -+ -+ memset (&arguments, 0, sizeof (struct arguments)); -+ arguments.input_max = argc+1; -+ arguments.inputs = xmalloc ((arguments.input_max + 1) -+ * sizeof (arguments.inputs[0])); -+ memset (arguments.inputs, 0, (arguments.input_max + 1) -+ * sizeof (arguments.inputs[0])); -+ -+ /* Parse our arguments */ -+ if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0) -+ grub_util_error ("%s", _("Error in parsing command line arguments\n")); -+ -+ /* If there's no inputs in argv, add one for stdin */ -+ if (!arguments.ninputs) -+ { -+ arguments.ninputs = 1; -+ arguments.inputs[0] = xmalloc (2); -+ strcpy(arguments.inputs[0], "-"); -+ } -+ -+ for (i = 0; i < arguments.ninputs; i++) -+ add_input(arguments.inputs[i], &package_names, &n_package_names); -+ -+ if (package_names == NULL || n_package_names < 1) -+ grub_util_error ("%s", _("Invalid input\n")); -+ -+ qsort (package_names, n_package_names, sizeof (char *), -+ package_version_compare); -+ -+ /* send sorted list to stdout */ -+ for (i = 0; i < n_package_names; i++) -+ { -+ fprintf (stdout, "%s\n", package_names[i]); -+ free (package_names[i]); -+ } -+ -+ free (package_names); -+ for (i = 0; i < arguments.ninputs; i++) -+ free (arguments.inputs[i]); -+ -+ free (arguments.inputs); -+ -+ return 0; -+} -diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 0f6505bf3b6..42c2ea9ba50 100644 ---- a/util/grub-mkconfig_lib.in -+++ b/util/grub-mkconfig_lib.in -@@ -33,6 +33,9 @@ fi - if test "x$grub_mkrelpath" = x; then - grub_mkrelpath="${bindir}/@grub_mkrelpath@" - fi -+if test "x$grub_rpm_sort" = x; then -+ grub_rpm_sort="${sbindir}/@grub_rpm_sort@" -+fi - - if command -v gettext >/dev/null; then - : -@@ -218,6 +221,12 @@ version_sort () - esac - } - -+if [ "x$grub_rpm_sort" != x -a -x "$grub_rpm_sort" ]; then -+ kernel_sort="$grub_rpm_sort" -+else -+ kernel_sort=version_sort -+fi -+ - version_test_numeric () - { - version_test_numeric_a="$1" -@@ -234,7 +243,7 @@ version_test_numeric () - version_test_numeric_a="$version_test_numeric_b" - version_test_numeric_b="$version_test_numeric_c" - fi -- if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then -+ if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | "$kernel_sort" | head -n 1 | grep -qx "$version_test_numeric_b" ; then - return 0 - else - return 1 -diff --git a/util/grub-rpm-sort.8 b/util/grub-rpm-sort.8 -new file mode 100644 -index 00000000000..8ce21488448 ---- /dev/null -+++ b/util/grub-rpm-sort.8 -@@ -0,0 +1,12 @@ -+.TH GRUB-RPM-SORT 8 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-rpm-sort\fR \(em Sort input according to RPM version compare. -+ -+.SH SYNOPSIS -+\fBgrub-rpm-sort\fR [OPTIONS]. -+ -+.SH DESCRIPTION -+You should not normally run this program directly. Use grub-mkconfig instead. -+ -+.SH SEE ALSO -+.BR "info grub" diff --git a/0046-Use-grub_efi_.-memory-helpers-where-reasonable.patch b/0046-Use-grub_efi_.-memory-helpers-where-reasonable.patch new file mode 100644 index 00000000..0523c643 --- /dev/null +++ b/0046-Use-grub_efi_.-memory-helpers-where-reasonable.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 1 Jun 2017 10:06:38 -0400 +Subject: [PATCH] Use grub_efi_...() memory helpers where reasonable. + +This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and +grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we +get more reasonable type checking. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/chainloader.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 1de98f78313..2036924504b 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -95,7 +95,7 @@ grub_chainloader_boot (void *context) + } + + if (exit_data) +- b->free_pool (exit_data); ++ grub_efi_free_pool (exit_data); + + grub_loader_unset (); + +@@ -419,7 +419,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_free (file_path); + + if (address) +- b->free_pages (address, pages); ++ grub_efi_free_pages (address, pages); + + if (image_handle != NULL) + b->unload_image (image_handle); diff --git a/0047-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch b/0047-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch new file mode 100644 index 00000000..c852ced5 --- /dev/null +++ b/0047-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 1 Jun 2017 10:07:50 -0400 +Subject: [PATCH] Add PRIxGRUB_EFI_STATUS and use it. + +This avoids syntax checkers getting confused about if it's llx or lx. + +Signed-off-by: Peter Jones +--- + include/grub/efi/api.h | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index c1b869db520..daa9268fdaa 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -577,7 +577,16 @@ typedef grub_uint64_t grub_efi_uint64_t; + typedef grub_uint8_t grub_efi_char8_t; + typedef grub_uint16_t grub_efi_char16_t; + ++ + typedef grub_efi_uintn_t grub_efi_status_t; ++/* Make grub_efi_status_t reasonably printable. */ ++#if GRUB_CPU_SIZEOF_VOID_P == 8 ++#define PRIxGRUB_EFI_STATUS "lx" ++#define PRIdGRUB_EFI_STATUS "ld" ++#else ++#define PRIxGRUB_EFI_STATUS "llx" ++#define PRIdGRUB_EFI_STATUS "lld" ++#endif + + /* + * On x86, the EFI calling convention may deviate from the local one, so diff --git a/0068-don-t-use-int-for-efi-status.patch b/0048-don-t-use-int-for-efi-status.patch similarity index 88% rename from 0068-don-t-use-int-for-efi-status.patch rename to 0048-don-t-use-int-for-efi-status.patch index 44d35554..de4367d4 100644 --- a/0068-don-t-use-int-for-efi-status.patch +++ b/0048-don-t-use-int-for-efi-status.patch @@ -8,10 +8,10 @@ Subject: [PATCH] don't use int for efi status 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 05d8237a9b2..ae9885edb84 100644 +index 885d7c6420e..2bb8a0e7a38 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -167,7 +167,7 @@ grub_reboot (void) +@@ -177,7 +177,7 @@ grub_reboot (void) void grub_exit (int retval) { diff --git a/0069-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch b/0049-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch similarity index 96% rename from 0069-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch rename to 0049-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch index 1014900c..44c08198 100644 --- a/0069-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch +++ b/0049-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch @@ -8,7 +8,7 @@ Subject: [PATCH] make GRUB_MOD_INIT() declare its function prototypes. 1 file changed, 2 insertions(+) diff --git a/include/grub/dl.h b/include/grub/dl.h -index b3753c9ca26..91933b85f2c 100644 +index cd1f46c8bad..f2bf50eb98d 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -54,6 +54,7 @@ grub_mod_fini (void) diff --git a/0070-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch b/0050-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch similarity index 92% rename from 0070-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch rename to 0050-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch index 890aa34c..8dfb85fd 100644 --- a/0070-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch +++ b/0050-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch @@ -16,10 +16,10 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/util/grub-install.c b/util/grub-install.c -index 84ed6e88ecb..a2bec7446cb 100644 +index d3ec2570d1d..66ef9494d9d 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -1190,18 +1190,8 @@ main (int argc, char *argv[]) +@@ -1234,18 +1234,8 @@ main (int argc, char *argv[]) char *d; is_guess = 1; diff --git a/0071-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch b/0051-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch similarity index 85% rename from 0071-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch rename to 0051-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch index 3fd779f7..026fe5e8 100644 --- a/0071-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch +++ b/0051-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch @@ -9,10 +9,10 @@ Signed-off-by: Peter Jones 1 file changed, 5 insertions(+) diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in -index e9e73b815fb..c23b064be6c 100644 +index efcded0fbb4..4ecf5deea17 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in -@@ -153,6 +153,7 @@ linux_entry_xsm () +@@ -156,6 +156,7 @@ linux_entry_xsm () else xen_rm_opts="no-real-mode edd=off" fi @@ -20,15 +20,15 @@ index e9e73b815fb..c23b064be6c 100644 ${xen_loader} ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts} echo '$(echo "$lmessage" | grub_quote)' ${module_loader} ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} -@@ -166,6 +167,7 @@ EOF - done - sed "s/^/$submenu_indentation/" << EOF +@@ -168,6 +169,7 @@ EOF + initrd_path="${rel_dirname}/${i}" + sed "s/^/$submenu_indentation/" << EOF echo '$(echo "$message" | grub_quote)' + insmod ${xen_module} ${module_loader} --nounzip $(echo $initrd_path) EOF - fi -@@ -253,13 +255,16 @@ while [ "x${xen_list}" != "x" ] ; do + done +@@ -269,13 +271,16 @@ for current_xen in ${reverse_sorted_xen_list}; do echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {" fi if ($grub_file --is-arm64-efi $current_xen); then diff --git a/0073-align-struct-efi_variable-better.patch b/0052-align-struct-efi_variable-better.patch similarity index 91% rename from 0073-align-struct-efi_variable-better.patch rename to 0052-align-struct-efi_variable-better.patch index ec26def5..24c32375 100644 --- a/0073-align-struct-efi_variable-better.patch +++ b/0052-align-struct-efi_variable-better.patch @@ -9,7 +9,7 @@ Subject: [PATCH] align struct efi_variable better... 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h -index 36d2dedf47e..9d93ba88bac 100644 +index 2ff42984545..6363fd522e1 100644 --- a/include/grub/efiemu/runtime.h +++ b/include/grub/efiemu/runtime.h @@ -33,5 +33,5 @@ struct efi_variable @@ -20,10 +20,10 @@ index 36d2dedf47e..9d93ba88bac 100644 +} GRUB_PACKED GRUB_ALIGNED(8); #endif /* ! GRUB_EFI_EMU_RUNTIME_HEADER */ diff --git a/include/grub/types.h b/include/grub/types.h -index 0a3ff159136..ba446d99040 100644 +index 064066e2e18..59e030268c2 100644 --- a/include/grub/types.h +++ b/include/grub/types.h -@@ -29,6 +29,7 @@ +@@ -30,6 +30,7 @@ #else #define GRUB_PACKED __attribute__ ((packed)) #endif diff --git a/0052-bz1374141-fix-incorrect-mask-for-ppc64.patch b/0052-bz1374141-fix-incorrect-mask-for-ppc64.patch deleted file mode 100644 index 1bb26586..00000000 --- a/0052-bz1374141-fix-incorrect-mask-for-ppc64.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Masahiro Matsuya -Date: Sat, 29 Oct 2016 08:35:26 +0900 -Subject: [PATCH] bz1374141 fix incorrect mask for ppc64 - -The netmask configured in firmware is not respected on ppc64 (big endian). -When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath(). - - /vdevice/l-lan@30000002:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512 - -The netmask in this bootpath is no problem, since it's a value specified in firmware. But, -The value of 'subnet_mask.ipv4' was set with 0xfffffc00, and __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)) returned 16 (not 22). -As a result, 16 was used for netmask wrongly. - -1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) -0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) -1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32 (subnet_mask.ipv4) - -And, the count of zero with __builtin_ctz can be 16. -This patch changes it as below. - -1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) -0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) -1111 1111 1111 1111 1111 1100 0000 0000 # grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)) -0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)) - -The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit) ---- - grub-core/net/drivers/ieee1275/ofnet.c | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - -diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c -index ac4e62a95c9..3860b6f78d8 100644 ---- a/grub-core/net/drivers/ieee1275/ofnet.c -+++ b/grub-core/net/drivers/ieee1275/ofnet.c -@@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, - flags); - inter->vlantag = vlantag; - grub_net_add_ipv4_local (inter, -- __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4))); -- -+ __builtin_clz (~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)))); - } - - if (gateway_addr.ipv4 != 0) diff --git a/0074-Add-BLS-support-to-grub-mkconfig.patch b/0053-Add-BLS-support-to-grub-mkconfig.patch similarity index 89% rename from 0074-Add-BLS-support-to-grub-mkconfig.patch rename to 0053-Add-BLS-support-to-grub-mkconfig.patch index 6c65440b..6b60ee76 100644 --- a/0074-Add-BLS-support-to-grub-mkconfig.patch +++ b/0053-Add-BLS-support-to-grub-mkconfig.patch @@ -20,30 +20,20 @@ kernels are found in the boot directory were proposed by Yclept Nemo and Tom Gundersen respectively. Signed-off-by: Peter Jones +[javierm: remove outdated URL for BLS document] Signed-off-by: Javier Martinez Canillas +[iwienand@redhat.com: skip machine ID check when updating entries] +Signed-off-by: Ian Wienand +[rharwood: use sort(1), commit message composits, drop man pages] +Signed-off-by: Robbie Harwood --- - util/grub-mkconfig.8 | 4 + util/grub-mkconfig.in | 9 +- util/grub-mkconfig_lib.in | 22 ++++- - util/grub.d/10_linux.in | 223 +++++++++++++++++++++++++++++++++++++++++++++- - 4 files changed, 252 insertions(+), 6 deletions(-) + util/grub.d/10_linux.in | 218 +++++++++++++++++++++++++++++++++++++++++++++- + 3 files changed, 243 insertions(+), 6 deletions(-) -diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8 -index a2d1f577b9b..434fa4deda4 100644 ---- a/util/grub-mkconfig.8 -+++ b/util/grub-mkconfig.8 -@@ -13,5 +13,9 @@ - \fB--output\fR=\fIFILE\fR - Write generated output to \fIFILE\fR. - -+.TP -+\fB--no-grubenv-update\fR -+Do not update variables in the grubenv file. -+ - .SH SEE ALSO - .BR "info grub" diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 535c0f02499..f55339a3f64 100644 +index 884e4d363ca..bec52e052fc 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -50,6 +50,8 @@ grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@" @@ -73,7 +63,7 @@ index 535c0f02499..f55339a3f64 100644 -*) gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 usage -@@ -253,7 +259,8 @@ export GRUB_DEFAULT \ +@@ -257,7 +263,8 @@ export GRUB_DEFAULT \ GRUB_OS_PROBER_SKIP_LIST \ GRUB_DISABLE_SUBMENU \ GRUB_DEFAULT_DTB \ @@ -84,7 +74,7 @@ index 535c0f02499..f55339a3f64 100644 if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index fafeac95061..d8bb4069360 100644 +index 0ba0e0e1c65..c2e107b41ab 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -30,6 +30,9 @@ fi @@ -97,7 +87,7 @@ index fafeac95061..d8bb4069360 100644 if test "x$grub_mkrelpath" = x; then grub_mkrelpath="${bindir}/@grub_mkrelpath@" fi -@@ -125,8 +128,19 @@ EOF +@@ -122,8 +125,19 @@ EOF fi } @@ -117,7 +107,7 @@ index fafeac95061..d8bb4069360 100644 old_ifs="$IFS" IFS=' ' -@@ -161,18 +175,18 @@ prepare_grub_to_access_device () +@@ -158,18 +172,18 @@ prepare_grub_to_access_device () # otherwise set root as per value in device.map. fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`" if [ "x$fs_hint" != x ]; then @@ -141,10 +131,10 @@ index fafeac95061..d8bb4069360 100644 fi IFS="$old_ifs" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index cbfaca34cc7..68adb55d893 100644 +index 48ff32c1da4..cd9aea0cc01 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -82,6 +82,223 @@ case x"$GRUB_FS" in +@@ -84,6 +84,218 @@ case x"$GRUB_FS" in ;; esac @@ -162,7 +152,7 @@ index cbfaca34cc7..68adb55d893 100644 +# +# The $bls_parser parses the BootLoaderSpec files stored in /boot/loader/entries and +# populates the boot menu. Please refer to the Boot Loader Specification documentation -+# for the files format: https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/. ++# for the files format: https://systemd.io/BOOT_LOADER_SPECIFICATION/. + +EOF +} @@ -204,25 +194,20 @@ index cbfaca34cc7..68adb55d893 100644 + +get_sorted_bls() +{ -+ if ! [ -d "${blsdir}" ] || ! [ -e /etc/machine-id ]; then -+ return -+ fi -+ -+ read machine_id < /etc/machine-id -+ if [ -z "${machine_id}" ]; then ++ if ! [ -d "${blsdir}" ]; then + return + fi + + local IFS=$'\n' + -+ files=($(for bls in ${blsdir}/${machine_id}-*.conf; do ++ files=($(for bls in ${blsdir}/*.conf; do + if ! [[ -e "${bls}" ]] ; then + continue + fi + bls="${bls%.conf}" + bls="${bls##*/}" + echo "${bls}" -+ done | ${kernel_sort} 2>/dev/null | tac)) || : ++ done | sort -Vr 2>/dev/null)) || : + + echo "${files[@]}" +} @@ -263,7 +248,7 @@ index cbfaca34cc7..68adb55d893 100644 +} + +# Make BLS the default if GRUB_ENABLE_BLSCFG was not set and grubby is not installed. -+if [ -z "${GRUB_ENABLE_BLSCFG}" ] && [ -z "$(which new-kernel-pkg 2> /dev/null)" ]; then ++if [ -z "${GRUB_ENABLE_BLSCFG}" ] && ! command -v new-kernel-pkg >/dev/null; then + GRUB_ENABLE_BLSCFG="true" +fi + @@ -368,7 +353,7 @@ index cbfaca34cc7..68adb55d893 100644 mktitle () { local title_type -@@ -121,6 +338,7 @@ linux_entry () +@@ -123,6 +335,7 @@ linux_entry () if [ -z "$boot_device_id" ]; then boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" fi @@ -376,15 +361,15 @@ index cbfaca34cc7..68adb55d893 100644 if [ x$type != xsimple ] ; then title=$(mktitle "$type" "$version") if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then -@@ -224,6 +442,7 @@ is_top_level=true - while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` +@@ -243,6 +456,7 @@ fi + is_top_level=true + for linux in ${reverse_sorted_list}; do gettext_printf "Found linux image: %s\n" "$linux" >&2 + basename=`basename $linux` dirname=`dirname $linux` rel_dirname=`make_system_path_relative_to_its_root $dirname` -@@ -262,7 +481,9 @@ while [ "x$list" != "x" ] ; do +@@ -283,7 +497,9 @@ for linux in ${reverse_sorted_list}; do for i in ${initrd}; do initrd_display="${initrd_display} ${dirname}/${i}" done diff --git a/0075-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch b/0054-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch similarity index 89% rename from 0075-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch rename to 0054-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch index 9ff4c8b8..4b925a58 100644 --- a/0075-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch +++ b/0054-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch @@ -12,10 +12,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index a3e215155bd..c60601b699d 100644 +index 465a8e74ea7..b1d399d37d7 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -1201,7 +1201,7 @@ static void __attribute__ ((noreturn)) +@@ -1303,7 +1303,7 @@ void __attribute__ ((noreturn)) grub_abort (void) { #ifndef GRUB_UTIL diff --git a/0054-Fix-up-some-man-pages-rpmdiff-noticed.patch b/0054-Fix-up-some-man-pages-rpmdiff-noticed.patch deleted file mode 100644 index 8016a621..00000000 --- a/0054-Fix-up-some-man-pages-rpmdiff-noticed.patch +++ /dev/null @@ -1,150 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 23 Sep 2014 09:58:49 -0400 -Subject: [PATCH] Fix up some man pages rpmdiff noticed. - ---- - configure.ac | 2 ++ - util/grub-macbless.8 | 26 +++++++++++++++++++ - util/grub-mkimage.1 | 2 +- - util/grub-syslinux2cfg.1 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ - 4 files changed, 94 insertions(+), 1 deletion(-) - create mode 100644 util/grub-macbless.8 - create mode 100644 util/grub-syslinux2cfg.1 - -diff --git a/configure.ac b/configure.ac -index ed31ea457d2..537ed411469 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -87,6 +87,7 @@ grub_TRANSFORM([grub-get-kernel-settings.3]) - grub_TRANSFORM([grub-glue-efi.3]) - grub_TRANSFORM([grub-install.1]) - grub_TRANSFORM([grub-kbdcomp.3]) -+grub_TRANSFORM([grub-macbless.8]) - grub_TRANSFORM([grub-menulst2cfg.1]) - grub_TRANSFORM([grub-mkconfig.1]) - grub_TRANSFORM([grub-mkfont.3]) -@@ -105,6 +106,7 @@ grub_TRANSFORM([grub-render-label.3]) - grub_TRANSFORM([grub-script-check.3]) - grub_TRANSFORM([grub-set-default.1]) - grub_TRANSFORM([grub-sparc64-setup.3]) -+grub_TRANSFORM([grub-syslinux2cfg.1]) - - # Optimization flag. Allow user to override. - if test "x$TARGET_CFLAGS" = x; then -diff --git a/util/grub-macbless.8 b/util/grub-macbless.8 -new file mode 100644 -index 00000000000..ae842f3a606 ---- /dev/null -+++ b/util/grub-macbless.8 -@@ -0,0 +1,26 @@ -+.TH GRUB-MACBLESS 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-macbless\fR \(em Mac-style bless utility for HFS or HFS+ -+ -+.SH SYNOPSIS -+\fBgrub-macbless\fR [-p | --ppc] [-v | --verbose] [-x | --x86] \fIFILE\fR -+ -+.SH DESCRIPTION -+\fBgrub-mkimage\fR blesses a file on an HFS or HFS+ file system, so that it -+can be used to boot a Mac. -+ -+.SH OPTIONS -+.TP -+--ppc -+Bless the file for use on PPC-based Macs. -+ -+.TP -+--verbose -+Print verbose messages. -+ -+.TP -+--x86 -+Bless the file for use on x86-based Macs. -+ -+.SH SEE ALSO -+.BR "info grub" -diff --git a/util/grub-mkimage.1 b/util/grub-mkimage.1 -index 4dea4f54597..0eaaafe505b 100644 ---- a/util/grub-mkimage.1 -+++ b/util/grub-mkimage.1 -@@ -17,7 +17,7 @@ - [-v | --verbose] \fIMODULES\fR - - .SH DESCRIPTION --\fBgrub-mkimage\fI builds a bootable image of GRUB. -+\fBgrub-mkimage\fR builds a bootable image of GRUB. - - .SH OPTIONS - .TP -diff --git a/util/grub-syslinux2cfg.1 b/util/grub-syslinux2cfg.1 -new file mode 100644 -index 00000000000..85309482718 ---- /dev/null -+++ b/util/grub-syslinux2cfg.1 -@@ -0,0 +1,65 @@ -+.TH GRUB-SYSLINUX2CFG 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-syslinux2cfg\fR \(em Transform a syslinux config file into a GRUB config. -+ -+.SH SYNOPSIS -+\fBgrub-syslinux2cfg\fR [-c | --cwd=\fRDIR\fI] [-r | --root=\fIDIR\fR] [-v | --verbose] -+.RE -+.RS 25 -+[-t | --target-root=\fIDIR\fR] [-T | --target-cwd=\fIDIR\fR] -+.RE -+.RS 25 -+[-o | --output=\fIFILE\fR] [[-i | --isolinux] | -+.RE -+.RS 46 -+ [-s | --syslinux] | -+.RE -+.RS 46 -+ [-p | --pxelinux]] \fIFILE\fR -+ -+.SH DESCRIPTION -+\fBgrub-syslinux2cfg\fR builds a GRUB configuration file out of an existing -+syslinux configuration file. -+ -+.SH OPTIONS -+.TP -+--cwd=\fIDIR\fR -+Set \fIDIR\fR as syslinux's working directory. The default is to use the -+parent directory of the input file. -+ -+.TP -+--root=\fIDIR\fR -+Set \fIDIR\fR as the root directory of the syslinux disk. The default value -+is "/". -+ -+.TP -+--verbose -+Print verbose messages. -+ -+.TP -+--target-root=\fIDIR\fR -+Root directory as it will be seen at runtime. The default value is "/". -+ -+.TP -+--target-cwd=\fIDIR\fR -+Working directory of syslinux as it will be seen at runtime. The default -+value is the parent directory of the input file. -+ -+.TP -+--output=\fIFILE\fR -+Write the new config file to \fIFILE\fR. The default value is standard output. -+ -+.TP -+--isolinux -+Assume that the input file is an isolinux configuration file. -+ -+.TP -+--pxelinux -+Assume that the input file is a pxelinux configuration file. -+ -+.TP -+--syslinux -+Assume that the input file is a syslinux configuration file. -+ -+.SH SEE ALSO -+.BR "info grub" diff --git a/0077-Add-grub2-switch-to-blscfg.patch b/0055-Add-grub2-switch-to-blscfg.patch similarity index 86% rename from 0077-Add-grub2-switch-to-blscfg.patch rename to 0055-Add-grub2-switch-to-blscfg.patch index ce40e907..76732205 100644 --- a/0077-Add-grub2-switch-to-blscfg.patch +++ b/0055-Add-grub2-switch-to-blscfg.patch @@ -7,20 +7,23 @@ Signed-off-by: Peter Jones Signed-off-by: Javier Martinez Canillas [jhlavac: Use ${etcdefaultgrub} instead of /etc/default/grub] Signed-off-by: Jan Hlavac +[rharwood: skip on ostree installations, migrate man to h2m] +Signed-off-by: Robbie Harwood --- - Makefile.util.def | 7 + - util/grub-set-password.in | 2 +- - util/grub-switch-to-blscfg.8 | 33 +++++ - util/grub-switch-to-blscfg.in | 317 ++++++++++++++++++++++++++++++++++++++++++ - 4 files changed, 358 insertions(+), 1 deletion(-) - create mode 100644 util/grub-switch-to-blscfg.8 + Makefile.util.def | 7 + + docs/man/grub-switch-to-blscfg.h2m | 2 + + util/grub-set-password.in | 2 +- + util/grub-switch-to-blscfg.in | 317 +++++++++++++++++++++++++++++++++++++ + util/grub.d/10_linux.in | 2 +- + 5 files changed, 328 insertions(+), 2 deletions(-) + create mode 100644 docs/man/grub-switch-to-blscfg.h2m create mode 100644 util/grub-switch-to-blscfg.in diff --git a/Makefile.util.def b/Makefile.util.def -index cdd2f51fe4b..afc4d7b0c3e 100644 +index 84a17ef5cfa..acbcc8c208c 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -1364,6 +1364,13 @@ program = { +@@ -1387,6 +1387,13 @@ program = { ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -34,6 +37,14 @@ index cdd2f51fe4b..afc4d7b0c3e 100644 program = { name = grub-glue-efi; mansection = 1; +diff --git a/docs/man/grub-switch-to-blscfg.h2m b/docs/man/grub-switch-to-blscfg.h2m +new file mode 100644 +index 00000000000..fa341426a50 +--- /dev/null ++++ b/docs/man/grub-switch-to-blscfg.h2m +@@ -0,0 +1,2 @@ ++[NAME] ++grub-switch-to-blscfg \- switch to using BLS config files diff --git a/util/grub-set-password.in b/util/grub-set-password.in index 5ebf50576d6..c0b5ebbfdc5 100644 --- a/util/grub-set-password.in @@ -46,45 +57,6 @@ index 5ebf50576d6..c0b5ebbfdc5 100644 if [ -d /sys/firmware/efi/efivars/ ]; then grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` else -diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 -new file mode 100644 -index 00000000000..9a886282976 ---- /dev/null -+++ b/util/grub-switch-to-blscfg.8 -@@ -0,0 +1,33 @@ -+.TH GRUB-SWITCH-TO-BLSCFG 1 "Wed Feb 26 2014" -+.SH NAME -+\fBgrub-switch-to-blscfg\fR \(em Switch to using BLS config files. -+ -+.SH SYNOPSIS -+\fBgrub-switch-to-blscfg\fR [--grub-directory=\fIDIR\fR] [--config-file=\fIFILE\fR] [--grub-defaults=\fIFILE\fR] -+ -+.SH DESCRIPTION -+\fBgrub-switch-to-blscfg\fR reconfigures grub-mkconfig to use BLS-style config files, and then regenerates the GRUB configuration. -+ -+.SH OPTIONS -+.TP -+--grub-directory=\fIDIR\fR -+Search for grub.cfg under \fIDIR\fR. The default value is \fI/boot/efi/EFI/\fBVENDOR\fR on UEFI machines and \fI/boot/grub2\fR elsewhere. -+ -+.TP -+--config-file=\fIFILE\fR -+The grub config file to use. The default value is \fI/etc/grub2-efi.cfg\fR on UEFI machines and \fI/etc/grub2.cfg\fR elsewhere. Symbolic links will be followed. -+ -+.TP -+--grub-defaults=\fIFILE\fR -+The defaults file for grub-mkconfig. The default value is \fI/etc/default/grub\fR. -+ -+.TP -+--bls-directory=\fIDIR\fR -+Create BootLoaderSpec fragments in \fIDIR\fR. The default value is \fI/boot/loader/entries\fR. -+ -+.TP -+--backup-suffix=\fSUFFIX\fR -+The suffix to use for saved backup files. The default value is \fI.bak\fR. -+ -+.SH SEE ALSO -+.BR "info grub" diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in new file mode 100644 index 00000000000..a851424beb2 @@ -157,7 +129,7 @@ index 00000000000..a851424beb2 +# Print the usage. +usage () { + gettext_printf "Usage: %s\n" "$self" -+ gettext "Switch to BLS config files.\n"; echo ++ gettext "Switch to BLS config files."; echo + echo + print_option_help "-h, --help" "$(gettext "print this message and exit")" + print_option_help "-V, --version" "$(gettext "print the version information and exit")" @@ -408,3 +380,16 @@ index 00000000000..a851424beb2 + +# Bye. +exit 0 +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index cd9aea0cc01..b8bc37e92aa 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -140,7 +140,7 @@ blsdir="/boot/loader/entries" + + get_sorted_bls() + { +- if ! [ -d "${blsdir}" ]; then ++ if ! [ -d "${blsdir}" ] || [ -f /run/ostree-booted ] || [ -d /ostree/repo ]; then + return + fi + diff --git a/0079-normal-don-t-draw-our-startup-message-if-debug-is-se.patch b/0056-normal-don-t-draw-our-startup-message-if-debug-is-se.patch similarity index 80% rename from 0079-normal-don-t-draw-our-startup-message-if-debug-is-se.patch rename to 0056-normal-don-t-draw-our-startup-message-if-debug-is-se.patch index 9922f2bb..7b261665 100644 --- a/0079-normal-don-t-draw-our-startup-message-if-debug-is-se.patch +++ b/0056-normal-don-t-draw-our-startup-message-if-debug-is-se.patch @@ -8,10 +8,10 @@ Subject: [PATCH] normal: don't draw our startup message if debug is set 1 file changed, 3 insertions(+) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index d5968797f4f..e349303c29b 100644 +index 3463f444f74..b5fa6156549 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -432,6 +432,9 @@ grub_normal_reader_init (int nested) +@@ -430,6 +430,9 @@ grub_normal_reader_init (int nested) const char *msg_esc = _("ESC at any time exits."); char *msg_formatted; @@ -20,4 +20,4 @@ index d5968797f4f..e349303c29b 100644 + msg_formatted = grub_xasprintf (_("Minimal BASH-like line editing is supported. For " "the first word, TAB lists possible command completions. Anywhere " - "else TAB lists possible device or file completions. %s"), + "else TAB lists possible device or file completions. To enable " diff --git a/0080-Work-around-some-minor-include-path-weirdnesses.patch b/0057-Work-around-some-minor-include-path-weirdnesses.patch similarity index 100% rename from 0080-Work-around-some-minor-include-path-weirdnesses.patch rename to 0057-Work-around-some-minor-include-path-weirdnesses.patch diff --git a/0081-Make-it-possible-to-enabled-build-id-sha1.patch b/0058-Make-it-possible-to-enabled-build-id-sha1.patch similarity index 93% rename from 0081-Make-it-possible-to-enabled-build-id-sha1.patch rename to 0058-Make-it-possible-to-enabled-build-id-sha1.patch index 356a4d81..201081d5 100644 --- a/0081-Make-it-possible-to-enabled-build-id-sha1.patch +++ b/0058-Make-it-possible-to-enabled-build-id-sha1.patch @@ -10,10 +10,10 @@ Signed-off-by: Peter Jones 2 files changed, 27 insertions(+) diff --git a/configure.ac b/configure.ac -index 537ed411469..b4455e4732d 100644 +index 3602b4ab62b..fcfbcbb664d 100644 --- a/configure.ac +++ b/configure.ac -@@ -1470,7 +1470,15 @@ grub_PROG_TARGET_CC +@@ -1540,7 +1540,15 @@ grub_PROG_TARGET_CC if test "x$TARGET_APPLE_LINKER" != x1 ; then grub_PROG_OBJCOPY_ABSOLUTE fi @@ -30,7 +30,7 @@ index 537ed411469..b4455e4732d 100644 if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then if test ! -z "$TARGET_IMG_LDSCRIPT"; then diff --git a/acinclude.m4 b/acinclude.m4 -index 6e14bb553c6..21238fcfd03 100644 +index fa7840f09af..0231e64e337 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -136,6 +136,25 @@ if test "x$grub_cv_prog_ld_build_id_none" = xyes; then diff --git a/0078-make-better-backtraces.patch b/0059-make-better-backtraces.patch similarity index 95% rename from 0078-make-better-backtraces.patch rename to 0059-make-better-backtraces.patch index a65af3db..d7f64a66 100644 --- a/0078-make-better-backtraces.patch +++ b/0059-make-better-backtraces.patch @@ -15,7 +15,7 @@ Signed-off-by: Peter Jones grub-core/kern/i386/backtrace.c | 125 ++++++++++++++++++++++++++++++++ grub-core/kern/i386/pc/init.c | 4 +- grub-core/kern/ieee1275/init.c | 1 - - grub-core/kern/misc.c | 13 ++-- + grub-core/kern/misc.c | 11 +-- grub-core/kern/mm.c | 6 +- grub-core/lib/arm64/backtrace.c | 62 ---------------- grub-core/lib/i386/backtrace.c | 78 -------------------- @@ -29,7 +29,7 @@ Signed-off-by: Peter Jones grub-core/kern/ia64/efi/startup.S | 3 +- grub-core/kern/sparc64/ieee1275/crt0.S | 3 +- grub-core/Makefile.am | 1 + - 24 files changed, 414 insertions(+), 167 deletions(-) + 24 files changed, 413 insertions(+), 166 deletions(-) rename grub-core/{lib => commands}/backtrace.c (98%) create mode 100644 grub-core/kern/arm64/backtrace.c create mode 100644 grub-core/kern/backtrace.c @@ -38,7 +38,7 @@ Signed-off-by: Peter Jones delete mode 100644 grub-core/lib/i386/backtrace.c diff --git a/Makefile.util.def b/Makefile.util.def -index afc4d7b0c3e..41906486a71 100644 +index acbcc8c208c..1079add5bbe 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -51,6 +51,12 @@ library = { @@ -55,10 +55,10 @@ index afc4d7b0c3e..41906486a71 100644 library = { diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 5354f9613d3..4b7c45a7b06 100644 +index 63f053b3add..6645fbae34f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -142,6 +142,12 @@ kernel = { +@@ -153,6 +153,12 @@ kernel = { common = kern/rescue_reader.c; common = kern/term.c; common = kern/verifiers.c; @@ -71,7 +71,7 @@ index 5354f9613d3..4b7c45a7b06 100644 noemu = kern/compiler-rt.c; noemu = kern/mm.c; -@@ -188,9 +194,6 @@ kernel = { +@@ -199,9 +205,6 @@ kernel = { softdiv = lib/division.c; @@ -81,7 +81,7 @@ index 5354f9613d3..4b7c45a7b06 100644 i386 = kern/i386/dl.c; i386_xen = kern/i386/dl.c; i386_xen_pvh = kern/i386/dl.c; -@@ -2398,15 +2401,12 @@ module = { +@@ -2455,15 +2458,12 @@ module = { module = { name = backtrace; @@ -331,10 +331,10 @@ index 00000000000..4a82e865cc6 + grub_backtrace (skip + 1); +} diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 7afb9e6f724..88d2077709e 100644 +index 0bf40caa61a..931f6e41442 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c -@@ -124,6 +124,50 @@ grub_dl_resolve_symbol (const char *name) +@@ -115,6 +115,50 @@ grub_dl_resolve_symbol (const char *name) return 0; } @@ -385,7 +385,7 @@ index 7afb9e6f724..88d2077709e 100644 /* Register a symbol with the name NAME and the address ADDR. */ grub_err_t grub_dl_register_symbol (const char *name, void *addr, int isfunc, -@@ -336,6 +380,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) +@@ -330,6 +374,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) const char *str; Elf_Word size, entsize; @@ -525,7 +525,7 @@ index 00000000000..2413f9a57db +#endif +} diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c -index 27bc68b8a53..b51d0abfa6e 100644 +index 326d491c586..fe7ad14d45c 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -153,7 +153,7 @@ compact_mem_regions (void) @@ -537,7 +537,7 @@ index 27bc68b8a53..b51d0abfa6e 100644 /* Helper for grub_machine_init. */ static int -@@ -217,7 +217,7 @@ grub_machine_init (void) +@@ -226,7 +226,7 @@ grub_machine_init (void) /* This has to happen before any BIOS calls. */ grub_via_workaround_init (); @@ -547,27 +547,23 @@ index 27bc68b8a53..b51d0abfa6e 100644 /* Initialize the console as early as possible. */ grub_console_init (); diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index 0cd2a627231..937c1bc44cb 100644 +index 51c1e1c9d9f..c4d6962197b 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c -@@ -63,7 +63,6 @@ - #define HEAP_MAX_ADDR (unsigned long) (32 * 1024 * 1024) - #endif +@@ -70,7 +70,6 @@ + */ + #define RUNTIME_MIN_SPACE (128UL * 1024 * 1024) -extern char _start[]; extern char _end[]; #ifdef __sparc__ diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index c60601b699d..a432a6be54a 100644 +index b1d399d37d7..779586658cb 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -1197,15 +1197,15 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) - - - /* Abort GRUB. This function does not return. */ --static void __attribute__ ((noreturn)) -+static inline void __attribute__ ((noreturn)) +@@ -1302,12 +1302,12 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) + void __attribute__ ((noreturn)) grub_abort (void) { -#ifndef GRUB_UTIL @@ -584,7 +580,7 @@ index c60601b699d..a432a6be54a 100644 #ifndef GRUB_UTIL if (grub_term_inputs) -@@ -1232,6 +1232,7 @@ grub_fatal (const char *fmt, ...) +@@ -1334,6 +1334,7 @@ grub_fatal (const char *fmt, ...) { va_list ap; @@ -593,10 +589,10 @@ index c60601b699d..a432a6be54a 100644 grub_vprintf (_(fmt), ap); va_end (ap); diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c -index c070afc621f..d8c8377578b 100644 +index 027a25cd1f0..1aeeba9e27e 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c -@@ -97,13 +97,13 @@ get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r) +@@ -144,13 +144,13 @@ get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r) break; if (! *r) @@ -787,10 +783,10 @@ index 395519762f0..275cf85e2d3 100644 #endif diff --git a/include/grub/dl.h b/include/grub/dl.h -index 91933b85f2c..2f76e6b0437 100644 +index f2bf50eb98d..8a3d188d1d1 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h -@@ -259,6 +259,8 @@ grub_dl_is_persistent (grub_dl_t mod) +@@ -258,6 +258,8 @@ grub_dl_is_persistent (grub_dl_t mod) #endif @@ -897,7 +893,7 @@ index 03b916f0534..701bf63abcf 100644 ba codestart mov %o4, %o0 diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index 80e7a83edf9..f512573c0da 100644 +index f18550c1c98..b7192a3da82 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -66,6 +66,7 @@ CLEANFILES += grub_script.yy.c grub_script.yy.h diff --git a/0060-Fixup-for-newer-compiler.patch b/0060-Fixup-for-newer-compiler.patch new file mode 100644 index 00000000..b0c1966d --- /dev/null +++ b/0060-Fixup-for-newer-compiler.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 May 2018 13:40:19 -0400 +Subject: [PATCH] Fixup for newer compiler + +--- + grub-core/fs/btrfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 87e4dd1a07a..ad35e75750b 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -218,7 +218,7 @@ struct grub_btrfs_inode + grub_uint64_t size; + grub_uint8_t dummy2[0x70]; + struct grub_btrfs_time mtime; +-} GRUB_PACKED; ++} GRUB_PACKED __attribute__ ((aligned(8))); + + struct grub_btrfs_extent_data + { diff --git a/0085-Don-t-attempt-to-export-the-start-and-_start-symbols.patch b/0061-Don-t-attempt-to-export-the-start-and-_start-symbols.patch similarity index 100% rename from 0085-Don-t-attempt-to-export-the-start-and-_start-symbols.patch rename to 0061-Don-t-attempt-to-export-the-start-and-_start-symbols.patch diff --git a/0086-Fixup-for-newer-compiler.patch b/0062-Fixup-for-newer-compiler.patch similarity index 79% rename from 0086-Fixup-for-newer-compiler.patch rename to 0062-Fixup-for-newer-compiler.patch index 11ed6e52..0d495c14 100644 --- a/0086-Fixup-for-newer-compiler.patch +++ b/0062-Fixup-for-newer-compiler.patch @@ -8,15 +8,15 @@ Subject: [PATCH] Fixup for newer compiler 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/Makefile.common b/conf/Makefile.common -index 191b1a70c6b..5f0ef969857 100644 +index ece9ed8a1bf..6262f21a772 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common -@@ -38,7 +38,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding +@@ -41,7 +41,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) -STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx +STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes - - CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding - LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d + if !COND_emu + if COND_HAVE_ASM_USCORE + LDFLAGS_KERNEL += -Wl,--defsym=_malloc=_grub_malloc -Wl,--defsym=_free=_grub_free diff --git a/0087-Add-support-for-non-Ethernet-network-cards.patch b/0063-Add-support-for-non-Ethernet-network-cards.patch similarity index 90% rename from 0087-Add-support-for-non-Ethernet-network-cards.patch rename to 0063-Add-support-for-non-Ethernet-network-cards.patch index 02fb951f..95ea8fc9 100644 --- a/0087-Add-support-for-non-Ethernet-network-cards.patch +++ b/0063-Add-support-for-non-Ethernet-network-cards.patch @@ -23,22 +23,22 @@ Signed-off-by: Andrzej Kacprowski [msalter: Fix max string calculation in grub_net_hwaddr_to_str] Signed-off-by: Mark Salter --- - grub-core/net/arp.c | 155 ++++++++++++++++++++++----------- + grub-core/net/arp.c | 156 ++++++++++++++++++++++----------- grub-core/net/bootp.c | 15 ++-- grub-core/net/drivers/efi/efinet.c | 8 +- grub-core/net/drivers/emu/emunet.c | 1 + grub-core/net/drivers/i386/pc/pxe.c | 13 +-- grub-core/net/drivers/ieee1275/ofnet.c | 2 + grub-core/net/drivers/uboot/ubootnet.c | 1 + - grub-core/net/ethernet.c | 88 +++++++++---------- + grub-core/net/ethernet.c | 89 +++++++++---------- grub-core/net/icmp6.c | 15 ++-- grub-core/net/ip.c | 4 +- grub-core/net/net.c | 50 ++++++----- include/grub/net.h | 19 ++-- - 12 files changed, 219 insertions(+), 152 deletions(-) + 12 files changed, 220 insertions(+), 153 deletions(-) diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c -index 54306e3b16d..67b409a8acc 100644 +index 1d367436cfc..8bf0a06e193 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -31,22 +31,12 @@ enum @@ -137,7 +137,7 @@ index 54306e3b16d..67b409a8acc 100644 nbd = nb.data; send_ethernet_packet (inf, &nb, target_mac_addr, GRUB_NET_ETHERTYPE_ARP); -@@ -114,28 +124,53 @@ grub_err_t +@@ -114,30 +124,56 @@ grub_err_t grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, grub_uint16_t *vlantag) { @@ -177,33 +177,36 @@ index 54306e3b16d..67b409a8acc 100644 + + /* The source protocol address. */ sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; -+ grub_memcpy(&sender_addr.ipv4, tmp_ptr, pln); -+ tmp_ptr += pln; -+ -+ grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); -+ -+ /* The target hardware address. */ -+ tmp_ptr += hln; -+ -+ /* The target protocol address. */ - target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; +- target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - sender_addr.ipv4 = arp_packet->sender_ip; - target_addr.ipv4 = arp_packet->recv_ip; + sender_addr.option = 0; + target_addr.option = 0; - if (arp_packet->sender_ip == pending_req) -+ grub_memcpy(&target_addr.ipv4, tmp_ptr, pln); -+ -+ if (sender_addr.ipv4 == pending_req) - have_pending = 1; +- have_pending = 1; - sender_mac_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - grub_memcpy (sender_mac_addr.mac, arp_packet->sender_mac, - sizeof (sender_mac_addr.mac)); -- grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); -- ++ grub_memcpy(&target_addr.ipv4, tmp_ptr, pln); ++ tmp_ptr += pln; ++ + grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); + ++ /* The target hardware address. */ ++ tmp_ptr += hln; ++ ++ /* The target protocol address. */ ++ target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; ++ grub_memcpy(&target_addr.ipv4, tmp_ptr, pln); ++ ++ if (sender_addr.ipv4 == pending_req) ++ have_pending = 1; ++ FOR_NET_NETWORK_LEVEL_INTERFACES (inf) { /* Verify vlantag id */ -@@ -148,11 +183,11 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, +@@ -150,11 +186,11 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, /* Am I the protocol address target? */ if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 @@ -217,7 +220,7 @@ index 54306e3b16d..67b409a8acc 100644 grub_uint8_t arp_data[128]; grub_err_t err; -@@ -161,25 +196,39 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, +@@ -163,25 +199,39 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, grub_netbuff_clear (&nb_reply); grub_netbuff_reserve (&nb_reply, 128); @@ -271,10 +274,10 @@ index 54306e3b16d..67b409a8acc 100644 /* Change operation to REPLY and send packet */ send_ethernet_packet (inf, &nb_reply, target, GRUB_NET_ETHERTYPE_ARP); diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index e28fb6a09f9..08b6b2b5d6c 100644 +index e0aec25233d..76e4c11a46f 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c -@@ -233,7 +233,6 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -325,7 +325,6 @@ grub_net_configure_by_dhcp_ack (const char *name, int is_def, char **device, char **path) { grub_net_network_level_address_t addr; @@ -282,7 +285,7 @@ index e28fb6a09f9..08b6b2b5d6c 100644 struct grub_net_network_level_interface *inter; int mask = -1; char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; -@@ -250,12 +249,8 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -343,12 +342,8 @@ grub_net_configure_by_dhcp_ack (const char *name, if (path) *path = 0; @@ -297,7 +300,7 @@ index e28fb6a09f9..08b6b2b5d6c 100644 if (!inter) return 0; -@@ -567,7 +562,9 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) +@@ -660,7 +655,9 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) grub_memset (pack, 0, sizeof (*pack)); pack->opcode = 1; pack->hw_type = 1; @@ -308,20 +311,20 @@ index e28fb6a09f9..08b6b2b5d6c 100644 err = grub_get_datetime (&date); if (err || !grub_datetime2unixtime (&date, &t)) { -@@ -580,7 +577,7 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) +@@ -673,7 +670,7 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) else pack->ident = iface->xid; - grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, 6); + grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, pack->hw_len); - grub_netbuff_push (nb, sizeof (*udph)); - + err = grub_netbuff_push (nb, sizeof (*udph)); + if (err) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 173fb63153c..a673bea807a 100644 +index 3e2432fb61c..7deb0a32efd 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -279,6 +279,9 @@ grub_efinet_findcards (void) +@@ -288,6 +288,9 @@ grub_efinet_findcards (void) /* This should not happen... Why? */ continue; @@ -329,12 +332,12 @@ index 173fb63153c..a673bea807a 100644 + continue; + if (net->mode->state == GRUB_EFI_NETWORK_STOPPED - && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) + && net->start (net) != GRUB_EFI_SUCCESS) continue; -@@ -315,10 +318,11 @@ grub_efinet_findcards (void) - card->name = grub_xasprintf ("efinet%d", i++); - card->driver = &efidriver; - card->flags = 0; +@@ -332,10 +335,11 @@ grub_efinet_findcards (void) + * such as LoadFile2 for initrd loading. + */ + card->flags = GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW; - card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + card->default_address.type = net->mode->if_type; + card->default_address.len = net->mode->hwaddr_size; @@ -346,7 +349,7 @@ index 173fb63153c..a673bea807a 100644 card->efi_handle = *handle; diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c -index b194920861f..5b6c5e16a6d 100644 +index 5f311d40f49..7461d13bbc2 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -46,6 +46,7 @@ static struct grub_net_card emucard = @@ -358,7 +361,7 @@ index b194920861f..5b6c5e16a6d 100644 }, .flags = 0 diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c -index 3f4152d036c..9f8fb4b6d2b 100644 +index db17186ee7d..816d1d0eeda 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -386,20 +386,21 @@ GRUB_MOD_INIT(pxe) @@ -390,7 +393,7 @@ index 3f4152d036c..9f8fb4b6d2b 100644 grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c -index 3860b6f78d8..bcb3f9ea02d 100644 +index 78f03df8e21..c56461ff1ae 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -160,6 +160,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, @@ -401,7 +404,7 @@ index 3860b6f78d8..bcb3f9ea02d 100644 args = bootpath + grub_strlen (devpath) + 1; do -@@ -503,6 +504,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias) +@@ -491,6 +492,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias) grub_memcpy (&lla.mac, pprop, 6); lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; @@ -410,7 +413,7 @@ index 3860b6f78d8..bcb3f9ea02d 100644 card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; diff --git a/grub-core/net/drivers/uboot/ubootnet.c b/grub-core/net/drivers/uboot/ubootnet.c -index 056052e40d5..22ebcbf211e 100644 +index b9d5a0cd494..9f3354a1b74 100644 --- a/grub-core/net/drivers/uboot/ubootnet.c +++ b/grub-core/net/drivers/uboot/ubootnet.c @@ -131,6 +131,7 @@ GRUB_MOD_INIT (ubootnet) @@ -422,7 +425,7 @@ index 056052e40d5..22ebcbf211e 100644 card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; card->txbuf = grub_zalloc (card->txbufsize); diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c -index 4d7ceed6f93..9aae83a5eb4 100644 +index 707bbb12cb2..1441a1bacff 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -29,13 +29,6 @@ @@ -447,7 +450,7 @@ index 4d7ceed6f93..9aae83a5eb4 100644 + grub_uint8_t *eth; grub_err_t err; - grub_uint8_t etherhdr_size; -- grub_uint16_t vlantag_id = VLANTAG_IDENTIFIER; +- grub_uint16_t vlantag_id = grub_cpu_to_be16_compile_time (VLANTAG_IDENTIFIER); + grub_uint32_t vlantag = 0; + grub_uint8_t hw_addr_len = inf->card->default_address.len; + grub_uint8_t etherhdr_size = 2 * hw_addr_len + 2; @@ -487,7 +490,7 @@ index 4d7ceed6f93..9aae83a5eb4 100644 if (!inf->card->opened) { err = GRUB_ERR_NONE; -@@ -85,18 +91,6 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, +@@ -85,19 +91,6 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, inf->card->opened = 1; } @@ -499,14 +502,15 @@ index 4d7ceed6f93..9aae83a5eb4 100644 - (char *) nb->data + etherhdr_size - 6, 2); - - /* Add the tag in the middle */ +- grub_uint16_t vlan = grub_cpu_to_be16 (inf->vlantag); - grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2); -- grub_memcpy ((char *) nb->data + etherhdr_size - 4, (char *) &(inf->vlantag), 2); +- grub_memcpy ((char *) nb->data + etherhdr_size - 4, &vlan, 2); - } - return inf->card->driver->send (inf->card, nb); } -@@ -104,31 +98,40 @@ grub_err_t +@@ -105,31 +98,40 @@ grub_err_t grub_net_recv_ethernet_packet (struct grub_net_buff *nb, struct grub_net_card *card) { @@ -528,7 +532,7 @@ index 4d7ceed6f93..9aae83a5eb4 100644 - /* Check if a vlan-tag is present. If so, the ethernet header is 4 bytes */ - /* longer than the original one. The vlantag id is extracted and the header */ - /* is reseted to the original size. */ -- if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == VLANTAG_IDENTIFIER) +- if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == grub_cpu_to_be16_compile_time (VLANTAG_IDENTIFIER)) + hwaddress.type = card->default_address.type; + hwaddress.len = hw_addr_len; + grub_memcpy (hwaddress.mac, eth, hw_addr_len); @@ -542,7 +546,7 @@ index 4d7ceed6f93..9aae83a5eb4 100644 + type = grub_be_to_cpu16 (*(grub_uint16_t*)(eth)); + if (type == VLANTAG_IDENTIFIER) { -- vlantag = grub_get_unaligned16 (nb->data + etherhdr_size); +- vlantag = grub_be_to_cpu16 (grub_get_unaligned16 (nb->data + etherhdr_size)); + /* Skip vlan tag */ + eth += 2; + vlantag = grub_be_to_cpu16 (*(grub_uint16_t*)(eth)); @@ -559,7 +563,7 @@ index 4d7ceed6f93..9aae83a5eb4 100644 err = grub_netbuff_pull (nb, etherhdr_size); if (err) return err; -@@ -148,11 +151,6 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, +@@ -149,11 +151,6 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, } } @@ -572,7 +576,7 @@ index 4d7ceed6f93..9aae83a5eb4 100644 { /* ARP packet. */ diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c -index 2cbd95dce25..56a3ec5c8e8 100644 +index 9a8c4511285..5924fd53aca 100644 --- a/grub-core/net/icmp6.c +++ b/grub-core/net/icmp6.c @@ -231,8 +231,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, @@ -612,10 +616,10 @@ index 2cbd95dce25..56a3ec5c8e8 100644 } if (ohdr->type == OPTION_PREFIX && ohdr->len == 4) diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c -index ea5edf8f1f6..a5896f6dc26 100644 +index f967618e53f..3c475762cc0 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c -@@ -276,8 +276,8 @@ handle_dgram (struct grub_net_buff *nb, +@@ -316,8 +316,8 @@ handle_dgram (struct grub_net_buff *nb, if (inf->card == card && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV && inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET @@ -627,7 +631,7 @@ index ea5edf8f1f6..a5896f6dc26 100644 grub_net_process_dhcp (nb, inf); grub_netbuff_free (nb); diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 22f2689aaeb..a46f82362ed 100644 +index 20c55257647..fa6b6537142 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -133,8 +133,9 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, @@ -650,7 +654,7 @@ index 22f2689aaeb..a46f82362ed 100644 hw_addr->mac[0] = 0x33; hw_addr->mac[1] = 0x33; hw_addr->mac[2] = ((grub_be_to_cpu64 (proto_addr->ipv6[1]) >> 24) & 0xff); -@@ -762,23 +764,23 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) +@@ -772,23 +774,23 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) void grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) { @@ -688,8 +692,8 @@ index 22f2689aaeb..a46f82362ed 100644 - grub_printf (_("Unsupported hw address type %d\n"), addr->type); } - int -@@ -789,13 +791,17 @@ grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, + void +@@ -813,13 +815,17 @@ grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, return -1; if (a->type > b->type) return +1; @@ -713,7 +717,7 @@ index 22f2689aaeb..a46f82362ed 100644 int diff --git a/include/grub/net.h b/include/grub/net.h -index 8a05ec4fe7a..af0404db7e3 100644 +index ff901b96e22..1d76fd9a1f5 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -29,7 +29,8 @@ @@ -728,7 +732,7 @@ index 8a05ec4fe7a..af0404db7e3 100644 GRUB_NET_OUR_IPV4_HEADER_SIZE = 20, @@ -42,15 +43,17 @@ enum - typedef enum grub_link_level_protocol_id + typedef enum grub_link_level_protocol_id { - GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET + /* IANA ARP constant to define hardware type. */ @@ -746,7 +750,7 @@ index 8a05ec4fe7a..af0404db7e3 100644 }; } grub_net_link_level_address_t; -@@ -566,11 +569,13 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a, +@@ -588,11 +591,13 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a, #define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX") /* @@ -762,5 +766,5 @@ index 8a05ec4fe7a..af0404db7e3 100644 + "XX:XX:XX:XX:XX:XX:XX:XX:"\ + "XX:XX:XX:XX:XX:XX:XX:XX")) - void - grub_net_addr_to_str (const grub_net_network_level_address_t *target, + /* Max VLAN id = 4094 */ + #define GRUB_NET_MAX_STR_VLAN_LEN (sizeof ("vlanXXXX")) diff --git a/0090-efinet-UEFI-IPv6-PXE-support.patch b/0064-efinet-UEFI-IPv6-PXE-support.patch similarity index 92% rename from 0090-efinet-UEFI-IPv6-PXE-support.patch rename to 0064-efinet-UEFI-IPv6-PXE-support.patch index d8b22b8c..2d8a3ae4 100644 --- a/0090-efinet-UEFI-IPv6-PXE-support.patch +++ b/0064-efinet-UEFI-IPv6-PXE-support.patch @@ -15,12 +15,12 @@ Signed-off-by: Ken Lin 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 8e25680db0c..014e5bf9802 100644 +index 7deb0a32efd..92bb7444782 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -409,6 +409,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -430,6 +430,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, grub_print_error (); - if (device && path) + if (inter && device && path) grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); + if (grub_errno) + grub_print_error (); @@ -28,10 +28,10 @@ index 8e25680db0c..014e5bf9802 100644 else { diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 7614b58dca8..91ab528e4d0 100644 +index daa9268fdaa..53f5c781ac3 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -1524,31 +1524,6 @@ typedef union +@@ -1571,31 +1571,6 @@ typedef union grub_efi_pxe_dhcpv6_packet_t dhcpv6; } grub_efi_pxe_packet_t; @@ -63,7 +63,7 @@ index 7614b58dca8..91ab528e4d0 100644 typedef struct grub_efi_pxe_icmp_error { grub_efi_uint8_t type; -@@ -1574,6 +1549,48 @@ typedef struct grub_efi_pxe_tftp_error +@@ -1621,6 +1596,48 @@ typedef struct grub_efi_pxe_tftp_error grub_efi_char8_t error_string[127]; } grub_efi_pxe_tftp_error_t; @@ -112,7 +112,7 @@ index 7614b58dca8..91ab528e4d0 100644 typedef struct grub_efi_pxe_mode { grub_efi_boolean_t started; -@@ -1605,9 +1622,9 @@ typedef struct grub_efi_pxe_mode +@@ -1652,9 +1669,9 @@ typedef struct grub_efi_pxe_mode grub_efi_pxe_packet_t pxe_bis_reply; grub_efi_pxe_ip_filter_t ip_filter; grub_efi_uint32_t arp_cache_entries; diff --git a/0091-grub.texi-Add-net_bootp6-doument.patch b/0065-grub.texi-Add-net_bootp6-doument.patch similarity index 88% rename from 0091-grub.texi-Add-net_bootp6-doument.patch rename to 0065-grub.texi-Add-net_bootp6-doument.patch index 3f8ec97a..72863180 100644 --- a/0091-grub.texi-Add-net_bootp6-doument.patch +++ b/0065-grub.texi-Add-net_bootp6-doument.patch @@ -12,10 +12,10 @@ Signed-off-by: Ken Lin 1 file changed, 17 insertions(+) diff --git a/docs/grub.texi b/docs/grub.texi -index 0615d0ed97e..04ed6ac1f07 100644 +index c30701b4e1f..44c4e665a0d 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -5487,6 +5487,7 @@ This command is only available on AArch64 systems. +@@ -5955,6 +5955,7 @@ Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}). * net_add_dns:: Add a DNS server * net_add_route:: Add routing entry * net_bootp:: Perform a bootp/DHCP autoconfiguration @@ -23,7 +23,7 @@ index 0615d0ed97e..04ed6ac1f07 100644 * net_del_addr:: Remove IP address from interface * net_del_dns:: Remove a DNS server * net_del_route:: Remove a route entry -@@ -5611,6 +5612,22 @@ Sets environment variable @samp{net_}@var{}@samp{_boot_file} +@@ -6080,6 +6081,22 @@ Sets environment variable @samp{net_}@var{}@samp{_boot_file} @end deffn diff --git a/0066-Use-grub_efi_.-memory-helpers-where-reasonable.patch b/0066-Use-grub_efi_.-memory-helpers-where-reasonable.patch deleted file mode 100644 index 4fa92c0d..00000000 --- a/0066-Use-grub_efi_.-memory-helpers-where-reasonable.patch +++ /dev/null @@ -1,106 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 1 Jun 2017 10:06:38 -0400 -Subject: [PATCH] Use grub_efi_...() memory helpers where reasonable. - -This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and -grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we -get more reasonable type checking. - -Signed-off-by: Peter Jones ---- - grub-core/loader/efi/chainloader.c | 24 +++++++++--------------- - 1 file changed, 9 insertions(+), 15 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 3ff305b1d32..ba3d2930197 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -65,7 +65,7 @@ grub_chainloader_unload (void) - - b = grub_efi_system_table->boot_services; - efi_call_1 (b->unload_image, image_handle); -- efi_call_2 (b->free_pages, address, pages); -+ grub_efi_free_pages (address, pages); - - grub_free (file_path); - grub_free (cmdline); -@@ -108,7 +108,7 @@ grub_chainloader_boot (void) - } - - if (exit_data) -- efi_call_1 (b->free_pool, exit_data); -+ grub_efi_free_pool (exit_data); - - grub_loader_unset (); - -@@ -523,10 +523,9 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp) - static grub_efi_boolean_t - handle_image (void *data, grub_efi_uint32_t datasize) - { -- grub_efi_boot_services_t *b; - grub_efi_loaded_image_t *li, li_bak; - grub_efi_status_t efi_status; -- char *buffer = NULL; -+ void *buffer = NULL; - char *buffer_aligned = NULL; - grub_efi_uint32_t i; - struct grub_pe32_section_table *section; -@@ -537,8 +536,6 @@ handle_image (void *data, grub_efi_uint32_t datasize) - int found_entry_point = 0; - int rc; - -- b = grub_efi_system_table->boot_services; -- - rc = read_header (data, datasize, &context); - if (rc < 0) - { -@@ -578,8 +575,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) - grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n", - context.image_size, datasize); - -- efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, -- buffer_size, &buffer); -+ efi_status = grub_efi_allocate_pool (GRUB_EFI_LOADER_DATA, buffer_size, -+ &buffer); - - if (efi_status != GRUB_EFI_SUCCESS) - { -@@ -811,14 +808,14 @@ handle_image (void *data, grub_efi_uint32_t datasize) - - grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); - grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); -- efi_status = efi_call_1 (b->free_pool, buffer); -+ efi_status = grub_efi_free_pool (buffer); - - return 1; - - error_exit: - grub_dprintf ("chain", "error_exit: grub_errno: %d\n", grub_errno); - if (buffer) -- efi_call_1 (b->free_pool, buffer); -+ grub_efi_free_pool (buffer); - - return 0; - } -@@ -826,10 +823,7 @@ error_exit: - static grub_err_t - grub_secureboot_chainloader_unload (void) - { -- grub_efi_boot_services_t *b; -- -- b = grub_efi_system_table->boot_services; -- efi_call_2 (b->free_pages, address, pages); -+ grub_efi_free_pages (address, pages); - grub_free (file_path); - grub_free (cmdline); - cmdline = 0; -@@ -1096,7 +1090,7 @@ fail: - grub_free (file_path); - - if (address) -- efi_call_2 (b->free_pages, address, pages); -+ grub_efi_free_pages (address, pages); - - if (cmdline) - grub_free (cmdline); diff --git a/0092-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch b/0066-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch similarity index 95% rename from 0092-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch rename to 0066-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch index e800dd23..7109c4e3 100644 --- a/0092-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch +++ b/0066-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch @@ -22,7 +22,7 @@ Signed-off-by: Ken Lin 2 files changed, 56 insertions(+) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index fe93b80f1cf..8fb8918ae7e 100644 +index 76e4c11a46f..f56b293ac72 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -20,6 +20,7 @@ @@ -33,7 +33,7 @@ index fe93b80f1cf..8fb8918ae7e 100644 #include #include #include -@@ -500,6 +501,60 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -501,6 +502,60 @@ grub_net_configure_by_dhcp_ack (const char *name, if (opt && opt_len) grub_env_set_net_property (name, "rootpath", (const char *) opt, opt_len); @@ -95,10 +95,10 @@ index fe93b80f1cf..8fb8918ae7e 100644 if (opt && opt_len) grub_env_set_net_property (name, "extensionspath", (const char *) opt, opt_len); diff --git a/include/grub/net.h b/include/grub/net.h -index 543251f7273..42af7de250a 100644 +index 1d76fd9a1f5..868c9a2ef29 100644 --- a/include/grub/net.h +++ b/include/grub/net.h -@@ -531,6 +531,7 @@ enum +@@ -533,6 +533,7 @@ enum GRUB_NET_DHCP_MESSAGE_TYPE = 53, GRUB_NET_DHCP_SERVER_IDENTIFIER = 54, GRUB_NET_DHCP_PARAMETER_REQUEST_LIST = 55, diff --git a/0067-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch b/0067-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch deleted file mode 100644 index 1a96b433..00000000 --- a/0067-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 1 Jun 2017 10:07:50 -0400 -Subject: [PATCH] Add PRIxGRUB_EFI_STATUS and use it. - -This avoids syntax checkers getting confused about if it's llx or lx. - -Signed-off-by: Peter Jones ---- - grub-core/loader/efi/chainloader.c | 3 ++- - include/grub/efi/api.h | 9 +++++++++ - 2 files changed, 11 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index ba3d2930197..47f5aa14817 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -806,7 +806,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) - efi_status = efi_call_2 (entry_point, grub_efi_image_handle, - grub_efi_system_table); - -- grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); -+ grub_dprintf ("chain", "entry_point returned 0x%"PRIxGRUB_EFI_STATUS"\n", -+ efi_status); - grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); - efi_status = grub_efi_free_pool (buffer); - -diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 117469450d3..99628801478 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -546,7 +546,16 @@ typedef grub_uint64_t grub_efi_uint64_t; - typedef grub_uint8_t grub_efi_char8_t; - typedef grub_uint16_t grub_efi_char16_t; - -+ - typedef grub_efi_uintn_t grub_efi_status_t; -+/* Make grub_efi_status_t reasonably printable. */ -+#if GRUB_CPU_SIZEOF_VOID_P == 8 -+#define PRIxGRUB_EFI_STATUS "lx" -+#define PRIdGRUB_EFI_STATUS "ld" -+#else -+#define PRIxGRUB_EFI_STATUS "llx" -+#define PRIdGRUB_EFI_STATUS "lld" -+#endif - - #define GRUB_EFI_ERROR_CODE(value) \ - ((((grub_efi_status_t) 1) << (sizeof (grub_efi_status_t) * 8 - 1)) | (value)) diff --git a/0161-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch b/0067-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch similarity index 93% rename from 0161-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch rename to 0067-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch index 9b0db5f9..4d843714 100644 --- a/0161-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch +++ b/0067-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 8fb8918ae7e..7baf3540c81 100644 +index f56b293ac72..9cbdc2264c9 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -329,7 +329,7 @@ grub_net_configure_by_dhcp_ack (const char *name, @@ -26,7 +26,7 @@ index 8fb8918ae7e..7baf3540c81 100644 grub_uint8_t opt_len, overload = 0; const char *boot_file = 0, *server_name = 0; grub_size_t boot_file_len, server_name_len; -@@ -505,7 +505,7 @@ grub_net_configure_by_dhcp_ack (const char *name, +@@ -506,7 +506,7 @@ grub_net_configure_by_dhcp_ack (const char *name, if (opt && opt_len) { grub_env_set_net_property (name, "vendor_class_identifier", (const char *) opt, opt_len); diff --git a/0093-efinet-Setting-network-from-UEFI-device-path.patch b/0068-efinet-Setting-network-from-UEFI-device-path.patch similarity index 89% rename from 0093-efinet-Setting-network-from-UEFI-device-path.patch rename to 0068-efinet-Setting-network-from-UEFI-device-path.patch index 11b2a724..71536301 100644 --- a/0093-efinet-Setting-network-from-UEFI-device-path.patch +++ b/0068-efinet-Setting-network-from-UEFI-device-path.patch @@ -27,12 +27,12 @@ the same way it used to be. Signed-off-by: Michael Chang Signed-off-by: Ken Lin --- - grub-core/net/drivers/efi/efinet.c | 284 +++++++++++++++++++++++++++++++++++-- + grub-core/net/drivers/efi/efinet.c | 286 ++++++++++++++++++++++++++++++++++--- include/grub/efi/api.h | 11 ++ - 2 files changed, 280 insertions(+), 15 deletions(-) + 2 files changed, 281 insertions(+), 16 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 014e5bf9802..8171ecaa5e4 100644 +index 92bb7444782..eb68de22023 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -26,6 +26,7 @@ @@ -43,7 +43,7 @@ index 014e5bf9802..8171ecaa5e4 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -331,6 +332,227 @@ grub_efinet_findcards (void) +@@ -348,6 +349,227 @@ grub_efinet_findcards (void) grub_free (handles); } @@ -271,7 +271,7 @@ index 014e5bf9802..8171ecaa5e4 100644 static void grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, char **path) -@@ -346,7 +568,11 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -367,7 +589,11 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, { grub_efi_device_path_t *cdp; struct grub_efi_pxe *pxe; @@ -284,7 +284,7 @@ index 014e5bf9802..8171ecaa5e4 100644 if (card->driver != &efidriver) continue; -@@ -370,11 +596,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -391,11 +617,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, */ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE @@ -307,7 +307,7 @@ index 014e5bf9802..8171ecaa5e4 100644 dup_ldp = grub_efi_find_last_device_path (dup_dp); dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; -@@ -387,23 +623,37 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -408,23 +644,37 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, pxe = grub_efi_open_protocol (hnd, &pxe_io_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); @@ -347,38 +347,45 @@ index 014e5bf9802..8171ecaa5e4 100644 + pxe_mode->dhcp_ack_received ? "yes" : "no", + pxe_mode->dhcp_ack_received ? "" : " cannot continue"); - grub_net_configure_by_dhcpv6_reply (card->name, card, 0, - (struct grub_net_dhcp6_packet *) -- &pxe_mode->dhcp_ack, -- sizeof (pxe_mode->dhcp_ack), -+ packet_buf, -+ packet_bufsz, - 1, device, path); + inter = grub_net_configure_by_dhcpv6_reply (card->name, card, 0, + (struct grub_net_dhcp6_packet *) +- &pxe_mode->dhcp_ack, +- sizeof (pxe_mode->dhcp_ack), ++ packet_buf, ++ packet_bufsz, + 1, device, path); if (grub_errno) grub_print_error (); -@@ -417,11 +667,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -438,8 +688,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, grub_dprintf ("efinet", "using ipv4 and dhcp\n"); - grub_net_configure_by_dhcp_ack (card->name, card, 0, - (struct grub_net_bootp_packet *) -- &pxe_mode->dhcp_ack, -- sizeof (pxe_mode->dhcp_ack), -+ packet_buf, -+ packet_bufsz, - 1, device, path); + inter = grub_net_configure_by_dhcp_ack (card->name, card, 0, + (struct grub_net_bootp_packet *) +- &pxe_mode->dhcp_ack, +- sizeof (pxe_mode->dhcp_ack), ++ packet_buf, ++ packet_bufsz, + 1, device, path); + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); +@@ -465,8 +715,12 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + vlan_dp = (grub_efi_device_path_t *) ((grub_efi_uint8_t *) vlan_dp + vlan_dp_len); + } + } +- return; } + + if (nb) + grub_netbuff_free (nb); + - return; ++ return; } } + diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 91ab528e4d0..4a51667adb1 100644 +index 53f5c781ac3..fa528e73a27 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -864,6 +864,8 @@ struct grub_efi_ipv4_device_path +@@ -891,6 +891,8 @@ struct grub_efi_ipv4_device_path grub_efi_uint16_t remote_port; grub_efi_uint16_t protocol; grub_efi_uint8_t static_ip_address; @@ -387,9 +394,9 @@ index 91ab528e4d0..4a51667adb1 100644 } GRUB_PACKED; typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t; -@@ -918,6 +920,15 @@ struct grub_efi_sata_device_path +@@ -954,6 +956,15 @@ struct grub_efi_vlan_device_path } GRUB_PACKED; - typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t; + typedef struct grub_efi_vlan_device_path grub_efi_vlan_device_path_t; +#define GRUB_EFI_URI_DEVICE_PATH_SUBTYPE 24 + diff --git a/0094-efinet-Setting-DNS-server-from-UEFI-protocol.patch b/0069-efinet-Setting-DNS-server-from-UEFI-protocol.patch similarity index 84% rename from 0094-efinet-Setting-DNS-server-from-UEFI-protocol.patch rename to 0069-efinet-Setting-DNS-server-from-UEFI-protocol.patch index 1460c8a6..43d2df03 100644 --- a/0094-efinet-Setting-DNS-server-from-UEFI-protocol.patch +++ b/0069-efinet-Setting-DNS-server-from-UEFI-protocol.patch @@ -29,34 +29,34 @@ Signed-off-by: Michael Chang Signed-off-by: Ken Lin --- grub-core/net/drivers/efi/efinet.c | 163 +++++++++++++++++++++++++++++++++++++ - include/grub/efi/api.h | 75 +++++++++++++++++ - 2 files changed, 238 insertions(+) + include/grub/efi/api.h | 76 +++++++++++++++++ + 2 files changed, 239 insertions(+) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 8171ecaa5e4..715a6168d77 100644 +index eb68de22023..a91df09ee6d 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -33,6 +33,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); /* GUID. */ - static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID; - static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; -+static grub_efi_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID; -+static grub_efi_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID; + static grub_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID; + static grub_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; ++static grub_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID; ++static grub_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID; static grub_err_t send_card_buffer (struct grub_net_card *dev, -@@ -332,6 +334,125 @@ grub_efinet_findcards (void) +@@ -349,6 +351,125 @@ grub_efinet_findcards (void) grub_free (handles); } +static grub_efi_handle_t -+grub_efi_locate_device_path (grub_efi_guid_t *protocol, grub_efi_device_path_t *device_path, ++grub_efi_locate_device_path (grub_guid_t *protocol, grub_efi_device_path_t *device_path, + grub_efi_device_path_t **r_device_path) +{ + grub_efi_handle_t handle; + grub_efi_status_t status; + -+ status = efi_call_3 (grub_efi_system_table->boot_services->locate_device_path, ++ status = grub_efi_system_table->boot_services->locate_device_path( + protocol, &device_path, &handle); + + if (status != GRUB_EFI_SUCCESS) @@ -92,9 +92,9 @@ index 8171ecaa5e4..715a6168d77 100644 + if (!addrs) + return 0; + -+ status = efi_call_4 (conf->get_data, conf, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, -+ &data_size, addrs); ++ status = conf->get_data(conf, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); + + if (status == GRUB_EFI_BUFFER_TOO_SMALL) + { @@ -103,9 +103,9 @@ index 8171ecaa5e4..715a6168d77 100644 + if (!addrs) + return 0; + -+ status = efi_call_4 (conf->get_data, conf, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, -+ &data_size, addrs); ++ status = conf->get_data(conf, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); + } + + if (status != GRUB_EFI_SUCCESS) @@ -142,9 +142,9 @@ index 8171ecaa5e4..715a6168d77 100644 + if (!addrs) + return 0; + -+ status = efi_call_4 (conf->get_data, conf, -+ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, -+ &data_size, addrs); ++ status = conf->get_data(conf, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); + + if (status == GRUB_EFI_BUFFER_TOO_SMALL) + { @@ -153,9 +153,9 @@ index 8171ecaa5e4..715a6168d77 100644 + if (!addrs) + return 0; + -+ status = efi_call_4 (conf->get_data, conf, -+ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, -+ &data_size, addrs); ++ status = conf->get_data(conf, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); + } + + if (status != GRUB_EFI_SUCCESS) @@ -171,7 +171,7 @@ index 8171ecaa5e4..715a6168d77 100644 static struct grub_net_buff * grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *use_ipv6) { -@@ -390,6 +511,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -407,6 +528,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) ldp; struct grub_net_bootp_packet *bp; grub_uint8_t *ptr; @@ -180,7 +180,7 @@ index 8171ecaa5e4..715a6168d77 100644 bp = (struct grub_net_bootp_packet *) nb->tail; err = grub_netbuff_put (nb, sizeof (*bp) + 4); -@@ -451,6 +574,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -468,6 +591,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u *ptr++ = sizeof ("HTTPClient") - 1; grub_memcpy (ptr, "HTTPClient", sizeof ("HTTPClient") - 1); @@ -206,7 +206,7 @@ index 8171ecaa5e4..715a6168d77 100644 ptr = nb->tail; err = grub_netbuff_put (nb, 1); if (err) -@@ -483,6 +625,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -500,6 +642,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u struct grub_net_dhcp6_option *opt; struct grub_net_dhcp6_option_iana *iana; struct grub_net_dhcp6_option_iaaddr *iaaddr; @@ -215,7 +215,7 @@ index 8171ecaa5e4..715a6168d77 100644 d6p = (struct grub_net_dhcp6_packet *)nb->tail; err = grub_netbuff_put (nb, sizeof(*d6p)); -@@ -546,6 +690,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -563,6 +707,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u opt->len = grub_cpu_to_be16 (uri_len); grub_memcpy (opt->data, uri_dp->uri, uri_len); @@ -242,14 +242,13 @@ index 8171ecaa5e4..715a6168d77 100644 } diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 4a51667adb1..0b490195ad9 100644 +index fa528e73a27..248d6a28ff9 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -352,6 +352,15 @@ - #define GRUB_EFI_RNG_PROTOCOL_GUID \ - { 0x3152bca5, 0xeade, 0x433d, \ +@@ -369,6 +369,16 @@ { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \ -+ + } + +#define GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID \ + { 0x5b446ed1, 0xe30b, 0x4faa, \ + { 0x87, 0x1a, 0x36, 0x54, 0xec, 0xa3, 0x60, 0x80 } \ @@ -258,12 +257,14 @@ index 4a51667adb1..0b490195ad9 100644 +#define GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID \ + { 0x937fe521, 0x95ae, 0x4d1a, \ + { 0x89, 0x29, 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a } \ - } - - struct grub_efi_sal_system_table -@@ -1883,6 +1892,72 @@ struct grub_efi_rng_protocol ++ } ++ + #define LINUX_EFI_INITRD_MEDIA_GUID \ + { 0x5568e427, 0x68fc, 0x4f3d, \ + { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \ +@@ -1963,6 +1973,72 @@ struct grub_efi_load_file2 }; - typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t; + typedef struct grub_efi_load_file2 grub_efi_load_file2_t; +enum grub_efi_ip4_config2_data_type { + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, @@ -331,6 +332,6 @@ index 4a51667adb1..0b490195ad9 100644 +}; +typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t; + - #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ - || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ - || defined(__riscv) + struct initrd_media_device_path { + grub_efi_vendor_media_device_path_t vendor; + grub_efi_device_path_t end; diff --git a/0095-Support-UEFI-networking-protocols.patch b/0070-Support-UEFI-networking-protocols.patch similarity index 94% rename from 0095-Support-UEFI-networking-protocols.patch rename to 0070-Support-UEFI-networking-protocols.patch index fb143862..efa3659a 100644 --- a/0095-Support-UEFI-networking-protocols.patch +++ b/0070-Support-UEFI-networking-protocols.patch @@ -33,18 +33,18 @@ Signed-off-by: Peter Jones grub-core/net/drivers/efi/efinet.c | 27 + grub-core/net/efi/dhcp.c | 397 ++++++++++ grub-core/net/efi/efi_netfs.c | 57 ++ - grub-core/net/efi/http.c | 419 +++++++++++ + grub-core/net/efi/http.c | 410 +++++++++++ grub-core/net/efi/ip4_config.c | 398 ++++++++++ grub-core/net/efi/ip6_config.c | 422 +++++++++++ grub-core/net/efi/net.c | 1428 ++++++++++++++++++++++++++++++++++++ grub-core/net/efi/pxe.c | 424 +++++++++++ grub-core/net/net.c | 74 ++ util/grub-mknetdir.c | 23 +- - include/grub/efi/api.h | 180 ++++- + include/grub/efi/api.h | 195 ++++- include/grub/efi/dhcp.h | 343 +++++++++ include/grub/efi/http.h | 215 ++++++ include/grub/net/efi.h | 144 ++++ - 17 files changed, 4620 insertions(+), 41 deletions(-) + 17 files changed, 4618 insertions(+), 49 deletions(-) create mode 100644 grub-core/net/efi/dhcp.c create mode 100644 grub-core/net/efi/efi_netfs.c create mode 100644 grub-core/net/efi/http.c @@ -57,10 +57,10 @@ Signed-off-by: Peter Jones create mode 100644 include/grub/net/efi.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 4b7c45a7b06..c40170f2dd2 100644 +index 6645fbae34f..56eb6a828e8 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -2299,6 +2299,12 @@ module = { +@@ -2356,6 +2356,12 @@ module = { common = hook/datehook.c; }; @@ -73,7 +73,7 @@ index 4b7c45a7b06..c40170f2dd2 100644 module = { name = net; common = net/net.c; -@@ -2312,6 +2318,12 @@ module = { +@@ -2369,6 +2375,12 @@ module = { common = net/ethernet.c; common = net/arp.c; common = net/netbuff.c; @@ -100,10 +100,10 @@ index a458c3aca78..1637731535e 100644 if (file->offset + res < next_buf) { diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index d6a2fb57789..2a446f5031b 100644 +index 2bb8a0e7a38..bf16c4307bc 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -755,7 +755,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) +@@ -775,7 +775,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) { grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) dp; @@ -112,7 +112,7 @@ index d6a2fb57789..2a446f5031b 100644 (unsigned) ipv4->local_ip_address[0], (unsigned) ipv4->local_ip_address[1], (unsigned) ipv4->local_ip_address[2], -@@ -768,33 +768,60 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) +@@ -788,33 +788,60 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) (unsigned) ipv4->remote_port, (unsigned) ipv4->protocol, (unsigned) ipv4->static_ip_address); @@ -190,7 +190,7 @@ index d6a2fb57789..2a446f5031b 100644 } break; case GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE: -@@ -834,6 +861,39 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) +@@ -861,6 +888,39 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) dump_vendor_path ("Messaging", (grub_efi_vendor_device_path_t *) dp); break; @@ -231,7 +231,7 @@ index d6a2fb57789..2a446f5031b 100644 grub_printf ("/UnknownMessaging(%x)", (unsigned) subtype); break; diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 715a6168d77..e11d759f19a 100644 +index a91df09ee6d..225dc896da0 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -27,6 +27,7 @@ @@ -242,7 +242,7 @@ index 715a6168d77..e11d759f19a 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -491,6 +492,17 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u +@@ -508,6 +509,17 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u ldp = grub_efi_find_last_device_path (ddp); @@ -260,7 +260,7 @@ index 715a6168d77..e11d759f19a 100644 if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) -@@ -760,6 +772,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -781,6 +793,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE @@ -268,7 +268,7 @@ index 715a6168d77..e11d759f19a 100644 && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_URI_DEVICE_PATH_SUBTYPE)) continue; dup_dp = grub_efi_duplicate_device_path (dp); -@@ -774,6 +787,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -795,6 +808,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, dup_ldp->length = sizeof (*dup_ldp); } @@ -284,7 +284,7 @@ index 715a6168d77..e11d759f19a 100644 dup_ldp = grub_efi_find_last_device_path (dup_dp); dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; -@@ -845,6 +867,9 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -889,6 +911,9 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, GRUB_MOD_INIT(efinet) { @@ -294,8 +294,8 @@ index 715a6168d77..e11d759f19a 100644 grub_efinet_findcards (); grub_efi_net_config = grub_efi_net_config_real; } -@@ -856,5 +881,7 @@ GRUB_MOD_FINI(efinet) - FOR_NET_CARDS_SAFE (card, next) +@@ -900,5 +925,7 @@ GRUB_MOD_FINI(efinet) + FOR_NET_CARDS_SAFE (card, next) if (card->driver == &efidriver) grub_net_card_unregister (card); + @@ -304,7 +304,7 @@ index 715a6168d77..e11d759f19a 100644 diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c new file mode 100644 -index 00000000000..dbef63d8c08 +index 00000000000..ca19902441b --- /dev/null +++ b/grub-core/net/efi/dhcp.c @@ -0,0 +1,397 @@ @@ -385,7 +385,7 @@ index 00000000000..dbef63d8c08 + grub_efi_uint32_t option_count = 0; + grub_efi_uint32_t i; + -+ status = efi_call_4 (dhcp4->parse, dhcp4, reply_packet, &option_count, NULL); ++ status = dhcp4->parse(dhcp4, reply_packet, &option_count, NULL); + + if (status != GRUB_EFI_BUFFER_TOO_SMALL) + return NULL; @@ -394,7 +394,7 @@ index 00000000000..dbef63d8c08 + if (!option_list) + return NULL; + -+ status = efi_call_4 (dhcp4->parse, dhcp4, reply_packet, &option_count, option_list); ++ status = dhcp4->parse(dhcp4, reply_packet, &option_count, option_list); + if (status != GRUB_EFI_SUCCESS) + { + grub_free (option_list); @@ -443,13 +443,13 @@ index 00000000000..dbef63d8c08 + + if (!mode->started) + { -+ status = efi_call_2 (pxe->start, pxe, 0); ++ status = pxe->start(pxe, 0); + + if (status != GRUB_EFI_SUCCESS) + grub_printf ("Couldn't start PXE\n"); + } + -+ status = efi_call_2 (pxe->dhcp, pxe, 0); ++ status = pxe->dhcp(pxe, 0); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("dhcp4 configure failed, %d\n", (int)status); @@ -500,7 +500,7 @@ index 00000000000..dbef63d8c08 + config.option_list = &options; + + /* FIXME: What if the dhcp has bounded */ -+ status = efi_call_2 (netdev->dhcp4->configure, netdev->dhcp4, &config); ++ status = netdev->dhcp4->configure(netdev->dhcp4, &config); + grub_free (options); + if (status != GRUB_EFI_SUCCESS) + { @@ -508,14 +508,14 @@ index 00000000000..dbef63d8c08 + continue; + } + -+ status = efi_call_2 (netdev->dhcp4->start, netdev->dhcp4, NULL); ++ status = netdev->dhcp4->start(netdev->dhcp4, NULL); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("dhcp4 start failed, %d\n", (int)status); + continue; + } + -+ status = efi_call_2 (netdev->dhcp4->get_mode_data, netdev->dhcp4, &mode); ++ status = netdev->dhcp4->get_mode_data(netdev->dhcp4, &mode); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("dhcp4 get mode failed, %d\n", (int)status); @@ -616,21 +616,21 @@ index 00000000000..dbef63d8c08 + config.rapid_commit = 0; + config.solicit_retransmission = &retrans; + -+ status = efi_call_2 (dev->dhcp6->configure, dev->dhcp6, &config); ++ status = dev->dhcp6->configure(dev->dhcp6, &config); + grub_free (opt); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("dhcp6 configure failed, %d\n", (int)status); + continue; + } -+ status = efi_call_1 (dev->dhcp6->start, dev->dhcp6); ++ status = dev->dhcp6->start(dev->dhcp6); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("dhcp6 start failed, %d\n", (int)status); + continue; + } + -+ status = efi_call_3 (dev->dhcp6->get_mode_data, dev->dhcp6, &mode, NULL); ++ status = dev->dhcp6->get_mode_data(dev->dhcp6, &mode, NULL); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("dhcp4 get mode failed, %d\n", (int)status); @@ -666,12 +666,12 @@ index 00000000000..dbef63d8c08 + grub_efi_dhcp6_packet_option_t **options = NULL; + grub_efi_uint32_t i; + -+ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, NULL); ++ status = dev->dhcp6->parse(dev->dhcp6, mode.ia->reply_packet, &count, NULL); + + if (status == GRUB_EFI_BUFFER_TOO_SMALL && count) + { + options = grub_malloc (count * sizeof(*options)); -+ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ status = dev->dhcp6->parse(dev->dhcp6, mode.ia->reply_packet, &count, options); + } + + if (status != GRUB_EFI_SUCCESS) @@ -696,8 +696,8 @@ index 00000000000..dbef63d8c08 + grub_free (options); + } + -+ efi_call_1 (b->free_pool, mode.client_id); -+ efi_call_1 (b->free_pool, mode.ia); ++ b->free_pool(mode.client_id); ++ b->free_pool(mode.ia); + } + + return GRUB_ERR_NONE; @@ -770,10 +770,10 @@ index 00000000000..ef371d885ea +} diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c new file mode 100644 -index 00000000000..3f61fd2fa5b +index 00000000000..de28badccb0 --- /dev/null +++ b/grub-core/net/efi/http.c -@@ -0,0 +1,419 @@ +@@ -0,0 +1,410 @@ + +#include +#include @@ -802,9 +802,9 @@ index 00000000000..3f61fd2fa5b + + http_config.local_address_is_ipv6 = 1; + sz = sizeof (manual_address); -+ status = efi_call_4 (dev->ip6_config->get_data, dev->ip6_config, -+ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, -+ &sz, &manual_address); ++ status = dev->ip6_config->get_data(dev->ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, &manual_address); + + if (status == GRUB_EFI_NOT_FOUND) + { @@ -834,19 +834,19 @@ index 00000000000..3f61fd2fa5b + http_config.access_point.ipv4_node = &httpv4_node; + } + -+ status = efi_call_2 (http->configure, http, &http_config); ++ status = http->configure(http, &http_config); + + if (status == GRUB_EFI_ALREADY_STARTED) + { + /* XXX: This hangs HTTPS boot */ +#if 0 -+ if (efi_call_2 (http->configure, http, NULL) != GRUB_EFI_SUCCESS) ++ if (http->configure(http, NULL) != GRUB_EFI_SUCCESS) + { + grub_error (GRUB_ERR_IO, N_("couldn't reset http instance")); + grub_print_error (); + return; + } -+ status = efi_call_2 (http->configure, http, &http_config); ++ status = http->configure(http, &http_config); +#endif + return; + } @@ -945,12 +945,9 @@ index 00000000000..3f61fd2fa5b + request_token.message = &request_message; + + request_callback_done = 0; -+ status = efi_call_5 (b->create_event, -+ GRUB_EFI_EVT_NOTIFY_SIGNAL, -+ GRUB_EFI_TPL_CALLBACK, -+ grub_efi_http_request_callback, -+ NULL, -+ &request_token.event); ++ status = b->create_event(GRUB_EFI_EVT_NOTIFY_SIGNAL, GRUB_EFI_TPL_CALLBACK, ++ grub_efi_http_request_callback, NULL, ++ &request_token.event); + + if (status != GRUB_EFI_SUCCESS) + { @@ -958,17 +955,17 @@ index 00000000000..3f61fd2fa5b + return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", status); + } + -+ status = efi_call_2 (http->request, http, &request_token); ++ status = http->request(http, &request_token); + + if (status != GRUB_EFI_SUCCESS) + { -+ efi_call_1 (b->close_event, request_token.event); ++ b->close_event(request_token.event); + grub_free (request_data.url); + return grub_error (GRUB_ERR_IO, "Fail to send a request! status=0x%x\n", status); + } + /* TODO: Add Timeout */ + while (!request_callback_done) -+ efi_call_1(http->poll, http); ++ http->poll(http); + + response_data.status_code = GRUB_EFI_HTTP_STATUS_UNSUPPORTED_STATUS; + response_message.data.response = &response_data; @@ -981,16 +978,13 @@ index 00000000000..3f61fd2fa5b + response_message.body = NULL; + response_token.event = NULL; + -+ status = efi_call_5 (b->create_event, -+ GRUB_EFI_EVT_NOTIFY_SIGNAL, -+ GRUB_EFI_TPL_CALLBACK, -+ grub_efi_http_response_callback, -+ NULL, -+ &response_token.event); ++ status = b->create_event(GRUB_EFI_EVT_NOTIFY_SIGNAL, GRUB_EFI_TPL_CALLBACK, ++ grub_efi_http_response_callback, NULL, ++ &response_token.event); + + if (status != GRUB_EFI_SUCCESS) + { -+ efi_call_1 (b->close_event, request_token.event); ++ b->close_event(request_token.event); + grub_free (request_data.url); + return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", status); + } @@ -1000,28 +994,28 @@ index 00000000000..3f61fd2fa5b + + /* wait for HTTP response */ + response_callback_done = 0; -+ status = efi_call_2 (http->response, http, &response_token); ++ status = http->response(http, &response_token); + + if (status != GRUB_EFI_SUCCESS) + { -+ efi_call_1 (b->close_event, response_token.event); -+ efi_call_1 (b->close_event, request_token.event); ++ b->close_event(response_token.event); ++ b->close_event(request_token.event); + grub_free (request_data.url); + return grub_error (GRUB_ERR_IO, "Fail to receive a response! status=%d\n", (int)status); + } + + /* TODO: Add Timeout */ + while (!response_callback_done) -+ efi_call_1 (http->poll, http); ++ http->poll(http); + + if (response_message.data.response->status_code != GRUB_EFI_HTTP_STATUS_200_OK) + { + grub_efi_http_status_code_t status_code = response_message.data.response->status_code; + + if (response_message.headers) -+ efi_call_1 (b->free_pool, response_message.headers); -+ efi_call_1 (b->close_event, response_token.event); -+ efi_call_1 (b->close_event, request_token.event); ++ b->free_pool(response_message.headers); ++ b->close_event(response_token.event); ++ b->close_event(request_token.event); + grub_free (request_data.url); + if (status_code == GRUB_EFI_HTTP_STATUS_404_NOT_FOUND) + { @@ -1049,9 +1043,9 @@ index 00000000000..3f61fd2fa5b + } + + if (response_message.headers) -+ efi_call_1 (b->free_pool, response_message.headers); -+ efi_call_1 (b->close_event, response_token.event); -+ efi_call_1 (b->close_event, request_token.event); ++ b->free_pool(response_message.headers); ++ b->close_event(response_token.event); ++ b->close_event(request_token.event); + grub_free (request_data.url); + + return GRUB_ERR_NONE; @@ -1076,12 +1070,9 @@ index 00000000000..3f61fd2fa5b + return -1; + } + -+ efi_call_5 (b->create_event, -+ GRUB_EFI_EVT_NOTIFY_SIGNAL, -+ GRUB_EFI_TPL_CALLBACK, -+ grub_efi_http_response_callback, -+ NULL, -+ &response_token.event); ++ b->create_event(GRUB_EFI_EVT_NOTIFY_SIGNAL, GRUB_EFI_TPL_CALLBACK, ++ grub_efi_http_response_callback, NULL, ++ &response_token.event); + + while (len) + { @@ -1096,23 +1087,23 @@ index 00000000000..3f61fd2fa5b + + response_callback_done = 0; + -+ status = efi_call_2 (http->response, http, &response_token); ++ status = http->response(http, &response_token); + if (status != GRUB_EFI_SUCCESS) + { -+ efi_call_1 (b->close_event, response_token.event); ++ b->close_event(response_token.event); + grub_error (GRUB_ERR_IO, "Error! status=%d\n", (int)status); + return -1; + } + + while (!response_callback_done) -+ efi_call_1(http->poll, http); ++ http->poll(http); + + sum += response_message.body_length; + buf += response_message.body_length; + len -= response_message.body_length; + } + -+ efi_call_1 (b->close_event, response_token.event); ++ b->close_event(response_token.event); + + return sum; +} @@ -1195,7 +1186,7 @@ index 00000000000..3f61fd2fa5b + }; diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c new file mode 100644 -index 00000000000..b711a5d9457 +index 00000000000..1deba25e79e --- /dev/null +++ b/grub-core/net/efi/ip4_config.c @@ -0,0 +1,398 @@ @@ -1305,17 +1296,17 @@ index 00000000000..b711a5d9457 + if (!interface_info) + return NULL; + -+ status = efi_call_4 (ip4_config->get_data, ip4_config, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, -+ &sz, interface_info); ++ status = ip4_config->get_data(ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, ++ &sz, interface_info); + + if (status == GRUB_EFI_BUFFER_TOO_SMALL) + { + grub_free (interface_info); + interface_info = grub_malloc (sz); -+ status = efi_call_4 (ip4_config->get_data, ip4_config, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, -+ &sz, interface_info); ++ status = ip4_config->get_data(ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, ++ &sz, interface_info); + } + + if (status != GRUB_EFI_SUCCESS) @@ -1339,9 +1330,9 @@ index 00000000000..b711a5d9457 + if (!manual_address) + return NULL; + -+ status = efi_call_4 (ip4_config->get_data, ip4_config, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, -+ &sz, manual_address); ++ status = ip4_config->get_data(ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, manual_address); + + if (status != GRUB_EFI_SUCCESS) + { @@ -1546,7 +1537,7 @@ index 00000000000..b711a5d9457 + } + } + -+ status = efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, ++ status = dev->ip4_config->set_data(dev->ip4_config, + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, + sizeof(*address), address); + @@ -1562,9 +1553,9 @@ index 00000000000..b711a5d9457 +{ + grub_efi_status_t status; + -+ status = efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_GATEWAY, -+ sizeof (address->ip4), &address->ip4); ++ status = dev->ip4_config->set_data(dev->ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_GATEWAY, ++ sizeof (address->ip4), &address->ip4); + + if (status != GRUB_EFI_SUCCESS) + return 0; @@ -1578,9 +1569,9 @@ index 00000000000..b711a5d9457 +{ + grub_efi_status_t status; + -+ status = efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, -+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, -+ sizeof (address->ip4), &address->ip4); ++ status = dev->ip4_config->set_data(dev->ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ sizeof (address->ip4), &address->ip4); + + if (status != GRUB_EFI_SUCCESS) + return 0; @@ -1599,7 +1590,7 @@ index 00000000000..b711a5d9457 + }; diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c new file mode 100644 -index 00000000000..017c4d05bc7 +index 00000000000..29a03973265 --- /dev/null +++ b/grub-core/net/efi/ip6_config.c @@ -0,0 +1,422 @@ @@ -1729,7 +1720,7 @@ index 00000000000..017c4d05bc7 + sz = sizeof (*interface_info) + sizeof (*interface_info->route_table); + interface_info = grub_malloc (sz); + -+ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ status = ip6_config->get_data(ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, + &sz, interface_info); + @@ -1737,7 +1728,7 @@ index 00000000000..017c4d05bc7 + { + grub_free (interface_info); + interface_info = grub_malloc (sz); -+ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ status = ip6_config->get_data(ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, + &sz, interface_info); + } @@ -1763,7 +1754,7 @@ index 00000000000..017c4d05bc7 + if (!manual_address) + return NULL; + -+ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ status = ip6_config->get_data(ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, + &sz, manual_address); + @@ -1974,7 +1965,7 @@ index 00000000000..017c4d05bc7 + } + } + -+ status = efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ status = dev->ip6_config->set_data(dev->ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, + sizeof(*address), address); + @@ -1990,7 +1981,7 @@ index 00000000000..017c4d05bc7 +{ + grub_efi_status_t status; + -+ status = efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ status = dev->ip6_config->set_data(dev->ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_GATEWAY, + sizeof (address->ip6), &address->ip6); + @@ -2006,7 +1997,7 @@ index 00000000000..017c4d05bc7 + + grub_efi_status_t status; + -+ status = efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ status = dev->ip6_config->set_data(dev->ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, + sizeof (address->ip6), &address->ip6); + @@ -2027,7 +2018,7 @@ index 00000000000..017c4d05bc7 + }; diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c new file mode 100644 -index 00000000000..86bce6535d3 +index 00000000000..1a19ee27144 --- /dev/null +++ b/grub-core/net/efi/net.c @@ -0,0 +1,1428 @@ @@ -2050,15 +2041,15 @@ index 00000000000..86bce6535d3 + +#define GRUB_EFI_IP6_PREFIX_LENGTH 64 + -+static grub_efi_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID; -+static grub_efi_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID; -+static grub_efi_guid_t http_service_binding_guid = GRUB_EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID; -+static grub_efi_guid_t http_guid = GRUB_EFI_HTTP_PROTOCOL_GUID; -+static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; -+static grub_efi_guid_t dhcp4_service_binding_guid = GRUB_EFI_DHCP4_SERVICE_BINDING_PROTOCOL_GUID; -+static grub_efi_guid_t dhcp4_guid = GRUB_EFI_DHCP4_PROTOCOL_GUID; -+static grub_efi_guid_t dhcp6_service_binding_guid = GRUB_EFI_DHCP6_SERVICE_BINDING_PROTOCOL_GUID; -+static grub_efi_guid_t dhcp6_guid = GRUB_EFI_DHCP6_PROTOCOL_GUID; ++static grub_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID; ++static grub_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID; ++static grub_guid_t http_service_binding_guid = GRUB_EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID; ++static grub_guid_t http_guid = GRUB_EFI_HTTP_PROTOCOL_GUID; ++static grub_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; ++static grub_guid_t dhcp4_service_binding_guid = GRUB_EFI_DHCP4_SERVICE_BINDING_PROTOCOL_GUID; ++static grub_guid_t dhcp4_guid = GRUB_EFI_DHCP4_PROTOCOL_GUID; ++static grub_guid_t dhcp6_service_binding_guid = GRUB_EFI_DHCP6_SERVICE_BINDING_PROTOCOL_GUID; ++static grub_guid_t dhcp6_guid = GRUB_EFI_DHCP6_PROTOCOL_GUID; + +struct grub_efi_net_device *net_devices; + @@ -2073,13 +2064,13 @@ index 00000000000..86bce6535d3 +#define efi_net_interface(m,...) efi_net_interface_ ## m (net_interface, ## __VA_ARGS__) + +static grub_efi_handle_t -+grub_efi_locate_device_path (grub_efi_guid_t *protocol, grub_efi_device_path_t *device_path, ++grub_efi_locate_device_path (grub_guid_t *protocol, grub_efi_device_path_t *device_path, + grub_efi_device_path_t **r_device_path) +{ + grub_efi_handle_t handle; + grub_efi_status_t status; + -+ status = efi_call_3 (grub_efi_system_table->boot_services->locate_device_path, ++ status = grub_efi_system_table->boot_services->locate_device_path( + protocol, &device_path, &handle); + + if (status != GRUB_EFI_SUCCESS) @@ -2721,7 +2712,7 @@ index 00000000000..86bce6535d3 +} + +static grub_efi_handle_t -+grub_efi_service_binding (grub_efi_handle_t dev, grub_efi_guid_t *service_binding_guid) ++grub_efi_service_binding (grub_efi_handle_t dev, grub_guid_t *service_binding_guid) +{ + grub_efi_service_binding_t *service; + grub_efi_status_t status; @@ -2734,7 +2725,7 @@ index 00000000000..86bce6535d3 + return NULL; + } + -+ status = efi_call_2 (service->create_child, service, &child_dev); ++ status = service->create_child(service, &child_dev); + if (status != GRUB_EFI_SUCCESS) + { + grub_error (GRUB_ERR_IO, N_("Failed to create child device of http service %x"), status); @@ -2944,7 +2935,7 @@ index 00000000000..86bce6535d3 + { + grub_efi_ip4_config2_policy_t ip4_policy = GRUB_EFI_IP4_CONFIG2_POLICY_STATIC; + -+ if (efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, ++ if (dev->ip4_config->set_data(dev->ip4_config, + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_POLICY, + sizeof (ip4_policy), &ip4_policy) != GRUB_EFI_SUCCESS) + grub_dprintf ("efinetfs", "could not set GRUB_EFI_IP4_CONFIG2_POLICY_STATIC on dev `%s'", dev->card_name); @@ -2953,7 +2944,7 @@ index 00000000000..86bce6535d3 + { + grub_efi_ip6_config_policy_t ip6_policy = GRUB_EFI_IP6_CONFIG_POLICY_MANUAL; + -+ if (efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ if (dev->ip6_config->set_data(dev->ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_POLICY, + sizeof (ip6_policy), &ip6_policy) != GRUB_EFI_SUCCESS) + grub_dprintf ("efinetfs", "could not set GRUB_EFI_IP6_CONFIG_POLICY_MANUAL on dev `%s'", dev->card_name); @@ -3461,7 +3452,7 @@ index 00000000000..86bce6535d3 +} diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c new file mode 100644 -index 00000000000..531949cba5c +index 00000000000..b84f86ea470 --- /dev/null +++ b/grub-core/net/efi/pxe.c @@ -0,0 +1,424 @@ @@ -3484,7 +3475,7 @@ index 00000000000..531949cba5c + if (!manual_address) + return NULL; + -+ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ status = ip6_config->get_data(ip6_config, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, + &sz, manual_address); + @@ -3509,7 +3500,7 @@ index 00000000000..531949cba5c + if (!manual_address) + return NULL; + -+ status = efi_call_4 (ip4_config->get_data, ip4_config, ++ status = ip4_config->get_data(ip4_config, + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, + &sz, manual_address); + @@ -3532,7 +3523,7 @@ index 00000000000..531949cba5c + if (!mode->started) + { + grub_efi_status_t status; -+ status = efi_call_2 (pxe->start, pxe, prefer_ip6); ++ status = pxe->start(pxe, prefer_ip6); + + if (status != GRUB_EFI_SUCCESS) + grub_printf ("Couldn't start PXE\n"); @@ -3555,7 +3546,7 @@ index 00000000000..531949cba5c + grub_efi_pxe_ip_address_t station_ip; + + grub_memcpy (station_ip.v6.addr, manual_address->address, sizeof (station_ip.v6.addr)); -+ status = efi_call_3 (pxe->set_station_ip, pxe, &station_ip, NULL); ++ status = pxe->set_station_ip(pxe, &station_ip, NULL); + + if (status != GRUB_EFI_SUCCESS) + grub_printf ("Couldn't set station ip\n"); @@ -3578,7 +3569,7 @@ index 00000000000..531949cba5c + grub_memcpy (station_ip.v4.addr, manual_address->address, sizeof (station_ip.v4.addr)); + grub_memcpy (subnet_mask.v4.addr, manual_address->subnet_mask, sizeof (subnet_mask.v4.addr)); + -+ status = efi_call_3 (pxe->set_station_ip, pxe, &station_ip, &subnet_mask); ++ status = pxe->set_station_ip(pxe, &station_ip, &subnet_mask); + + if (status != GRUB_EFI_SUCCESS) + grub_printf ("Couldn't set station ip\n"); @@ -3731,7 +3722,7 @@ index 00000000000..531949cba5c + server_ip.v4.addr[i] = grub_strtoul (p, &p, 10); + } + -+ status = efi_call_10 (pxe->mtftp, ++ status = pxe->mtftp( + pxe, + GRUB_EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, + NULL, @@ -3816,7 +3807,7 @@ index 00000000000..531949cba5c + server_ip.v4.addr[i] = grub_strtoul (p, &p, 10); + } + -+ status = efi_call_10 (pxe->mtftp, ++ status = pxe->mtftp( + pxe, + GRUB_EFI_PXE_BASE_CODE_TFTP_READ_FILE, + buf, @@ -3847,7 +3838,7 @@ index 00000000000..531949cba5c + return 0; + } + -+ status = efi_call_10 (pxe->mtftp, ++ status = pxe->mtftp( + pxe, + GRUB_EFI_PXE_BASE_CODE_TFTP_READ_FILE, + buf2, @@ -3890,7 +3881,7 @@ index 00000000000..531949cba5c + }; + diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 0ce5e675ed7..55aed92722c 100644 +index fa6b6537142..fdec64d55ee 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -32,6 +32,9 @@ @@ -3903,8 +3894,8 @@ index 0ce5e675ed7..55aed92722c 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -2033,8 +2036,49 @@ static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; - static grub_command_t cmd_lsroutes, cmd_lscards; +@@ -2092,8 +2095,49 @@ static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; + static grub_command_t cmd_setvlan, cmd_lsroutes, cmd_lscards; static grub_command_t cmd_lsaddr, cmd_slaac; +#ifdef GRUB_MACHINE_EFI @@ -3953,7 +3944,7 @@ index 0ce5e675ed7..55aed92722c 100644 grub_register_variable_hook ("net_default_server", defserver_get_env, defserver_set_env); grub_env_export ("net_default_server"); -@@ -2082,10 +2126,37 @@ GRUB_MOD_INIT(net) +@@ -2144,10 +2188,37 @@ GRUB_MOD_INIT(net) grub_net_restore_hw, GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; @@ -3991,16 +3982,16 @@ index 0ce5e675ed7..55aed92722c 100644 grub_register_variable_hook ("net_default_server", 0, 0); grub_register_variable_hook ("pxe_default_server", 0, 0); -@@ -2104,4 +2175,7 @@ GRUB_MOD_FINI(net) +@@ -2166,4 +2237,7 @@ GRUB_MOD_FINI(net) grub_net_fini_hw (0); grub_loader_unregister_preboot_hook (fini_hnd); - grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; + grub_net_poll_cards_idle = NULL; +#ifdef GRUB_MACHINE_EFI + init_mode = INIT_MODE_NONE; +#endif } diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c -index a2461cda1c4..77958dd9dd5 100644 +index 46f304c2b47..11c9db11775 100644 --- a/util/grub-mknetdir.c +++ b/util/grub-mknetdir.c @@ -32,13 +32,15 @@ @@ -4055,7 +4046,7 @@ index a2461cda1c4..77958dd9dd5 100644 { const char *mkimage_target; const char *netmodule; -@@ -156,6 +161,7 @@ process_input_dir (const char *input_dir, enum grub_install_plat platform) +@@ -157,6 +162,7 @@ process_input_dir (const char *input_dir, enum grub_install_plat platform) grub_install_push_module (targets[platform].netmodule); output = grub_util_path_concat_ext (2, grubdir, "core", targets[platform].ext); @@ -4063,7 +4054,7 @@ index a2461cda1c4..77958dd9dd5 100644 grub_install_make_image_wrap (input_dir, prefix, output, 0, load_cfg, targets[platform].mkimage_target, 0); -@@ -195,7 +201,16 @@ main (int argc, char *argv[]) +@@ -196,7 +202,16 @@ main (int argc, char *argv[]) grub_install_mkdir_p (base); @@ -4082,10 +4073,10 @@ index a2461cda1c4..77958dd9dd5 100644 if (!grub_install_source_directory) { diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index 0b490195ad9..f431f49973e 100644 +index 248d6a28ff9..805a9d7adf9 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h -@@ -622,6 +622,23 @@ typedef union +@@ -668,6 +668,23 @@ typedef union typedef grub_efi_uint64_t grub_efi_physical_address_t; typedef grub_efi_uint64_t grub_efi_virtual_address_t; @@ -4107,9 +4098,9 @@ index 0b490195ad9..f431f49973e 100644 + grub_efi_pxe_ipv6_address_t v6; +} grub_efi_pxe_ip_address_t; - struct grub_efi_guid - { -@@ -889,6 +906,8 @@ struct grub_efi_ipv6_device_path + /* XXX although the spec does not specify the padding, this actually + must have the padding! */ +@@ -917,6 +934,8 @@ struct grub_efi_ipv6_device_path grub_efi_uint16_t remote_port; grub_efi_uint16_t protocol; grub_efi_uint8_t static_ip_address; @@ -4118,7 +4109,7 @@ index 0b490195ad9..f431f49973e 100644 } GRUB_PACKED; typedef struct grub_efi_ipv6_device_path grub_efi_ipv6_device_path_t; -@@ -938,6 +957,15 @@ struct grub_efi_uri_device_path +@@ -975,6 +994,15 @@ struct grub_efi_uri_device_path } GRUB_PACKED; typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t; @@ -4134,7 +4125,7 @@ index 0b490195ad9..f431f49973e 100644 #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 /* Media Device Path. */ -@@ -1020,6 +1048,23 @@ struct grub_efi_bios_device_path +@@ -1057,6 +1085,23 @@ struct grub_efi_bios_device_path } GRUB_PACKED; typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t; @@ -4158,7 +4149,7 @@ index 0b490195ad9..f431f49973e 100644 struct grub_efi_open_protocol_information_entry { grub_efi_handle_t agent_handle; -@@ -1569,23 +1614,27 @@ typedef struct grub_efi_pxe_tftp_error +@@ -1617,23 +1662,27 @@ typedef struct grub_efi_pxe_tftp_error grub_efi_char8_t error_string[127]; } grub_efi_pxe_tftp_error_t; @@ -4200,18 +4191,27 @@ index 0b490195ad9..f431f49973e 100644 #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8 typedef struct grub_efi_pxe_ip_filter -@@ -1652,17 +1701,31 @@ typedef struct grub_efi_pxe_mode +@@ -1700,18 +1749,31 @@ typedef struct grub_efi_pxe_mode typedef struct grub_efi_pxe { grub_uint64_t rev; -- void (*start) (void); +- void *start; +- void *stop; +- void *dhcp; +- void *discover; +- void *mftp; +- void *udpwrite; +- void *udpread; +- void *setipfilter; +- void *arp; +- void *setparams; +- void *setstationip; +- void *setpackets; + grub_efi_status_t (*start) (struct grub_efi_pxe *this, grub_efi_boolean_t use_ipv6); - void (*stop) (void); -- void (*dhcp) (void); ++ void (*stop) (void); + grub_efi_status_t (*dhcp) (struct grub_efi_pxe *this, + grub_efi_boolean_t sort_offers); - void (*discover) (void); -- void (*mftp) (void); ++ void (*discover) (void); + grub_efi_status_t (*mtftp) (struct grub_efi_pxe *this, + grub_efi_pxe_base_code_tftp_opcode_t operation, + void *buffer_ptr, @@ -4223,20 +4223,19 @@ index 0b490195ad9..f431f49973e 100644 + grub_efi_char8_t *filename, + grub_efi_pxe_base_code_mtftp_info_t *info, + grub_efi_boolean_t dont_use_buffer); - void (*udpwrite) (void); - void (*udpread) (void); - void (*setipfilter) (void); - void (*arp) (void); - void (*setparams) (void); -- void (*setstationip) (void); ++ void (*udpwrite) (void); ++ void (*udpread) (void); ++ void (*setipfilter) (void); ++ void (*arp) (void); ++ void (*setparams) (void); + grub_efi_status_t (*set_station_ip) (struct grub_efi_pxe *this, + grub_efi_pxe_ip_address_t *new_station_ip, + grub_efi_pxe_ip_address_t *new_subnet_mask); -+ //void (*setstationip) (void); - void (*setpackets) (void); ++ void (*setpackets) (void); struct grub_efi_pxe_mode *mode; } grub_efi_pxe_t; -@@ -1924,6 +1987,44 @@ struct grub_efi_ip4_config2_protocol + +@@ -2005,6 +2067,44 @@ struct grub_efi_ip4_config2_protocol }; typedef struct grub_efi_ip4_config2_protocol grub_efi_ip4_config2_protocol_t; @@ -4281,7 +4280,7 @@ index 0b490195ad9..f431f49973e 100644 enum grub_efi_ip6_config_data_type { GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID, -@@ -1958,6 +2059,49 @@ struct grub_efi_ip6_config_protocol +@@ -2039,6 +2139,49 @@ struct grub_efi_ip6_config_protocol }; typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t; @@ -4328,9 +4327,9 @@ index 0b490195ad9..f431f49973e 100644 +}; +typedef struct grub_efi_ip6_config_manual_address grub_efi_ip6_config_manual_address_t; + - #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ - || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ - || defined(__riscv) + struct initrd_media_device_path { + grub_efi_vendor_media_device_path_t vendor; + grub_efi_device_path_t end; diff --git a/include/grub/efi/dhcp.h b/include/grub/efi/dhcp.h new file mode 100644 index 00000000000..fdb88eb810e diff --git a/0096-AUDIT-0-http-boot-tracker-bug.patch b/0071-AUDIT-0-http-boot-tracker-bug.patch similarity index 82% rename from 0096-AUDIT-0-http-boot-tracker-bug.patch rename to 0071-AUDIT-0-http-boot-tracker-bug.patch index ef3e67b7..db7f9c75 100644 --- a/0096-AUDIT-0-http-boot-tracker-bug.patch +++ b/0071-AUDIT-0-http-boot-tracker-bug.patch @@ -18,11 +18,11 @@ signed code is allowed to be executed. Signed-off-by: Michael Chang --- grub-core/net/efi/net.c | 4 +++- - grub-core/net/http.c | 5 ++++- - 2 files changed, 7 insertions(+), 2 deletions(-) + grub-core/net/http.c | 8 +++++++- + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 86bce6535d3..4bb308026ce 100644 +index 1a19ee27144..ed04f05ad21 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -645,8 +645,10 @@ grub_efihttp_chunk_read (grub_file_t file, char *buf, @@ -38,20 +38,23 @@ index 86bce6535d3..4bb308026ce 100644 if (buf) { diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index 12a2632ea55..b52b558d631 100644 +index f389bf03d96..af486198399 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c -@@ -31,7 +31,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); +@@ -29,7 +29,11 @@ - enum - { -- HTTP_PORT = 80 + GRUB_MOD_LICENSE ("GPLv3+"); + +-#define HTTP_PORT ((grub_uint16_t) 80) ++enum ++ { + HTTP_PORT = 80, + HTTP_MAX_CHUNK_SIZE = 0x80000000 - }; ++ }; - -@@ -78,6 +79,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) + typedef struct http_data + { +@@ -82,6 +86,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) if (data->in_chunk_len == 2) { data->chunk_rem = grub_strtoul (ptr, 0, 16); diff --git a/0072-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch b/0072-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch deleted file mode 100644 index acfb116d..00000000 --- a/0072-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch +++ /dev/null @@ -1,211 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 7 Nov 2017 17:12:17 -0500 -Subject: [PATCH] Make pmtimer tsc calibration not take 51 seconds to fail. - -On my laptop running at 2.4GHz, if I run a VM where tsc calibration -using pmtimer will fail presuming a broken pmtimer, it takes ~51 seconds -to do so (as measured with the stopwatch on my phone), with a tsc delta -of 0x1cd1c85300, or around 125 billion cycles. - -If instead of trying to wait for 5-200ms to show up on the pmtimer, we try -to wait for 5-200us, it decides it's broken in ~0x2626aa0 TSCs, aka ~2.4 -million cycles, or more or less instantly. - -Additionally, this reading the pmtimer was returning 0xffffffff anyway, -and that's obviously an invalid return. I've added a check for that and -0 so we don't bother waiting for the test if what we're seeing is dead -pins with no response at all. - -If "debug" is includes "pmtimer", you will see one of the following -three outcomes. If pmtimer gives all 0 or all 1 bits, you will see: - -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 1 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 2 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 3 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 4 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 5 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 6 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 7 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 8 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 9 -kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 10 -kern/i386/tsc_pmtimer.c:78: timer is broken; giving up. - -This outcome was tested using qemu+kvm with UEFI (OVMF) firmware and -these options: -machine pc-q35-2.10 -cpu Broadwell-noTSX - -If pmtimer gives any other bit patterns but is not actually marching -forward fast enough to use for clock calibration, you will see: - -kern/i386/tsc_pmtimer.c:121: pmtimer delta is 0x0 (1904 iterations) -kern/i386/tsc_pmtimer.c:124: tsc delta is implausible: 0x2626aa0 - -This outcome was tested using grub compiled with GRUB_PMTIMER_IGNORE_BAD_READS -defined (so as not to trip the bad read test) using qemu+kvm with UEFI -(OVMF) firmware, and these options: -machine pc-q35-2.10 -cpu Broadwell-noTSX - -If pmtimer actually works, you'll see something like: - -kern/i386/tsc_pmtimer.c:121: pmtimer delta is 0x0 (1904 iterations) -kern/i386/tsc_pmtimer.c:124: tsc delta is implausible: 0x2626aa0 - -This outcome was tested using qemu+kvm with UEFI (OVMF) firmware, and -these options: -machine pc-i440fx-2.4 -cpu Broadwell-noTSX - -I've also tested this outcome on a real Intel Xeon E3-1275v3 on an Intel -Server Board S1200V3RPS using the SDV.RP.B8 "Release" build here: -https://firmware.intel.com/sites/default/files/UEFIDevKit_S1200RP_vB8.zip - -Signed-off-by: Peter Jones ---- - grub-core/kern/i386/tsc_pmtimer.c | 109 +++++++++++++++++++++++++++++++------- - 1 file changed, 89 insertions(+), 20 deletions(-) - -diff --git a/grub-core/kern/i386/tsc_pmtimer.c b/grub-core/kern/i386/tsc_pmtimer.c -index c9c36169978..ca15c3aacd7 100644 ---- a/grub-core/kern/i386/tsc_pmtimer.c -+++ b/grub-core/kern/i386/tsc_pmtimer.c -@@ -28,40 +28,101 @@ - #include - #include - -+/* -+ * Define GRUB_PMTIMER_IGNORE_BAD_READS if you're trying to test a timer that's -+ * present but doesn't keep time well. -+ */ -+// #define GRUB_PMTIMER_IGNORE_BAD_READS -+ - grub_uint64_t - grub_pmtimer_wait_count_tsc (grub_port_t pmtimer, - grub_uint16_t num_pm_ticks) - { - grub_uint32_t start; -- grub_uint32_t last; -- grub_uint32_t cur, end; -+ grub_uint64_t cur, end; - grub_uint64_t start_tsc; - grub_uint64_t end_tsc; -- int num_iter = 0; -+ unsigned int num_iter = 0; -+#ifndef GRUB_PMTIMER_IGNORE_BAD_READS -+ int bad_reads = 0; -+#endif - -- start = grub_inl (pmtimer) & 0xffffff; -- last = start; -+ /* -+ * Some timers are 24-bit and some are 32-bit, but it doesn't make much -+ * difference to us. Caring which one we have isn't really worth it since -+ * the low-order digits will give us enough data to calibrate TSC. So just -+ * mask the top-order byte off. -+ */ -+ cur = start = grub_inl (pmtimer) & 0xffffffUL; - end = start + num_pm_ticks; - start_tsc = grub_get_tsc (); - while (1) - { -- cur = grub_inl (pmtimer) & 0xffffff; -- if (cur < last) -- cur |= 0x1000000; -- num_iter++; -+ cur &= 0xffffffffff000000ULL; -+ cur |= grub_inl (pmtimer) & 0xffffffUL; -+ -+ end_tsc = grub_get_tsc(); -+ -+#ifndef GRUB_PMTIMER_IGNORE_BAD_READS -+ /* -+ * If we get 10 reads in a row that are obviously dead pins, there's no -+ * reason to do this thousands of times. -+ */ -+ if (cur == 0xffffffUL || cur == 0) -+ { -+ bad_reads++; -+ grub_dprintf ("pmtimer", -+ "pmtimer: 0x%"PRIxGRUB_UINT64_T" bad_reads: %d\n", -+ cur, bad_reads); -+ grub_dprintf ("pmtimer", "timer is broken; giving up.\n"); -+ -+ if (bad_reads == 10) -+ return 0; -+ } -+#endif -+ -+ if (cur < start) -+ cur += 0x1000000; -+ - if (cur >= end) - { -- end_tsc = grub_get_tsc (); -+ grub_dprintf ("pmtimer", "pmtimer delta is 0x%"PRIxGRUB_UINT64_T"\n", -+ cur - start); -+ grub_dprintf ("pmtimer", "tsc delta is 0x%"PRIxGRUB_UINT64_T"\n", -+ end_tsc - start_tsc); - return end_tsc - start_tsc; - } -- /* Check for broken PM timer. -- 50000000 TSCs is between 5 ms (10GHz) and 200 ms (250 MHz) -- if after this time we still don't have 1 ms on pmtimer, then -- pmtimer is broken. -+ -+ /* -+ * Check for broken PM timer. 1ms at 10GHz should be 1E+7 TSCs; at -+ * 250MHz it should be 2.5E6. So if after 4E+7 TSCs on a 10GHz machine, -+ * we should have seen pmtimer show 4ms of change (i.e. cur =~ -+ * start+14320); on a 250MHz machine that should be 16ms (start+57280). -+ * If after this a time we still don't have 1ms on pmtimer, then pmtimer -+ * is broken. -+ * -+ * Likewise, if our code is perfectly efficient and introduces no delays -+ * whatsoever, on a 10GHz system we should see a TSC delta of 3580 in -+ * ~3580 iterations. On a 250MHz machine that should be ~900 iterations. -+ * -+ * With those factors in mind, there are two limits here. There's a hard -+ * limit here at 8x our desired pm timer delta, picked as an arbitrarily -+ * large value that's still not a lot of time to humans, because if we -+ * get that far this is either an implausibly fast machine or the pmtimer -+ * is not running. And there's another limit on 4x our 10GHz tsc delta -+ * without seeing cur converge on our target value. - */ -- if ((num_iter & 0xffffff) == 0 && grub_get_tsc () - start_tsc > 5000000) { -- return 0; -- } -+ if ((++num_iter > (grub_uint32_t)num_pm_ticks << 3UL) || -+ end_tsc - start_tsc > 40000000) -+ { -+ grub_dprintf ("pmtimer", -+ "pmtimer delta is 0x%"PRIxGRUB_UINT64_T" (%u iterations)\n", -+ cur - start, num_iter); -+ grub_dprintf ("pmtimer", -+ "tsc delta is implausible: 0x%"PRIxGRUB_UINT64_T"\n", -+ end_tsc - start_tsc); -+ return 0; -+ } - } - } - -@@ -74,12 +135,20 @@ grub_tsc_calibrate_from_pmtimer (void) - - fadt = grub_acpi_find_fadt (); - if (!fadt) -- return 0; -+ { -+ grub_dprintf ("pmtimer", "No FADT found; not using pmtimer.\n"); -+ return 0; -+ } - pmtimer = fadt->pmtimer; - if (!pmtimer) -- return 0; -+ { -+ grub_dprintf ("pmtimer", "FADT does not specify pmtimer; skipping.\n"); -+ return 0; -+ } - -- /* It's 3.579545 MHz clock. Wait 1 ms. */ -+ /* -+ * It's 3.579545 MHz clock. Wait 1 ms. -+ */ - tsc_diff = grub_pmtimer_wait_count_tsc (pmtimer, 3580); - if (tsc_diff == 0) - return 0; diff --git a/0097-grub-editenv-Add-incr-command-to-increment-integer-v.patch b/0072-grub-editenv-Add-incr-command-to-increment-integer-v.patch similarity index 100% rename from 0097-grub-editenv-Add-incr-command-to-increment-integer-v.patch rename to 0072-grub-editenv-Add-incr-command-to-increment-integer-v.patch diff --git a/0098-Add-auto-hide-menu-support.patch b/0073-Add-auto-hide-menu-support.patch similarity index 90% rename from 0098-Add-auto-hide-menu-support.patch rename to 0073-Add-auto-hide-menu-support.patch index efb76c40..5b9a0d7a 100644 --- a/0098-Add-auto-hide-menu-support.patch +++ b/0073-Add-auto-hide-menu-support.patch @@ -35,12 +35,6 @@ fastboot If set to "1" and the conditions for auto-hiding the menu https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/quick_boot.patch Signed-off-by: Hans de Goede ---- -Changes in v2: --Drop shutdown_success tests, there is no meaningful way for systemd to set - this flag (by the time it knows all filesystems are unmounted or read-only --Drop fwsetup_once support, systemd already supports booting directly into - the fwsetup by doing "systemctl reboot --firmware" --- Makefile.util.def | 6 +++++ util/grub.d/01_menu_auto_hide.in | 48 ++++++++++++++++++++++++++++++++++++++++ @@ -49,10 +43,10 @@ Changes in v2: create mode 100644 util/grub.d/01_menu_auto_hide.in diff --git a/Makefile.util.def b/Makefile.util.def -index 41906486a71..04551e095bd 100644 +index 1079add5bbe..5b9f85d4869 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -458,6 +458,12 @@ script = { +@@ -461,6 +461,12 @@ script = { installdir = grubconf; }; @@ -120,7 +114,7 @@ index 00000000000..ad175870a54 +fi +EOF diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 4b27bd20153..3c9431cfcfb 100644 +index d7d423b2eaf..18fe02cefd8 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -42,6 +42,7 @@ if [ -z "${OSPROBED}" ] ; then @@ -131,7 +125,7 @@ index 4b27bd20153..3c9431cfcfb 100644 # TRANSLATORS: it refers on the OS residing on device %s onstr="$(gettext_printf "(on %s)" "${DEVICE}")" hints="" -@@ -102,6 +103,7 @@ for OS in ${OSPROBED} ; do +@@ -106,6 +107,7 @@ for OS in ${OSPROBED} ; do case ${BOOT} in chain) @@ -139,7 +133,7 @@ index 4b27bd20153..3c9431cfcfb 100644 onstr="$(gettext_printf "(on %s)" "${DEVICE}")" cat << EOF -@@ -132,6 +134,7 @@ EOF +@@ -136,6 +138,7 @@ EOF EOF ;; efi) @@ -147,7 +141,7 @@ index 4b27bd20153..3c9431cfcfb 100644 EFIPATH=${DEVICE#*@} DEVICE=${DEVICE%@*} -@@ -176,6 +179,7 @@ EOF +@@ -180,6 +183,7 @@ EOF LINITRD="${LINITRD#/boot}" fi @@ -155,7 +149,7 @@ index 4b27bd20153..3c9431cfcfb 100644 onstr="$(gettext_printf "(on %s)" "${DEVICE}")" recovery_params="$(echo "${LPARAMS}" | grep single)" || true counter=1 -@@ -257,6 +261,7 @@ EOF +@@ -261,6 +265,7 @@ EOF done ;; hurd) @@ -163,7 +157,7 @@ index 4b27bd20153..3c9431cfcfb 100644 onstr="$(gettext_printf "(on %s)" "${DEVICE}")" cat << EOF menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' { -@@ -283,6 +288,7 @@ EOF +@@ -287,6 +292,7 @@ EOF EOF ;; minix) @@ -171,7 +165,7 @@ index 4b27bd20153..3c9431cfcfb 100644 cat << EOF menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" { EOF -@@ -299,3 +305,15 @@ EOF +@@ -303,3 +309,15 @@ EOF ;; esac done diff --git a/0099-Add-grub-set-bootflag-utility.patch b/0074-Add-grub-set-bootflag-utility.patch similarity index 83% rename from 0099-Add-grub-set-bootflag-utility.patch rename to 0074-Add-grub-set-bootflag-utility.patch index f5ff7d38..f6dc7314 100644 --- a/0099-Add-grub-set-bootflag-utility.patch +++ b/0074-Add-grub-set-bootflag-utility.patch @@ -31,24 +31,28 @@ and a symlink to grub-boot-success.timer should be added to /lib/systemd/user/timers.target.wants. Signed-off-by: Hans de Goede +[makhomed: grub-boot-success.timer: Only run if not in a container] +Signed-off-by: Gena Makhomed +[rharwood: migrate to h2m] +Signed-off-by: Robbie Harwood --- Makefile.util.def | 7 ++ - util/grub-set-bootflag.c | 160 +++++++++++++++++++++++++++++++++++++++++ + util/grub-set-bootflag.c | 172 +++++++++++++++++++++++++++++++++++++++++ conf/Makefile.extra-dist | 3 + docs/grub-boot-success.service | 6 ++ - docs/grub-boot-success.timer | 6 ++ - util/grub-set-bootflag.1 | 20 ++++++ - 6 files changed, 202 insertions(+) + docs/grub-boot-success.timer | 7 ++ + docs/man/grub-set-bootflag.h2m | 2 + + 6 files changed, 197 insertions(+) create mode 100644 util/grub-set-bootflag.c create mode 100644 docs/grub-boot-success.service create mode 100644 docs/grub-boot-success.timer - create mode 100644 util/grub-set-bootflag.1 + create mode 100644 docs/man/grub-set-bootflag.h2m diff --git a/Makefile.util.def b/Makefile.util.def -index 04551e095bd..c6375933faa 100644 +index 5b9f85d4869..01096ded815 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -1445,3 +1445,10 @@ program = { +@@ -1468,3 +1468,10 @@ program = { ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -61,10 +65,10 @@ index 04551e095bd..c6375933faa 100644 +}; diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c new file mode 100644 -index 00000000000..bb198f02351 +index 00000000000..d506f7e75bc --- /dev/null +++ b/util/grub-set-bootflag.c -@@ -0,0 +1,160 @@ +@@ -0,0 +1,172 @@ +/* grub-set-bootflag.c - tool to set boot-flags in the grubenv. */ +/* + * GRUB -- GRand Unified Bootloader @@ -98,6 +102,8 @@ index 00000000000..bb198f02351 +#include +#include + ++#include "progname.h" ++ +#define GRUBENV "/" GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME "/" GRUB_ENVBLK_DEFCFG +#define GRUBENV_SIZE 1024 + @@ -107,13 +113,13 @@ index 00000000000..bb198f02351 + NULL +}; + -+static void usage(void) ++static void usage(FILE *out) +{ + int i; + -+ fprintf (stderr, "Usage: 'grub-set-bootflag ', where is one of:\n"); ++ fprintf (out, "Usage: 'grub-set-bootflag ', where is one of:\n"); + for (i = 0; bootflags[i]; i++) -+ fprintf (stderr, " %s\n", bootflags[i]); ++ fprintf (out, " %s\n", bootflags[i]); +} + +int main(int argc, char *argv[]) @@ -126,9 +132,19 @@ index 00000000000..bb198f02351 + + if (argc != 2) + { -+ usage(); ++ usage (stderr); + return 1; + } ++ else if (!strcmp (argv[1], "--help")) ++ { ++ usage (stdout); ++ return 0; ++ } ++ else if (!strcmp (argv[1], "--version")) ++ { ++ printf ("grub-set-bootflag (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); ++ return 0; ++ } + + for (i = 0; bootflags[i]; i++) + if (!strcmp (argv[1], bootflags[i])) @@ -136,7 +152,7 @@ index 00000000000..bb198f02351 + if (!bootflags[i]) + { + fprintf (stderr, "Invalid bootflag: '%s'\n", argv[1]); -+ usage(); ++ usage (stderr); + return 1; + } + @@ -226,10 +242,10 @@ index 00000000000..bb198f02351 + return 0; +} diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist -index b909f2c073a..ea58362b555 100644 +index 5e7126f9878..26ac8765e30 100644 --- a/conf/Makefile.extra-dist +++ b/conf/Makefile.extra-dist -@@ -14,6 +14,9 @@ EXTRA_DIST += util/import_unicode.py +@@ -15,6 +15,9 @@ EXTRA_DIST += docs/man EXTRA_DIST += docs/autoiso.cfg EXTRA_DIST += docs/grub.cfg EXTRA_DIST += docs/osdetect.cfg @@ -253,39 +269,22 @@ index 00000000000..80e79584c91 +ExecStart=/usr/sbin/grub2-set-bootflag boot_success diff --git a/docs/grub-boot-success.timer b/docs/grub-boot-success.timer new file mode 100644 -index 00000000000..5d8fcba21aa +index 00000000000..406f1720056 --- /dev/null +++ b/docs/grub-boot-success.timer -@@ -0,0 +1,6 @@ +@@ -0,0 +1,7 @@ +[Unit] +Description=Mark boot as successful after the user session has run 2 minutes +ConditionUser=!@system ++ConditionVirtualization=!container + +[Timer] +OnActiveSec=2min -diff --git a/util/grub-set-bootflag.1 b/util/grub-set-bootflag.1 +diff --git a/docs/man/grub-set-bootflag.h2m b/docs/man/grub-set-bootflag.h2m new file mode 100644 -index 00000000000..57801da22a0 +index 00000000000..94ec0b92ede --- /dev/null -+++ b/util/grub-set-bootflag.1 -@@ -0,0 +1,20 @@ -+.TH GRUB-SET-BOOTFLAG 1 "Tue Jun 12 2018" -+.SH NAME -+\fBgrub-set-bootflag\fR \(em Set a bootflag in the GRUB environment block. -+ -+.SH SYNOPSIS -+\fBgrub-set-bootflag\fR <\fIBOOTFLAG\fR> -+ -+.SH DESCRIPTION -+\fBgrub-set-bootflag\fR is a command line to set bootflags in GRUB's -+stored environment. -+ -+.SH COMMANDS -+.TP -+\fBBOOTFLAG\fR -+.RS 7 -+Bootflag to set, one of \fIboot_success\fR or \fIshow_menu_once\fR. -+.RE -+ -+.SH SEE ALSO -+.BR "info grub" ++++ b/docs/man/grub-set-bootflag.h2m +@@ -0,0 +1,2 @@ ++[NAME] ++grub-set-bootflag \- set a bootflag in the GRUB environment block diff --git a/0100-docs-Add-grub-boot-indeterminate.service-example.patch b/0075-docs-Add-grub-boot-indeterminate.service-example.patch similarity index 100% rename from 0100-docs-Add-grub-boot-indeterminate.service-example.patch rename to 0075-docs-Add-grub-boot-indeterminate.service-example.patch diff --git a/0076-Add-linux-and-initrd-commands-for-grub-emu.patch b/0076-Add-linux-and-initrd-commands-for-grub-emu.patch deleted file mode 100644 index dd69b130..00000000 --- a/0076-Add-linux-and-initrd-commands-for-grub-emu.patch +++ /dev/null @@ -1,347 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Tue, 6 Feb 2018 09:09:00 +0100 -Subject: [PATCH] Add linux and initrd commands for grub-emu - -When using grub-emu, the linux and initrd commands are used as arguments -to the kexec command line tool, to allow booting the selected menu entry. ---- - grub-core/Makefile.core.def | 1 - - grub-core/kern/emu/main.c | 4 + - grub-core/kern/emu/misc.c | 18 ++++- - grub-core/loader/emu/linux.c | 172 +++++++++++++++++++++++++++++++++++++++++++ - include/grub/emu/exec.h | 4 +- - include/grub/emu/hostfile.h | 3 +- - include/grub/emu/misc.h | 3 + - grub-core/Makefile.am | 1 + - 8 files changed, 202 insertions(+), 4 deletions(-) - create mode 100644 grub-core/loader/emu/linux.c - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 058c88ac3af..5354f9613d3 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1826,7 +1826,6 @@ module = { - - common = loader/linux.c; - common = lib/cmdline.c; -- enable = noemu; - - efi = loader/efi/linux.c; - }; -diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c -index 55ea5a11ccd..846fe9715ec 100644 ---- a/grub-core/kern/emu/main.c -+++ b/grub-core/kern/emu/main.c -@@ -107,6 +107,7 @@ static struct argp_option options[] = { - N_("use GRUB files in the directory DIR [default=%s]"), 0}, - {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, - {"hold", 'H', N_("SECS"), OPTION_ARG_OPTIONAL, N_("wait until a debugger will attach"), 0}, -+ {"kexec", 'X', 0, 0, N_("try the untryable."), 0}, - { 0, 0, 0, 0, 0, 0 } - }; - -@@ -164,6 +165,9 @@ argp_parser (int key, char *arg, struct argp_state *state) - case 'v': - verbosity++; - break; -+ case 'X': -+ grub_util_set_kexecute(); -+ break; - - case ARGP_KEY_ARG: - { -diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index 0ff13bcaf8c..eeea092752d 100644 ---- a/grub-core/kern/emu/misc.c -+++ b/grub-core/kern/emu/misc.c -@@ -39,6 +39,7 @@ - #include - - int verbosity; -+int kexecute; - - void - grub_util_warn (const char *fmt, ...) -@@ -82,7 +83,7 @@ grub_util_error (const char *fmt, ...) - vfprintf (stderr, fmt, ap); - va_end (ap); - fprintf (stderr, ".\n"); -- exit (1); -+ grub_exit (1); - } - - void * -@@ -154,6 +155,9 @@ void - __attribute__ ((noreturn)) - grub_exit (int rc) - { -+#if defined (GRUB_KERNEL) -+ grub_reboot(); -+#endif - exit (rc < 0 ? 1 : rc); - } - #endif -@@ -215,3 +219,15 @@ grub_util_load_image (const char *path, char *buf) - - fclose (fp); - } -+ -+void -+grub_util_set_kexecute(void) -+{ -+ kexecute++; -+} -+ -+int -+grub_util_get_kexecute(void) -+{ -+ return kexecute; -+} -diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c -new file mode 100644 -index 00000000000..fda9e00d24c ---- /dev/null -+++ b/grub-core/loader/emu/linux.c -@@ -0,0 +1,172 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#include -+#include -+#include -+#include -+ -+#include -+#include -+#include -+ -+GRUB_MOD_LICENSE ("GPLv3+"); -+ -+static grub_dl_t my_mod; -+ -+static char *kernel_path; -+static char *initrd_path; -+static char *boot_cmdline; -+ -+static grub_err_t -+grub_linux_boot (void) -+{ -+ grub_err_t rc = GRUB_ERR_NONE; -+ char *initrd_param; -+ const char *kexec[] = { "kexec", "-l", kernel_path, boot_cmdline, NULL, NULL }; -+ const char *systemctl[] = { "systemctl", "kexec", NULL }; -+ int kexecute = grub_util_get_kexecute(); -+ -+ if (initrd_path) { -+ initrd_param = grub_xasprintf("--initrd=%s", initrd_path); -+ kexec[3] = initrd_param; -+ kexec[4] = boot_cmdline; -+ } else { -+ initrd_param = grub_xasprintf("%s", ""); -+ } -+ -+ grub_printf("%serforming 'kexec -l %s %s %s'\n", -+ (kexecute) ? "P" : "Not p", -+ kernel_path, initrd_param, boot_cmdline); -+ -+ if (kexecute) -+ rc = grub_util_exec(kexec); -+ -+ grub_free(initrd_param); -+ -+ if (rc != GRUB_ERR_NONE) { -+ grub_error (rc, N_("Error trying to perform kexec load operation.")); -+ grub_sleep (3); -+ return rc; -+ } -+ if (kexecute < 1) -+ grub_fatal (N_("Use '"PACKAGE"-emu --kexec' to force a system restart.")); -+ -+ grub_printf("Performing 'systemctl kexec' (%s) ", -+ (kexecute==1) ? "do-or-die" : "just-in-case"); -+ rc = grub_util_exec (systemctl); -+ -+ if (kexecute == 1) -+ grub_fatal (N_("Error trying to perform 'systemctl kexec'")); -+ -+ /* need to check read-only root before resetting hard!? */ -+ grub_printf("Performing 'kexec -e'"); -+ kexec[1] = "-e"; -+ kexec[2] = NULL; -+ rc = grub_util_exec(kexec); -+ if ( rc != GRUB_ERR_NONE ) -+ grub_fatal (N_("Error trying to directly perform 'kexec -e'.")); -+ -+ return rc; -+} -+ -+static grub_err_t -+grub_linux_unload (void) -+{ -+ grub_dl_unref (my_mod); -+ if ( boot_cmdline != NULL ) -+ grub_free (boot_cmdline); -+ boot_cmdline = NULL; -+ return GRUB_ERR_NONE; -+} -+ -+static grub_err_t -+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) -+{ -+ int i; -+ char *tempstr; -+ -+ grub_dl_ref (my_mod); -+ -+ if (argc == 0) -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -+ -+ if ( !grub_util_is_regular(argv[0]) ) -+ return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("Cannot find kernel file %s"), argv[0]); -+ -+ if ( kernel_path != NULL ) -+ grub_free(kernel_path); -+ -+ kernel_path = grub_xasprintf("%s", argv[0]); -+ -+ if ( boot_cmdline != NULL ) { -+ grub_free(boot_cmdline); -+ boot_cmdline = NULL; -+ } -+ -+ if ( argc > 1 ) -+ { -+ boot_cmdline = grub_xasprintf("--command-line=%s", argv[1]); -+ for ( i = 2; i < argc; i++ ) { -+ tempstr = grub_xasprintf("%s %s", boot_cmdline, argv[i]); -+ grub_free(boot_cmdline); -+ boot_cmdline = tempstr; -+ } -+ } -+ -+ grub_loader_set (grub_linux_boot, grub_linux_unload, 0); -+ -+ return GRUB_ERR_NONE; -+} -+ -+static grub_err_t -+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) -+{ -+ if (argc == 0) -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -+ -+ if ( !grub_util_is_regular(argv[0]) ) -+ return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("Cannot find initrd file %s"), argv[0]); -+ -+ if ( initrd_path != NULL ) -+ grub_free(initrd_path); -+ -+ initrd_path = grub_xasprintf("%s", argv[0]); -+ -+ grub_dl_unref (my_mod); -+ -+ return GRUB_ERR_NONE; -+} -+ -+static grub_command_t cmd_linux, cmd_initrd; -+ -+GRUB_MOD_INIT(linux) -+{ -+ cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, N_("Load Linux.")); -+ cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, N_("Load initrd.")); -+ my_mod = mod; -+ kernel_path = NULL; -+ initrd_path = NULL; -+ boot_cmdline = NULL; -+} -+ -+GRUB_MOD_FINI(linux) -+{ -+ grub_unregister_command (cmd_linux); -+ grub_unregister_command (cmd_initrd); -+} -diff --git a/include/grub/emu/exec.h b/include/grub/emu/exec.h -index d1073ef86af..1b61b4a2e5d 100644 ---- a/include/grub/emu/exec.h -+++ b/include/grub/emu/exec.h -@@ -23,6 +23,8 @@ - #include - - #include -+#include -+ - pid_t - grub_util_exec_pipe (const char *const *argv, int *fd); - pid_t -@@ -32,7 +34,7 @@ int - grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, - const char *stdout_file, const char *stderr_file); - int --grub_util_exec (const char *const *argv); -+EXPORT_FUNC(grub_util_exec) (const char *const *argv); - int - grub_util_exec_redirect (const char *const *argv, const char *stdin_file, - const char *stdout_file); -diff --git a/include/grub/emu/hostfile.h b/include/grub/emu/hostfile.h -index cfb1e2b5661..a61568e36e9 100644 ---- a/include/grub/emu/hostfile.h -+++ b/include/grub/emu/hostfile.h -@@ -22,6 +22,7 @@ - #include - #include - #include -+#include - #include - - int -@@ -29,7 +30,7 @@ grub_util_is_directory (const char *path); - int - grub_util_is_special_file (const char *path); - int --grub_util_is_regular (const char *path); -+EXPORT_FUNC(grub_util_is_regular) (const char *path); - - char * - grub_util_path_concat (size_t n, ...); -diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h -index ff9c48a6490..01056954b96 100644 ---- a/include/grub/emu/misc.h -+++ b/include/grub/emu/misc.h -@@ -57,6 +57,9 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( - void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); - void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2), noreturn)); - -+void EXPORT_FUNC(grub_util_set_kexecute) (void); -+int EXPORT_FUNC(grub_util_get_kexecute) (void) WARN_UNUSED_RESULT; -+ - grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void); - - #ifdef HAVE_DEVICE_MAPPER -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index ee88e44e97a..80e7a83edf9 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -307,6 +307,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/exec.h - if COND_GRUB_EMU_SDL - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h - endif diff --git a/0101-gentpl-add-disable-support.patch b/0076-gentpl-add-disable-support.patch similarity index 89% rename from 0101-gentpl-add-disable-support.patch rename to 0076-gentpl-add-disable-support.patch index 2c3c998f..949cfe8f 100644 --- a/0101-gentpl-add-disable-support.patch +++ b/0076-gentpl-add-disable-support.patch @@ -9,10 +9,10 @@ Signed-off-by: Peter Jones 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gentpl.py b/gentpl.py -index 2cba0bbbd6f..628e8bec1d7 100644 +index bfab2113a1d..6cad9b8231f 100644 --- a/gentpl.py +++ b/gentpl.py -@@ -592,11 +592,21 @@ def platform_conditional(platform, closure): +@@ -594,11 +594,21 @@ def platform_conditional(platform, closure): # }; # def foreach_enabled_platform(defn, closure): @@ -35,7 +35,7 @@ index 2cba0bbbd6f..628e8bec1d7 100644 for platform in GRUB_PLATFORMS: platform_conditional(platform, closure) -@@ -655,6 +665,8 @@ def first_time(defn, snippet): +@@ -657,6 +667,8 @@ def first_time(defn, snippet): def is_platform_independent(defn): if 'enable' in defn: return False diff --git a/0102-gentpl-add-pc-firmware-type.patch b/0077-gentpl-add-pc-firmware-type.patch similarity index 74% rename from 0102-gentpl-add-pc-firmware-type.patch rename to 0077-gentpl-add-pc-firmware-type.patch index 96dd2b8c..608582a5 100644 --- a/0102-gentpl-add-pc-firmware-type.patch +++ b/0077-gentpl-add-pc-firmware-type.patch @@ -9,14 +9,14 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+) diff --git a/gentpl.py b/gentpl.py -index 628e8bec1d7..34a4eba2b42 100644 +index 6cad9b8231f..597129a2bc4 100644 --- a/gentpl.py +++ b/gentpl.py -@@ -51,6 +51,7 @@ GROUPS["riscv32"] = [ "riscv32_efi" ] - GROUPS["riscv64"] = [ "riscv64_efi" ] +@@ -52,6 +52,7 @@ GROUPS["riscv32"] = [ "riscv32_efi" ] + GROUPS["riscv64"] = [ "riscv64_efi" ] # Groups based on firmware +GROUPS["pc"] = [ "i386_pc" ] GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", - "riscv32_efi", "riscv64_efi" ] + "loongarch64_efi", "riscv32_efi", "riscv64_efi" ] GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] diff --git a/0103-efinet-also-use-the-firmware-acceleration-for-http.patch b/0078-efinet-also-use-the-firmware-acceleration-for-http.patch similarity index 96% rename from 0103-efinet-also-use-the-firmware-acceleration-for-http.patch rename to 0078-efinet-also-use-the-firmware-acceleration-for-http.patch index 915b5aa1..8ce3e014 100644 --- a/0103-efinet-also-use-the-firmware-acceleration-for-http.patch +++ b/0078-efinet-also-use-the-firmware-acceleration-for-http.patch @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 4bb308026ce..6603cd83edc 100644 +index ed04f05ad21..1f7e1b63557 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -1324,7 +1324,9 @@ grub_efi_net_boot_from_https (void) diff --git a/0104-efi-http-Make-root_url-reflect-the-protocol-hostname.patch b/0079-efi-http-Make-root_url-reflect-the-protocol-hostname.patch similarity index 93% rename from 0104-efi-http-Make-root_url-reflect-the-protocol-hostname.patch rename to 0079-efi-http-Make-root_url-reflect-the-protocol-hostname.patch index 985a0378..6f98f25e 100644 --- a/0104-efi-http-Make-root_url-reflect-the-protocol-hostname.patch +++ b/0079-efi-http-Make-root_url-reflect-the-protocol-hostname.patch @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 19 insertions(+) diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index 3f61fd2fa5b..243acbaa35b 100644 +index de28badccb0..b94dbc68eef 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c @@ -4,6 +4,7 @@ @@ -23,7 +23,7 @@ index 3f61fd2fa5b..243acbaa35b 100644 static void http_configure (struct grub_efi_net_device *dev, int prefer_ip6) -@@ -351,6 +352,24 @@ grub_efihttp_open (struct grub_efi_net_device *dev, +@@ -342,6 +343,24 @@ grub_efihttp_open (struct grub_efi_net_device *dev, grub_err_t err; grub_off_t size; char *buf; diff --git a/0105-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch b/0080-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch similarity index 87% rename from 0105-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch rename to 0080-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch index b65eafcc..9d8be1eb 100644 --- a/0105-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch +++ b/0080-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch @@ -17,11 +17,11 @@ Signed-off-by: Peter Jones 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac -index b4455e4732d..3405348178a 100644 +index fcfbcbb664d..c17e83acf87 100644 --- a/configure.ac +++ b/configure.ac -@@ -877,11 +877,23 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$p - TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" +@@ -914,11 +914,23 @@ if test "x$target_cpu" = xloongarch64; then + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs" fi +# Should grub utils get the host CFLAGS, or the target CFLAGS? @@ -45,7 +45,7 @@ index b4455e4732d..3405348178a 100644 AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [ grub_cv_target_cc_soft_float=no if test "x$target_cpu" = xarm64; then -@@ -2018,6 +2030,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" +@@ -2111,6 +2123,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include" @@ -88,19 +88,19 @@ index b4455e4732d..3405348178a 100644 GRUB_PLATFORM="${platform}" diff --git a/conf/Makefile.common b/conf/Makefile.common -index 5f0ef969857..2ff9b39357c 100644 +index 6262f21a772..54f0f7f7664 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common -@@ -40,24 +40,25 @@ CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 - CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) - STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes +@@ -50,24 +50,25 @@ else + endif + endif -CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding --LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +-LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r -CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) +CFLAGS_MODULE = $(TARGET_CFLAGS) $(CFLAGS_PLATFORM) -ffreestanding -+LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d ++LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r +CPPFLAGS_MODULE = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) +CCASFLAGS_MODULE = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) @@ -129,10 +129,10 @@ index 5f0ef969857..2ff9b39357c 100644 # Other variables diff --git a/gentpl.py b/gentpl.py -index 34a4eba2b42..59f62ef9522 100644 +index 597129a2bc4..5826a6b14e8 100644 --- a/gentpl.py +++ b/gentpl.py -@@ -697,10 +697,10 @@ def module(defn, platform): +@@ -699,10 +699,10 @@ def module(defn, platform): var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources") var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources") var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform)) diff --git a/0107-Rework-how-the-fdt-command-builds.patch b/0081-Rework-how-the-fdt-command-builds.patch similarity index 76% rename from 0107-Rework-how-the-fdt-command-builds.patch rename to 0081-Rework-how-the-fdt-command-builds.patch index 71328da1..8c00d382 100644 --- a/0107-Rework-how-the-fdt-command-builds.patch +++ b/0081-Rework-how-the-fdt-command-builds.patch @@ -13,19 +13,22 @@ grub_fdt_load in xen_boot is not defined grub_fdt_unload in xen_boot is not defined Signed-off-by: Peter Jones +[javierm: Fix build with platform emu, aarch64, and risc-v] +Signed-off-by: Javier Martinez Canillas +Signed-off-by: Robbie Harwood --- - grub-core/Makefile.core.def | 5 ++--- + grub-core/Makefile.core.def | 4 ++-- grub-core/lib/fdt.c | 2 -- grub-core/loader/efi/fdt.c | 2 ++ - include/grub/fdt.h | 4 ++++ + include/grub/fdt.h | 6 ++++++ grub-core/Makefile.am | 1 + - 5 files changed, 9 insertions(+), 5 deletions(-) + 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index c40170f2dd2..84a3d89de9a 100644 +index 56eb6a828e8..4629c179e40 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -177,7 +177,6 @@ kernel = { +@@ -188,7 +188,6 @@ kernel = { arm_coreboot = kern/arm/coreboot/init.c; arm_coreboot = kern/arm/coreboot/timer.c; arm_coreboot = kern/arm/coreboot/coreboot.S; @@ -33,7 +36,7 @@ index c40170f2dd2..84a3d89de9a 100644 arm_coreboot = bus/fdt.c; arm_coreboot = term/ps2.c; arm_coreboot = term/arm/pl050.c; -@@ -351,6 +350,8 @@ kernel = { +@@ -370,6 +369,8 @@ kernel = { riscv64 = kern/riscv/cache_flush.S; riscv64 = kern/riscv/dl.c; @@ -42,15 +45,7 @@ index c40170f2dd2..84a3d89de9a 100644 emu = disk/host.c; emu = kern/emu/cache_s.S; emu = kern/emu/hostdisk.c; -@@ -1825,7 +1826,6 @@ module = { - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; - emu = loader/emu/linux.c; -- fdt = lib/fdt.c; - - common = loader/linux.c; - common = lib/cmdline.c; -@@ -1836,7 +1836,6 @@ module = { +@@ -1882,7 +1883,6 @@ module = { module = { name = fdt; efi = loader/efi/fdt.c; @@ -59,7 +54,7 @@ index c40170f2dd2..84a3d89de9a 100644 }; diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c -index 0d371c5633e..37e04bd69e7 100644 +index 73cfa94a2df..fbf749e1d61 100644 --- a/grub-core/lib/fdt.c +++ b/grub-core/lib/fdt.c @@ -21,8 +21,6 @@ @@ -72,7 +67,7 @@ index 0d371c5633e..37e04bd69e7 100644 #define FDT_BEGIN_NODE 0x00000001 diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c -index c86f283d756..c572415d38a 100644 +index 439964b9ca6..e08d8738afc 100644 --- a/grub-core/loader/efi/fdt.c +++ b/grub-core/loader/efi/fdt.c @@ -27,6 +27,8 @@ @@ -85,27 +80,29 @@ index c86f283d756..c572415d38a 100644 static void *fdt; diff --git a/include/grub/fdt.h b/include/grub/fdt.h -index e609c7e4111..22b7c5463fc 100644 +index e609c7e4111..3514aa4a5b6 100644 --- a/include/grub/fdt.h +++ b/include/grub/fdt.h -@@ -19,6 +19,8 @@ +@@ -19,6 +19,9 @@ #ifndef GRUB_FDT_HEADER #define GRUB_FDT_HEADER 1 -+#if defined(__arm__) || defined(__aarch64__) ++#if !defined(GRUB_MACHINE_EMU) && \ ++ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) + #include #include -@@ -144,4 +146,6 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch +@@ -144,4 +147,7 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \ }) -+#endif /* defined(__arm__) || defined(__aarch64__) */ ++#endif /* !defined(GRUB_MACHINE_EMU) && \ ++ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) */ + #endif /* ! GRUB_FDT_HEADER */ diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index f512573c0da..dd49939aaa9 100644 +index b7192a3da82..7953ba95399 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -76,6 +76,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h diff --git a/0108-Disable-non-wordsize-allocations-on-arm.patch b/0082-Disable-non-wordsize-allocations-on-arm.patch similarity index 93% rename from 0108-Disable-non-wordsize-allocations-on-arm.patch rename to 0082-Disable-non-wordsize-allocations-on-arm.patch index f614c9ee..e8c46418 100644 --- a/0108-Disable-non-wordsize-allocations-on-arm.patch +++ b/0082-Disable-non-wordsize-allocations-on-arm.patch @@ -9,10 +9,10 @@ Signed-off-by: Peter Jones 1 file changed, 20 insertions(+) diff --git a/configure.ac b/configure.ac -index 3405348178a..152e7dba652 100644 +index c17e83acf87..3f3a170ab17 100644 --- a/configure.ac +++ b/configure.ac -@@ -1288,6 +1288,26 @@ if test "x$target_cpu" = xarm; then +@@ -1346,6 +1346,26 @@ if test "x$target_cpu" = xarm; then done ]) diff --git a/0083-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch b/0083-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch deleted file mode 100644 index 75de764a..00000000 --- a/0083-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch +++ /dev/null @@ -1,178 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 25 Jun 2015 15:11:36 -0400 -Subject: [PATCH] Make a "gdb" dprintf that tells us load addresses. - -This makes a grub_dprintf() call during platform init and during module -loading that tells us the virtual addresses of the .text and .data -sections of grub-core/kernel.exec and any modules it loads. - -Specifically, it displays them in the gdb "add-symbol-file" syntax, with -the presumption that there's a variable $grubdir that reflects the path -to any such binaries. - -Signed-off-by: Peter Jones ---- - grub-core/kern/dl.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ - grub-core/kern/efi/efi.c | 4 ++-- - grub-core/kern/efi/init.c | 26 +++++++++++++++++++++++- - include/grub/efi/efi.h | 2 +- - 4 files changed, 78 insertions(+), 4 deletions(-) - -diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 88d2077709e..9557254035e 100644 ---- a/grub-core/kern/dl.c -+++ b/grub-core/kern/dl.c -@@ -501,6 +501,23 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name) - return s; - return NULL; - } -+static long -+grub_dl_find_section_index (Elf_Ehdr *e, const char *name) -+{ -+ Elf_Shdr *s; -+ const char *str; -+ unsigned i; -+ -+ s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize); -+ str = (char *) e + s->sh_offset; -+ -+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); -+ i < e->e_shnum; -+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) -+ if (grub_strcmp (str + s->sh_name, name) == 0) -+ return (long)i; -+ return -1; -+} - - /* Me, Vladimir Serbinenko, hereby I add this module check as per new - GNU module policy. Note that this license check is informative only. -@@ -653,6 +670,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) - - return GRUB_ERR_NONE; - } -+static void -+grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e) -+{ -+ void *text, *data = NULL; -+ long idx; -+ -+ idx = grub_dl_find_section_index (e, ".text"); -+ if (idx < 0) -+ return; -+ -+ text = grub_dl_get_section_addr (mod, idx); -+ if (!text) -+ return; -+ -+ idx = grub_dl_find_section_index (e, ".data"); -+ if (idx >= 0) -+ data = grub_dl_get_section_addr (mod, idx); -+ -+ if (data) -+ grub_qdprintf ("gdb", "add-symbol-file \\\n" -+ "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug " -+ "\\\n %p -s .data %p\n", -+ GRUB_TARGET_CPU, GRUB_PLATFORM, -+ mod->name, text, data); -+ else -+ grub_qdprintf ("gdb", "add-symbol-file \\\n" -+ "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug " -+ "\\\n%p\n", -+ GRUB_TARGET_CPU, GRUB_PLATFORM, -+ mod->name, text); -+} - - /* Load a module from core memory. */ - grub_dl_t -@@ -712,6 +760,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) - grub_dprintf ("modules", "module name: %s\n", mod->name); - grub_dprintf ("modules", "init function: %p\n", mod->init); - -+ grub_dl_print_gdb_info (mod, e); -+ - if (grub_dl_add (mod)) - { - grub_dl_unload (mod); -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index ae9885edb84..d6a2fb57789 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -296,7 +296,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - /* Search the mods section from the PE32/PE32+ image. This code uses - a PE32 header, but should work with PE32+ as well. */ - grub_addr_t --grub_efi_modules_addr (void) -+grub_efi_section_addr (const char *section_name) - { - grub_efi_loaded_image_t *image; - struct grub_pe32_header *header; -@@ -321,7 +321,7 @@ grub_efi_modules_addr (void) - i < coff_header->num_sections; - i++, section++) - { -- if (grub_strcmp (section->name, "mods") == 0) -+ if (grub_strcmp (section->name, section_name) == 0) - break; - } - -diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 6d39bd3ad29..2d12e6188fd 100644 ---- a/grub-core/kern/efi/init.c -+++ b/grub-core/kern/efi/init.c -@@ -115,10 +115,33 @@ grub_efi_env_init (void) - grub_free (envblk_s.buf); - } - -+static void -+grub_efi_print_gdb_info (void) -+{ -+ grub_addr_t text; -+ grub_addr_t data; -+ -+ text = grub_efi_section_addr (".text"); -+ if (!text) -+ return; -+ -+ data = grub_efi_section_addr (".data"); -+ if (data) -+ grub_qdprintf ("gdb", -+ "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/" -+ "kernel.exec %p -s .data %p\n", -+ GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text, (void *)data); -+ else -+ grub_qdprintf ("gdb", -+ "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/" -+ "kernel.exec %p\n", -+ GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text); -+} -+ - void - grub_efi_init (void) - { -- grub_modbase = grub_efi_modules_addr (); -+ grub_modbase = grub_efi_section_addr ("mods"); - /* First of all, initialize the console so that GRUB can display - messages. */ - grub_console_init (); -@@ -142,6 +165,7 @@ grub_efi_init (void) - 0, 0, 0, NULL); - - grub_efi_env_init (); -+ grub_efi_print_gdb_info (); - grub_efidisk_init (); - } - -diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 03f9a9d0118..2e0691454b1 100644 ---- a/include/grub/efi/efi.h -+++ b/include/grub/efi/efi.h -@@ -138,7 +138,7 @@ grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); - grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); - #endif - --grub_addr_t grub_efi_modules_addr (void); -+grub_addr_t grub_efi_section_addr (const char *section); - - void grub_efi_mm_init (void); - void grub_efi_mm_fini (void); diff --git a/0109-Prepend-prefix-when-HTTP-path-is-relative.patch b/0083-Prepend-prefix-when-HTTP-path-is-relative.patch similarity index 95% rename from 0109-Prepend-prefix-when-HTTP-path-is-relative.patch rename to 0083-Prepend-prefix-when-HTTP-path-is-relative.patch index fc861d97..ac6c8062 100644 --- a/0109-Prepend-prefix-when-HTTP-path-is-relative.patch +++ b/0083-Prepend-prefix-when-HTTP-path-is-relative.patch @@ -8,13 +8,15 @@ http_path: /foo/bar http_url: http://www.example.com/foo/bar Signed-off-by: Peter Jones +Signed-off-by: Stephen Benjamin +Signed-off-by: Robbie Harwood --- grub-core/kern/main.c | 10 +++++- grub-core/net/efi/http.c | 82 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index 48058d983ce..4ec3f5e4d33 100644 +index 463dafdba02..7347a8de676 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -131,11 +131,19 @@ grub_set_prefix_and_root (void) @@ -39,7 +41,7 @@ index 48058d983ce..4ec3f5e4d33 100644 } } diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index 243acbaa35b..de351b2cd03 100644 +index b94dbc68eef..5e97f5d5e70 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c @@ -9,10 +9,52 @@ @@ -95,7 +97,7 @@ index 243acbaa35b..de351b2cd03 100644 grub_efi_http_t *http = dev->http; -@@ -352,32 +394,32 @@ grub_efihttp_open (struct grub_efi_net_device *dev, +@@ -343,32 +385,32 @@ grub_efihttp_open (struct grub_efi_net_device *dev, grub_err_t err; grub_off_t size; char *buf; diff --git a/0084-Fixup-for-newer-compiler.patch b/0084-Fixup-for-newer-compiler.patch deleted file mode 100644 index 12dd193e..00000000 --- a/0084-Fixup-for-newer-compiler.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 10 May 2018 13:40:19 -0400 -Subject: [PATCH] Fixup for newer compiler - ---- - grub-core/fs/btrfs.c | 2 +- - include/grub/gpt_partition.h | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c -index 2b21cbaa67e..4cc86e9b79e 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -218,7 +218,7 @@ struct grub_btrfs_inode - grub_uint64_t size; - grub_uint8_t dummy2[0x70]; - struct grub_btrfs_time mtime; --} GRUB_PACKED; -+} GRUB_PACKED __attribute__ ((aligned(8))); - - struct grub_btrfs_extent_data - { -diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h -index 7a93f43291c..8212697bf6b 100644 ---- a/include/grub/gpt_partition.h -+++ b/include/grub/gpt_partition.h -@@ -76,7 +76,7 @@ struct grub_gpt_partentry - grub_uint64_t end; - grub_uint64_t attrib; - char name[72]; --} GRUB_PACKED; -+} GRUB_PACKED __attribute__ ((aligned(8))); - - grub_err_t - grub_gpt_partition_map_iterate (grub_disk_t disk, diff --git a/0110-Make-grub_error-more-verbose.patch b/0084-Make-grub_error-more-verbose.patch similarity index 96% rename from 0110-Make-grub_error-more-verbose.patch rename to 0084-Make-grub_error-more-verbose.patch index 2492e9f6..5ad26840 100644 --- a/0110-Make-grub_error-more-verbose.patch +++ b/0084-Make-grub_error-more-verbose.patch @@ -41,10 +41,10 @@ index 53c734de70e..aebfe0cf839 100644 return n; diff --git a/include/grub/err.h b/include/grub/err.h -index b08d5d0de4c..c0f90ef07c8 100644 +index 1c07034cd60..3c587b9b822 100644 --- a/include/grub/err.h +++ b/include/grub/err.h -@@ -85,8 +85,12 @@ struct grub_error_saved +@@ -86,8 +86,12 @@ struct grub_error_saved extern grub_err_t EXPORT_VAR(grub_errno); extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG]; diff --git a/0111-Make-reset-an-alias-for-the-reboot-command.patch b/0085-Make-reset-an-alias-for-the-reboot-command.patch similarity index 100% rename from 0111-Make-reset-an-alias-for-the-reboot-command.patch rename to 0085-Make-reset-an-alias-for-the-reboot-command.patch diff --git a/0112-Add-a-version-command.patch b/0086-Add-a-version-command.patch similarity index 82% rename from 0112-Add-a-version-command.patch rename to 0086-Add-a-version-command.patch index 30c8224f..b8770eed 100644 --- a/0112-Add-a-version-command.patch +++ b/0086-Add-a-version-command.patch @@ -1,13 +1,15 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 11 Sep 2018 14:20:37 -0400 -Subject: [PATCH] Add a "version" command. +Subject: [PATCH] Add a "version" command -This adds a command that shows you info about grub's version, the grub target -platform, the compiler version, and if you built with +This adds a command that shows you info about grub's version, the grub +target platform, the compiler version, and if you built with --with-rpm-version=, the rpm package version. Signed-off-by: Peter Jones +[rharwood: don't say GNU, commit message cleanup] +Signed-off-by: Robbie Harwood --- configure.ac | 13 ++++++++++ grub-core/Makefile.core.def | 5 ++++ @@ -17,10 +19,10 @@ Signed-off-by: Peter Jones create mode 100644 grub-core/commands/version.c diff --git a/configure.ac b/configure.ac -index 152e7dba652..cfdac6bed5a 100644 +index 3f3a170ab17..2175aa56997 100644 --- a/configure.ac +++ b/configure.ac -@@ -312,6 +312,19 @@ AC_SUBST(target_cpu) +@@ -289,6 +289,19 @@ AC_SUBST(target_cpu) AC_SUBST(platform) # Define default variables @@ -41,10 +43,10 @@ index 152e7dba652..cfdac6bed5a 100644 have_with_bootdir=n AC_ARG_WITH([bootdir], diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 84a3d89de9a..498ca11762a 100644 +index 4629c179e40..f26c689723c 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -579,6 +579,11 @@ image = { +@@ -598,6 +598,11 @@ image = { enable = mips_loongson; }; @@ -58,7 +60,7 @@ index 84a3d89de9a..498ca11762a 100644 common = lib/disk.c; diff --git a/grub-core/commands/version.c b/grub-core/commands/version.c new file mode 100644 -index 00000000000..f0966a518f7 +index 00000000000..de0acb07ba2 --- /dev/null +++ b/grub-core/commands/version.c @@ -0,0 +1,56 @@ @@ -97,7 +99,7 @@ index 00000000000..f0966a518f7 + if (argc != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no arguments expected")); + -+ grub_printf (_("GNU GRUB version %s\n"), PACKAGE_VERSION); ++ grub_printf (_("GRUB version %s\n"), PACKAGE_VERSION); + grub_printf (_("Platform %s-%s\n"), GRUB_TARGET_CPU, GRUB_PLATFORM); + if (grub_strlen(GRUB_RPM_VERSION) != 0) + grub_printf (_("RPM package version %s\n"), GRUB_RPM_VERSION); @@ -119,14 +121,14 @@ index 00000000000..f0966a518f7 + grub_unregister_command (cmd); +} diff --git a/config.h.in b/config.h.in -index 9e8f9911b18..c7e316f0f1f 100644 +index 9b1d3997185..d294d2c653f 100644 --- a/config.h.in +++ b/config.h.in -@@ -59,6 +59,7 @@ +@@ -63,6 +63,7 @@ - #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@" - #define GRUB_PLATFORM "@GRUB_PLATFORM@" -+#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@" + # define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@" + # define GRUB_PLATFORM "@GRUB_PLATFORM@" ++# define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@" - #define RE_ENABLE_I18N 1 + # define GRUB_STACK_PROTECTOR_INIT @GRUB_STACK_PROTECTOR_INIT@ diff --git a/0113-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch b/0087-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch similarity index 90% rename from 0113-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch rename to 0087-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch index 9afb3151..9ad4036f 100644 --- a/0113-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch +++ b/0087-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 4 files changed, 10 insertions(+) diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c -index 0320115662f..7cdffe3ebd5 100644 +index 21e2395111a..c35ce8915b2 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -188,6 +188,8 @@ scan_disk (const char *name, int accept_diskfilter) @@ -24,7 +24,7 @@ index 0320115662f..7cdffe3ebd5 100644 if (!accept_diskfilter && is_valid_diskfilter_name (name)) return 0; -@@ -1212,6 +1214,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, +@@ -1247,6 +1249,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, the same. */ if (pv->disk && grub_disk_native_sectors (disk) >= pv->part_size) return GRUB_ERR_NONE; @@ -33,10 +33,10 @@ index 0320115662f..7cdffe3ebd5 100644 if (!pv->disk) return grub_errno; diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c -index f077b5f5535..fe8ba6e6c93 100644 +index 3b5ed569133..822005456eb 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c -@@ -855,6 +855,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) +@@ -865,6 +865,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) return 0; } @@ -45,7 +45,7 @@ index f077b5f5535..fe8ba6e6c93 100644 grub_free (dup_dp); diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c -index 73b8ecc0c09..f58b58c89d5 100644 +index 670e213cf3c..d019637470d 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -34,6 +34,7 @@ grub_device_open (const char *name) diff --git a/0088-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch b/0088-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch new file mode 100644 index 00000000..2868f23e --- /dev/null +++ b/0088-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch @@ -0,0 +1,185 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 18:03:25 +0200 +Subject: [PATCH] Attempt to fix up all the places -Wsign-compare=error finds. + +Signed-off-by: Peter Jones +--- + grub-core/kern/emu/misc.c | 2 +- + grub-core/lib/reed_solomon.c | 4 ++-- + grub-core/osdep/linux/blocklist.c | 2 +- + grub-core/osdep/linux/getroot.c | 2 +- + util/grub-fstest.c | 2 +- + util/grub-menulst2cfg.c | 2 +- + util/grub-mkfont.c | 13 +++++++------ + util/grub-probe.c | 2 +- + util/setup.c | 2 +- + 9 files changed, 16 insertions(+), 15 deletions(-) + +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index 16c79bc9488..d145e5796b3 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -189,7 +189,7 @@ grub_util_get_image_size (const char *path) + sz = ftello (f); + if (sz < 0) + grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); +- if (sz != (size_t) sz) ++ if (sz > (off_t)(GRUB_SIZE_MAX >> 1)) + grub_util_error (_("file `%s' is too big"), path); + ret = (size_t) sz; + +diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c +index 562bd2e3e3f..5fee7f2a1a4 100644 +--- a/grub-core/lib/reed_solomon.c ++++ b/grub-core/lib/reed_solomon.c +@@ -162,7 +162,7 @@ static void + rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) + { + gf_single_t *rs_polynomial; +- int i, j; ++ unsigned int i, j; + gf_single_t *m; + m = xcalloc (s + rs, sizeof (gf_single_t)); + grub_memcpy (m, data, s * sizeof (gf_single_t)); +@@ -333,7 +333,7 @@ static void + encode_block (gf_single_t *ptr, grub_size_t s, + gf_single_t *rptr, grub_size_t rs) + { +- int i, j; ++ unsigned int i, j; + for (i = 0; i < SECTOR_SIZE; i++) + { + grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; +diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c +index 2efee2c2aee..902cfee53ae 100644 +--- a/grub-core/osdep/linux/blocklist.c ++++ b/grub-core/osdep/linux/blocklist.c +@@ -109,7 +109,7 @@ grub_install_get_blocklist (grub_device_t root_dev, + else + { + struct fiemap *fie2; +- int i; ++ unsigned int i; + fie2 = xmalloc (sizeof (*fie2) + + fie1.fm_mapped_extents + * sizeof (fie1.fm_extents[1])); +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 74a48c03026..477fb420992 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -233,7 +233,7 @@ grub_find_root_devices_from_btrfs (const char *dir) + { + int fd; + struct btrfs_ioctl_fs_info_args fsi; +- int i, j = 0; ++ unsigned int i, j = 0; + char **ret; + + fd = open (dir, 0); +diff --git a/util/grub-fstest.c b/util/grub-fstest.c +index 25ae52ab6f4..982ce9ed7d8 100644 +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -329,7 +329,7 @@ cmd_cmp (char *src, char *dest) + read_file (src, cmp_hook, ff); + + { +- grub_uint64_t pre; ++ long long pre; + pre = ftell (ff); + fseek (ff, 0, SEEK_END); + if (pre != ftell (ff)) +diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c +index b80e15cc36e..1ea2a86e129 100644 +--- a/util/grub-menulst2cfg.c ++++ b/util/grub-menulst2cfg.c +@@ -34,7 +34,7 @@ main (int argc, char **argv) + char *buf = NULL; + size_t bufsize = 0; + char *suffix = xstrdup (""); +- int suffixlen = 0; ++ size_t suffixlen = 0; + const char *out_fname = 0; + + grub_util_host_init (&argc, &argv); +diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c +index 7624d7808b7..e8a914021b2 100644 +--- a/util/grub-mkfont.c ++++ b/util/grub-mkfont.c +@@ -143,7 +143,8 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + int width, height; + int cuttop, cutbottom, cutleft, cutright; + grub_uint8_t *data; +- int mask, i, j, bitmap_size; ++ int mask, i, bitmap_size; ++ unsigned int j; + FT_GlyphSlot glyph; + int flag = FT_LOAD_RENDER | FT_LOAD_MONOCHROME; + FT_Error err; +@@ -188,7 +189,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + cuttop = cutbottom = cutleft = cutright = 0; + else + { +- for (cuttop = 0; cuttop < glyph->bitmap.rows; cuttop++) ++ for (cuttop = 0; cuttop < (long)glyph->bitmap.rows; cuttop++) + { + for (j = 0; j < glyph->bitmap.width; j++) + if (glyph->bitmap.buffer[j / 8 + cuttop * glyph->bitmap.pitch] +@@ -208,10 +209,10 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + break; + } + cutbottom = glyph->bitmap.rows - 1 - cutbottom; +- if (cutbottom + cuttop >= glyph->bitmap.rows) ++ if (cutbottom + cuttop >= (long)glyph->bitmap.rows) + cutbottom = 0; + +- for (cutleft = 0; cutleft < glyph->bitmap.width; cutleft++) ++ for (cutleft = 0; cutleft < (long)glyph->bitmap.width; cutleft++) + { + for (j = 0; j < glyph->bitmap.rows; j++) + if (glyph->bitmap.buffer[cutleft / 8 + j * glyph->bitmap.pitch] +@@ -230,7 +231,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + break; + } + cutright = glyph->bitmap.width - 1 - cutright; +- if (cutright + cutleft >= glyph->bitmap.width) ++ if (cutright + cutleft >= (long)glyph->bitmap.width) + cutright = 0; + } + +@@ -267,7 +268,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + + mask = 0; + data = &glyph_info->bitmap[0] - 1; +- for (j = cuttop; j < height + cuttop; j++) ++ for (j = cuttop; j < (long)height + cuttop; j++) + for (i = cutleft; i < width + cutleft; i++) + add_pixel (&data, &mask, + glyph->bitmap.buffer[i / 8 + j * glyph->bitmap.pitch] & +diff --git a/util/grub-probe.c b/util/grub-probe.c +index 65c1ca3f8b6..08ae915e8d7 100644 +--- a/util/grub-probe.c ++++ b/util/grub-probe.c +@@ -799,7 +799,7 @@ argp_parser (int key, char *arg, struct argp_state *state) + + case 't': + { +- int i; ++ unsigned int i; + + for (i = PRINT_FS; i < ARRAY_SIZE (targets); i++) + if (strcmp (arg, targets[i]) == 0) +diff --git a/util/setup.c b/util/setup.c +index 87a889ff7e3..7aab468b0eb 100644 +--- a/util/setup.c ++++ b/util/setup.c +@@ -406,7 +406,7 @@ SETUP (const char *dir, + int is_ldm; + grub_err_t err; + grub_disk_addr_t *sectors; +- int i; ++ unsigned int i; + grub_fs_t fs; + unsigned int nsec, maxsec; + diff --git a/0088-net-read-bracketed-ipv6-addrs-and-port-numbers.patch b/0088-net-read-bracketed-ipv6-addrs-and-port-numbers.patch deleted file mode 100644 index 834b96e2..00000000 --- a/0088-net-read-bracketed-ipv6-addrs-and-port-numbers.patch +++ /dev/null @@ -1,270 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aaron Miller -Date: Fri, 29 Jul 2016 17:41:38 +0800 -Subject: [PATCH] net: read bracketed ipv6 addrs and port numbers - -Allow specifying port numbers for http and tftp paths, and allow ipv6 addresses -to be recognized with brackets around them, which is required to specify a port -number - -Signed-off-by: Aaron Miller -[pjones: various bug fixes] -Signed-off-by: Peter Jones ---- - grub-core/net/http.c | 25 ++++++++++++--- - grub-core/net/net.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++--- - grub-core/net/tftp.c | 8 +++-- - include/grub/net.h | 1 + - 4 files changed, 109 insertions(+), 12 deletions(-) - -diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index b616cf40b1e..12a2632ea55 100644 ---- a/grub-core/net/http.c -+++ b/grub-core/net/http.c -@@ -289,7 +289,9 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)), - nb2 = grub_netbuff_alloc (data->chunk_rem); - if (!nb2) - return grub_errno; -- grub_netbuff_put (nb2, data->chunk_rem); -+ err = grub_netbuff_put (nb2, data->chunk_rem); -+ if (err) -+ return grub_errno; - grub_memcpy (nb2->data, nb->data, data->chunk_rem); - if (file->device->net->packs.count >= 20) - { -@@ -312,12 +314,14 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) - int i; - struct grub_net_buff *nb; - grub_err_t err; -+ char* server = file->device->net->server; -+ int port = file->device->net->port; - - nb = grub_netbuff_alloc (GRUB_NET_TCP_RESERVE_SIZE - + sizeof ("GET ") - 1 - + grub_strlen (data->filename) - + sizeof (" HTTP/1.1\r\nHost: ") - 1 -- + grub_strlen (file->device->net->server) -+ + grub_strlen (server) + sizeof (":XXXXXXXXXX") - + sizeof ("\r\nUser-Agent: " PACKAGE_STRING - "\r\n") - 1 - + sizeof ("Range: bytes=XXXXXXXXXXXXXXXXXXXX" -@@ -356,7 +360,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) - sizeof (" HTTP/1.1\r\nHost: ") - 1); - - ptr = nb->tail; -- err = grub_netbuff_put (nb, grub_strlen (file->device->net->server)); -+ err = grub_netbuff_put (nb, grub_strlen (server)); - if (err) - { - grub_netbuff_free (nb); -@@ -365,6 +369,15 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) - grub_memcpy (ptr, file->device->net->server, - grub_strlen (file->device->net->server)); - -+ if (port) -+ { -+ ptr = nb->tail; -+ grub_snprintf ((char *) ptr, -+ sizeof (":XXXXXXXXXX"), -+ ":%d", -+ port); -+ } -+ - ptr = nb->tail; - err = grub_netbuff_put (nb, - sizeof ("\r\nUser-Agent: " PACKAGE_STRING "\r\n") -@@ -390,8 +403,10 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) - grub_netbuff_put (nb, 2); - grub_memcpy (ptr, "\r\n", 2); - -- data->sock = grub_net_tcp_open (file->device->net->server, -- HTTP_PORT, http_receive, -+ grub_dprintf ("http", "opening path %s on host %s TCP port %d\n", -+ data->filename, server, port ? port : HTTP_PORT); -+ data->sock = grub_net_tcp_open (server, -+ port ? port : HTTP_PORT, http_receive, - http_err, NULL, - file); - if (!data->sock) -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index a46f82362ed..0ce5e675ed7 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -444,6 +444,13 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) - grub_uint16_t newip[8]; - const char *ptr = val; - int word, quaddot = -1; -+ int bracketed = 0; -+ -+ if (ptr[0] == '[') -+ { -+ bracketed = 1; -+ ptr++; -+ } - - if (ptr[0] == ':' && ptr[1] != ':') - return 0; -@@ -482,6 +489,8 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) - grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0])); - } - grub_memcpy (ip, newip, 16); -+ if (bracketed && *ptr == ']') -+ ptr++; - if (rest) - *rest = ptr; - return 1; -@@ -1343,8 +1352,10 @@ grub_net_open_real (const char *name) - { - grub_net_app_level_t proto; - const char *protname, *server; -+ char *host; - grub_size_t protnamelen; - int try; -+ int port = 0; - - if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) - { -@@ -1382,6 +1393,72 @@ grub_net_open_real (const char *name) - return NULL; - } - -+ char* port_start; -+ /* ipv6 or port specified? */ -+ if ((port_start = grub_strchr (server, ':'))) -+ { -+ char* ipv6_begin; -+ if((ipv6_begin = grub_strchr (server, '['))) -+ { -+ char* ipv6_end = grub_strchr (server, ']'); -+ if(!ipv6_end) -+ { -+ grub_error (GRUB_ERR_NET_BAD_ADDRESS, -+ N_("mismatched [ in address")); -+ return NULL; -+ } -+ /* port number after bracketed ipv6 addr */ -+ if(ipv6_end[1] == ':') -+ { -+ port = grub_strtoul (ipv6_end + 2, NULL, 10); -+ if(port > 65535) -+ { -+ grub_error (GRUB_ERR_NET_BAD_ADDRESS, -+ N_("bad port number")); -+ return NULL; -+ } -+ } -+ host = grub_strndup (ipv6_begin, (ipv6_end - ipv6_begin) + 1); -+ } -+ else -+ { -+ if (grub_strchr (port_start + 1, ':')) -+ { -+ int iplen = grub_strlen (server); -+ /* bracket bare ipv6 addrs */ -+ host = grub_malloc (iplen + 3); -+ if(!host) -+ { -+ return NULL; -+ } -+ host[0] = '['; -+ grub_memcpy (host + 1, server, iplen); -+ host[iplen + 1] = ']'; -+ host[iplen + 2] = '\0'; -+ } -+ else -+ { -+ /* hostname:port or ipv4:port */ -+ port = grub_strtol (port_start + 1, NULL, 10); -+ if(port > 65535) -+ { -+ grub_error (GRUB_ERR_NET_BAD_ADDRESS, -+ N_("bad port number")); -+ return NULL; -+ } -+ host = grub_strndup (server, port_start - server); -+ } -+ } -+ } -+ else -+ { -+ host = grub_strdup (server); -+ } -+ if (!host) -+ { -+ return NULL; -+ } -+ - for (try = 0; try < 2; try++) - { - FOR_NET_APP_LEVEL (proto) -@@ -1391,14 +1468,13 @@ grub_net_open_real (const char *name) - { - grub_net_t ret = grub_zalloc (sizeof (*ret)); - if (!ret) -- return NULL; -- ret->protocol = proto; -- ret->server = grub_strdup (server); -- if (!ret->server) - { -- grub_free (ret); -+ grub_free (host); - return NULL; - } -+ ret->protocol = proto; -+ ret->port = port; -+ ret->server = host; - ret->fs = &grub_net_fs; - return ret; - } -@@ -1473,6 +1549,7 @@ grub_net_open_real (const char *name) - grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"), - name); - -+ grub_free (host); - return NULL; - } - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index 4ab2f5c7357..d54b13f09ff 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -295,6 +295,7 @@ tftp_open (struct grub_file *file, const char *filename) - grub_err_t err; - grub_uint8_t *nbd; - grub_net_network_level_address_t addr; -+ int port = file->device->net->port; - - data = grub_zalloc (sizeof (*data)); - if (!data) -@@ -362,14 +363,17 @@ tftp_open (struct grub_file *file, const char *filename) - err = grub_net_resolve_address (file->device->net->server, &addr); - if (err) - { -- grub_dprintf("tftp", "Address resolution failed: %d\n", err); -+ grub_dprintf ("tftp", "Address resolution failed: %d\n", err); -+ grub_dprintf ("tftp", "file_size is %llu, block_size is %llu\n", -+ (unsigned long long)data->file_size, -+ (unsigned long long)data->block_size); - grub_free (data); - return err; - } - - grub_dprintf("tftp", "opening connection\n"); - data->sock = grub_net_udp_open (addr, -- TFTP_SERVER_PORT, tftp_receive, -+ port ? port : TFTP_SERVER_PORT, tftp_receive, - file); - if (!data->sock) - { -diff --git a/include/grub/net.h b/include/grub/net.h -index af0404db7e3..d55d505a03a 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -273,6 +273,7 @@ typedef struct grub_net - { - char *server; - char *name; -+ int port; - grub_net_app_level_t protocol; - grub_net_packets_t packs; - grub_off_t offset; diff --git a/0117-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch b/0089-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch similarity index 55% rename from 0117-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch rename to 0089-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch index de71484b..668a20ce 100644 --- a/0117-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch +++ b/0089-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch @@ -4,33 +4,21 @@ Date: Thu, 11 Jul 2019 18:20:37 +0200 Subject: [PATCH] Don't use -Wno-sign-compare -Wno-conversion -Wno-error, do use -Wextra. +Updated for grub-2.12 which introduced new sign comparison problems: +we're using -Wno-error=sign-compare + Signed-off-by: Peter Jones --- - configure.ac | 14 +++++++++++--- - conf/Makefile.common | 2 +- - 2 files changed, 12 insertions(+), 4 deletions(-) + configure.ac | 8 ++++++++ + conf/Makefile.common | 2 +- + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac -index cfdac6bed5a..bd28edf3141 100644 +index 2175aa56997..81240397384 100644 --- a/configure.ac +++ b/configure.ac -@@ -1480,11 +1480,11 @@ fi - # Set them to their new values for the tests below. - CC="$TARGET_CC" - if test x"$platform" = xemu ; then --CFLAGS="$TARGET_CFLAGS -Wno-error" -+CFLAGS="$TARGET_CFLAGS" - elif test "x$TARGET_APPLE_LINKER" = x1 ; then --CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error" -+CFLAGS="$TARGET_CFLAGS -nostdlib -static" - else --CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error" -+CFLAGS="$TARGET_CFLAGS -nostdlib" - fi - CPPFLAGS="$TARGET_CPPFLAGS" - -@@ -2054,6 +2054,14 @@ if test x"$enable_werror" != xno ; then - HOST_CFLAGS="$HOST_CFLAGS -Werror" +@@ -2147,6 +2147,14 @@ if test x"$enable_werror" != xno ; then + fi fi +AC_ARG_ENABLE([wextra], @@ -45,15 +33,15 @@ index cfdac6bed5a..bd28edf3141 100644 TARGET_CCAS=$TARGET_CC diff --git a/conf/Makefile.common b/conf/Makefile.common -index 2ff9b39357c..35e14ff017e 100644 +index 54f0f7f7664..e53ff352407 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common -@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d +@@ -76,7 +76,7 @@ grubconfdir = $(sysconfdir)/grub.d platformdir = $(pkglibdir)/$(target_cpu)-$(platform) starfielddir = $(pkgdatadir)/themes/starfield --CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -+CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code +-CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-error=attributes ++CFLAGS_GNULIB = -Wno-undef -Wno-error=sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-error=attributes CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib CFLAGS_POSIX = -fno-builtin diff --git a/0122-Fix-getroot.c-s-trampolines.patch b/0090-Fix-getroot.c-s-trampolines.patch similarity index 92% rename from 0122-Fix-getroot.c-s-trampolines.patch rename to 0090-Fix-getroot.c-s-trampolines.patch index 29ec44c9..b1f65dea 100644 --- a/0122-Fix-getroot.c-s-trampolines.patch +++ b/0090-Fix-getroot.c-s-trampolines.patch @@ -12,10 +12,10 @@ Signed-off-by: Peter Jones 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 9f730b35189..f0c503f43d3 100644 +index 477fb420992..b32582eb302 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c -@@ -1264,22 +1264,20 @@ grub_util_get_grub_dev_os (const char *os_dev) +@@ -1261,22 +1261,20 @@ grub_util_get_grub_dev_os (const char *os_dev) return grub_dev; } diff --git a/0123-Do-not-allow-stack-trampolines-anywhere.patch b/0091-Do-not-allow-stack-trampolines-anywhere.patch similarity index 65% rename from 0123-Do-not-allow-stack-trampolines-anywhere.patch rename to 0091-Do-not-allow-stack-trampolines-anywhere.patch index 4ee639d4..0c3b2985 100644 --- a/0123-Do-not-allow-stack-trampolines-anywhere.patch +++ b/0091-Do-not-allow-stack-trampolines-anywhere.patch @@ -10,10 +10,10 @@ Signed-off-by: Peter Jones 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac -index bd28edf3141..907477a585c 100644 +index 81240397384..ae7683d0693 100644 --- a/configure.ac +++ b/configure.ac -@@ -2062,6 +2062,9 @@ if test x"$enable_wextra" != xno ; then +@@ -2155,6 +2155,9 @@ if test x"$enable_wextra" != xno ; then HOST_CFLAGS="$HOST_CFLAGS -Wextra" fi @@ -24,15 +24,15 @@ index bd28edf3141..907477a585c 100644 TARGET_CCAS=$TARGET_CC diff --git a/conf/Makefile.common b/conf/Makefile.common -index 35e14ff017e..0647c53b916 100644 +index e53ff352407..91ff6c905fb 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common -@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d +@@ -76,7 +76,7 @@ grubconfdir = $(sysconfdir)/grub.d platformdir = $(pkglibdir)/$(target_cpu)-$(platform) starfielddir = $(pkgdatadir)/themes/starfield --CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -+CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines +-CFLAGS_GNULIB = -Wno-undef -Wno-error=sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-error=attributes ++CFLAGS_GNULIB = -Wno-undef -Wno-error=sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-error=attributes -Werror=trampolines -fno-trampolines CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib CFLAGS_POSIX = -fno-builtin diff --git a/0124-Reimplement-boot_counter.patch b/0092-Reimplement-boot_counter.patch similarity index 97% rename from 0124-Reimplement-boot_counter.patch rename to 0092-Reimplement-boot_counter.patch index 164b2291..1f0cb967 100644 --- a/0124-Reimplement-boot_counter.patch +++ b/0092-Reimplement-boot_counter.patch @@ -23,10 +23,10 @@ Signed-off-by: Christian Glombek create mode 100644 util/grub.d/01_fallback_counting.in diff --git a/Makefile.util.def b/Makefile.util.def -index c6375933faa..2e5e05b25f1 100644 +index 01096ded815..0bb47c6d40a 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -458,6 +458,12 @@ script = { +@@ -461,6 +461,12 @@ script = { installdir = grubconf; }; @@ -40,10 +40,10 @@ index c6375933faa..2e5e05b25f1 100644 name = '01_menu_auto_hide'; common = util/grub.d/01_menu_auto_hide.in; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 498ca11762a..1e15345107e 100644 +index f26c689723c..08c0c67bcf2 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -398,6 +398,11 @@ kernel = { +@@ -417,6 +417,11 @@ kernel = { extra_dist = kern/mips/cache_flush.S; }; diff --git a/0125-Fix-menu-entry-selection-based-on-ID-and-title.patch b/0093-Fix-menu-entry-selection-based-on-ID-and-title.patch similarity index 99% rename from 0125-Fix-menu-entry-selection-based-on-ID-and-title.patch rename to 0093-Fix-menu-entry-selection-based-on-ID-and-title.patch index 84c13706..597e0c1c 100644 --- a/0125-Fix-menu-entry-selection-based-on-ID-and-title.patch +++ b/0093-Fix-menu-entry-selection-based-on-ID-and-title.patch @@ -24,7 +24,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index 37d753d8081..ea714d27176 100644 +index 6444ee6f969..b0cfa32ddd8 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout) diff --git a/0126-Make-the-menu-entry-users-option-argument-to-be-opti.patch b/0094-Make-the-menu-entry-users-option-argument-to-be-opti.patch similarity index 100% rename from 0126-Make-the-menu-entry-users-option-argument-to-be-opti.patch rename to 0094-Make-the-menu-entry-users-option-argument-to-be-opti.patch diff --git a/0127-Add-efi-export-env-and-efi-load-env-commands.patch b/0095-Add-efi-export-env-and-efi-load-env-commands.patch similarity index 94% rename from 0127-Add-efi-export-env-and-efi-load-env-commands.patch rename to 0095-Add-efi-export-env-and-efi-load-env-commands.patch index 73456bc9..6a5abefe 100644 --- a/0127-Add-efi-export-env-and-efi-load-env-commands.patch +++ b/0095-Add-efi-export-env-and-efi-load-env-commands.patch @@ -21,10 +21,10 @@ Signed-off-by: Peter Jones create mode 100644 grub-core/commands/efi/env.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 1e15345107e..81fc274148e 100644 +index 08c0c67bcf2..4aa20cdfc13 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -820,6 +820,12 @@ module = { +@@ -842,6 +842,12 @@ module = { enable = efi; }; @@ -39,7 +39,7 @@ index 1e15345107e..81fc274148e 100644 efi = commands/efi/efifwsetup.c; diff --git a/grub-core/commands/efi/env.c b/grub-core/commands/efi/env.c new file mode 100644 -index 00000000000..cbd13e03e81 +index 00000000000..45f107ccd5b --- /dev/null +++ b/grub-core/commands/efi/env.c @@ -0,0 +1,168 @@ @@ -74,7 +74,7 @@ index 00000000000..cbd13e03e81 + +GRUB_MOD_LICENSE ("GPLv3+"); + -+static const grub_efi_guid_t grub_env_guid = GRUB_EFI_GRUB_VARIABLE_GUID; ++static const grub_guid_t grub_env_guid = GRUB_EFI_GRUB_VARIABLE_GUID; + +static grub_err_t +grub_efi_export_env(grub_command_t cmd __attribute__ ((unused)), @@ -212,10 +212,10 @@ index 00000000000..cbd13e03e81 + grub_unregister_command (loadenv_cmd); +} diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 2a446f5031b..14bc10eb564 100644 +index bf16c4307bc..ef837387368 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c -@@ -225,6 +225,9 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, +@@ -227,6 +227,9 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid, if (status == GRUB_EFI_SUCCESS) return GRUB_ERR_NONE; @@ -226,10 +226,10 @@ index 2a446f5031b..14bc10eb564 100644 } diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c -index 2d12e6188fd..0574d8d6217 100644 +index b5201974a76..dee3918fd35 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c -@@ -85,11 +85,6 @@ stack_protector_init (void) +@@ -106,11 +106,6 @@ stack_protector_init (void) grub_addr_t grub_modbase; @@ -296,7 +296,7 @@ index 2e4e78b132d..874506da169 100644 grub_envblk_iterate (grub_envblk_t envblk, void *hook_data, diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c -index bb198f02351..6a79ee67444 100644 +index d506f7e75bc..a6ccc113839 100644 --- a/util/grub-set-bootflag.c +++ b/util/grub-set-bootflag.c @@ -25,6 +25,7 @@ @@ -308,12 +308,12 @@ index bb198f02351..6a79ee67444 100644 #include #include diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 2e0691454b1..8dfc89a33b9 100644 +index 8d98203a784..6c2c1f36e37 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h -@@ -24,6 +24,11 @@ - #include - #include +@@ -36,6 +36,11 @@ struct linux_arch_kernel_header { + struct grub_pe_image_header pe_image_header; + }; +#define GRUB_EFI_GRUB_VARIABLE_GUID \ + { 0x91376aff, 0xcba6, 0x42be, \ diff --git a/0129-Export-all-variables-from-the-initial-context-when-c.patch b/0096-Export-all-variables-from-the-initial-context-when-c.patch similarity index 95% rename from 0129-Export-all-variables-from-the-initial-context-when-c.patch rename to 0096-Export-all-variables-from-the-initial-context-when-c.patch index bfe31653..a35174b4 100644 --- a/0129-Export-all-variables-from-the-initial-context-when-c.patch +++ b/0096-Export-all-variables-from-the-initial-context-when-c.patch @@ -17,7 +17,7 @@ Signed-off-by: Javier Martinez Canillas 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c -index ee53d4a68e5..87edd254c44 100644 +index ba185e91599..b4baa4392cd 100644 --- a/grub-core/normal/context.c +++ b/grub-core/normal/context.c @@ -99,7 +99,7 @@ grub_env_new_context (int export_all) @@ -30,7 +30,7 @@ index ee53d4a68e5..87edd254c44 100644 int grub_extractor_level = 0; diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index ea714d27176..d4832f17699 100644 +index b0cfa32ddd8..30ddcea0c11 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -375,8 +375,6 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) diff --git a/0130-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch b/0097-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch similarity index 96% rename from 0130-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch rename to 0097-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch index 9788fd52..08cc5632 100644 --- a/0130-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch +++ b/0097-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch @@ -7,6 +7,9 @@ Subject: [PATCH] grub.d: Split out boot success reset from menu auto hide Also rename fallback and menu auto hide script to be executed before and after boot success reset script. In menu auto hide script, rename last_boot_ok var to menu_hide_ok + +Signed-off-by: Christian Glombek +Signed-off-by: Robbie Harwood --- Makefile.util.def | 14 ++++++++---- ...allback_counting.in => 08_fallback_counting.in} | 14 ++++++------ @@ -18,10 +21,10 @@ In menu auto hide script, rename last_boot_ok var to menu_hide_ok rename util/grub.d/{01_menu_auto_hide.in => 12_menu_auto_hide.in} (58%) diff --git a/Makefile.util.def b/Makefile.util.def -index 2e5e05b25f1..11ab2d6fad1 100644 +index 0bb47c6d40a..885dc688a60 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -459,14 +459,14 @@ script = { +@@ -462,14 +462,14 @@ script = { }; script = { @@ -40,7 +43,7 @@ index 2e5e05b25f1..11ab2d6fad1 100644 installdir = grubconf; }; -@@ -518,6 +518,12 @@ script = { +@@ -521,6 +521,12 @@ script = { condition = COND_HOST_LINUX; }; diff --git a/0133-Don-t-assume-that-boot-commands-will-only-return-on-.patch b/0098-Don-t-assume-that-boot-commands-will-only-return-on-.patch similarity index 98% rename from 0133-Don-t-assume-that-boot-commands-will-only-return-on-.patch rename to 0098-Don-t-assume-that-boot-commands-will-only-return-on-.patch index 418a1ef4..06c6581d 100644 --- a/0133-Don-t-assume-that-boot-commands-will-only-return-on-.patch +++ b/0098-Don-t-assume-that-boot-commands-will-only-return-on-.patch @@ -17,7 +17,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c -index d4832f17699..14ceb9bb060 100644 +index 30ddcea0c11..cda10fa8b3f 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -285,7 +285,7 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) diff --git a/0138-grub-set-bootflag-Update-comment-about-running-as-ro.patch b/0099-grub-set-bootflag-Update-comment-about-running-as-ro.patch similarity index 96% rename from 0138-grub-set-bootflag-Update-comment-about-running-as-ro.patch rename to 0099-grub-set-bootflag-Update-comment-about-running-as-ro.patch index cd4ef775..4fa4df49 100644 --- a/0138-grub-set-bootflag-Update-comment-about-running-as-ro.patch +++ b/0099-grub-set-bootflag-Update-comment-about-running-as-ro.patch @@ -13,7 +13,7 @@ Signed-off-by: Hans de Goede 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c -index 6a79ee67444..65d74ce010f 100644 +index a6ccc113839..3eb04beb5e7 100644 --- a/util/grub-set-bootflag.c +++ b/util/grub-set-bootflag.c @@ -18,7 +18,7 @@ diff --git a/0139-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch b/0100-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch similarity index 95% rename from 0139-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch rename to 0100-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch index 122bf686..ab3f79ea 100644 --- a/0139-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch +++ b/0100-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch @@ -13,7 +13,7 @@ Signed-off-by: Hans de Goede 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c -index 65d74ce010f..d1c5e28862b 100644 +index 3eb04beb5e7..3b4c25ca2ac 100644 --- a/util/grub-set-bootflag.c +++ b/util/grub-set-bootflag.c @@ -28,7 +28,9 @@ @@ -26,7 +26,7 @@ index 65d74ce010f..d1c5e28862b 100644 #include #include -@@ -54,8 +56,10 @@ int main(int argc, char *argv[]) +@@ -56,8 +58,10 @@ int main(int argc, char *argv[]) { /* NOTE buf must be at least the longest bootflag length + 4 bytes */ char env[GRUBENV_SIZE + 1], buf[64], *s; @@ -38,7 +38,7 @@ index 65d74ce010f..d1c5e28862b 100644 FILE *f; if (argc != 2) -@@ -77,7 +81,32 @@ int main(int argc, char *argv[]) +@@ -89,7 +93,32 @@ int main(int argc, char *argv[]) bootflag = bootflags[i]; len = strlen (bootflag); @@ -72,7 +72,7 @@ index 65d74ce010f..d1c5e28862b 100644 if (!f) { perror ("Error opening " GRUBENV " for reading"); -@@ -132,30 +161,70 @@ int main(int argc, char *argv[]) +@@ -144,30 +173,70 @@ int main(int argc, char *argv[]) snprintf(buf, sizeof(buf), "%s=1\n", bootflag); memcpy(s, buf, len + 3); diff --git a/0140-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch b/0101-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch similarity index 91% rename from 0140-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch rename to 0101-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch index 54b73e6c..a32c1465 100644 --- a/0140-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch +++ b/0101-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch @@ -3,6 +3,9 @@ From: Hans de Goede Date: Tue, 26 Nov 2019 09:51:41 +0100 Subject: [PATCH] grub.d: Fix boot_indeterminate getting set on boot_success=0 boot +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit The "grub.d: Split out boot success reset from menu auto hide script" not only moved the code to clear boot_success and boot_indeterminate @@ -42,12 +45,15 @@ boot_indeterminate to 2 when it was 1 before. Fixes: "grub.d: Split out boot success reset from menu auto hide script" Signed-off-by: Hans de Goede +[jpokorny: 01_menu_auto_hide.in: fix a then/than typo] +Signed-off-by: Jan Pokorný +Signed-off-by: Robbie Harwood --- util/grub.d/10_reset_boot_success.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in -index 6c88d933dde..737e1ae5b68 100644 +index 6c88d933dde..e73f4137b36 100644 --- a/util/grub.d/10_reset_boot_success.in +++ b/util/grub.d/10_reset_boot_success.in @@ -6,18 +6,18 @@ @@ -67,7 +73,7 @@ index 6c88d933dde..737e1ae5b68 100644 set boot_indeterminate=0 -else - increment boot_indeterminate -+# Avoid boot_indeterminate causing the menu to be hidden more then once ++# Avoid boot_indeterminate causing the menu to be hidden more than once +elif [ "\${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 fi diff --git a/0143-Add-start-symbol-for-RISC-V.patch b/0102-Add-start-symbol-for-RISC-V.patch similarity index 100% rename from 0143-Add-start-symbol-for-RISC-V.patch rename to 0102-Add-start-symbol-for-RISC-V.patch diff --git a/0144-bootstrap.conf-Force-autogen.sh-to-use-python3.patch b/0103-bootstrap.conf-Force-autogen.sh-to-use-python3.patch similarity index 92% rename from 0144-bootstrap.conf-Force-autogen.sh-to-use-python3.patch rename to 0103-bootstrap.conf-Force-autogen.sh-to-use-python3.patch index 5c3b968b..c25b28ea 100644 --- a/0144-bootstrap.conf-Force-autogen.sh-to-use-python3.patch +++ b/0103-bootstrap.conf-Force-autogen.sh-to-use-python3.patch @@ -19,10 +19,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.conf b/bootstrap.conf -index 452f4d79b0d..03f10930230 100644 +index 7a7813d2825..60de0597c50 100644 --- a/bootstrap.conf +++ b/bootstrap.conf -@@ -93,7 +93,7 @@ bootstrap_post_import_hook () { +@@ -94,7 +94,7 @@ bootstrap_post_import_hook () { patch -d po -p3 \ < "po/gettext-patches/$patchname.patch" done diff --git a/0145-efi-http-Export-fw-http-_path-variables-to-make-them.patch b/0104-efi-http-Export-fw-http-_path-variables-to-make-them.patch similarity index 95% rename from 0145-efi-http-Export-fw-http-_path-variables-to-make-them.patch rename to 0104-efi-http-Export-fw-http-_path-variables-to-make-them.patch index 6f2e93dd..55cce245 100644 --- a/0145-efi-http-Export-fw-http-_path-variables-to-make-them.patch +++ b/0104-efi-http-Export-fw-http-_path-variables-to-make-them.patch @@ -25,7 +25,7 @@ Signed-off-by: Javier Martinez Canillas 2 files changed, 2 insertions(+) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c -index 4ec3f5e4d33..0285e95a2bb 100644 +index 7347a8de676..353a62ef1e1 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -143,6 +143,7 @@ grub_set_prefix_and_root (void) @@ -37,7 +37,7 @@ index 4ec3f5e4d33..0285e95a2bb 100644 grub_free (fw_path); } diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index de351b2cd03..755b7a6d054 100644 +index 5e97f5d5e70..3be86c141f5 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c @@ -39,6 +39,7 @@ http_configure (struct grub_efi_net_device *dev, int prefer_ip6) diff --git a/0146-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch b/0105-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch similarity index 94% rename from 0146-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch rename to 0105-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch index c3945498..30d206e8 100644 --- a/0146-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch +++ b/0105-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch @@ -43,7 +43,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index 755b7a6d054..fc8cb25ae0a 100644 +index 3be86c141f5..c37c359c713 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c @@ -158,13 +158,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, @@ -102,13 +102,13 @@ index 755b7a6d054..fc8cb25ae0a 100644 request_data.method = (headeronly > 0) ? GRUB_EFI_HTTPMETHODHEAD : GRUB_EFI_HTTPMETHODGET; request_message.data.request = &request_data; -@@ -228,6 +244,9 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, +@@ -225,6 +241,9 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, - status = efi_call_2 (http->request, http, &request_token); + status = http->request(http, &request_token); + if (hostname) + grub_free (hostname); + if (status != GRUB_EFI_SUCCESS) { - efi_call_1 (b->close_event, request_token.event); + b->close_event(request_token.event); diff --git a/0147-efi-net-Allow-to-specify-a-port-number-in-addresses.patch b/0106-efi-net-Allow-to-specify-a-port-number-in-addresses.patch similarity index 97% rename from 0147-efi-net-Allow-to-specify-a-port-number-in-addresses.patch rename to 0106-efi-net-Allow-to-specify-a-port-number-in-addresses.patch index 209aed80..96ebab3e 100644 --- a/0147-efi-net-Allow-to-specify-a-port-number-in-addresses.patch +++ b/0106-efi-net-Allow-to-specify-a-port-number-in-addresses.patch @@ -25,7 +25,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 6603cd83edc..84573937b18 100644 +index 1f7e1b63557..4ef3f709ee2 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -742,7 +742,7 @@ grub_efi_net_parse_address (const char *address, diff --git a/0106-module-verifier-make-it-possible-to-run-checkers-on-.patch b/0106-module-verifier-make-it-possible-to-run-checkers-on-.patch deleted file mode 100644 index e31b38f6..00000000 --- a/0106-module-verifier-make-it-possible-to-run-checkers-on-.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 1 Aug 2018 10:24:52 -0400 -Subject: [PATCH] module-verifier: make it possible to run checkers on - grub-module-verifierxx.c - -This makes it so you can treat grub-module-verifierxx.c as a file you can -build directly, so syntax checkers like vim's "syntastic" plugin, which uses -"gcc -x c -fsyntax-only" to build it, will work. - -One still has to do whatever setup is required to make it pick the right -include dirs, which -W options we use, etc., but this makes it so you can do -the checking on the file you're editing, rather than on a different file. - -v2: fix the typo in the #else clause in util/grub-module-verifierXX.c - -Signed-off-by: Peter Jones ---- - util/grub-module-verifier32.c | 2 ++ - util/grub-module-verifier64.c | 2 ++ - util/grub-module-verifierXX.c | 9 +++++++++ - 3 files changed, 13 insertions(+) - -diff --git a/util/grub-module-verifier32.c b/util/grub-module-verifier32.c -index 257229f8f08..ba7d41aafea 100644 ---- a/util/grub-module-verifier32.c -+++ b/util/grub-module-verifier32.c -@@ -1,2 +1,4 @@ - #define MODULEVERIFIER_ELF32 1 -+#ifndef GRUB_MODULE_VERIFIERXX - #include "grub-module-verifierXX.c" -+#endif -diff --git a/util/grub-module-verifier64.c b/util/grub-module-verifier64.c -index 4db6b4bedd1..fc23ef800b3 100644 ---- a/util/grub-module-verifier64.c -+++ b/util/grub-module-verifier64.c -@@ -1,2 +1,4 @@ - #define MODULEVERIFIER_ELF64 1 -+#ifndef GRUB_MODULE_VERIFIERXX - #include "grub-module-verifierXX.c" -+#endif -diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c -index ceb24309aec..a98e2f9b1ac 100644 ---- a/util/grub-module-verifierXX.c -+++ b/util/grub-module-verifierXX.c -@@ -1,3 +1,12 @@ -+#define GRUB_MODULE_VERIFIERXX -+#if !defined(MODULEVERIFIER_ELF32) && !defined(MODULEVERIFIER_ELF64) -+#if __SIZEOF_POINTER__ == 8 -+#include "grub-module-verifier64.c" -+#else -+#include "grub-module-verifier32.c" -+#endif -+#endif -+ - #include - - #include diff --git a/0148-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch b/0107-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch similarity index 97% rename from 0148-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch rename to 0107-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch index f92dee44..eb342e8c 100644 --- a/0148-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch +++ b/0107-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch @@ -21,7 +21,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c -index b711a5d9457..313c818b184 100644 +index 1deba25e79e..fb2fe850d0e 100644 --- a/grub-core/net/efi/ip4_config.c +++ b/grub-core/net/efi/ip4_config.c @@ -56,9 +56,20 @@ int diff --git a/0149-efi-net-Print-a-debug-message-if-parsing-the-address.patch b/0108-efi-net-Print-a-debug-message-if-parsing-the-address.patch similarity index 98% rename from 0149-efi-net-Print-a-debug-message-if-parsing-the-address.patch rename to 0108-efi-net-Print-a-debug-message-if-parsing-the-address.patch index 33d8f886..8ef8514f 100644 --- a/0149-efi-net-Print-a-debug-message-if-parsing-the-address.patch +++ b/0108-efi-net-Print-a-debug-message-if-parsing-the-address.patch @@ -22,7 +22,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index 84573937b18..a3f0535d43c 100644 +index 4ef3f709ee2..a9536c66550 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -778,9 +778,9 @@ grub_efi_net_parse_address (const char *address, diff --git a/0150-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch b/0109-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch similarity index 100% rename from 0150-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch rename to 0109-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch diff --git a/0154-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch b/0110-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch similarity index 93% rename from 0154-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch rename to 0110-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch index 97d2e06f..2f443d7a 100644 --- a/0154-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch +++ b/0110-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch @@ -20,10 +20,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index b52b558d631..7f878b56157 100644 +index af486198399..ce2b492c353 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c -@@ -501,13 +501,20 @@ http_open (struct grub_file *file, const char *filename) +@@ -502,13 +502,20 @@ http_open (struct grub_file *file, const char *filename) { grub_err_t err; struct http_data *data; diff --git a/0155-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch b/0111-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch similarity index 95% rename from 0155-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch rename to 0111-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch index 1657d7a8..f29706f3 100644 --- a/0155-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch +++ b/0111-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch @@ -13,7 +13,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+) diff --git a/grub-core/commands/efi/env.c b/grub-core/commands/efi/env.c -index cbd13e03e81..977edb6b065 100644 +index 45f107ccd5b..4080f24fdb8 100644 --- a/grub-core/commands/efi/env.c +++ b/grub-core/commands/efi/env.c @@ -149,6 +149,8 @@ grub_efi_load_env(grub_command_t cmd __attribute__ ((unused)), diff --git a/0156-efi-dhcp-fix-some-allocation-error-checking.patch b/0112-efi-dhcp-fix-some-allocation-error-checking.patch similarity index 83% rename from 0156-efi-dhcp-fix-some-allocation-error-checking.patch rename to 0112-efi-dhcp-fix-some-allocation-error-checking.patch index 75497338..e891757c 100644 --- a/0156-efi-dhcp-fix-some-allocation-error-checking.patch +++ b/0112-efi-dhcp-fix-some-allocation-error-checking.patch @@ -9,7 +9,7 @@ Signed-off-by: Peter Jones 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c -index dbef63d8c08..e5c79b748b0 100644 +index ca19902441b..6cc0dad85a7 100644 --- a/grub-core/net/efi/dhcp.c +++ b/grub-core/net/efi/dhcp.c @@ -80,7 +80,7 @@ grub_efi_dhcp4_parse_dns (grub_efi_dhcp4_protocol_t *dhcp4, grub_efi_dhcp4_packe @@ -26,10 +26,10 @@ index dbef63d8c08..e5c79b748b0 100644 if (status == GRUB_EFI_BUFFER_TOO_SMALL && count) { - options = grub_malloc (count * sizeof(*options)); -- status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); +- status = dev->dhcp6->parse(dev->dhcp6, mode.ia->reply_packet, &count, options); + options = grub_calloc (count, sizeof(*options)); + if (options) -+ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ status = dev->dhcp6->parse(dev->dhcp6, mode.ia->reply_packet, &count, options); + else + status = GRUB_EFI_OUT_OF_RESOURCES; } diff --git a/0157-efi-http-fix-some-allocation-error-checking.patch b/0113-efi-http-fix-some-allocation-error-checking.patch similarity index 84% rename from 0157-efi-http-fix-some-allocation-error-checking.patch rename to 0113-efi-http-fix-some-allocation-error-checking.patch index 4dffab9e..ba34e7fb 100644 --- a/0157-efi-http-fix-some-allocation-error-checking.patch +++ b/0113-efi-http-fix-some-allocation-error-checking.patch @@ -9,10 +9,10 @@ Signed-off-by: Peter Jones 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c -index fc8cb25ae0a..26647a50fa4 100644 +index c37c359c713..0568ea5d43e 100644 --- a/grub-core/net/efi/http.c +++ b/grub-core/net/efi/http.c -@@ -412,8 +412,8 @@ grub_efihttp_open (struct grub_efi_net_device *dev, +@@ -403,8 +403,8 @@ grub_efihttp_open (struct grub_efi_net_device *dev, int type) { grub_err_t err; @@ -23,7 +23,7 @@ index fc8cb25ae0a..26647a50fa4 100644 char *file_name = NULL; const char *http_path; -@@ -441,8 +441,11 @@ grub_efihttp_open (struct grub_efi_net_device *dev, +@@ -432,8 +432,11 @@ grub_efihttp_open (struct grub_efi_net_device *dev, return err; } diff --git a/0158-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch b/0114-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch similarity index 98% rename from 0158-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch rename to 0114-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch index 30c21a58..c4beaa47 100644 --- a/0158-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch +++ b/0114-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch @@ -13,7 +13,7 @@ Signed-off-by: Peter Jones 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c -index 313c818b184..9725e928f7e 100644 +index fb2fe850d0e..e9fc24865ec 100644 --- a/grub-core/net/efi/ip4_config.c +++ b/grub-core/net/efi/ip4_config.c @@ -4,15 +4,20 @@ @@ -82,7 +82,7 @@ index 313c818b184..9725e928f7e 100644 char *subnet, *gateway, *mask; grub_uint32_t u32_subnet, u32_gateway; diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c -index 017c4d05bc7..a46f6f9b685 100644 +index 29a03973265..050af4fbfd1 100644 --- a/grub-core/net/efi/ip6_config.c +++ b/grub-core/net/efi/ip6_config.c @@ -3,6 +3,7 @@ diff --git a/0162-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch b/0115-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch similarity index 97% rename from 0162-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch rename to 0115-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch index 6c16e9ef..d0dd8870 100644 --- a/0162-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch +++ b/0115-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c -index 9725e928f7e..cb880fc3e8f 100644 +index e9fc24865ec..85a090ec422 100644 --- a/grub-core/net/efi/ip4_config.c +++ b/grub-core/net/efi/ip4_config.c @@ -61,7 +61,8 @@ int diff --git a/0116-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch b/0116-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch deleted file mode 100644 index c2f2a597..00000000 --- a/0116-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch +++ /dev/null @@ -1,397 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 11 Jul 2019 18:03:25 +0200 -Subject: [PATCH] Attempt to fix up all the places -Wsign-compare=error finds. - -Signed-off-by: Peter Jones ---- - grub-core/kern/emu/misc.c | 2 +- - grub-core/lib/reed_solomon.c | 4 +- - grub-core/osdep/linux/blocklist.c | 2 +- - grub-core/osdep/linux/getroot.c | 2 +- - grub-core/osdep/linux/hostdisk.c | 2 +- - util/grub-fstest.c | 2 +- - util/grub-menulst2cfg.c | 2 +- - util/grub-mkfont.c | 13 +- - util/grub-probe.c | 2 +- - util/grub-rpm-sort.c | 2 +- - util/setup.c | 2 +- - bootstrap.conf | 3 +- - .../gnulib-patches/fix-sign-compare-errors.patch | 161 +++++++++++++++++++++ - 13 files changed, 181 insertions(+), 18 deletions(-) - create mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch - -diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c -index eeea092752d..f08a1bb8415 100644 ---- a/grub-core/kern/emu/misc.c -+++ b/grub-core/kern/emu/misc.c -@@ -189,7 +189,7 @@ grub_util_get_image_size (const char *path) - sz = ftello (f); - if (sz < 0) - grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); -- if (sz != (size_t) sz) -+ if (sz > (off_t)(GRUB_SIZE_MAX >> 1)) - grub_util_error (_("file `%s' is too big"), path); - ret = (size_t) sz; - -diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c -index 467305b46ab..79037c093f7 100644 ---- a/grub-core/lib/reed_solomon.c -+++ b/grub-core/lib/reed_solomon.c -@@ -157,7 +157,7 @@ static void - rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) - { - gf_single_t *rs_polynomial; -- int i, j; -+ unsigned int i, j; - gf_single_t *m; - m = xcalloc (s + rs, sizeof (gf_single_t)); - grub_memcpy (m, data, s * sizeof (gf_single_t)); -@@ -324,7 +324,7 @@ static void - encode_block (gf_single_t *ptr, grub_size_t s, - gf_single_t *rptr, grub_size_t rs) - { -- int i, j; -+ unsigned int i, j; - for (i = 0; i < SECTOR_SIZE; i++) - { - grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; -diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c -index c77d6085ccb..42a315031ff 100644 ---- a/grub-core/osdep/linux/blocklist.c -+++ b/grub-core/osdep/linux/blocklist.c -@@ -109,7 +109,7 @@ grub_install_get_blocklist (grub_device_t root_dev, - else - { - struct fiemap *fie2; -- int i; -+ unsigned int i; - fie2 = xmalloc (sizeof (*fie2) - + fie1.fm_mapped_extents - * sizeof (fie1.fm_extents[1])); -diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c -index 28790307e00..9f730b35189 100644 ---- a/grub-core/osdep/linux/getroot.c -+++ b/grub-core/osdep/linux/getroot.c -@@ -236,7 +236,7 @@ grub_find_root_devices_from_btrfs (const char *dir) - { - int fd; - struct btrfs_ioctl_fs_info_args fsi; -- int i, j = 0; -+ unsigned int i, j = 0; - char **ret; - - fd = open (dir, 0); -diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c -index da62f924e35..7bc99ac1c1d 100644 ---- a/grub-core/osdep/linux/hostdisk.c -+++ b/grub-core/osdep/linux/hostdisk.c -@@ -83,7 +83,7 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec - if (sector_size & (sector_size - 1) || !sector_size) - return -1; - for (log_sector_size = 0; -- (1 << log_sector_size) < sector_size; -+ (1U << log_sector_size) < sector_size; - log_sector_size++); - - if (log_secsize) -diff --git a/util/grub-fstest.c b/util/grub-fstest.c -index 83865642009..bfcef852d83 100644 ---- a/util/grub-fstest.c -+++ b/util/grub-fstest.c -@@ -323,7 +323,7 @@ cmd_cmp (char *src, char *dest) - read_file (src, cmp_hook, ff); - - { -- grub_uint64_t pre; -+ long long pre; - pre = ftell (ff); - fseek (ff, 0, SEEK_END); - if (pre != ftell (ff)) -diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c -index a39f8693947..358d604210b 100644 ---- a/util/grub-menulst2cfg.c -+++ b/util/grub-menulst2cfg.c -@@ -34,7 +34,7 @@ main (int argc, char **argv) - char *buf = NULL; - size_t bufsize = 0; - char *suffix = xstrdup (""); -- int suffixlen = 0; -+ size_t suffixlen = 0; - const char *out_fname = 0; - - grub_util_host_init (&argc, &argv); -diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c -index 0fe45a6103d..3e09240b99f 100644 ---- a/util/grub-mkfont.c -+++ b/util/grub-mkfont.c -@@ -138,7 +138,8 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, - int width, height; - int cuttop, cutbottom, cutleft, cutright; - grub_uint8_t *data; -- int mask, i, j, bitmap_size; -+ int mask, i, bitmap_size; -+ unsigned int j; - FT_GlyphSlot glyph; - int flag = FT_LOAD_RENDER | FT_LOAD_MONOCHROME; - FT_Error err; -@@ -183,7 +184,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, - cuttop = cutbottom = cutleft = cutright = 0; - else - { -- for (cuttop = 0; cuttop < glyph->bitmap.rows; cuttop++) -+ for (cuttop = 0; cuttop < (long)glyph->bitmap.rows; cuttop++) - { - for (j = 0; j < glyph->bitmap.width; j++) - if (glyph->bitmap.buffer[j / 8 + cuttop * glyph->bitmap.pitch] -@@ -203,10 +204,10 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, - break; - } - cutbottom = glyph->bitmap.rows - 1 - cutbottom; -- if (cutbottom + cuttop >= glyph->bitmap.rows) -+ if (cutbottom + cuttop >= (long)glyph->bitmap.rows) - cutbottom = 0; - -- for (cutleft = 0; cutleft < glyph->bitmap.width; cutleft++) -+ for (cutleft = 0; cutleft < (long)glyph->bitmap.width; cutleft++) - { - for (j = 0; j < glyph->bitmap.rows; j++) - if (glyph->bitmap.buffer[cutleft / 8 + j * glyph->bitmap.pitch] -@@ -225,7 +226,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, - break; - } - cutright = glyph->bitmap.width - 1 - cutright; -- if (cutright + cutleft >= glyph->bitmap.width) -+ if (cutright + cutleft >= (long)glyph->bitmap.width) - cutright = 0; - } - -@@ -262,7 +263,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, - - mask = 0; - data = &glyph_info->bitmap[0] - 1; -- for (j = cuttop; j < height + cuttop; j++) -+ for (j = cuttop; j < (long)height + cuttop; j++) - for (i = cutleft; i < width + cutleft; i++) - add_pixel (&data, &mask, - glyph->bitmap.buffer[i / 8 + j * glyph->bitmap.pitch] & -diff --git a/util/grub-probe.c b/util/grub-probe.c -index c08e46bbb40..c6fac732b40 100644 ---- a/util/grub-probe.c -+++ b/util/grub-probe.c -@@ -798,7 +798,7 @@ argp_parser (int key, char *arg, struct argp_state *state) - - case 't': - { -- int i; -+ unsigned int i; - - for (i = PRINT_FS; i < ARRAY_SIZE (targets); i++) - if (strcmp (arg, targets[i]) == 0) -diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c -index f33bd1ed568..8345944105f 100644 ---- a/util/grub-rpm-sort.c -+++ b/util/grub-rpm-sort.c -@@ -232,7 +232,7 @@ main (int argc, char *argv[]) - struct arguments arguments; - char **package_names = NULL; - size_t n_package_names = 0; -- int i; -+ unsigned int i; - - grub_util_host_init (&argc, &argv); - -diff --git a/util/setup.c b/util/setup.c -index da5f2c07f50..8b22bb8ccac 100644 ---- a/util/setup.c -+++ b/util/setup.c -@@ -406,7 +406,7 @@ SETUP (const char *dir, - int is_ldm; - grub_err_t err; - grub_disk_addr_t *sectors; -- int i; -+ unsigned int i; - grub_fs_t fs; - unsigned int nsec, maxsec; - -diff --git a/bootstrap.conf b/bootstrap.conf -index 6b043fc354c..186be9c48ce 100644 ---- a/bootstrap.conf -+++ b/bootstrap.conf -@@ -80,7 +80,8 @@ cp -a INSTALL INSTALL.grub - bootstrap_post_import_hook () { - set -e - for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \ -- fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do -+ fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort \ -+ fix-sign-compare-errors; do - patch -d grub-core/lib/gnulib -p2 \ - < "grub-core/lib/gnulib-patches/$patchname.patch" - done -diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch -new file mode 100644 -index 00000000000..479029c0565 ---- /dev/null -+++ b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch -@@ -0,0 +1,161 @@ -+diff --git a/lib/regcomp.c b/lib/regcomp.c -+index cc85f35ac58..361079d82d6 100644 -+--- a/lib/regcomp.c -++++ b/lib/regcomp.c -+@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, -+ *p++ = dfa->nodes[node].opr.c; -+ memset (&state, '\0', sizeof (state)); -+ if (__mbrtowc (&wc, (const char *) buf, p - buf, -+- &state) == p - buf -++ &state) == (size_t)(p - buf) -+ && (__wcrtomb ((char *) buf, __towlower (wc), &state) -+ != (size_t) -1)) -+ re_set_fastmap (fastmap, false, buf[0]); -+@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) -+ num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) -+ ? -2 -+ : num == -1 -+- ? c - '0' -++ ? (Idx)(c - '0') -+ : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); -+ } -+ return num; -+diff --git a/lib/regex_internal.c b/lib/regex_internal.c -+index 9004ce809eb..193a1e3d332 100644 -+--- a/lib/regex_internal.c -++++ b/lib/regex_internal.c -+@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) -+ /* Apply the translation if we need. */ -+ if (__glibc_unlikely (pstr->trans != NULL)) -+ { -+- int i, ch; -++ unsigned int i, ch; -+ -+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) -+ { -+@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) -+ prev_st = pstr->cur_state; -+ if (__glibc_unlikely (pstr->trans != NULL)) -+ { -+- int i, ch; -++ unsigned int i, ch; -+ -+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) -+ { -+@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) -+ memset (&cur_state, 0, sizeof (cur_state)); -+ mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, -+ &cur_state); -+- if (raw + offset - p <= mbclen -++ if ((size_t)(raw + offset - p) <= mbclen -+ && mbclen < (size_t) -2) -+ { -+ memset (&pstr->cur_state, '\0', -+diff --git a/lib/regex_internal.h b/lib/regex_internal.h -+index 5462419b787..e0f8292395d 100644 -+--- a/lib/regex_internal.h -++++ b/lib/regex_internal.h -+@@ -425,7 +425,7 @@ struct re_string_t -+ unsigned char offsets_needed; -+ unsigned char newline_anchor; -+ unsigned char word_ops_used; -+- int mb_cur_max; -++ unsigned int mb_cur_max; -+ }; -+ typedef struct re_string_t re_string_t; -+ -+@@ -702,7 +702,7 @@ struct re_dfa_t -+ unsigned int is_utf8 : 1; -+ unsigned int map_notascii : 1; -+ unsigned int word_ops_used : 1; -+- int mb_cur_max; -++ unsigned int mb_cur_max; -+ bitset_t word_char; -+ reg_syntax_t syntax; -+ Idx *subexp_map; -+diff --git a/lib/regexec.c b/lib/regexec.c -+index 0a7a27b772e..b57d4f9141d 100644 -+--- a/lib/regexec.c -++++ b/lib/regexec.c -+@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, -+ { -+ if (ret_len) -+ { -+- assert (pmatch[0].rm_so == start); -++ assert (pmatch[0].rm_so == (long)start); -+ rval = pmatch[0].rm_eo - start; -+ } -+ else -+@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, -+ if (__glibc_unlikely (mctx.input.offsets_needed != 0)) -+ { -+ pmatch[reg_idx].rm_so = -+- (pmatch[reg_idx].rm_so == mctx.input.valid_len -++ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len -+ ? mctx.input.valid_raw_len -+ : mctx.input.offsets[pmatch[reg_idx].rm_so]); -+ pmatch[reg_idx].rm_eo = -+- (pmatch[reg_idx].rm_eo == mctx.input.valid_len -++ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len -+ ? mctx.input.valid_raw_len -+ : mctx.input.offsets[pmatch[reg_idx].rm_eo]); -+ } -+@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, -+ } -+ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); -+ -+- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) -++ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) -+ { -+ update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); -+ -+- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) -++ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) -+ { -+ Idx reg_idx; -+ if (fs) -+@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, -+ if (reg_num < nmatch) -+ { -+ /* We are at the last node of this sub expression. */ -+- if (pmatch[reg_num].rm_so < cur_idx) -++ if (pmatch[reg_num].rm_so < (long)cur_idx) -+ { -+ pmatch[reg_num].rm_eo = cur_idx; -+ /* This is a non-empty match or we are not inside an optional -+@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, -+ mctx->state_log[str_idx] = cur_state; -+ } -+ -+- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) -++ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) -+ { -+ re_node_set_empty (&next_nodes); -+ if (mctx->state_log[str_idx + 1]) -+@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, -+ const re_string_t *input, Idx str_idx) -+ { -+ const re_token_t *node = dfa->nodes + node_idx; -+- int char_len, elem_len; -++ unsigned int char_len, elem_len; -+ Idx i; -+ -+ if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) -+@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) -+ /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ -+ ret = re_string_realloc_buffers (pstr, -+ MAX (min_len, -+- MIN (pstr->len, pstr->bufs_len * 2))); -++ MIN ((long)pstr->len, pstr->bufs_len * 2))); -+ if (__glibc_unlikely (ret != REG_NOERROR)) -+ return ret; -+ -+@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, -+ = (from == to ? -1 : 0); -+ -+ mctx->bkref_ents[mctx->nbkref_ents++].more = 0; -+- if (mctx->max_mb_elem_len < to - from) -++ if (mctx->max_mb_elem_len < (long)(to - from)) -+ mctx->max_mb_elem_len = to - from; -+ return REG_NOERROR; -+ } diff --git a/0163-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch b/0116-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch similarity index 96% rename from 0163-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch rename to 0116-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch index 7c29683e..1ecbfd88 100644 --- a/0163-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch +++ b/0116-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c -index a46f6f9b685..1c5415d7185 100644 +index 050af4fbfd1..952bda9fa74 100644 --- a/grub-core/net/efi/ip6_config.c +++ b/grub-core/net/efi/ip6_config.c @@ -85,7 +85,7 @@ grub_efi_string_to_ip6_address (const char *val, grub_efi_ipv6_address_t *addres diff --git a/0164-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch b/0117-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch similarity index 97% rename from 0164-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch rename to 0117-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch index 0fe90c8b..fe583d35 100644 --- a/0164-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch +++ b/0117-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c -index a3f0535d43c..78e5442fc52 100644 +index a9536c66550..0a1e604b5bd 100644 --- a/grub-core/net/efi/net.c +++ b/grub-core/net/efi/net.c @@ -729,7 +729,7 @@ grub_efi_net_parse_address (const char *address, diff --git a/0165-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch b/0118-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch similarity index 97% rename from 0165-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch rename to 0118-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch index 59f29e4f..ea5be7c4 100644 --- a/0165-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch +++ b/0118-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch @@ -14,7 +14,7 @@ Signed-off-by: Peter Jones 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c -index 531949cba5c..73e2bb01c1b 100644 +index b84f86ea470..e828fb23e96 100644 --- a/grub-core/net/efi/pxe.c +++ b/grub-core/net/efi/pxe.c @@ -187,7 +187,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) diff --git a/0166-Add-systemd-integration-scripts-to-make-systemctl-re.patch b/0119-Add-systemd-integration-scripts-to-make-systemctl-re.patch similarity index 93% rename from 0166-Add-systemd-integration-scripts-to-make-systemctl-re.patch rename to 0119-Add-systemd-integration-scripts-to-make-systemctl-re.patch index 130dc778..ce424e17 100644 --- a/0166-Add-systemd-integration-scripts-to-make-systemctl-re.patch +++ b/0119-Add-systemd-integration-scripts-to-make-systemctl-re.patch @@ -65,10 +65,10 @@ Signed-off-by: Hans de Goede create mode 100644 util/systemd/systemd-integration.sh.in diff --git a/Makefile.util.def b/Makefile.util.def -index 11ab2d6fad1..e1242f54022 100644 +index 885dc688a60..8e52e48c780 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -470,6 +470,12 @@ script = { +@@ -473,6 +473,12 @@ script = { installdir = grubconf; }; @@ -81,7 +81,7 @@ index 11ab2d6fad1..e1242f54022 100644 script = { name = '01_users'; common = util/grub.d/01_users.in; -@@ -569,6 +575,27 @@ script = { +@@ -578,6 +584,27 @@ script = { installdir = grubconf; }; @@ -110,10 +110,10 @@ index 11ab2d6fad1..e1242f54022 100644 mansection = 1; name = grub-mkrescue; diff --git a/conf/Makefile.common b/conf/Makefile.common -index 0647c53b916..9fe5863b2d9 100644 +index 91ff6c905fb..c8756d8146f 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common -@@ -63,8 +63,11 @@ CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) +@@ -73,8 +73,11 @@ CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) # Other variables grubconfdir = $(sysconfdir)/grub.d @@ -123,18 +123,18 @@ index 0647c53b916..9fe5863b2d9 100644 +systemdunitdir = ${prefix}/lib/systemd/system +systemd_logind_service_ddir = $(systemdunitdir)/systemd-logind.service.d - CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines + CFLAGS_GNULIB = -Wno-undef -Wno-error=sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-error=attributes -Werror=trampolines -fno-trampolines CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib -@@ -121,6 +124,9 @@ noinst_LIBRARIES = - dist_noinst_DATA = - platform_SCRIPTS = +@@ -133,6 +136,9 @@ platform_SCRIPTS = platform_PROGRAMS = + sbin_SCRIPTS = + sbin_PROGRAMS = +grublibexec_SCRIPTS = +systemdunit_SCRIPTS = +systemd_logind_service_d_SCRIPTS = - TESTS = EXTRA_DIST = + CLEANFILES = diff --git a/util/grub.d/14_menu_show_once.in b/util/grub.d/14_menu_show_once.in new file mode 100755 index 00000000000..1cd7f36142b diff --git a/0167-systemd-integration.sh-Also-set-old-menu_show_once-g.patch b/0120-systemd-integration.sh-Also-set-old-menu_show_once-g.patch similarity index 100% rename from 0167-systemd-integration.sh-Also-set-old-menu_show_once-g.patch rename to 0120-systemd-integration.sh-Also-set-old-menu_show_once-g.patch diff --git a/0168-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch b/0121-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch similarity index 94% rename from 0168-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch rename to 0121-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch index c3388409..6011b339 100644 --- a/0168-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch +++ b/0121-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch @@ -29,10 +29,10 @@ Signed-off-by: Renaud Métrich 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c -index 597111077bd..26014382608 100644 +index f8a129eb7f1..2d9ab65aee0 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c -@@ -135,20 +135,28 @@ query_mode (void) +@@ -145,20 +145,28 @@ query_mode (void) int e; e = write_mode (0); @@ -65,7 +65,7 @@ index 597111077bd..26014382608 100644 return 0; } -@@ -165,7 +173,13 @@ set_scancodes (void) +@@ -175,7 +183,13 @@ set_scancodes (void) } #if !USE_SCANCODE_SET @@ -80,7 +80,7 @@ index 597111077bd..26014382608 100644 return; #else -@@ -266,6 +280,7 @@ grub_keyboard_controller_init (void) +@@ -276,6 +290,7 @@ grub_keyboard_controller_init (void) grub_keyboard_orig_set = 2; #else grub_keyboard_controller_orig = grub_keyboard_controller_read (); @@ -88,7 +88,7 @@ index 597111077bd..26014382608 100644 grub_keyboard_orig_set = query_mode (); #endif set_scancodes (); -@@ -275,11 +290,15 @@ grub_keyboard_controller_init (void) +@@ -285,11 +300,15 @@ grub_keyboard_controller_init (void) static grub_err_t grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ ((unused))) { diff --git a/0169-grub-install-disable-support-for-EFI-platforms.patch b/0122-grub-install-disable-support-for-EFI-platforms.patch similarity index 69% rename from 0169-grub-install-disable-support-for-EFI-platforms.patch rename to 0122-grub-install-disable-support-for-EFI-platforms.patch index 41003e25..380dbef1 100644 --- a/0169-grub-install-disable-support-for-EFI-platforms.patch +++ b/0122-grub-install-disable-support-for-EFI-platforms.patch @@ -19,17 +19,17 @@ build-time option. Resolves: rhbz#1737444 Signed-off-by: Jan Hlavac +[rharwood: drop man page] --- - util/grub-install.c | 37 ++++++++++++++++--------------------- + util/grub-install.c | 41 +++++++++++++++++++---------------------- docs/grub.texi | 7 +++++++ - util/grub-install.8 | 4 +++- - 3 files changed, 26 insertions(+), 22 deletions(-) + 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/util/grub-install.c b/util/grub-install.c -index a2bec7446cb..5babc7af551 100644 +index 66ef9494d9d..828e8722ba5 100644 --- a/util/grub-install.c +++ b/util/grub-install.c -@@ -899,6 +899,22 @@ main (int argc, char *argv[]) +@@ -915,6 +915,25 @@ main (int argc, char *argv[]) platform = grub_install_get_target (grub_install_source_directory); @@ -39,6 +39,9 @@ index a2bec7446cb..5babc7af551 100644 + case GRUB_INSTALL_PLATFORM_ARM64_EFI: + case GRUB_INSTALL_PLATFORM_I386_EFI: + case GRUB_INSTALL_PLATFORM_IA64_EFI: ++ case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI: ++ case GRUB_INSTALL_PLATFORM_RISCV32_EFI: ++ case GRUB_INSTALL_PLATFORM_RISCV64_EFI: + case GRUB_INSTALL_PLATFORM_X86_64_EFI: + is_efi = 1; + grub_util_error (_("this utility cannot be used for EFI platforms" @@ -52,7 +55,7 @@ index a2bec7446cb..5babc7af551 100644 { char *platname = grub_install_get_platform_name (platform); fprintf (stderr, _("Installing for %s platform.\n"), platname); -@@ -1011,28 +1027,7 @@ main (int argc, char *argv[]) +@@ -1029,27 +1048,6 @@ main (int argc, char *argv[]) grub_hostfs_init (); grub_host_init (); @@ -62,6 +65,7 @@ index a2bec7446cb..5babc7af551 100644 - case GRUB_INSTALL_PLATFORM_X86_64_EFI: - case GRUB_INSTALL_PLATFORM_ARM_EFI: - case GRUB_INSTALL_PLATFORM_ARM64_EFI: +- case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: - case GRUB_INSTALL_PLATFORM_IA64_EFI: @@ -76,16 +80,22 @@ index a2bec7446cb..5babc7af551 100644 - break; - } - + switch (platform) + { + case GRUB_INSTALL_PLATFORM_I386_IEEE1275: +@@ -1065,7 +1063,6 @@ main (int argc, char *argv[]) + } + /* Find the EFI System Partition. */ - if (is_efi) { grub_fs_t fs; diff --git a/docs/grub.texi b/docs/grub.texi -index 04ed6ac1f07..4870faaa00a 100644 +index 44c4e665a0d..1e577d2fee9 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -6509,6 +6509,13 @@ grub2-install @var{install_device} +@@ -7112,6 +7112,13 @@ grub2-install @var{install_device} The device name @var{install_device} is an OS device name or a GRUB device name. @@ -99,22 +109,3 @@ index 04ed6ac1f07..4870faaa00a 100644 @command{grub2-install} accepts the following options: @table @option -diff --git a/util/grub-install.8 b/util/grub-install.8 -index 1db89e94b3b..811d441b16c 100644 ---- a/util/grub-install.8 -+++ b/util/grub-install.8 -@@ -1,4 +1,4 @@ --.TH GRUB-INSTALL 1 "Wed Feb 26 2014" -+.TH GRUB-INSTALL 1 "Fri Nov 20 2020" - .SH NAME - \fBgrub-install\fR \(em Install GRUB on a device. - -@@ -31,6 +31,8 @@ - .SH DESCRIPTION - \fBgrub-install\fR installs GRUB onto a device. This includes copying GRUB images into the target directory (generally \fI/boot/grub\fR), and on some platforms may also include installing GRUB onto a boot sector. - -+In order to support UEFI Secure Boot, the resulting GRUB EFI binary must be signed by a recognized private key. For this reason, for EFI platforms, most distributions also ship prebuilt GRUB EFI binaries signed by a distribution-specific private key. In this case, however, the \fBgrub-install\fR utility should not be used because it would overwrite the signed EFI binary. -+ - .SH OPTIONS - .TP - \fB--modules\fR=\fIMODULES\fR\! diff --git a/0170-New-with-debug-timestamps-configure-flag-to-prepend-.patch b/0123-New-with-debug-timestamps-configure-flag-to-prepend-.patch similarity index 84% rename from 0170-New-with-debug-timestamps-configure-flag-to-prepend-.patch rename to 0123-New-with-debug-timestamps-configure-flag-to-prepend-.patch index 3eb0d00c..426d5be9 100644 --- a/0170-New-with-debug-timestamps-configure-flag-to-prepend-.patch +++ b/0123-New-with-debug-timestamps-configure-flag-to-prepend-.patch @@ -15,10 +15,10 @@ Signed-off-by: Renaud Métrich 3 files changed, 39 insertions(+) diff --git a/configure.ac b/configure.ac -index 907477a585c..d5d2a28b4ef 100644 +index ae7683d0693..016cd3d4e0e 100644 --- a/configure.ac +++ b/configure.ac -@@ -1613,6 +1613,17 @@ else +@@ -1686,6 +1686,17 @@ else fi AC_SUBST([BOOT_TIME_STATS]) @@ -33,10 +33,10 @@ index 907477a585c..d5d2a28b4ef 100644 +fi +AC_SUBST([DEBUG_WITH_TIMESTAMPS]) + - AC_ARG_ENABLE([grub-emu-sdl], - [AS_HELP_STRING([--enable-grub-emu-sdl], - [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])]) -@@ -2200,6 +2211,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1]) + AC_ARG_ENABLE([grub-emu-sdl2], + [AS_HELP_STRING([--enable-grub-emu-sdl2], + [build and install the `grub-emu' debugging utility with SDL2 support (default=guessed)])]) +@@ -2296,6 +2307,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1]) AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes]) AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1]) AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1]) @@ -44,7 +44,7 @@ index 907477a585c..d5d2a28b4ef 100644 AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes]) -@@ -2295,6 +2307,12 @@ else +@@ -2397,6 +2409,12 @@ else echo With boot time statistics: No fi @@ -58,12 +58,12 @@ index 907477a585c..d5d2a28b4ef 100644 echo efiemu runtime: Yes else diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 578bf51a5fc..9f54b6b7d2d 100644 +index 779586658cb..d40586b9268 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -25,6 +25,9 @@ - #include - #include +@@ -27,6 +27,9 @@ + #include + #include #include +#if DEBUG_WITH_TIMESTAMPS +#include @@ -71,7 +71,7 @@ index 578bf51a5fc..9f54b6b7d2d 100644 union printf_arg { -@@ -192,9 +195,26 @@ grub_real_dprintf (const char *file, const int line, const char *condition, +@@ -236,9 +239,26 @@ grub_real_dprintf (const char *file, const int line, const char *condition, const char *fmt, ...) { va_list args; @@ -95,14 +95,14 @@ index 578bf51a5fc..9f54b6b7d2d 100644 + else + last_had_cr = 0; +#endif - grub_printf ("%s:%d: ", file, line); + grub_printf ("%s:%d:%s: ", file, line, condition); va_start (args, fmt); grub_vprintf (fmt, args); diff --git a/config.h.in b/config.h.in -index c7e316f0f1f..c80e3e0aba3 100644 +index d294d2c653f..39f4e5472ce 100644 --- a/config.h.in +++ b/config.h.in -@@ -12,6 +12,7 @@ +@@ -16,6 +16,7 @@ /* Define to 1 to enable disk cache statistics. */ #define DISK_CACHE_STATS @DISK_CACHE_STATS@ #define BOOT_TIME_STATS @BOOT_TIME_STATS@ diff --git a/0171-Added-debug-statements-to-grub_disk_open-and-grub_di.patch b/0124-Added-debug-statements-to-grub_disk_open-and-grub_di.patch similarity index 67% rename from 0171-Added-debug-statements-to-grub_disk_open-and-grub_di.patch rename to 0124-Added-debug-statements-to-grub_disk_open-and-grub_di.patch index cbb1a38e..0cd12c44 100644 --- a/0171-Added-debug-statements-to-grub_disk_open-and-grub_di.patch +++ b/0124-Added-debug-statements-to-grub_disk_open-and-grub_di.patch @@ -9,11 +9,11 @@ Content-Transfer-Encoding: 8bit Signed-off-by: Renaud Métrich --- - grub-core/kern/disk.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) + grub-core/kern/disk.c | 4 ++++ + 1 file changed, 4 insertions(+) diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c -index e1b0e073e09..05a28ab1429 100644 +index 1eda58fe9a1..355b6579d87 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -285,6 +285,8 @@ grub_disk_open (const char *name) @@ -25,16 +25,7 @@ index e1b0e073e09..05a28ab1429 100644 return disk; } -@@ -292,7 +294,7 @@ void - grub_disk_close (grub_disk_t disk) - { - grub_partition_t part; -- grub_dprintf ("disk", "Closing `%s'.\n", disk->name); -+ grub_dprintf ("disk", "Closing `%s'...\n", disk->name); - - if (disk->dev && disk->dev->disk_close) - (disk->dev->disk_close) (disk); -@@ -306,8 +308,10 @@ grub_disk_close (grub_disk_t disk) +@@ -310,8 +312,10 @@ grub_disk_close (grub_disk_t disk) grub_free (disk->partition); disk->partition = part; } diff --git a/0172-Introduce-function-grub_debug_is_enabled-void-return.patch b/0125-Introduce-function-grub_debug_is_enabled-void-return.patch similarity index 87% rename from 0172-Introduce-function-grub_debug_is_enabled-void-return.patch rename to 0125-Introduce-function-grub_debug_is_enabled-void-return.patch index 4e4718b7..224d2044 100644 --- a/0172-Introduce-function-grub_debug_is_enabled-void-return.patch +++ b/0125-Introduce-function-grub_debug_is_enabled-void-return.patch @@ -14,10 +14,10 @@ Signed-off-by: Renaud Métrich 2 files changed, 14 insertions(+) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 9f54b6b7d2d..a186ad3dd41 100644 +index d40586b9268..d3a493e3552 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -163,6 +163,19 @@ int grub_err_printf (const char *fmt, ...) +@@ -186,6 +186,19 @@ int grub_err_printf (const char *fmt, ...) __attribute__ ((alias("grub_printf"))); #endif @@ -38,10 +38,10 @@ index 9f54b6b7d2d..a186ad3dd41 100644 grub_debug_enabled (const char * condition) { diff --git a/include/grub/misc.h b/include/grub/misc.h -index 3adc4036e3b..6c4aa85ac50 100644 +index 72aff15750d..3f5f5b61695 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h -@@ -340,6 +340,7 @@ grub_puts (const char *s) +@@ -369,6 +369,7 @@ grub_puts (const char *s) } int EXPORT_FUNC(grub_puts_) (const char *s); diff --git a/0173-Don-t-clear-screen-when-debugging-is-enabled.patch b/0126-Don-t-clear-screen-when-debugging-is-enabled.patch similarity index 65% rename from 0173-Don-t-clear-screen-when-debugging-is-enabled.patch rename to 0126-Don-t-clear-screen-when-debugging-is-enabled.patch index d2a59886..8cca97ca 100644 --- a/0173-Don-t-clear-screen-when-debugging-is-enabled.patch +++ b/0126-Don-t-clear-screen-when-debugging-is-enabled.patch @@ -7,21 +7,23 @@ Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Renaud Métrich +[rharwood@redhat.com: rebase fuzz] +Signed-off-by: Robbie Harwood --- grub-core/normal/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index e349303c29b..155bf366da2 100644 +index b5fa6156549..0ea27d3c534 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c -@@ -210,7 +210,8 @@ void - grub_normal_init_page (struct grub_term_output *term, - int y __attribute__((__unused__))) - { +@@ -216,7 +216,8 @@ grub_normal_init_page (struct grub_term_output *term, + grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; + - grub_term_cls (term); + if (! grub_debug_is_enabled ()) + grub_term_cls (term); - #if 0 - grub_ssize_t msg_len; + msg_formatted = grub_xasprintf (_("GRUB version %s"), PACKAGE_VERSION); + if (!msg_formatted) diff --git a/0174-grub_file_-instrumentation-new-file-debug-tag.patch b/0127-grub_file_-instrumentation-new-file-debug-tag.patch similarity index 81% rename from 0174-grub_file_-instrumentation-new-file-debug-tag.patch rename to 0127-grub_file_-instrumentation-new-file-debug-tag.patch index 0cc6b8c9..1d35707f 100644 --- a/0174-grub_file_-instrumentation-new-file-debug-tag.patch +++ b/0127-grub_file_-instrumentation-new-file-debug-tag.patch @@ -12,7 +12,7 @@ Signed-off-by: Renaud Métrich 1 file changed, 14 insertions(+) diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c -index 58454458c47..e19aea3e514 100644 +index 750177248f9..264211b1143 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -66,6 +66,8 @@ grub_file_open (const char *name, enum grub_file_type type) @@ -21,10 +21,10 @@ index 58454458c47..e19aea3e514 100644 + grub_dprintf ("file", "Opening `%s' ...\n", name); + - device_name = grub_file_get_device_name (name); - if (grub_errno) - goto fail; -@@ -128,6 +130,8 @@ grub_file_open (const char *name, enum grub_file_type type) + /* Reset grub_errno before we start. */ + grub_errno = GRUB_ERR_NONE; + +@@ -132,6 +134,8 @@ grub_file_open (const char *name, enum grub_file_type type) if (!file) grub_file_close (last_file); @@ -33,7 +33,7 @@ index 58454458c47..e19aea3e514 100644 return file; fail: -@@ -138,6 +142,8 @@ grub_file_open (const char *name, enum grub_file_type type) +@@ -143,6 +147,8 @@ grub_file_open (const char *name, enum grub_file_type type) grub_free (file); @@ -42,7 +42,7 @@ index 58454458c47..e19aea3e514 100644 return 0; } -@@ -169,6 +175,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) +@@ -174,6 +180,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) if (len == 0) return 0; @@ -50,7 +50,7 @@ index 58454458c47..e19aea3e514 100644 read_hook = file->read_hook; read_hook_data = file->read_hook_data; if (!file->read_hook) -@@ -189,11 +196,18 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) +@@ -194,11 +201,18 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) grub_err_t grub_file_close (grub_file_t file) { diff --git a/0128-Make-it-possible-to-subtract-conditions-from-debug.patch b/0128-Make-it-possible-to-subtract-conditions-from-debug.patch deleted file mode 100644 index fce51eac..00000000 --- a/0128-Make-it-possible-to-subtract-conditions-from-debug.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 17 Jan 2019 13:10:39 -0500 -Subject: [PATCH] Make it possible to subtract conditions from debug= - -This makes it so you can do set debug to "all,-scripting,-lexer" and get the -obvious outcome. Any negation present will take preference over that -conditional, so "all,-scripting,scripting" is the same thing as -"all,-scripting". - -Signed-off-by: Peter Jones ---- - grub-core/kern/misc.c | 14 +++++++++++++- - 1 file changed, 13 insertions(+), 1 deletion(-) - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 9a2fae6398e..578bf51a5fc 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -164,12 +164,24 @@ int - grub_debug_enabled (const char * condition) - { - const char *debug; -+ char *negcond; -+ int negated = 0; - - debug = grub_env_get ("debug"); - if (!debug) - return 0; - -- if (grub_strword (debug, "all") || grub_strword (debug, condition)) -+ negcond = grub_zalloc (grub_strlen (condition) + 2); -+ if (negcond) -+ { -+ grub_strcpy (negcond, "-"); -+ grub_strcpy (negcond+1, condition); -+ negated = grub_strword (debug, negcond); -+ grub_free (negcond); -+ } -+ -+ if (!negated && -+ (grub_strword (debug, "all") || grub_strword (debug, condition))) - return 1; - - return 0; diff --git a/0175-ieee1275-Avoiding-many-unecessary-open-close.patch b/0128-ieee1275-Avoiding-many-unecessary-open-close.patch similarity index 94% rename from 0175-ieee1275-Avoiding-many-unecessary-open-close.patch rename to 0128-ieee1275-Avoiding-many-unecessary-open-close.patch index 6a0ad75b..fac8dc7e 100644 --- a/0175-ieee1275-Avoiding-many-unecessary-open-close.patch +++ b/0128-ieee1275-Avoiding-many-unecessary-open-close.patch @@ -9,7 +9,7 @@ Signed-off-by: Diego Domingos 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c -index 03674cb477e..ea7f78ac7d8 100644 +index c6cba0c8aaf..629fc15f284 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -44,7 +44,7 @@ struct ofdisk_hash_ent @@ -94,7 +94,7 @@ index 03674cb477e..ea7f78ac7d8 100644 if (err) { grub_free (devpath); -@@ -532,13 +555,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) +@@ -528,13 +551,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) static void grub_ofdisk_close (grub_disk_t disk) { @@ -108,7 +108,7 @@ index 03674cb477e..ea7f78ac7d8 100644 disk->data = 0; } -@@ -685,7 +701,7 @@ grub_ofdisk_init (void) +@@ -681,7 +697,7 @@ grub_ofdisk_init (void) } static grub_err_t @@ -117,7 +117,7 @@ index 03674cb477e..ea7f78ac7d8 100644 struct ofdisk_hash_ent *op) { struct size_args_ieee1275 -@@ -698,16 +714,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, +@@ -694,16 +710,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, grub_ieee1275_cell_t size2; } args_ieee1275; diff --git a/0176-ieee1275-powerpc-implements-fibre-channel-discovery-.patch b/0129-ieee1275-powerpc-implements-fibre-channel-discovery-.patch similarity index 100% rename from 0176-ieee1275-powerpc-implements-fibre-channel-discovery-.patch rename to 0129-ieee1275-powerpc-implements-fibre-channel-discovery-.patch diff --git a/0177-ieee1275-powerpc-enables-device-mapper-discovery.patch b/0130-ieee1275-powerpc-enables-device-mapper-discovery.patch similarity index 100% rename from 0177-ieee1275-powerpc-enables-device-mapper-discovery.patch rename to 0130-ieee1275-powerpc-enables-device-mapper-discovery.patch diff --git a/0178-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch b/0131-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch similarity index 92% rename from 0178-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch rename to 0131-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch index 968a9c14..65646f7d 100644 --- a/0178-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch +++ b/0131-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch @@ -2,6 +2,9 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20M=C3=A9trich?= Date: Fri, 18 Dec 2020 15:39:26 +0100 Subject: [PATCH] Add 'at_keyboard_fallback_set' var to force the set manually +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit This seems required with HP DL380p Gen 8 systems. Indeed, with this system, we can see the following sequence: @@ -24,12 +27,15 @@ solution": - https://wiki.osdev.org/%228042%22_PS/2_Controller - http://www-ug.eecg.toronto.edu/msl/nios_devices/datasheets/PS2%20Keyboard%20Protocol.htm - http://www.s100computers.com/My%20System%20Pages/MSDOS%20Board/PC%20Keyboard.pdf + +Signed-off-by: Renaud Métrich +Signed-off-by: Robbie Harwood --- grub-core/term/at_keyboard.c | 121 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 25 deletions(-) diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c -index 26014382608..dac0f946fe6 100644 +index 2d9ab65aee0..378deb321d9 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -31,6 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); @@ -40,7 +46,7 @@ index 26014382608..dac0f946fe6 100644 static int ping_sent; -@@ -76,6 +77,8 @@ at_command (grub_uint8_t data) +@@ -86,6 +87,8 @@ at_command (grub_uint8_t data) break; return 0; } @@ -49,7 +55,7 @@ index 26014382608..dac0f946fe6 100644 return (i != GRUB_AT_TRIES); } -@@ -105,6 +108,21 @@ grub_keyboard_controller_read (void) +@@ -115,6 +118,21 @@ grub_keyboard_controller_read (void) #endif @@ -71,7 +77,7 @@ index 26014382608..dac0f946fe6 100644 static int write_mode (int mode) { -@@ -113,11 +131,14 @@ write_mode (int mode) +@@ -123,11 +141,14 @@ write_mode (int mode) { grub_uint8_t ack; keyboard_controller_wait_until_ready (); @@ -86,7 +92,7 @@ index 26014382608..dac0f946fe6 100644 if (ack == GRUB_AT_NACK) continue; if (ack == GRUB_AT_ACK) -@@ -125,6 +146,9 @@ write_mode (int mode) +@@ -135,6 +156,9 @@ write_mode (int mode) return 0; } @@ -96,7 +102,7 @@ index 26014382608..dac0f946fe6 100644 return (i != GRUB_AT_TRIES); } -@@ -132,31 +156,66 @@ static int +@@ -142,31 +166,66 @@ static int query_mode (void) { grub_uint8_t ret; @@ -183,7 +189,7 @@ index 26014382608..dac0f946fe6 100644 return 0; } -@@ -165,14 +224,25 @@ set_scancodes (void) +@@ -175,14 +234,25 @@ set_scancodes (void) { /* You must have visited computer museum. Keyboard without scancode set knowledge. Assume XT. */ @@ -213,7 +219,7 @@ index 26014382608..dac0f946fe6 100644 if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) == KEYBOARD_AT_TRANSLATE) { grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate mode, so actually in set 1\n", grub_keyboard_orig_set); ps2_state.current_set = 1; -@@ -261,6 +331,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) +@@ -271,6 +341,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) static void grub_keyboard_controller_init (void) { @@ -221,7 +227,7 @@ index 26014382608..dac0f946fe6 100644 ps2_state.at_keyboard_status = 0; /* Drain input buffer. */ while (1) -@@ -282,6 +353,7 @@ grub_keyboard_controller_init (void) +@@ -292,6 +363,7 @@ grub_keyboard_controller_init (void) grub_keyboard_controller_orig = grub_keyboard_controller_read (); grub_dprintf ("atkeyb", "grub_keyboard_controller_orig = 0x%x\n", grub_keyboard_controller_orig); grub_keyboard_orig_set = query_mode (); @@ -229,7 +235,7 @@ index 26014382608..dac0f946fe6 100644 #endif set_scancodes (); keyboard_controller_led (ps2_state.led_status); -@@ -329,7 +401,6 @@ grub_at_restore_hw (void) +@@ -339,7 +411,6 @@ grub_at_restore_hw (void) return GRUB_ERR_NONE; } diff --git a/0131-Fix-systemctl-kexec-exit-status-check.patch b/0131-Fix-systemctl-kexec-exit-status-check.patch deleted file mode 100644 index 74ecedcc..00000000 --- a/0131-Fix-systemctl-kexec-exit-status-check.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 9 Apr 2019 12:30:38 +0200 -Subject: [PATCH] Fix systemctl kexec exit status check - -There's always an error printed even when the systemctl kexec command does -succeed. That's because systemctl executes it asynchronously, but the emu -loader seems to expect it to be synchronous and that should never return. - -Also, it's wrong to test if kexecute == 1 since we already know that's the -case or otherwise the function wouldn't had called grub_fatal() earlier. - -Finally, systemctl kexec failing shouldn't be a fatal error since the emu -loader fallbacks to executing the kexec command in case of a failure. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/loader/emu/linux.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c -index fda9e00d24c..5b85b225eed 100644 ---- a/grub-core/loader/emu/linux.c -+++ b/grub-core/loader/emu/linux.c -@@ -71,8 +71,10 @@ grub_linux_boot (void) - (kexecute==1) ? "do-or-die" : "just-in-case"); - rc = grub_util_exec (systemctl); - -- if (kexecute == 1) -- grub_fatal (N_("Error trying to perform 'systemctl kexec'")); -+ if (rc == GRUB_ERR_NONE) -+ return rc; -+ -+ grub_error (rc, N_("Error trying to perform 'systemctl kexec'")); - - /* need to check read-only root before resetting hard!? */ - grub_printf("Performing 'kexec -e'"); diff --git a/0179-Add-suport-for-signing-grub-with-an-appended-signatu.patch b/0132-Add-suport-for-signing-grub-with-an-appended-signatu.patch similarity index 84% rename from 0179-Add-suport-for-signing-grub-with-an-appended-signatu.patch rename to 0132-Add-suport-for-signing-grub-with-an-appended-signatu.patch index a8632985..c9a45b1d 100644 --- a/0179-Add-suport-for-signing-grub-with-an-appended-signatu.patch +++ b/0132-Add-suport-for-signing-grub-with-an-appended-signatu.patch @@ -33,29 +33,20 @@ under this scheme. Signed-off-by: Daniel Axtens Signed-off-by: Rashmica Gupta - --- - -You can experiment with this code with a patched version of SLOF -that verifies these signatures. You can find one at: - https://github.com/daxtens/SLOF - -I will be proposing this for inclusion in a future Power Architecture -Platform Reference (PAPR). ---- - util/grub-install-common.c | 18 ++++++++++++++++-- - util/grub-mkimage.c | 16 ++++++++++++++-- + util/grub-install-common.c | 14 ++++++++++++-- + util/grub-mkimage.c | 15 +++++++++++++-- util/grub-mkimagexx.c | 39 ++++++++++++++++++++++++++++++++++++++- util/mkimage.c | 13 +++++++------ include/grub/util/install.h | 8 ++++++-- include/grub/util/mkimage.h | 4 ++-- - 6 files changed, 83 insertions(+), 15 deletions(-) + 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/util/grub-install-common.c b/util/grub-install-common.c -index 4e212e690c5..aab2a941f85 100644 +index ce854d86f86..1fa0f7f6f00 100644 --- a/util/grub-install-common.c +++ b/util/grub-install-common.c -@@ -461,10 +461,12 @@ static size_t npubkeys; +@@ -466,10 +466,12 @@ static size_t npubkeys; static char *sbat; static int disable_shim_lock; static grub_compression_t compression; @@ -67,8 +58,8 @@ index 4e212e690c5..aab2a941f85 100644 + const char *end; switch (key) { - case 'C': -@@ -562,6 +564,12 @@ grub_install_parse (int key, char *arg) + case GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS: +@@ -567,6 +569,12 @@ grub_install_parse (int key, char *arg) grub_util_error (_("Unrecognized compression `%s'"), arg); case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE: return 1; @@ -81,22 +72,20 @@ index 4e212e690c5..aab2a941f85 100644 default: return 0; } -@@ -665,7 +673,13 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, - dir, prefix, - outname, dtb ? : "", sbat ? : "", mkimage_target, - compnames[compression], note ? "--note" : "", -- disable_shim_lock ? "--disable-shim-lock" : "", s); -+ disable_shim_lock ? "--disable-shim-lock" : "", -+ "--format '%s' --compression '%s' " -+ "--appended-signature-size %zu %s %s\n", -+ dir, prefix, -+ outname, dtb ? : "", mkimage_target, -+ compnames[compression], appsig_size, -+ note ? "--note" : "", s); - free (s); +@@ -679,9 +687,11 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + *p = '\0'; - tgt = grub_install_get_image_target (mkimage_target); -@@ -675,7 +689,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + grub_util_info ("grub-mkimage --directory '%s' --prefix '%s' --output '%s'" +- " --format '%s' --compression '%s'%s%s%s\n", ++ " --format '%s' --compression '%s'" ++ " --appended-signture-size %zu %s%s%s\n", + dir, prefix, outname, + mkimage_target, compnames[compression], ++ appsig_size, + note ? " --note" : "", + disable_shim_lock ? " --disable-shim-lock" : "", s); + free (s); +@@ -693,7 +703,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, grub_install_generate_image (dir, prefix, fp, outname, modules.entries, memdisk_path, pubkeys, npubkeys, config_path, tgt, @@ -106,14 +95,14 @@ index 4e212e690c5..aab2a941f85 100644 while (dc--) grub_install_pop_module (); diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c -index c0d55993702..26d1ecbf74e 100644 +index c0d55993702..8a53310548b 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -84,6 +84,7 @@ static struct argp_option options[] = { {"sbat", 's', N_("FILE"), 0, N_("SBAT metadata"), 0}, {"disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, N_("disable shim_lock verifier"), 0}, {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, -+ {"appended-signature-size", 's', N_("SIZE"), 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), 0}, ++ {"appended-signature-size", 'S', N_("SIZE"), 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), 0}, { 0, 0, 0, 0, 0, 0 } }; @@ -147,24 +136,23 @@ index c0d55993702..26d1ecbf74e 100644 case 'm': if (arguments->memdisk) free (arguments->memdisk); -@@ -324,8 +334,10 @@ main (int argc, char *argv[]) +@@ -324,8 +334,9 @@ main (int argc, char *argv[]) arguments.memdisk, arguments.pubkeys, arguments.npubkeys, arguments.config, arguments.image_target, arguments.note, - arguments.comp, arguments.dtb, - arguments.sbat, arguments.disable_shim_lock); -+ -+ arguments.comp, arguments.appsig_size, ++ arguments.appsig_size, arguments.comp, + arguments.dtb, arguments.sbat, + arguments.disable_shim_lock); if (grub_util_file_sync (fp) < 0) grub_util_error (_("cannot sync `%s': %s"), arguments.output ? : "stdout", diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c -index d78fa3e5330..393119486d3 100644 +index e50b29533c6..9488f052510 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c -@@ -84,6 +84,15 @@ struct grub_ieee1275_note +@@ -85,6 +85,15 @@ struct grub_ieee1275_note struct grub_ieee1275_note_desc descriptor; }; @@ -180,7 +168,7 @@ index d78fa3e5330..393119486d3 100644 #define GRUB_XEN_NOTE_NAME "Xen" struct fixup_block_list -@@ -207,7 +216,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr) +@@ -208,7 +217,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr) void SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target, @@ -189,7 +177,7 @@ index d78fa3e5330..393119486d3 100644 Elf_Addr target_addr, struct grub_mkimage_layout *layout) { -@@ -221,6 +230,12 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc +@@ -222,6 +231,12 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc int shnum = 4; int string_size = sizeof (".text") + sizeof ("mods") + 1; @@ -202,7 +190,7 @@ index d78fa3e5330..393119486d3 100644 if (image_target->id != IMAGE_LOONGSON_ELF) phnum += 2; -@@ -484,6 +499,28 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc +@@ -485,6 +500,28 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc phdr->p_offset = grub_host_to_target32 (header_size + program_size); } @@ -232,10 +220,10 @@ index d78fa3e5330..393119486d3 100644 char *str_start = (elf_img + sizeof (*ehdr) + phnum * sizeof (*phdr) + shnum * sizeof (*shdr)); diff --git a/util/mkimage.c b/util/mkimage.c -index a26cf76f72f..bab12276010 100644 +index 4237383acaf..d33838bec6b 100644 --- a/util/mkimage.c +++ b/util/mkimage.c -@@ -869,8 +869,9 @@ grub_install_generate_image (const char *dir, const char *prefix, +@@ -885,8 +885,9 @@ grub_install_generate_image (const char *dir, const char *prefix, char *memdisk_path, char **pubkey_paths, size_t npubkeys, char *config_path, const struct grub_install_image_target_desc *image_target, @@ -247,7 +235,7 @@ index a26cf76f72f..bab12276010 100644 { char *kernel_img, *core_img; size_t total_module_size, core_size; -@@ -1773,11 +1774,11 @@ grub_install_generate_image (const char *dir, const char *prefix, +@@ -1810,11 +1811,11 @@ grub_install_generate_image (const char *dir, const char *prefix, else target_addr = image_target->link_addr; if (image_target->voidp_sizeof == 4) @@ -264,7 +252,7 @@ index a26cf76f72f..bab12276010 100644 break; } diff --git a/include/grub/util/install.h b/include/grub/util/install.h -index 7df3191f47e..cf4531e02b6 100644 +index 35cf17a8d93..2720428602b 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -67,6 +67,9 @@ @@ -277,7 +265,7 @@ index 7df3191f47e..cf4531e02b6 100644 { "verbose", 'v', 0, 0, \ N_("print verbose messages."), 1 } -@@ -128,7 +131,8 @@ enum grub_install_options { +@@ -129,7 +132,8 @@ enum grub_install_options { GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, GRUB_INSTALL_OPTIONS_DTB, GRUB_INSTALL_OPTIONS_SBAT, @@ -287,7 +275,7 @@ index 7df3191f47e..cf4531e02b6 100644 }; extern char *grub_install_source_directory; -@@ -188,7 +192,7 @@ grub_install_generate_image (const char *dir, const char *prefix, +@@ -189,7 +193,7 @@ grub_install_generate_image (const char *dir, const char *prefix, size_t npubkeys, char *config_path, const struct grub_install_image_target_desc *image_target, diff --git a/0132-Print-grub-emu-linux-loader-messages-as-debug.patch b/0132-Print-grub-emu-linux-loader-messages-as-debug.patch deleted file mode 100644 index a49ec44c..00000000 --- a/0132-Print-grub-emu-linux-loader-messages-as-debug.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 9 Apr 2019 12:42:37 +0200 -Subject: [PATCH] Print grub-emu linux loader messages as debug - -They just polute the output and should better be debug messages instead. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/loader/emu/linux.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c -index 5b85b225eed..22ab6af1727 100644 ---- a/grub-core/loader/emu/linux.c -+++ b/grub-core/loader/emu/linux.c -@@ -50,7 +50,7 @@ grub_linux_boot (void) - initrd_param = grub_xasprintf("%s", ""); - } - -- grub_printf("%serforming 'kexec -l %s %s %s'\n", -+ grub_dprintf ("linux", "%serforming 'kexec -l %s %s %s'\n", - (kexecute) ? "P" : "Not p", - kernel_path, initrd_param, boot_cmdline); - -@@ -67,7 +67,7 @@ grub_linux_boot (void) - if (kexecute < 1) - grub_fatal (N_("Use '"PACKAGE"-emu --kexec' to force a system restart.")); - -- grub_printf("Performing 'systemctl kexec' (%s) ", -+ grub_dprintf ("linux", "Performing 'systemctl kexec' (%s) ", - (kexecute==1) ? "do-or-die" : "just-in-case"); - rc = grub_util_exec (systemctl); - diff --git a/0180-docs-grub-Document-signing-grub-under-UEFI.patch b/0133-docs-grub-Document-signing-grub-under-UEFI.patch similarity index 92% rename from 0180-docs-grub-Document-signing-grub-under-UEFI.patch rename to 0133-docs-grub-Document-signing-grub-under-UEFI.patch index 9b9b19a7..69c352d4 100644 --- a/0180-docs-grub-Document-signing-grub-under-UEFI.patch +++ b/0133-docs-grub-Document-signing-grub-under-UEFI.patch @@ -13,10 +13,10 @@ Signed-off-by: Daniel Axtens 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/grub.texi b/docs/grub.texi -index 4870faaa00a..365d1d6931b 100644 +index 1e577d2fee9..30d4046a931 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -5817,6 +5817,7 @@ environment variables and commands are listed in the same order. +@@ -6403,6 +6403,7 @@ environment variables and commands are listed in the same order. * Secure Boot Advanced Targeting:: Embedded information for generation number based revocation * Measured Boot:: Measuring boot components * Lockdown:: Lockdown when booting on a secure setup @@ -24,7 +24,7 @@ index 4870faaa00a..365d1d6931b 100644 @end menu @node Authentication and authorisation -@@ -5895,7 +5896,7 @@ commands. +@@ -6481,7 +6482,7 @@ commands. GRUB's @file{core.img} can optionally provide enforcement that all files subsequently read from disk are covered by a valid digital signature. @@ -33,7 +33,7 @@ index 4870faaa00a..365d1d6931b 100644 platform's firmware (e.g., Coreboot) validates @file{core.img}. If environment variable @code{check_signatures} -@@ -6067,6 +6068,25 @@ be restricted and some operations/commands cannot be executed. +@@ -6654,6 +6655,25 @@ be restricted and some operations/commands cannot be executed. The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down. Otherwise it does not exit. diff --git a/0134-Fix-undefined-references-for-fdt-when-building-with-.patch b/0134-Fix-undefined-references-for-fdt-when-building-with-.patch deleted file mode 100644 index 9065da8a..00000000 --- a/0134-Fix-undefined-references-for-fdt-when-building-with-.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 1 May 2019 00:36:19 +0200 -Subject: [PATCH] Fix undefined references for fdt when building with platform - emu - -The fdt module isn't build for this platform, so adding the declarations -with platform emu will lead to the following undefined reference errors: - -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x500): undefined reference to `grub_fdt_add_subnode' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x518): undefined reference to `grub_fdt_check_header' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x530): undefined reference to `grub_fdt_check_header_nosize' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x548): undefined reference to `grub_fdt_create_empty_tree' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x560): undefined reference to `grub_fdt_find_subnode' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x578): undefined reference to `grub_fdt_first_node' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x590): undefined reference to `grub_fdt_get_nodename' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5a8): undefined reference to `grub_fdt_get_prop' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5c0): undefined reference to `grub_fdt_next_node' -BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5d8): undefined reference to `grub_fdt_set_prop' -BUILDSTDERR: collect2: error: ld returned 1 exit status -BUILDSTDERR: make[1]: *** [Makefile:27093: grub-emu-lite] Error 1 -BUILDSTDERR: make[1]: *** Waiting for unfinished jobs.... - -Signed-off-by: Javier Martinez Canillas ---- - include/grub/fdt.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/include/grub/fdt.h b/include/grub/fdt.h -index 22b7c5463fc..2041341fd68 100644 ---- a/include/grub/fdt.h -+++ b/include/grub/fdt.h -@@ -19,7 +19,7 @@ - #ifndef GRUB_FDT_HEADER - #define GRUB_FDT_HEADER 1 - --#if defined(__arm__) || defined(__aarch64__) -+#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__aarch64__)) - - #include - #include diff --git a/0181-docs-grub-Document-signing-grub-with-an-appended-sig.patch b/0134-docs-grub-Document-signing-grub-with-an-appended-sig.patch similarity index 95% rename from 0181-docs-grub-Document-signing-grub-with-an-appended-sig.patch rename to 0134-docs-grub-Document-signing-grub-with-an-appended-sig.patch index 4d85d938..e5c63208 100644 --- a/0181-docs-grub-Document-signing-grub-with-an-appended-sig.patch +++ b/0134-docs-grub-Document-signing-grub-with-an-appended-sig.patch @@ -13,10 +13,10 @@ Signed-off-by: Daniel Axtens 1 file changed, 42 insertions(+) diff --git a/docs/grub.texi b/docs/grub.texi -index 365d1d6931b..afbde7c1f7b 100644 +index 30d4046a931..0ac0a1b3735 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -6087,6 +6087,48 @@ image works under UEFI secure boot and can maintain the secure-boot chain. It +@@ -6674,6 +6674,48 @@ image works under UEFI secure boot and can maintain the secure-boot chain. It will also be necessary to enrol the public key used into a relevant firmware key database. diff --git a/0135-Do-better-in-bootstrap.conf.patch b/0135-Do-better-in-bootstrap.conf.patch deleted file mode 100644 index ec9d8ecc..00000000 --- a/0135-Do-better-in-bootstrap.conf.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 29 Jul 2019 10:58:52 -0400 -Subject: [PATCH] Do better in bootstrap.conf - ---- - bootstrap.conf | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/bootstrap.conf b/bootstrap.conf -index 186be9c48ce..9259526e891 100644 ---- a/bootstrap.conf -+++ b/bootstrap.conf -@@ -16,7 +16,13 @@ - # along with this program. If not, see . - - --GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 -+# GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 -+if [[ -z "${GNULIB_REVISION}" ]] ;then -+ GNULIB_REVISION=fixes -+fi -+if [[ -z "${GNULIB_URL}" ]] ;then -+ GNULIB_URL=https://github.com/rhboot/gnulib.git -+fi - - # gnulib modules used by this package. - # mbswidth is used by gnulib-fix-width.diff's changes to argp rather than diff --git a/0182-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch b/0135-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch similarity index 92% rename from 0182-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch rename to 0135-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch index 6e46db01..c25927d5 100644 --- a/0182-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch +++ b/0135-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch @@ -16,10 +16,10 @@ Signed-off-by: Daniel Axtens 1 file changed, 11 insertions(+) diff --git a/include/grub/dl.h b/include/grub/dl.h -index 2f76e6b0437..20d870f2a47 100644 +index 8a3d188d1d1..3f10e27d62c 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h -@@ -245,11 +245,22 @@ grub_dl_get (const char *name) +@@ -244,11 +244,22 @@ grub_dl_get (const char *name) return 0; } diff --git a/0136-Use-git-to-apply-gnulib-patches.patch b/0136-Use-git-to-apply-gnulib-patches.patch deleted file mode 100644 index 76546488..00000000 --- a/0136-Use-git-to-apply-gnulib-patches.patch +++ /dev/null @@ -1,631 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 29 Jul 2019 11:21:27 -0400 -Subject: [PATCH] Use git to apply gnulib patches. - -Signed-off-by: Peter Jones ---- - bootstrap.conf | 6 - - conf/Makefile.extra-dist | 10 - - grub-core/lib/gnulib-patches/fix-base64.patch | 21 -- - grub-core/lib/gnulib-patches/fix-null-deref.patch | 13 -- - .../lib/gnulib-patches/fix-null-state-deref.patch | 12 -- - .../gnulib-patches/fix-regcomp-uninit-token.patch | 15 -- - .../gnulib-patches/fix-regexec-null-deref.patch | 12 -- - .../gnulib-patches/fix-sign-compare-errors.patch | 161 --------------- - .../lib/gnulib-patches/fix-uninit-structure.patch | 11 -- - .../lib/gnulib-patches/fix-unused-value.patch | 14 -- - grub-core/lib/gnulib-patches/fix-width.patch | 217 --------------------- - grub-core/lib/gnulib-patches/no-abort.patch | 26 --- - 12 files changed, 518 deletions(-) - delete mode 100644 grub-core/lib/gnulib-patches/fix-base64.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-null-deref.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-null-state-deref.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-uninit-structure.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-unused-value.patch - delete mode 100644 grub-core/lib/gnulib-patches/fix-width.patch - delete mode 100644 grub-core/lib/gnulib-patches/no-abort.patch - -diff --git a/bootstrap.conf b/bootstrap.conf -index 9259526e891..452f4d79b0d 100644 ---- a/bootstrap.conf -+++ b/bootstrap.conf -@@ -85,12 +85,6 @@ cp -a INSTALL INSTALL.grub - - bootstrap_post_import_hook () { - set -e -- for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \ -- fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort \ -- fix-sign-compare-errors; do -- patch -d grub-core/lib/gnulib -p2 \ -- < "grub-core/lib/gnulib-patches/$patchname.patch" -- done - for patchname in \ - 0001-Support-POTFILES-shell \ - 0002-Handle-gettext_printf-shell-function \ -diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist -index ea58362b555..8ddf22e6c99 100644 ---- a/conf/Makefile.extra-dist -+++ b/conf/Makefile.extra-dist -@@ -30,16 +30,6 @@ EXTRA_DIST += grub-core/gensymlist.sh - EXTRA_DIST += grub-core/genemuinit.sh - EXTRA_DIST += grub-core/genemuinitheader.sh - --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-base64.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-deref.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-state-deref.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-uninit-structure.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-unused-value.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/fix-width.patch --EXTRA_DIST += grub-core/lib/gnulib-patches/no-abort.patch -- - EXTRA_DIST += grub-core/lib/libgcrypt - EXTRA_DIST += grub-core/lib/libgcrypt-grub/mpi/generic - EXTRA_DIST += $(shell find $(top_srcdir)/include -name '*.h') -diff --git a/grub-core/lib/gnulib-patches/fix-base64.patch b/grub-core/lib/gnulib-patches/fix-base64.patch -deleted file mode 100644 -index 985db127971..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-base64.patch -+++ /dev/null -@@ -1,21 +0,0 @@ --diff --git a/lib/base64.h b/lib/base64.h --index 9cd0183b8..185a2afa1 100644 ----- a/lib/base64.h --+++ b/lib/base64.h --@@ -21,8 +21,14 @@ -- /* Get size_t. */ -- # include -- ---/* Get bool. */ ---# include --+#ifndef GRUB_POSIX_BOOL_DEFINED --+typedef enum { false = 0, true = 1 } bool; --+#define GRUB_POSIX_BOOL_DEFINED 1 --+#endif --+ --+#ifndef _GL_ATTRIBUTE_CONST --+# define _GL_ATTRIBUTE_CONST /* empty */ --+#endif -- -- # ifdef __cplusplus -- extern "C" { -diff --git a/grub-core/lib/gnulib-patches/fix-null-deref.patch b/grub-core/lib/gnulib-patches/fix-null-deref.patch -deleted file mode 100644 -index 8fafa153a47..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-null-deref.patch -+++ /dev/null -@@ -1,13 +0,0 @@ --diff --git a/lib/argp-parse.c b/lib/argp-parse.c --index 6dec57310..900adad54 100644 ----- a/lib/argp-parse.c --+++ b/lib/argp-parse.c --@@ -940,7 +940,7 @@ weak_alias (__argp_parse, argp_parse) -- void * -- __argp_input (const struct argp *argp, const struct argp_state *state) -- { --- if (state) --+ if (state && state->pstate) -- { -- struct group *group; -- struct parser *parser = state->pstate; -diff --git a/grub-core/lib/gnulib-patches/fix-null-state-deref.patch b/grub-core/lib/gnulib-patches/fix-null-state-deref.patch -deleted file mode 100644 -index 813ec09c8a1..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-null-state-deref.patch -+++ /dev/null -@@ -1,12 +0,0 @@ ----- a/lib/argp-help.c 2020-10-28 14:32:19.189215988 +0000 --+++ b/lib/argp-help.c 2020-10-28 14:38:21.204673940 +0000 --@@ -145,7 +145,8 @@ -- if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin) -- { -- __argp_failure (state, 0, 0, --- dgettext (state->root_argp->argp_domain, --+ dgettext (state == NULL ? NULL --+ : state->root_argp->argp_domain, -- "\ -- ARGP_HELP_FMT: %s value is less than or equal to %s"), -- "rmargin", up->name); -diff --git a/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch b/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch -deleted file mode 100644 -index 02e06315dff..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch -+++ /dev/null -@@ -1,15 +0,0 @@ ----- a/lib/regcomp.c 2020-11-24 17:06:08.159223858 +0000 --+++ b/lib/regcomp.c 2020-11-24 17:06:15.630253923 +0000 --@@ -3808,11 +3808,7 @@ -- create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, -- re_token_type_t type) -- { --- re_token_t t; ---#if defined GCC_LINT || defined lint --- memset (&t, 0, sizeof t); ---#endif --- t.type = type; --+ re_token_t t = { .type = type }; -- return create_token_tree (dfa, left, right, &t); -- } -- -diff --git a/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch b/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch -deleted file mode 100644 -index db6dac9c9e3..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch -+++ /dev/null -@@ -1,12 +0,0 @@ ----- a/lib/regexec.c 2020-10-21 14:25:35.310195912 +0000 --+++ b/lib/regexec.c 2020-11-05 10:55:09.621542984 +0000 --@@ -1692,6 +1692,9 @@ -- { -- Idx top = mctx->state_log_top; -- --+ if (mctx->state_log == NULL) --+ return REG_NOERROR; --+ -- if ((next_state_log_idx >= mctx->input.bufs_len -- && mctx->input.bufs_len < mctx->input.len) -- || (next_state_log_idx >= mctx->input.valid_len -diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch -deleted file mode 100644 -index 479029c0565..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch -+++ /dev/null -@@ -1,161 +0,0 @@ --diff --git a/lib/regcomp.c b/lib/regcomp.c --index cc85f35ac58..361079d82d6 100644 ----- a/lib/regcomp.c --+++ b/lib/regcomp.c --@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, -- *p++ = dfa->nodes[node].opr.c; -- memset (&state, '\0', sizeof (state)); -- if (__mbrtowc (&wc, (const char *) buf, p - buf, --- &state) == p - buf --+ &state) == (size_t)(p - buf) -- && (__wcrtomb ((char *) buf, __towlower (wc), &state) -- != (size_t) -1)) -- re_set_fastmap (fastmap, false, buf[0]); --@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) -- num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) -- ? -2 -- : num == -1 --- ? c - '0' --+ ? (Idx)(c - '0') -- : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); -- } -- return num; --diff --git a/lib/regex_internal.c b/lib/regex_internal.c --index 9004ce809eb..193a1e3d332 100644 ----- a/lib/regex_internal.c --+++ b/lib/regex_internal.c --@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) -- /* Apply the translation if we need. */ -- if (__glibc_unlikely (pstr->trans != NULL)) -- { --- int i, ch; --+ unsigned int i, ch; -- -- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) -- { --@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) -- prev_st = pstr->cur_state; -- if (__glibc_unlikely (pstr->trans != NULL)) -- { --- int i, ch; --+ unsigned int i, ch; -- -- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) -- { --@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) -- memset (&cur_state, 0, sizeof (cur_state)); -- mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, -- &cur_state); --- if (raw + offset - p <= mbclen --+ if ((size_t)(raw + offset - p) <= mbclen -- && mbclen < (size_t) -2) -- { -- memset (&pstr->cur_state, '\0', --diff --git a/lib/regex_internal.h b/lib/regex_internal.h --index 5462419b787..e0f8292395d 100644 ----- a/lib/regex_internal.h --+++ b/lib/regex_internal.h --@@ -425,7 +425,7 @@ struct re_string_t -- unsigned char offsets_needed; -- unsigned char newline_anchor; -- unsigned char word_ops_used; --- int mb_cur_max; --+ unsigned int mb_cur_max; -- }; -- typedef struct re_string_t re_string_t; -- --@@ -702,7 +702,7 @@ struct re_dfa_t -- unsigned int is_utf8 : 1; -- unsigned int map_notascii : 1; -- unsigned int word_ops_used : 1; --- int mb_cur_max; --+ unsigned int mb_cur_max; -- bitset_t word_char; -- reg_syntax_t syntax; -- Idx *subexp_map; --diff --git a/lib/regexec.c b/lib/regexec.c --index 0a7a27b772e..b57d4f9141d 100644 ----- a/lib/regexec.c --+++ b/lib/regexec.c --@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, -- { -- if (ret_len) -- { --- assert (pmatch[0].rm_so == start); --+ assert (pmatch[0].rm_so == (long)start); -- rval = pmatch[0].rm_eo - start; -- } -- else --@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, -- if (__glibc_unlikely (mctx.input.offsets_needed != 0)) -- { -- pmatch[reg_idx].rm_so = --- (pmatch[reg_idx].rm_so == mctx.input.valid_len --+ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len -- ? mctx.input.valid_raw_len -- : mctx.input.offsets[pmatch[reg_idx].rm_so]); -- pmatch[reg_idx].rm_eo = --- (pmatch[reg_idx].rm_eo == mctx.input.valid_len --+ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len -- ? mctx.input.valid_raw_len -- : mctx.input.offsets[pmatch[reg_idx].rm_eo]); -- } --@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, -- } -- memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); -- --- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) --+ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) -- { -- update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); -- --- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) --+ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) -- { -- Idx reg_idx; -- if (fs) --@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, -- if (reg_num < nmatch) -- { -- /* We are at the last node of this sub expression. */ --- if (pmatch[reg_num].rm_so < cur_idx) --+ if (pmatch[reg_num].rm_so < (long)cur_idx) -- { -- pmatch[reg_num].rm_eo = cur_idx; -- /* This is a non-empty match or we are not inside an optional --@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, -- mctx->state_log[str_idx] = cur_state; -- } -- --- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) --+ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) -- { -- re_node_set_empty (&next_nodes); -- if (mctx->state_log[str_idx + 1]) --@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, -- const re_string_t *input, Idx str_idx) -- { -- const re_token_t *node = dfa->nodes + node_idx; --- int char_len, elem_len; --+ unsigned int char_len, elem_len; -- Idx i; -- -- if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) --@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) -- /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ -- ret = re_string_realloc_buffers (pstr, -- MAX (min_len, --- MIN (pstr->len, pstr->bufs_len * 2))); --+ MIN ((long)pstr->len, pstr->bufs_len * 2))); -- if (__glibc_unlikely (ret != REG_NOERROR)) -- return ret; -- --@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, -- = (from == to ? -1 : 0); -- -- mctx->bkref_ents[mctx->nbkref_ents++].more = 0; --- if (mctx->max_mb_elem_len < to - from) --+ if (mctx->max_mb_elem_len < (long)(to - from)) -- mctx->max_mb_elem_len = to - from; -- return REG_NOERROR; -- } -diff --git a/grub-core/lib/gnulib-patches/fix-uninit-structure.patch b/grub-core/lib/gnulib-patches/fix-uninit-structure.patch -deleted file mode 100644 -index 7b4d9f67af4..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-uninit-structure.patch -+++ /dev/null -@@ -1,11 +0,0 @@ ----- a/lib/regcomp.c 2020-10-22 13:49:06.770168928 +0000 --+++ b/lib/regcomp.c 2020-10-22 13:50:37.026528298 +0000 --@@ -3662,7 +3662,7 @@ -- Idx alloc = 0; -- #endif /* not RE_ENABLE_I18N */ -- reg_errcode_t ret; --- re_token_t br_token; --+ re_token_t br_token = {0}; -- bin_tree_t *tree; -- -- sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); -diff --git a/grub-core/lib/gnulib-patches/fix-unused-value.patch b/grub-core/lib/gnulib-patches/fix-unused-value.patch -deleted file mode 100644 -index ba51f1bf223..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-unused-value.patch -+++ /dev/null -@@ -1,14 +0,0 @@ ----- a/lib/regexec.c 2020-10-21 14:25:35.310195912 +0000 --+++ b/lib/regexec.c 2020-10-21 14:32:07.961765604 +0000 --@@ -828,7 +828,11 @@ -- break; -- if (__glibc_unlikely (err != REG_NOMATCH)) -- goto free_return; --+#ifdef DEBUG --+ /* Only used for assertion below when DEBUG is set, otherwise --+ it will be over-written when we loop around. */ -- match_last = -1; --+#endif -- } -- else -- break; /* We found a match. */ -diff --git a/grub-core/lib/gnulib-patches/fix-width.patch b/grub-core/lib/gnulib-patches/fix-width.patch -deleted file mode 100644 -index 0a208ad08b5..00000000000 ---- a/grub-core/lib/gnulib-patches/fix-width.patch -+++ /dev/null -@@ -1,217 +0,0 @@ --diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c --index ba6a407f7..d0685b3d4 100644 ----- a/lib/argp-fmtstream.c --+++ b/lib/argp-fmtstream.c --@@ -28,9 +28,11 @@ -- #include -- #include -- #include --+#include -- -- #include "argp-fmtstream.h" -- #include "argp-namefrob.h" --+#include "mbswidth.h" -- -- #ifndef ARGP_FMTSTREAM_USE_LINEWRAP -- --@@ -115,6 +117,51 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free) -- #endif -- #endif -- --+ --+/* Return the pointer to the first character that doesn't fit in l columns. */ --+static inline const ptrdiff_t --+add_width (const char *ptr, const char *end, size_t l) --+{ --+ mbstate_t ps; --+ const char *ptr0 = ptr; --+ --+ memset (&ps, 0, sizeof (ps)); --+ --+ while (ptr < end) --+ { --+ wchar_t wc; --+ size_t s, k; --+ --+ s = mbrtowc (&wc, ptr, end - ptr, &ps); --+ if (s == (size_t) -1) --+ break; --+ if (s == (size_t) -2) --+ { --+ if (1 >= l) --+ break; --+ l--; --+ ptr++; --+ continue; --+ } --+ --+ if (wc == '\e' && ptr + 3 < end --+ && ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1') --+ && ptr[3] == 'm') --+ { --+ ptr += 4; --+ continue; --+ } --+ --+ k = wcwidth (wc); --+ --+ if (k >= l) --+ break; --+ l -= k; --+ ptr += s; --+ } --+ return ptr - ptr0; --+} --+ -- /* Process FS's buffer so that line wrapping is done from POINT_OFFS to the -- end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ -- void --@@ -168,13 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) -- if (!nl) -- { -- /* The buffer ends in a partial line. */ --+ size_t display_width = mbsnwidth (buf, fs->p - buf, --+ MBSW_STOP_AT_NUL); -- --- if (fs->point_col + len < fs->rmargin) --+ if (fs->point_col + display_width < fs->rmargin) -- { -- /* The remaining buffer text is a partial line and fits -- within the maximum line width. Advance point for the -- characters to be written and stop scanning. */ --- fs->point_col += len; --+ fs->point_col += display_width; -- break; -- } -- else --@@ -182,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs) -- the end of the buffer. */ -- nl = fs->p; -- } --- else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) --- { --- /* The buffer contains a full line that fits within the maximum --- line width. Reset point and scan the next line. */ --- fs->point_col = 0; --- buf = nl + 1; --- continue; --- } --+ else --+ { --+ size_t display_width = mbsnwidth (buf, nl - buf, MBSW_STOP_AT_NUL); --+ if (display_width < (ssize_t) fs->rmargin) --+ { --+ /* The buffer contains a full line that fits within the maximum --+ line width. Reset point and scan the next line. */ --+ fs->point_col = 0; --+ buf = nl + 1; --+ continue; --+ } --+ } -- -- /* This line is too long. */ -- r = fs->rmargin - 1; --@@ -225,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) -- char *p, *nextline; -- int i; -- --- p = buf + (r + 1 - fs->point_col); --+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); -- while (p >= buf && !isblank ((unsigned char) *p)) -- --p; -- nextline = p + 1; /* This will begin the next line. */ --@@ -243,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) -- { -- /* A single word that is greater than the maximum line width. -- Oh well. Put it on an overlong line by itself. */ --- p = buf + (r + 1 - fs->point_col); --+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); -- /* Find the end of the long word. */ -- if (p < nl) -- do --@@ -277,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs) -- && fs->p > nextline) -- { -- /* The margin needs more blanks than we removed. */ --- if (fs->end - fs->p > fs->wmargin + 1) --+ if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL) --+ > fs->wmargin + 1) -- /* Make some space for them. */ -- { -- size_t mv = fs->p - nextline; --diff --git a/lib/argp-help.c b/lib/argp-help.c --index e5375a0f0..5d8f451ec 100644 ----- a/lib/argp-help.c --+++ b/lib/argp-help.c --@@ -51,6 +51,7 @@ -- #include "argp.h" -- #include "argp-fmtstream.h" -- #include "argp-namefrob.h" --+#include "mbswidth.h" -- -- #ifndef SIZE_MAX -- # define SIZE_MAX ((size_t) -1) --@@ -1432,7 +1433,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, -- -- /* Manually do line wrapping so that it (probably) won't get wrapped at -- any embedded spaces. */ --- space (stream, 1 + nl - cp); --+ space (stream, 1 + mbsnwidth (cp, nl - cp, MBSW_STOP_AT_NUL)); -- -- __argp_fmtstream_write (stream, cp, nl - cp); -- } --diff --git a/lib/mbswidth.c b/lib/mbswidth.c --index 408a15e34..b3fb7f83a 100644 ----- a/lib/mbswidth.c --+++ b/lib/mbswidth.c --@@ -38,6 +38,14 @@ -- /* Get INT_MAX. */ -- #include -- --+#ifndef FALLTHROUGH --+# if __GNUC__ < 7 --+# define FALLTHROUGH ((void) 0) --+# else --+# define FALLTHROUGH __attribute__ ((__fallthrough__)) --+# endif --+#endif --+ -- /* Returns the number of columns needed to represent the multibyte -- character string pointed to by STRING. If a non-printable character -- occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned. --@@ -90,6 +98,10 @@ mbsnwidth (const char *string, size_t nbytes, int flags) -- p++; -- width++; -- break; --+ case '\0': --+ if (flags & MBSW_STOP_AT_NUL) --+ return width; --+ FALLTHROUGH; -- default: -- /* If we have a multibyte sequence, scan it up to its end. */ -- { --@@ -168,6 +180,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags) -- { -- unsigned char c = (unsigned char) *p++; -- --+ if (c == 0 && (flags & MBSW_STOP_AT_NUL)) --+ return width; --+ -- if (isprint (c)) -- { -- if (width == INT_MAX) --diff --git a/lib/mbswidth.h b/lib/mbswidth.h --index 2b5c53c37..45a123e63 100644 ----- a/lib/mbswidth.h --+++ b/lib/mbswidth.h --@@ -45,6 +45,10 @@ extern "C" { -- control characters and 1 otherwise. */ -- #define MBSW_REJECT_UNPRINTABLE 2 -- --+/* If this bit is set \0 is treated as the end of string. --+ Otherwise it's treated as a normal one column width character. */ --+#define MBSW_STOP_AT_NUL 4 --+ -- -- /* Returns the number of screen columns needed for STRING. */ -- #define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ -diff --git a/grub-core/lib/gnulib-patches/no-abort.patch b/grub-core/lib/gnulib-patches/no-abort.patch -deleted file mode 100644 -index e469c4762eb..00000000000 ---- a/grub-core/lib/gnulib-patches/no-abort.patch -+++ /dev/null -@@ -1,26 +0,0 @@ --diff --git a/lib/regcomp.c b/lib/regcomp.c --index cc85f35ac..de45ebb5c 100644 ----- a/lib/regcomp.c --+++ b/lib/regcomp.c --@@ -528,9 +528,9 @@ regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf, -- to this routine. If we are given anything else, or if other regex -- code generates an invalid error code, then the program has a bug. -- Dump core so we can fix it. */ --- abort (); --- --- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); --+ msg = gettext ("unknown regexp error"); --+ else --+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); -- -- msg_size = strlen (msg) + 1; /* Includes the null. */ -- --@@ -1136,7 +1136,7 @@ optimize_utf8 (re_dfa_t *dfa) -- } -- break; -- default: --- abort (); --+ break; -- } -- -- if (mb_chars || has_period) diff --git a/0183-pgp-factor-out-rsa_pad.patch b/0136-pgp-factor-out-rsa_pad.patch similarity index 98% rename from 0183-pgp-factor-out-rsa_pad.patch rename to 0136-pgp-factor-out-rsa_pad.patch index a8154e74..6e629a4f 100644 --- a/0183-pgp-factor-out-rsa_pad.patch +++ b/0136-pgp-factor-out-rsa_pad.patch @@ -27,10 +27,10 @@ Signed-off-by: Daniel Axtens create mode 100644 include/grub/pkcs1_v15.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 81fc274148e..97347ae76f9 100644 +index 4aa20cdfc13..82f2e169ad1 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -2510,6 +2510,14 @@ module = { +@@ -2568,6 +2568,14 @@ module = { cppflags = '$(CPPFLAGS_GCRY)'; }; @@ -46,7 +46,7 @@ index 81fc274148e..97347ae76f9 100644 name = all_video; common = lib/fake_module.c; diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c -index 5daa1e9d00c..2408db4994f 100644 +index c6766f044aa..b084dc9a22f 100644 --- a/grub-core/commands/pgp.c +++ b/grub-core/commands/pgp.c @@ -24,6 +24,7 @@ diff --git a/0137-Fix-build-error-with-the-fdt-module-on-risc-v.patch b/0137-Fix-build-error-with-the-fdt-module-on-risc-v.patch deleted file mode 100644 index 35f2878b..00000000 --- a/0137-Fix-build-error-with-the-fdt-module-on-risc-v.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 27 Aug 2019 10:34:24 +0200 -Subject: [PATCH] Fix build error with the fdt module on risc-v - -The risc-v architecture also uses Device Trees, but the symbols in the -fdt header aren't defined for this arch which lead to following error: - -BUILDSTDERR: ../../grub-core/loader/efi/fdt.c: In function 'grub_fdt_load': -BUILDSTDERR: ../../grub-core/loader/efi/fdt.c:48:39: warning: implicit declaration of function 'grub_fdt_get_totalsize' [-Wimplicit-function-declaration] -BUILDSTDERR: 48 | size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)); - -Signed-off-by: Javier Martinez Canillas ---- - include/grub/fdt.h | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/include/grub/fdt.h b/include/grub/fdt.h -index 2041341fd68..3514aa4a5b6 100644 ---- a/include/grub/fdt.h -+++ b/include/grub/fdt.h -@@ -19,7 +19,8 @@ - #ifndef GRUB_FDT_HEADER - #define GRUB_FDT_HEADER 1 - --#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__aarch64__)) -+#if !defined(GRUB_MACHINE_EMU) && \ -+ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) - - #include - #include -@@ -146,6 +147,7 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch - grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \ - }) - --#endif /* defined(__arm__) || defined(__aarch64__) */ -+#endif /* !defined(GRUB_MACHINE_EMU) && \ -+ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) */ - - #endif /* ! GRUB_FDT_HEADER */ diff --git a/0184-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch b/0137-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch similarity index 96% rename from 0184-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch rename to 0137-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch index 763cdc63..732b91c4 100644 --- a/0184-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch +++ b/0137-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch @@ -40,7 +40,7 @@ Signed-off-by: Daniel Axtens 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c -index 2408db4994f..355a43844ac 100644 +index b084dc9a22f..a45c2213c4a 100644 --- a/grub-core/commands/pgp.c +++ b/grub-core/commands/pgp.c @@ -147,10 +147,6 @@ const char *hashes[] = { @@ -55,7 +55,7 @@ index 2408db4994f..355a43844ac 100644 dsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval, const gcry_md_spec_t *hash, struct grub_public_subkey *sk); diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c -index ca334d5a40e..c578128a59d 100644 +index 396f7641080..d53ddbe2c44 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -121,6 +121,10 @@ grub_md_unregister (gcry_md_spec_t *cipher) diff --git a/0185-posix_wrap-tweaks-in-preparation-for-libtasn1.patch b/0138-posix_wrap-tweaks-in-preparation-for-libtasn1.patch similarity index 88% rename from 0185-posix_wrap-tweaks-in-preparation-for-libtasn1.patch rename to 0138-posix_wrap-tweaks-in-preparation-for-libtasn1.patch index a09cab19..a473c1de 100644 --- a/0185-posix_wrap-tweaks-in-preparation-for-libtasn1.patch +++ b/0138-posix_wrap-tweaks-in-preparation-for-libtasn1.patch @@ -23,10 +23,10 @@ Signed-off-by: Daniel Axtens 3 files changed, 10 insertions(+) diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/limits.h -index 7217138ffd6..591dbf3289d 100644 +index 26918c8a01b..4be7b408063 100644 --- a/grub-core/lib/posix_wrap/limits.h +++ b/grub-core/lib/posix_wrap/limits.h -@@ -37,5 +37,6 @@ +@@ -41,5 +41,6 @@ #define LONG_MAX GRUB_LONG_MAX #define CHAR_BIT 8 @@ -34,11 +34,11 @@ index 7217138ffd6..591dbf3289d 100644 #endif diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h -index 7a8d385e973..4634db09f29 100644 +index f5279756abe..14e4efdd0d6 100644 --- a/grub-core/lib/posix_wrap/stdlib.h +++ b/grub-core/lib/posix_wrap/stdlib.h -@@ -58,4 +58,12 @@ abs (int c) - return (c >= 0) ? c : -c; +@@ -64,4 +64,12 @@ abort (void) + grub_abort (); } +#define strtol grub_strtol @@ -51,10 +51,10 @@ index 7a8d385e973..4634db09f29 100644 + #endif diff --git a/grub-core/lib/posix_wrap/sys/types.h b/grub-core/lib/posix_wrap/sys/types.h -index 854eb0122ef..f63412c8da0 100644 +index eeda543c47e..2f3e865495a 100644 --- a/grub-core/lib/posix_wrap/sys/types.h +++ b/grub-core/lib/posix_wrap/sys/types.h -@@ -51,6 +51,7 @@ typedef grub_uint8_t byte; +@@ -50,6 +50,7 @@ typedef grub_uint8_t byte; typedef grub_addr_t uintptr_t; #define SIZEOF_UNSIGNED_LONG GRUB_CPU_SIZEOF_LONG diff --git a/0186-libtasn1-import-libtasn1-4.16.0.patch b/0139-libtasn1-import-libtasn1-4.16.0.patch similarity index 100% rename from 0186-libtasn1-import-libtasn1-4.16.0.patch rename to 0139-libtasn1-import-libtasn1-4.16.0.patch diff --git a/0187-libtasn1-disable-code-not-needed-in-grub.patch b/0140-libtasn1-disable-code-not-needed-in-grub.patch similarity index 100% rename from 0187-libtasn1-disable-code-not-needed-in-grub.patch rename to 0140-libtasn1-disable-code-not-needed-in-grub.patch diff --git a/0141-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch b/0141-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch deleted file mode 100644 index b694ec9c..00000000 --- a/0141-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: David Abdurachmanov -Date: Thu, 16 Jan 2020 13:10:10 +0100 -Subject: [PATCH] Also define GRUB_EFI_MAX_ALLOCATION_ADDRESS for RISC-V - -The commit "Try to pick better locations for kernel and initrd" missed to -define this macro for the RISC-V (riscv64) architecture, so add it there. - -Signed-off-by: David Abdurachmanov ---- - include/grub/riscv64/efi/memory.h | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h -index c6cb3241714..acb61dca44b 100644 ---- a/include/grub/riscv64/efi/memory.h -+++ b/include/grub/riscv64/efi/memory.h -@@ -2,5 +2,6 @@ - #include - - #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL -+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS - - #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/0188-libtasn1-changes-for-grub-compatibility.patch b/0141-libtasn1-changes-for-grub-compatibility.patch similarity index 100% rename from 0188-libtasn1-changes-for-grub-compatibility.patch rename to 0141-libtasn1-changes-for-grub-compatibility.patch diff --git a/0142-chainloader-Define-machine-types-for-RISC-V.patch b/0142-chainloader-Define-machine-types-for-RISC-V.patch deleted file mode 100644 index 480db52d..00000000 --- a/0142-chainloader-Define-machine-types-for-RISC-V.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: David Abdurachmanov -Date: Sat, 9 Nov 2019 18:06:32 +0000 -Subject: [PATCH] chainloader: Define machine types for RISC-V - -The commit "Add secureboot support on efi chainloader" didn't add machine -types for RISC-V, so this patch adds them. - -Note, that grub-core/loader/riscv/linux.c is skipped because Linux is not -supported yet. This patch might need a new revision once that's the case. - -Signed-off-by: David Abdurachmanov ---- - grub-core/loader/efi/chainloader.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 47f5aa14817..ac8dfd40c61 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -333,6 +333,10 @@ static const grub_uint16_t machine_type __attribute__((__unused__)) = - GRUB_PE32_MACHINE_I386; - #elif defined(__ia64__) - GRUB_PE32_MACHINE_IA64; -+#elif defined(__riscv) && (__riscv_xlen == 32) -+ GRUB_PE32_MACHINE_RISCV32; -+#elif defined(__riscv) && (__riscv_xlen == 64) -+ GRUB_PE32_MACHINE_RISCV64; - #else - #error this architecture is not supported by grub2 - #endif diff --git a/0189-libtasn1-compile-into-asn1-module.patch b/0142-libtasn1-compile-into-asn1-module.patch similarity index 95% rename from 0189-libtasn1-compile-into-asn1-module.patch rename to 0142-libtasn1-compile-into-asn1-module.patch index 67be4e87..bdd6f631 100644 --- a/0189-libtasn1-compile-into-asn1-module.patch +++ b/0142-libtasn1-compile-into-asn1-module.patch @@ -14,12 +14,12 @@ Signed-off-by: Daniel Axtens create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 97347ae76f9..21d2c541850 100644 +index 82f2e169ad1..05b976d9a77 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -2576,3 +2576,18 @@ module = { - common = commands/i386/wrmsr.c; - enable = x86; +@@ -2646,3 +2646,18 @@ module = { + efi = commands/bli.c; + enable = efi; }; + +module = { diff --git a/0190-test_asn1-test-module-for-libtasn1.patch b/0143-test_asn1-test-module-for-libtasn1.patch similarity index 99% rename from 0190-test_asn1-test-module-for-libtasn1.patch rename to 0143-test_asn1-test-module-for-libtasn1.patch index 3a02b247..23f4bbf0 100644 --- a/0190-test_asn1-test-module-for-libtasn1.patch +++ b/0143-test_asn1-test-module-for-libtasn1.patch @@ -18,6 +18,9 @@ This doesn't test the full decoder but that will be exercised in test suites for coming patch sets. Signed-off-by: Daniel Axtens + +[pjones updated the Makefile.util.def part to have "testcase = native;" +syntax.] --- Makefile.util.def | 6 + grub-core/Makefile.core.def | 13 ++ @@ -51,27 +54,27 @@ Signed-off-by: Daniel Axtens create mode 100644 tests/test_asn1.in diff --git a/Makefile.util.def b/Makefile.util.def -index e1242f54022..8cfbe69a76e 100644 +index 8e52e48c780..ef344f5aa8c 100644 --- a/Makefile.util.def +++ b/Makefile.util.def -@@ -1305,6 +1305,12 @@ script = { - common = tests/syslinux_test.in; +@@ -1328,6 +1328,12 @@ script = { + common = tests/luks2_test.in; }; +script = { -+ testcase; ++ testcase = native; + name = test_asn1; + common = tests/test_asn1.in; +}; + program = { - testcase; + testcase = native; name = example_unit_test; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 21d2c541850..b4aaccf7b57 100644 +index 05b976d9a77..0e65fefb195 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -2591,3 +2591,16 @@ module = { +@@ -2661,3 +2661,16 @@ module = { // -Wno-type-limits comes from libtasn1's configure.ac cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1/lib -Wno-type-limits'; }; @@ -1426,10 +1429,10 @@ index 00000000000..555e56dd202 + +#endif diff --git a/.gitignore b/.gitignore -index 594d0134d33..856e69bc5c1 100644 +index a18787dcfe6..f2e8e1e42d7 100644 --- a/.gitignore +++ b/.gitignore -@@ -264,6 +264,7 @@ widthspec.bin +@@ -268,6 +268,7 @@ widthspec.bin /stamp-h1 /syslinux_test /tar_test diff --git a/0191-grub-install-support-embedding-x509-certificates.patch b/0144-grub-install-support-embedding-x509-certificates.patch similarity index 88% rename from 0191-grub-install-support-embedding-x509-certificates.patch rename to 0144-grub-install-support-embedding-x509-certificates.patch index 04722ad7..9ebbeb02 100644 --- a/0191-grub-install-support-embedding-x509-certificates.patch +++ b/0144-grub-install-support-embedding-x509-certificates.patch @@ -12,15 +12,15 @@ Signed-off-by: Alastair D'Silva Signed-off-by: Daniel Axtens --- grub-core/commands/pgp.c | 2 +- - util/grub-install-common.c | 22 +++++++++++++++++++++- + util/grub-install-common.c | 23 ++++++++++++++++++++++- util/grub-mkimage.c | 15 +++++++++++++-- util/mkimage.c | 38 ++++++++++++++++++++++++++++++++++++-- include/grub/kernel.h | 4 +++- include/grub/util/install.h | 7 +++++-- - 6 files changed, 79 insertions(+), 9 deletions(-) + 6 files changed, 80 insertions(+), 9 deletions(-) diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c -index 355a43844ac..b81ac0ae46c 100644 +index a45c2213c4a..847a5046a5c 100644 --- a/grub-core/commands/pgp.c +++ b/grub-core/commands/pgp.c @@ -944,7 +944,7 @@ GRUB_MOD_INIT(pgp) @@ -33,10 +33,10 @@ index 355a43844ac..b81ac0ae46c 100644 pseudo_file.fs = &pseudo_fs; diff --git a/util/grub-install-common.c b/util/grub-install-common.c -index aab2a941f85..422f82362c7 100644 +index 1fa0f7f6f00..b58539111da 100644 --- a/util/grub-install-common.c +++ b/util/grub-install-common.c -@@ -460,6 +460,8 @@ static char **pubkeys; +@@ -465,6 +465,8 @@ static char **pubkeys; static size_t npubkeys; static char *sbat; static int disable_shim_lock; @@ -45,30 +45,31 @@ index aab2a941f85..422f82362c7 100644 static grub_compression_t compression; static size_t appsig_size; -@@ -500,6 +502,11 @@ grub_install_parse (int key, char *arg) - return 1; +@@ -506,6 +508,12 @@ grub_install_parse (int key, char *arg) case GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK: disable_shim_lock = 1; + return 1; + case 'x': + x509keys = xrealloc (x509keys, + sizeof (x509keys[0]) + * (nx509keys + 1)); + x509keys[nx509keys++] = xstrdup (arg); - return 1; ++ return 1; case GRUB_INSTALL_OPTIONS_VERBOSITY: -@@ -627,6 +634,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + verbosity++; +@@ -636,6 +644,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, for (pk = pubkeys; pk < pubkeys + npubkeys; pk++) - slen += 20 + grub_strlen (*pk); + slen += sizeof (" --pubkey ''") + grub_strlen (*pk); + for (pk = x509keys; pk < x509keys + nx509keys; pk++) + slen += 10 + grub_strlen (*pk); + for (md = modules.entries; *md; md++) - { - slen += 10 + grub_strlen (*md); -@@ -655,6 +665,14 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, - *p++ = ' '; + slen += sizeof (" ''") + grub_strlen (*md); + +@@ -676,6 +687,14 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + *p++ = '\''; } + for (pk = x509keys; pk < x509keys + nx509keys; pk++) @@ -81,8 +82,8 @@ index aab2a941f85..422f82362c7 100644 + for (md = modules.entries; *md; md++) { - *p++ = '\''; -@@ -688,7 +706,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + *p++ = ' '; +@@ -702,7 +721,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, grub_install_generate_image (dir, prefix, fp, outname, modules.entries, memdisk_path, @@ -94,7 +95,7 @@ index aab2a941f85..422f82362c7 100644 disable_shim_lock); while (dc--) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c -index 26d1ecbf74e..c5cdda498eb 100644 +index 8a53310548b..e1f1112784a 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -75,7 +75,8 @@ static struct argp_option options[] = { @@ -138,13 +139,13 @@ index 26d1ecbf74e..c5cdda498eb 100644 + arguments.npubkeys, arguments.x509keys, + arguments.nx509keys, arguments.config, arguments.image_target, arguments.note, - - arguments.comp, arguments.appsig_size, + arguments.appsig_size, arguments.comp, + arguments.dtb, arguments.sbat, diff --git a/util/mkimage.c b/util/mkimage.c -index bab12276010..8319e8dfbde 100644 +index d33838bec6b..e2bb4d4cd05 100644 --- a/util/mkimage.c +++ b/util/mkimage.c -@@ -867,7 +867,8 @@ void +@@ -883,7 +883,8 @@ void grub_install_generate_image (const char *dir, const char *prefix, FILE *out, const char *outname, char *mods[], char *memdisk_path, char **pubkey_paths, @@ -154,7 +155,7 @@ index bab12276010..8319e8dfbde 100644 const struct grub_install_image_target_desc *image_target, int note, size_t appsig_size, grub_compression_t comp, const char *dtb_path, const char *sbat_path, -@@ -913,6 +914,19 @@ grub_install_generate_image (const char *dir, const char *prefix, +@@ -929,6 +930,19 @@ grub_install_generate_image (const char *dir, const char *prefix, } } @@ -174,7 +175,7 @@ index bab12276010..8319e8dfbde 100644 if (memdisk_path) { memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512); -@@ -1034,7 +1048,7 @@ grub_install_generate_image (const char *dir, const char *prefix, +@@ -1050,7 +1064,7 @@ grub_install_generate_image (const char *dir, const char *prefix, curs = grub_util_get_image_size (pubkey_paths[i]); header = (struct grub_module_header *) (kernel_img + offset); @@ -183,7 +184,7 @@ index bab12276010..8319e8dfbde 100644 header->size = grub_host_to_target32 (curs + sizeof (*header)); offset += sizeof (*header); -@@ -1043,6 +1057,26 @@ grub_install_generate_image (const char *dir, const char *prefix, +@@ -1059,6 +1073,26 @@ grub_install_generate_image (const char *dir, const char *prefix, } } @@ -226,7 +227,7 @@ index 55849777eaa..98edc0863f6 100644 /* The module header. */ diff --git a/include/grub/util/install.h b/include/grub/util/install.h -index cf4531e02b6..51f3b13ac13 100644 +index 2720428602b..59eabb9bb86 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -67,6 +67,8 @@ @@ -238,7 +239,7 @@ index cf4531e02b6..51f3b13ac13 100644 { "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE,\ "SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), \ 1}, \ -@@ -188,8 +190,9 @@ void +@@ -189,8 +191,9 @@ void grub_install_generate_image (const char *dir, const char *prefix, FILE *out, const char *outname, char *mods[], diff --git a/0192-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch b/0145-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch similarity index 100% rename from 0192-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch rename to 0145-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch diff --git a/0193-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch b/0146-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch similarity index 100% rename from 0193-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch rename to 0146-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch diff --git a/0194-appended-signatures-support-verifying-appended-signa.patch b/0147-appended-signatures-support-verifying-appended-signa.patch similarity index 98% rename from 0194-appended-signatures-support-verifying-appended-signa.patch rename to 0147-appended-signatures-support-verifying-appended-signa.patch index 262efc0d..01442649 100644 --- a/0194-appended-signatures-support-verifying-appended-signa.patch +++ b/0147-appended-signatures-support-verifying-appended-signa.patch @@ -20,6 +20,8 @@ other mechanisms, such as a password or lockdown, must be used to ensure that a user cannot drop to the grub shell and disable verification. Signed-off-by: Daniel Axtens +[pjones: fix missing format specifier] +Signed-off-by: Robbie Harwood --- grub-core/Makefile.core.def | 12 + grub-core/commands/appendedsig/appendedsig.c | 645 +++++++++++++++++++++++++++ @@ -28,10 +30,10 @@ Signed-off-by: Daniel Axtens create mode 100644 grub-core/commands/appendedsig/appendedsig.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index b4aaccf7b57..77321d218c8 100644 +index 0e65fefb195..ebe98551960 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -980,6 +980,18 @@ module = { +@@ -1009,6 +1009,18 @@ module = { cppflags = '-I$(srcdir)/lib/posix_wrap'; }; @@ -52,7 +54,7 @@ index b4aaccf7b57..77321d218c8 100644 common = commands/hdparm.c; diff --git a/grub-core/commands/appendedsig/appendedsig.c b/grub-core/commands/appendedsig/appendedsig.c new file mode 100644 -index 00000000000..dc294cd339e +index 00000000000..1b8a8078061 --- /dev/null +++ b/grub-core/commands/appendedsig/appendedsig.c @@ -0,0 +1,645 @@ @@ -387,7 +389,7 @@ index 00000000000..dc294cd339e + data = grub_malloc (file_size); + if (!data) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ N_("Could not allocate data buffer size " ++ N_("Could not allocate data buffer size %" + PRIuGRUB_UINT64_T " for verification"), file_size); + + while (total_read_size < file_size) @@ -460,7 +462,7 @@ index 00000000000..dc294cd339e + } + + return grub_error (GRUB_ERR_BAD_ARGUMENT, -+ N_("No certificate number %d found - only %d certificates in the store"), ++ N_("No certificate number %lu found - only %lu certificates in the store"), + cert_num, i - 1); +} + @@ -702,7 +704,7 @@ index 00000000000..dc294cd339e + grub_unregister_command (cmd_distrust); +} diff --git a/include/grub/file.h b/include/grub/file.h -index 31567483ccf..96827a4f896 100644 +index a5bf3a792d6..d678de06325 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -80,6 +80,8 @@ enum grub_file_type diff --git a/0195-appended-signatures-verification-tests.patch b/0148-appended-signatures-verification-tests.patch similarity index 99% rename from 0195-appended-signatures-verification-tests.patch rename to 0148-appended-signatures-verification-tests.patch index 9f6c3c62..7c4ae86f 100644 --- a/0195-appended-signatures-verification-tests.patch +++ b/0148-appended-signatures-verification-tests.patch @@ -17,10 +17,10 @@ Signed-off-by: Daniel Axtens create mode 100644 grub-core/tests/appended_signatures.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 77321d218c8..6bddc841b85 100644 +index ebe98551960..c81c9107249 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -2161,6 +2161,12 @@ module = { +@@ -2211,6 +2211,12 @@ module = { common = tests/setjmp_test.c; }; diff --git a/0196-appended-signatures-documentation.patch b/0149-appended-signatures-documentation.patch similarity index 91% rename from 0196-appended-signatures-documentation.patch rename to 0149-appended-signatures-documentation.patch index 864cfa31..c212ed3c 100644 --- a/0196-appended-signatures-documentation.patch +++ b/0149-appended-signatures-documentation.patch @@ -13,10 +13,10 @@ Signed-off-by: Daniel Axtens 1 file changed, 182 insertions(+), 17 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi -index afbde7c1f7b..4816be85611 100644 +index 0ac0a1b3735..eab81718a59 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -3214,6 +3214,7 @@ These variables have special meaning to GRUB. +@@ -3275,6 +3275,7 @@ These variables have special meaning to GRUB. @menu * biosnum:: @@ -24,7 +24,7 @@ index afbde7c1f7b..4816be85611 100644 * check_signatures:: * chosen:: * cmdpath:: -@@ -3273,11 +3274,18 @@ For an alternative approach which also changes BIOS drive mappings for the +@@ -3339,11 +3340,18 @@ For an alternative approach which also changes BIOS drive mappings for the chain-loaded system, @pxref{drivemap}. @@ -45,23 +45,23 @@ index afbde7c1f7b..4816be85611 100644 @node chosen @subsection chosen -@@ -3994,6 +4002,7 @@ you forget a command, you can run the command @command{help} +@@ -4362,6 +4370,7 @@ you forget a command, you can run the command @command{help} * date:: Display or set current date and time * devicetree:: Load a device tree blob * distrust:: Remove a pubkey from trusted keys +* distrust_certificate:: Remove a certificate from the list of trusted certificates * drivemap:: Map a drive to another * echo:: Display a line of text - * eval:: Evaluate agruments as GRUB commands -@@ -4010,6 +4019,7 @@ you forget a command, you can run the command @command{help} + * efitextmode:: Set/Get text output mode resolution +@@ -4378,6 +4387,7 @@ you forget a command, you can run the command @command{help} + * hexdump:: Show raw contents of a file or memory + * insmod:: Insert a module * keystatus:: Check key modifier status - * linux:: Load a Linux kernel - * linux16:: Load a Linux kernel (16-bit mode) +* list_certificates:: List trusted certificates * list_env:: List variables in environment block * list_trusted:: List trusted public keys * load_env:: Load variables from environment block -@@ -4047,8 +4057,10 @@ you forget a command, you can run the command @command{help} +@@ -4416,8 +4426,10 @@ you forget a command, you can run the command @command{help} * test:: Check file types and compare values * true:: Do nothing, successfully * trust:: Add public key to list of trusted keys @@ -71,8 +71,8 @@ index afbde7c1f7b..4816be85611 100644 +* verify_appended:: Verify appended digital signature * verify_detached:: Verify detached digital signature * videoinfo:: List available video modes - @comment * xen_*:: Xen boot commands for AArch64 -@@ -4376,9 +4388,28 @@ These keys are used to validate signatures when environment variable + * wrmsr:: Write values to model-specific registers +@@ -4757,9 +4769,28 @@ These keys are used to validate signatures when environment variable @code{check_signatures} is set to @code{enforce} (@pxref{check_signatures}), and by some invocations of @command{verify_detached} (@pxref{verify_detached}). @xref{Using @@ -102,7 +102,7 @@ index afbde7c1f7b..4816be85611 100644 @node drivemap @subsection drivemap -@@ -4636,6 +4667,21 @@ This command is only available on x86 systems. +@@ -5036,6 +5067,21 @@ only if checking key modifier status is supported. @end deffn @@ -124,7 +124,7 @@ index afbde7c1f7b..4816be85611 100644 @node list_env @subsection list_env -@@ -4655,7 +4701,7 @@ The output is in GPG's v4 key fingerprint format (i.e., the output of +@@ -5055,7 +5101,7 @@ The output is in GPG's v4 key fingerprint format (i.e., the output of @code{gpg --fingerprint}). The least significant four bytes (last eight hexadecimal digits) can be used as an argument to @command{distrust} (@pxref{distrust}). @@ -133,7 +133,7 @@ index afbde7c1f7b..4816be85611 100644 these keys. @end deffn -@@ -4690,8 +4736,13 @@ When used with care, @option{--skip-sig} and the whitelist enable an +@@ -5090,8 +5136,13 @@ When used with care, @option{--skip-sig} and the whitelist enable an administrator to configure a system to boot only signed configurations, but to allow the user to select from among multiple configurations, and to enable ``one-shot'' boot attempts and @@ -148,7 +148,7 @@ index afbde7c1f7b..4816be85611 100644 @end deffn -@@ -4987,7 +5038,7 @@ read. It is possible to modify a digitally signed environment block +@@ -5462,7 +5513,7 @@ read. It is possible to modify a digitally signed environment block file from within GRUB using this command, such that its signature will no longer be valid on subsequent boots. Care should be taken in such advanced configurations to avoid rendering the system @@ -157,7 +157,7 @@ index afbde7c1f7b..4816be85611 100644 @end deffn -@@ -5387,11 +5438,32 @@ signatures when environment variable @code{check_signatures} is set to +@@ -5878,11 +5929,32 @@ signatures when environment variable @code{check_signatures} is set to must itself be properly signed. The @option{--skip-sig} option can be used to disable signature-checking when reading @var{pubkey_file} itself. It is expected that @option{--skip-sig} is useful for testing @@ -191,7 +191,7 @@ index afbde7c1f7b..4816be85611 100644 @node unset @subsection unset -@@ -5410,6 +5482,18 @@ only on PC BIOS platforms. +@@ -5901,6 +5973,18 @@ only on PC BIOS platforms. @end deffn @end ignore @@ -210,7 +210,7 @@ index afbde7c1f7b..4816be85611 100644 @node verify_detached @subsection verify_detached -@@ -5428,7 +5512,7 @@ tried. +@@ -5919,7 +6003,7 @@ tried. Exit code @code{$?} is set to 0 if the signature validates successfully. If validation fails, it is set to a non-zero value. @@ -219,7 +219,7 @@ index afbde7c1f7b..4816be85611 100644 @end deffn @node videoinfo -@@ -5811,13 +5895,14 @@ environment variables and commands are listed in the same order. +@@ -6397,13 +6481,14 @@ environment variables and commands are listed in the same order. @chapter Security @menu @@ -241,7 +241,7 @@ index afbde7c1f7b..4816be85611 100644 @end menu @node Authentication and authorisation -@@ -5891,8 +5976,8 @@ generating configuration files with authentication. You can use +@@ -6477,8 +6562,8 @@ generating configuration files with authentication. You can use adding @kbd{set superusers=} and @kbd{password} or @kbd{password_pbkdf2} commands. @@ -252,7 +252,7 @@ index afbde7c1f7b..4816be85611 100644 GRUB's @file{core.img} can optionally provide enforcement that all files subsequently read from disk are covered by a valid digital signature. -@@ -5985,6 +6070,86 @@ or BIOS) configuration to cause the machine to boot from a different +@@ -6571,6 +6656,86 @@ or BIOS) configuration to cause the machine to boot from a different (attacker-controlled) device. GRUB is at best only one link in a secure boot chain. diff --git a/0197-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch b/0150-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch similarity index 85% rename from 0197-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch rename to 0150-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch index 40c3b3e8..a8fdba36 100644 --- a/0197-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch +++ b/0150-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch @@ -15,10 +15,10 @@ Signed-off-by: Daniel Axtens 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 6bddc841b85..3f3459b2c70 100644 +index c81c9107249..c748a37b4c5 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -323,6 +323,7 @@ kernel = { +@@ -337,6 +337,7 @@ kernel = { powerpc_ieee1275 = kern/powerpc/cache.S; powerpc_ieee1275 = kern/powerpc/dl.c; powerpc_ieee1275 = kern/powerpc/compiler-rt.S; @@ -27,18 +27,18 @@ index 6bddc841b85..3f3459b2c70 100644 sparc64_ieee1275 = kern/sparc64/cache.S; sparc64_ieee1275 = kern/sparc64/dl.c; diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index 937c1bc44cb..fc7d9712729 100644 +index c4d6962197b..85d50e2965f 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c -@@ -44,6 +44,7 @@ - #ifdef __sparc__ - #include +@@ -49,6 +49,7 @@ + #if defined(__powerpc__) || defined(__i386__) + #include #endif +#include - /* The minimal heap size we can live with. */ - #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) -@@ -271,6 +272,30 @@ grub_parse_cmdline (void) + /* The maximum heap size we're going to claim at boot. Not used by sparc. */ + #ifdef __i386__ +@@ -893,6 +894,30 @@ grub_parse_cmdline (void) } } @@ -69,7 +69,7 @@ index 937c1bc44cb..fc7d9712729 100644 grub_addr_t grub_modbase; void -@@ -296,6 +321,8 @@ grub_machine_init (void) +@@ -918,6 +943,8 @@ grub_machine_init (void) #else grub_install_get_time_ms (grub_rtc_get_time_ms); #endif @@ -93,10 +93,10 @@ index 40531fa823b..ebfee4bf06e 100644 EXPORT_FUNC (grub_lockdown) (void); extern int diff --git a/docs/grub.texi b/docs/grub.texi -index 4816be85611..a4da9c2a1b9 100644 +index eab81718a59..096a3cde075 100644 --- a/docs/grub.texi +++ b/docs/grub.texi -@@ -6227,8 +6227,8 @@ Measured boot is currently only supported on EFI platforms. +@@ -6814,8 +6814,8 @@ platforms. @section Lockdown when booting on a secure setup The GRUB can be locked down when booted on a secure boot environment, for example diff --git a/0151-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch b/0151-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch new file mode 100644 index 00000000..3ca51396 --- /dev/null +++ b/0151-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Wed, 14 Apr 2021 20:10:23 +1000 +Subject: [PATCH] ieee1275: drop HEAP_MAX_ADDR, HEAP_MIN_SIZE + +HEAP_MAX_ADDR is confusing. Currently it is set to 32MB, except +on ieee1275 on x86, where it is 64MB. + +There is a comment which purports to explain it: + +/* If possible, we will avoid claiming heap above this address, because it + seems to cause relocation problems with OSes that link at 4 MiB */ + +This doesn't make a lot of sense when the constants are well above 4MB +already. It was not always this way. Prior to +commit 7b5d0fe4440c ("Increase heap limit") in 2010, HEAP_MAX_SIZE and +HEAP_MAX_ADDR were indeed 4MB. However, when the constants were increased +the comment was left unchanged. + +It's been over a decade. It doesn't seem like we have problems with +claims over 4MB on powerpc or x86 ieee1275. (sparc does things completely +differently and never used the constant.) + +Drop the constant and the check. + +The only use of HEAP_MIN_SIZE was to potentially override the +HEAP_MAX_ADDR check. It is now unused. Remove it. + +Signed-off-by: Daniel Axtens +--- + grub-core/kern/ieee1275/init.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 85d50e2965f..8ce1a0f09ee 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -51,7 +51,7 @@ + #endif + #include + +-/* The maximum heap size we're going to claim at boot. Not used by sparc. */ ++/* The maximum heap size we're going to claim. Not used by sparc. */ + #ifdef __i386__ + #define HEAP_MAX_SIZE (unsigned long) (64 * 1024 * 1024) + #else /* __powerpc__ */ diff --git a/0201-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch b/0152-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch similarity index 100% rename from 0201-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch rename to 0152-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch diff --git a/0152-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch b/0152-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch deleted file mode 100644 index 747773d1..00000000 --- a/0152-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Sat, 16 May 2020 11:33:18 +0200 -Subject: [PATCH] tpm: Don't propagate TPM measurement errors to the verifiers - layer - -Currently if the EFI firmware fails to do a TPM measurement for a file, -the error will be propagated to the verifiers framework and so opening -the file will not succeed. - -This mean that buggy firmwares will prevent the system to boot since the -loader won't be able to open any file. But failing to do TPM measurements -shouldn't be a fatal error and the system should still be able to boot. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/tpm.c | 14 +++++++------- - 1 file changed, 7 insertions(+), 7 deletions(-) - -diff --git a/grub-core/commands/tpm.c b/grub-core/commands/tpm.c -index 2052c36eaba..e287d042e6b 100644 ---- a/grub-core/commands/tpm.c -+++ b/grub-core/commands/tpm.c -@@ -42,7 +42,8 @@ grub_tpm_verify_init (grub_file_t io, - static grub_err_t - grub_tpm_verify_write (void *context, void *buf, grub_size_t size) - { -- return grub_tpm_measure (buf, size, GRUB_BINARY_PCR, context); -+ grub_tpm_measure (buf, size, GRUB_BINARY_PCR, context); -+ return GRUB_ERR_NONE; - } - - static grub_err_t -@@ -50,7 +51,6 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) - { - const char *prefix = NULL; - char *description; -- grub_err_t status; - - switch (type) - { -@@ -66,15 +66,15 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) - } - description = grub_malloc (grub_strlen (str) + grub_strlen (prefix) + 1); - if (!description) -- return grub_errno; -+ return GRUB_ERR_NONE; - grub_memcpy (description, prefix, grub_strlen (prefix)); - grub_memcpy (description + grub_strlen (prefix), str, - grub_strlen (str) + 1); -- status = -- grub_tpm_measure ((unsigned char *) str, grub_strlen (str), -- GRUB_STRING_PCR, description); -+ -+ grub_tpm_measure ((unsigned char *) str, grub_strlen (str), GRUB_STRING_PCR, -+ description); - grub_free (description); -- return status; -+ return GRUB_ERR_NONE; - } - - struct grub_file_verifier grub_tpm_verifier = { diff --git a/0202-ieee1275-ofdisk-retry-on-open-failure.patch b/0153-ieee1275-ofdisk-retry-on-open-failure.patch similarity index 94% rename from 0202-ieee1275-ofdisk-retry-on-open-failure.patch rename to 0153-ieee1275-ofdisk-retry-on-open-failure.patch index 275d14f4..160f0c9f 100644 --- a/0202-ieee1275-ofdisk-retry-on-open-failure.patch +++ b/0153-ieee1275-ofdisk-retry-on-open-failure.patch @@ -16,7 +16,7 @@ Signed-off-by: Diego Domingos 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c -index ea7f78ac7d8..55346849d35 100644 +index 629fc15f284..b413822bb87 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -225,7 +225,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) @@ -50,7 +50,7 @@ index ea7f78ac7d8..55346849d35 100644 if (! last_ihandle) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); last_devpath = op->open_path; -@@ -571,7 +575,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector) +@@ -567,7 +571,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector) last_ihandle = 0; last_devpath = NULL; @@ -58,8 +58,8 @@ index ea7f78ac7d8..55346849d35 100644 + RETRY_IEEE1275_OFDISK_OPEN(disk->data, &last_ihandle); if (! last_ihandle) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); - last_devpath = disk->data; -@@ -598,12 +602,23 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, + last_devpath = disk->data; +@@ -594,12 +598,23 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, return err; grub_ieee1275_read (last_ihandle, buf, size << disk->log_sector_size, &actual); diff --git a/0207-efinet-Add-DHCP-proxy-support.patch b/0154-efinet-Add-DHCP-proxy-support.patch similarity index 76% rename from 0207-efinet-Add-DHCP-proxy-support.patch rename to 0154-efinet-Add-DHCP-proxy-support.patch index a8755a39..6d1b6da5 100644 --- a/0207-efinet-Add-DHCP-proxy-support.patch +++ b/0154-efinet-Add-DHCP-proxy-support.patch @@ -6,15 +6,18 @@ Subject: [PATCH] efinet: Add DHCP proxy support If a proxyDHCP configuration is used, the server name, server IP and boot file values should be taken from the DHCP proxy offer instead of the DHCP server ack packet. Currently that case is not handled, add support for it. + +Signed-off-by: Ian Page Hands +Signed-off-by: Robbie Harwood --- - grub-core/net/drivers/efi/efinet.c | 25 +++++++++++++++++++++++-- - 1 file changed, 23 insertions(+), 2 deletions(-) + grub-core/net/drivers/efi/efinet.c | 22 +++++++++++++++++++++- + 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index e11d759f19a..1a24f38a21a 100644 +index 225dc896da0..83005ea9f88 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c -@@ -850,10 +850,31 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, +@@ -871,12 +871,32 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, else { grub_dprintf ("efinet", "using ipv4 and dhcp\n"); @@ -39,12 +42,12 @@ index e11d759f19a..1a24f38a21a 100644 + } + } + - grub_net_configure_by_dhcp_ack (card->name, card, 0, - (struct grub_net_bootp_packet *) -- packet_buf, -- packet_bufsz, -+ &pxe_mode->dhcp_ack, -+ sizeof (pxe_mode->dhcp_ack), - 1, device, path); + inter = grub_net_configure_by_dhcp_ack (card->name, card, 0, + (struct grub_net_bootp_packet *) + packet_buf, + packet_bufsz, + 1, device, path); +- grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); - } + if (inter != NULL) + { diff --git a/0209-Don-t-update-the-cmdline-when-generating-legacy-menu.patch b/0155-Don-t-update-the-cmdline-when-generating-legacy-menu.patch similarity index 92% rename from 0209-Don-t-update-the-cmdline-when-generating-legacy-menu.patch rename to 0155-Don-t-update-the-cmdline-when-generating-legacy-menu.patch index c55b7e3c..47eca898 100644 --- a/0209-Don-t-update-the-cmdline-when-generating-legacy-menu.patch +++ b/0155-Don-t-update-the-cmdline-when-generating-legacy-menu.patch @@ -20,10 +20,10 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 68adb55d893..c9296154f51 100644 +index b8bc37e92aa..360ce26e5f9 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in -@@ -261,7 +261,9 @@ if [ -z "\${kernelopts}" ]; then +@@ -258,7 +258,9 @@ if [ -z "\${kernelopts}" ]; then fi EOF diff --git a/0210-Suppress-gettext-error-message.patch b/0156-Suppress-gettext-error-message.patch similarity index 96% rename from 0210-Suppress-gettext-error-message.patch rename to 0156-Suppress-gettext-error-message.patch index c57e7ff4..e2484951 100644 --- a/0210-Suppress-gettext-error-message.patch +++ b/0156-Suppress-gettext-error-message.patch @@ -14,7 +14,7 @@ Signed-off-by: Paulo Flabiano Smorigo 1 file changed, 7 insertions(+) diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c -index 84d520cd494..87a912ac6e5 100644 +index 7a1c14e4f33..631af7a946b 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -424,6 +424,13 @@ grub_gettext_init_ext (struct grub_gettext_context *ctx, diff --git a/0212-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch b/0157-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch similarity index 100% rename from 0212-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch rename to 0157-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch diff --git a/0158-normal-main-Discover-the-device-to-read-the-config-f.patch b/0158-normal-main-Discover-the-device-to-read-the-config-f.patch new file mode 100644 index 00000000..d6420264 --- /dev/null +++ b/0158-normal-main-Discover-the-device-to-read-the-config-f.patch @@ -0,0 +1,123 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 30 Aug 2021 12:31:18 +0200 +Subject: [PATCH] normal/main: Discover the device to read the config from as a + fallback + +The GRUB core.img is generated locally, when this is done the grub2-probe +tool figures out the device and partition that needs to be read to parse +the GRUB configuration file. + +But in some cases the core.img can't be generated on the host and instead +has to be done at package build time. For example, if needs to get signed +with a key that's only available on the package building infrastructure. + +If that's the case, the prefix variable won't have a device and partition +but only a directory path. So there's no way for GRUB to know from which +device has to read the configuration file. + +To allow GRUB to continue working on that scenario, fallback to iterating +over all the available devices, if reading the config failed when using +the prefix and fw_path variables. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/normal/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++------ + 1 file changed, 51 insertions(+), 7 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 0ea27d3c534..fc3ed551cec 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -337,18 +337,13 @@ grub_enter_normal_mode (const char *config) + } + + static grub_err_t +-grub_try_normal (const char *variable) ++grub_try_normal_prefix (const char *prefix) + { + char *config; +- const char *prefix; + grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; + const char *net_search_cfg; + int disable_net_search = 0; + +- prefix = grub_env_get (variable); +- if (!prefix) +- return GRUB_ERR_FILE_NOT_FOUND; +- + net_search_cfg = grub_env_get ("feature_net_search_cfg"); + if (net_search_cfg && net_search_cfg[0] == 'n') + disable_net_search = 1; +@@ -362,7 +357,7 @@ grub_try_normal (const char *variable) + config = grub_malloc (config_len); + + if (! config) +- return GRUB_ERR_FILE_NOT_FOUND; ++ return err; + + grub_snprintf (config, config_len, "%s/grub.cfg", prefix); + err = grub_net_search_config_file (config); +@@ -391,6 +386,53 @@ grub_try_normal (const char *variable) + return err; + } + ++static int ++grub_try_normal_dev (const char *name, void *data) ++{ ++ grub_err_t err; ++ const char *prefix = grub_xasprintf ("(%s)%s", name, (char *)data); ++ ++ if (!prefix) ++ return 0; ++ ++ err = grub_try_normal_prefix (prefix); ++ if (err == GRUB_ERR_NONE) ++ return 1; ++ ++ return 0; ++} ++ ++static grub_err_t ++grub_try_normal_discover (void) ++{ ++ char *prefix = grub_env_get ("prefix"); ++ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; ++ ++ if (!prefix) ++ return err; ++ ++ if (grub_device_iterate (grub_try_normal_dev, (void *)prefix)) ++ return GRUB_ERR_NONE; ++ ++ return err; ++} ++ ++static grub_err_t ++grub_try_normal (const char *variable) ++{ ++ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; ++ const char *prefix; ++ ++ if (!variable) ++ return err; ++ ++ prefix = grub_env_get (variable); ++ if (!prefix) ++ return err; ++ ++ return grub_try_normal_prefix (prefix); ++} ++ + /* Enter normal mode from rescue mode. */ + static grub_err_t + grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), +@@ -405,6 +447,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + err = grub_try_normal ("fw_path"); + if (err == GRUB_ERR_FILE_NOT_FOUND) + err = grub_try_normal ("prefix"); ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ err = grub_try_normal_discover (); + if (err == GRUB_ERR_FILE_NOT_FOUND) + grub_enter_normal_mode (0); + } diff --git a/0159-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch b/0159-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch new file mode 100644 index 00000000..61bb0b5c --- /dev/null +++ b/0159-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch @@ -0,0 +1,86 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Mon, 19 Jul 2021 14:35:55 +1000 +Subject: [PATCH] powerpc: adjust setting of prefix for signed binary case + +On RHEL-signed powerpc grub, we sign a grub with -p /grub2 and expect +that there's a boot partition. + +Unfortunately grub_set_prefix_and_root tries to convert this to +($fwdevice)/grub2. This ends up being (ieee1275/disk)/grub2 and that +falls apart pretty quickly - there's no file-system on ieee1275/disk, +and it makes the search routine try things like +(ieee1275/disk,msdos2)(ieee1275/disk)/grub2 which also doesn't work. + +Detect if we would be about to create (ieee1275/disk)/path and don't: +preserve a prefix of /path instead and hope the search later finds us. + +Related: rhbz#1899864 + +Signed-off-by: Daniel Axtens +[rharwood@redhat.com: squash in fixup commit] +Signed-off-by: Robbie Harwood +--- + grub-core/kern/main.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- + 1 file changed, 43 insertions(+), 4 deletions(-) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index 353a62ef1e1..dbd4f596fbe 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -217,12 +217,51 @@ grub_set_prefix_and_root (void) + { + char *prefix_set; + +- prefix_set = grub_xasprintf ("(%s)%s", device, path ? : ""); +- if (prefix_set) ++#ifdef __powerpc__ ++ /* We have to be careful here on powerpc-ieee1275 + signed grub. We ++ will have signed something with a prefix that doesn't have a device ++ because we cannot know in advance what partition we're on. ++ ++ We will have had !device earlier, so we will have set device=fwdevice ++ However, we want to make sure we do not end up setting prefix to be ++ ($fwdevice)/path, because we will then end up trying to boot or search ++ based on a prefix of (ieee1275/disk)/path, which will not work because ++ it's missing a partition. ++ ++ Also: ++ - You can end up with a device with an FS directly on it, without ++ a partition, e.g. ieee1275/cdrom. ++ ++ - powerpc-ieee1275 + grub-install sets e.g. prefix=(,gpt2)/path, ++ which will have now been extended to device=$fwdisk,partition ++ and path=/path ++ ++ - PowerVM will give us device names like ++ ieee1275//vdevice/v-scsi@3000006c/disk@8100000000000000 ++ and we don't want to try to encode some sort of truth table about ++ what sorts of paths represent disks with partition tables and those ++ without partition tables. ++ ++ So we act unless there is a comma in the device, which would indicate ++ a partition has already been specified. ++ ++ (If we only have a path, the code in normal to discover config files ++ will try both without partitions and then with any partitions so we ++ will cover both CDs and HDs.) ++ */ ++ if (grub_strchr (device, ',') == NULL) ++ grub_env_set ("prefix", path); ++ else ++#endif + { +- grub_env_set ("prefix", prefix_set); +- grub_free (prefix_set); ++ prefix_set = grub_xasprintf ("(%s)%s", device, path ? : ""); ++ if (prefix_set) ++ { ++ grub_env_set ("prefix", prefix_set); ++ grub_free (prefix_set); ++ } + } ++ + grub_env_set ("root", device); + } + diff --git a/0160-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch b/0160-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch new file mode 100644 index 00000000..a6b31cc6 --- /dev/null +++ b/0160-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 22 Oct 2021 09:53:15 +1100 +Subject: [PATCH] powerpc-ieee1275: load grub at 4MB, not 2MB + +This was first reported under PFW but reproduces under SLOF. + + - The core.elf was 2126152 = 0x207148 bytes in size with the following + program headers (per readelf): + +Entry point 0x200000 +There are 4 program headers, starting at offset 52 + +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + LOAD 0x000160 0x00200000 0x00200000 0x21f98 0x2971c RWE 0x8 + GNU_STACK 0x0220f8 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4 + LOAD 0x0220f8 0x00232000 0x00232000 0x1e4e50 0x1e4e50 RWE 0x4 + NOTE 0x206f48 0x00000000 0x00000000 0x00200 0x00000 R 0x4 + + - SLOF places the ELF file at 0x4000 (after the reserved space for + interrupt handlers etc.) upwards. The image was 2126152 = 0x207148 + bytes in size, so it runs from 0x4000 - 0x20b148. We'll call 0x4000 the + load address. + +0x0 0x4000 0x20b148 + |----------|--------------| + | reserved | ELF contents | + + - SLOF then copies the first LOAD program header (for .text). That runs + for 0x21f98 bytes. It runs from + (load addr + 0x160) to (load addr + 0x160 + 0x21f98) + = 0x4160 to 0x260f8 + and we copy it to 0x200000 to 0x221f98. This overwrites the end of the + image: + +0x0 0x4000 0x200000 0x221f98 + |----------|------------|---------------| + | reserved | ELF cont.. | .text section | + + - SLOF zeros the bss up to PhysAddr + MemSize = 0x22971c + +0x0 0x4000 0x200000 0x221f98 0x22971c + |----------|------------|---------------|--------| + | reserved | ELF cont.. | .text section | bss 0s | + + - SLOF then goes to fulfil the next LOAD header (for mods), which is + for 0x1e4e50 bytes. We copy from + (load addr + 0x220f8) to (load addr + 0x220f8 + 0x1e4e50) + = 0x260f8 to 0x20af48 + and we copy it to 0x232000 to 0x416e50: + +0x0 0x4000 0x200000 0x221f98 0x22971c + |----------|------------|---------------|--------| + | reserved | ELF cont.. | .text section | bss 0s | + |-------------| + | copied area | + 0x260f8 0x20af48 + + This goes poorly: + +0x0 0x4000 0x200000 0x221f98 0x22971c 0x232000 0x40bf08 0x416e50 + |----------|------------|---------------|--------|-----|-----------|-------------| + | reserved | ELF cont.. | .text section | bss 0s | pad | some mods | .text start | + +This matches the observations on the running system - 0x40bf08 was where +the contents of memory no longer matched the contents of the ELF file. + +This was reported as a license verification failure on SLOF as the +last module's .module_license section fell past where the corruption +began. + +Signed-off-by: Daniel Axtens +[rharwood@redhat.com: trim very detailed commit message] +Signed-off-by: Robbie Harwood +--- + grub-core/Makefile.core.def | 2 +- + include/grub/offsets.h | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index c748a37b4c5..ceb15879272 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -99,7 +99,7 @@ kernel = { + i386_xen_pvh_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x100000'; + + mips_loongson_ldflags = '-Wl,-Ttext,0x80200000'; +- powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; ++ powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x400000'; + sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400'; + mips_arc_ldflags = '-Wl,-Ttext,$(TARGET_LINK_ADDR)'; + mips_qemu_mips_ldflags = '-Wl,-Ttext,0x80200000'; +diff --git a/include/grub/offsets.h b/include/grub/offsets.h +index 871e1cd4c38..69211aa798b 100644 +--- a/include/grub/offsets.h ++++ b/include/grub/offsets.h +@@ -63,7 +63,7 @@ + #define GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR 0x4400 + + #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4 +-#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000 ++#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x400000 + + #define GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR 0x80200000 + diff --git a/0161-Add-Fedora-location-of-DejaVu-SANS-font.patch b/0161-Add-Fedora-location-of-DejaVu-SANS-font.patch new file mode 100644 index 00000000..63bbc18a --- /dev/null +++ b/0161-Add-Fedora-location-of-DejaVu-SANS-font.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: fluteze +Date: Sat, 27 Nov 2021 10:54:44 -0600 +Subject: [PATCH] Add Fedora location of DejaVu SANS font + +In Fedora 35, and possibly earlier, grub would fail to configure with a +complaint about DejaVu being "not found" even though it was installed. +The DejaVu sans font search path is updated to reflect the +distribution's current install path. + +Signed-off-by: Erik Edwards +[rharwood@redhat.com: slight commit message edits] +Signed-off-by: Robbie Harwood +--- + configure.ac | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 016cd3d4e0e..d223fe3ef6e 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1924,7 +1924,7 @@ if test "x$with_dejavufont" = x; then + # search in well-known directories + if test x"$starfield_excuse" = x; then + for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do +- for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF /usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF; do ++ for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF /usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF /usr/share/fonts/dejavu-sans-fonts; do + if test -f "$dir/DejaVuSans.$ext"; then + DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext" + break 2 diff --git a/0162-efi-new-connectefi-command.patch b/0162-efi-new-connectefi-command.patch new file mode 100644 index 00000000..f36d9ca0 --- /dev/null +++ b/0162-efi-new-connectefi-command.patch @@ -0,0 +1,395 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Tue, 15 Feb 2022 14:05:22 +0100 +Subject: [PATCH] efi: new 'connectefi' command +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +When efi.quickboot is enabled on VMWare (which is the default for +hardware release 16 and later), it may happen that not all EFI devices +are connected. Due to this, browsing the devices in make_devices() just +fails to find devices, in particular disks or partitions for a given +disk. +This typically happens when network booting, then trying to chainload to +local disk (this is used in deployment tools such as Red Hat Satellite), +which is done through using the following grub.cfg snippet: +-------- 8< ---------------- 8< ---------------- 8< -------- +unset prefix +search --file --set=prefix /EFI/redhat/grubx64.efi +if [ -n "$prefix" ]; then + chainloader ($prefix)/EFI/redhat/grubx64/efi +... +-------- 8< ---------------- 8< ---------------- 8< -------- + +With efi.quickboot, none of the devices are connected, causing "search" +to fail. Sometimes devices are connected but not the partition of the +disk matching $prefix, causing partition to not be found by +"chainloader". + +This patch introduces a new "connectefi pciroot|scsi" command which +recursively connects all EFI devices starting from a given controller +type: +- if 'pciroot' is specified, recursion is performed for all PCI root + handles +- if 'scsi' is specified, recursion is performed for all SCSI I/O + handles (recommended usage to avoid connecting unwanted handles which + may impact Grub performances) + +Typical grub.cfg snippet would then be: +-------- 8< ---------------- 8< ---------------- 8< -------- +connectefi scsi +unset prefix +search --file --set=prefix /EFI/redhat/grubx64.efi +if [ -n "$prefix" ]; then + chainloader ($prefix)/EFI/redhat/grubx64/efi +... +-------- 8< ---------------- 8< ---------------- 8< -------- + +The code is easily extensible to handle other arguments in the future if +needed. + +Signed-off-by: Renaud Métrich +Signed-off-by: Robbie Harwood +--- + grub-core/Makefile.core.def | 6 ++ + grub-core/commands/efi/connectefi.c | 205 ++++++++++++++++++++++++++++++++++++ + grub-core/commands/efi/lsefi.c | 1 + + grub-core/disk/efi/efidisk.c | 13 +++ + grub-core/kern/efi/efi.c | 13 +++ + include/grub/efi/disk.h | 2 + + include/grub/efi/efi.h | 5 + + NEWS | 2 +- + 8 files changed, 246 insertions(+), 1 deletion(-) + create mode 100644 grub-core/commands/efi/connectefi.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index ceb15879272..c9dcfa00e85 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -861,6 +861,12 @@ module = { + enable = efi; + }; + ++module = { ++ name = connectefi; ++ common = commands/efi/connectefi.c; ++ enable = efi; ++}; ++ + module = { + name = blocklist; + common = commands/blocklist.c; +diff --git a/grub-core/commands/efi/connectefi.c b/grub-core/commands/efi/connectefi.c +new file mode 100644 +index 00000000000..0f840ea0575 +--- /dev/null ++++ b/grub-core/commands/efi/connectefi.c +@@ -0,0 +1,205 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2022 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++typedef struct handle_list ++{ ++ grub_efi_handle_t handle; ++ struct handle_list *next; ++} handle_list_t; ++ ++static handle_list_t *already_handled = NULL; ++ ++static grub_err_t ++add_handle (grub_efi_handle_t handle) ++{ ++ handle_list_t *e; ++ e = grub_malloc (sizeof (*e)); ++ if (! e) ++ return grub_errno; ++ e->handle = handle; ++ e->next = already_handled; ++ already_handled = e; ++ return GRUB_ERR_NONE; ++} ++ ++static int ++is_in_list (grub_efi_handle_t handle) ++{ ++ handle_list_t *e; ++ for (e = already_handled; e != NULL; e = e->next) ++ if (e->handle == handle) ++ return 1; ++ return 0; ++} ++ ++static void ++free_handle_list (void) ++{ ++ handle_list_t *e; ++ while ((e = already_handled) != NULL) ++ { ++ already_handled = already_handled->next; ++ grub_free (e); ++ } ++} ++ ++typedef enum searched_item_flag ++{ ++ SEARCHED_ITEM_FLAG_LOOP = 1, ++ SEARCHED_ITEM_FLAG_RECURSIVE = 2 ++} searched_item_flags; ++ ++typedef struct searched_item ++{ ++ grub_guid_t guid; ++ const char *name; ++ searched_item_flags flags; ++} searched_items; ++ ++static grub_err_t ++grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)), ++ int argc, char **args) ++{ ++ unsigned s; ++ searched_items pciroot_items[] = ++ { ++ { GRUB_EFI_PCI_ROOT_IO_GUID, "PCI root", SEARCHED_ITEM_FLAG_RECURSIVE } ++ }; ++ searched_items scsi_items[] = ++ { ++ { GRUB_EFI_PCI_ROOT_IO_GUID, "PCI root", 0 }, ++ { GRUB_EFI_PCI_IO_GUID, "PCI", SEARCHED_ITEM_FLAG_LOOP }, ++ { GRUB_EFI_SCSI_IO_PROTOCOL_GUID, "SCSI I/O", SEARCHED_ITEM_FLAG_RECURSIVE } ++ }; ++ searched_items *items = NULL; ++ unsigned nitems = 0; ++ grub_err_t grub_err = GRUB_ERR_NONE; ++ unsigned total_connected = 0; ++ ++ if (argc != 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); ++ ++ if (grub_strcmp(args[0], N_("pciroot")) == 0) ++ { ++ items = pciroot_items; ++ nitems = ARRAY_SIZE (pciroot_items); ++ } ++ else if (grub_strcmp(args[0], N_("scsi")) == 0) ++ { ++ items = scsi_items; ++ nitems = ARRAY_SIZE (scsi_items); ++ } ++ else ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("unexpected argument `%s'"), args[0]); ++ ++ for (s = 0; s < nitems; s++) ++ { ++ grub_efi_handle_t *handles; ++ grub_efi_uintn_t num_handles; ++ unsigned i, connected = 0, loop = 0; ++ ++loop: ++ loop++; ++ grub_dprintf ("efi", "step '%s' loop %d:\n", items[s].name, loop); ++ ++ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, ++ &items[s].guid, 0, &num_handles); ++ ++ if (!handles) ++ continue; ++ ++ for (i = 0; i < num_handles; i++) ++ { ++ grub_efi_handle_t handle = handles[i]; ++ grub_efi_status_t status; ++ unsigned j; ++ ++ /* Skip already handled handles */ ++ if (is_in_list (handle)) ++ { ++ grub_dprintf ("efi", " handle %p: already processed\n", ++ handle); ++ continue; ++ } ++ ++ status = grub_efi_connect_controller(handle, NULL, NULL, ++ items[s].flags & SEARCHED_ITEM_FLAG_RECURSIVE ? 1 : 0); ++ if (status == GRUB_EFI_SUCCESS) ++ { ++ connected++; ++ total_connected++; ++ grub_dprintf ("efi", " handle %p: connected\n", handle); ++ } ++ else ++ grub_dprintf ("efi", " handle %p: failed to connect (%d)\n", ++ handle, (grub_efi_int8_t) status); ++ ++ if ((grub_err = add_handle (handle)) != GRUB_ERR_NONE) ++ break; /* fatal */ ++ } ++ ++ grub_free (handles); ++ if (grub_err != GRUB_ERR_NONE) ++ break; /* fatal */ ++ ++ if (items[s].flags & SEARCHED_ITEM_FLAG_LOOP && connected) ++ { ++ connected = 0; ++ goto loop; ++ } ++ ++ free_handle_list (); ++ } ++ ++ free_handle_list (); ++ ++ if (total_connected) ++ grub_efidisk_reenumerate_disks (); ++ ++ return grub_err; ++} ++ ++static grub_command_t cmd; ++ ++GRUB_MOD_INIT(connectefi) ++{ ++ cmd = grub_register_command ("connectefi", grub_cmd_connectefi, ++ N_("pciroot|scsi"), ++ N_("Connect EFI handles." ++ " If 'pciroot' is specified, connect PCI" ++ " root EFI handles recursively." ++ " If 'scsi' is specified, connect SCSI" ++ " I/O EFI handles recursively.")); ++} ++ ++GRUB_MOD_FINI(connectefi) ++{ ++ grub_unregister_command (cmd); ++} +diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c +index 7b8316d4184..3635cd99b75 100644 +--- a/grub-core/commands/efi/lsefi.c ++++ b/grub-core/commands/efi/lsefi.c +@@ -19,6 +19,7 @@ + #include + #include + #include ++#include + #include + #include + #include +diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c +index 822005456eb..af69cc3bc8a 100644 +--- a/grub-core/disk/efi/efidisk.c ++++ b/grub-core/disk/efi/efidisk.c +@@ -396,6 +396,19 @@ enumerate_disks (void) + free_devices (devices); + } + ++void ++grub_efidisk_reenumerate_disks (void) ++{ ++ free_devices (fd_devices); ++ free_devices (hd_devices); ++ free_devices (cd_devices); ++ fd_devices = 0; ++ hd_devices = 0; ++ cd_devices = 0; ++ ++ enumerate_disks (); ++} ++ + static int + grub_efidisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, + grub_disk_pull_t pull) +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index ef837387368..412a2073f41 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -96,6 +96,19 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type, + return buffer; + } + ++grub_efi_status_t ++grub_efi_connect_controller (grub_efi_handle_t controller_handle, ++ grub_efi_handle_t *driver_image_handle, ++ grub_efi_device_path_protocol_t *remaining_device_path, ++ grub_efi_boolean_t recursive) ++{ ++ grub_efi_boot_services_t *b; ++ ++ b = grub_efi_system_table->boot_services; ++ return b->connect_controller(controller_handle, ++ driver_image_handle, remaining_device_path, recursive); ++} ++ + void * + grub_efi_open_protocol (grub_efi_handle_t handle, + grub_guid_t *protocol, +diff --git a/include/grub/efi/disk.h b/include/grub/efi/disk.h +index 254475c8428..6845c2f1fd8 100644 +--- a/include/grub/efi/disk.h ++++ b/include/grub/efi/disk.h +@@ -27,6 +27,8 @@ grub_efi_handle_t + EXPORT_FUNC(grub_efidisk_get_device_handle) (grub_disk_t disk); + char *EXPORT_FUNC(grub_efidisk_get_device_name) (grub_efi_handle_t *handle); + ++void EXPORT_FUNC(grub_efidisk_reenumerate_disks) (void); ++ + void grub_efidisk_init (void); + void grub_efidisk_fini (void); + +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 6c2c1f36e37..736d6f25694 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -53,6 +53,11 @@ EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type, + grub_guid_t *protocol, + void *search_key, + grub_efi_uintn_t *num_handles); ++grub_efi_status_t ++EXPORT_FUNC(grub_efi_connect_controller) (grub_efi_handle_t controller_handle, ++ grub_efi_handle_t *driver_image_handle, ++ grub_efi_device_path_protocol_t *remaining_device_path, ++ grub_efi_boolean_t recursive); + void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle, + grub_guid_t *protocol, + grub_efi_uint32_t attributes); +diff --git a/NEWS b/NEWS +index 3101309621b..e3cfcd569c2 100644 +--- a/NEWS ++++ b/NEWS +@@ -118,7 +118,7 @@ New in 2.02: + * Prefer pmtimer for TSC calibration. + + * New/improved platform support: +- * New `efifwsetup' and `lsefi' commands on EFI platforms. ++ * New `efifwsetup', `lsefi' and `connectefi` commands on EFI platforms. + * New `cmosdump' and `cmosset' commands on platforms with CMOS support. + * New command `pcidump' for PCI platforms. + * Improve opcode parsing in ACPI halt implementation. diff --git a/0163-powerpc-prefix-detection-support-device-names-with-c.patch b/0163-powerpc-prefix-detection-support-device-names-with-c.patch new file mode 100644 index 00000000..57444137 --- /dev/null +++ b/0163-powerpc-prefix-detection-support-device-names-with-c.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Thu, 24 Mar 2022 14:34:32 +1100 +Subject: [PATCH] powerpc: prefix detection: support device names with commas + +Frustratingly, the device name itself can contain an embedded comma: +e.g /pci@800000020000015/pci1014,034A@0/sas/disk@5000c50098a0ee8b + +So my previous approach was wrong: we cannot rely upon the presence +of a comma to say that a partition has been specified! + +It turns out for prefixes like (,gpt2)/grub2 we really want to make +up a full (device,partition)/patch prefix, because root discovery code +in 10_linux will reset the root variable and use search to fill it again. +If you have run grub-install, you probably don't have search built in, +and if you don't have prefix containing (device,partition), grub will +construct ($root)$prefix/powerpc-ieee1275/search.mod - but because $root +has just been changed, this will no longer work, and the boot will fail! + +Retain the gist of the logic, but instead of looking for a comma, look for +a leading '('. This matches the earlier code better anyway. + +There's certainly a better fix to be had. But any time you chose to build +with a bare prefix like '/grub2', you're almost certainly going to build in +search anyway, so this will do. + +Signed-off-by: Daniel Axtens +--- + grub-core/kern/main.c | 27 +++++++++++++++++++++------ + 1 file changed, 21 insertions(+), 6 deletions(-) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index dbd4f596fbe..8e89763f43b 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -242,14 +242,29 @@ grub_set_prefix_and_root (void) + what sorts of paths represent disks with partition tables and those + without partition tables. + +- So we act unless there is a comma in the device, which would indicate +- a partition has already been specified. ++ - Frustratingly, the device name itself can contain an embedded comma: ++ /pci@800000020000015/pci1014,034A@0/sas/disk@5000c50098a0ee8b ++ So we cannot even rely upon the presence of a comma to say that a ++ partition has been specified! + +- (If we only have a path, the code in normal to discover config files +- will try both without partitions and then with any partitions so we +- will cover both CDs and HDs.) ++ If we only have a path in $prefix, the code in normal to discover ++ config files will try all disks, both without partitions and then with ++ any partitions so we will cover both CDs and HDs. ++ ++ However, it doesn't then set the prefix to be something like ++ (discovered partition)/path, and so it is fragile against runtime ++ changes to $root. For example some of the stuff done in 10_linux to ++ reload $root sets root differently and then uses search to find it ++ again. If the search module is not built in, when we change root, grub ++ will look in (new root)/path/powerpc-ieee1275, that won't work, and we ++ will not be able to load the search module and the boot will fail. ++ ++ This is particularly likely to hit us in the grub-install ++ (,msdos2)/grub2 case, so we act unless the supplied prefix starts with ++ '(', which would likely indicate a partition has already been ++ specified. + */ +- if (grub_strchr (device, ',') == NULL) ++ if (prefix && prefix[0] != '(') + grub_env_set ("prefix", path); + else + #endif diff --git a/0164-make-ofdisk_retries-optional.patch b/0164-make-ofdisk_retries-optional.patch new file mode 100644 index 00000000..791c0a6f --- /dev/null +++ b/0164-make-ofdisk_retries-optional.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Diego Domingos +Date: Thu, 24 Mar 2022 13:14:42 -0400 +Subject: [PATCH] make ofdisk_retries optional + +The feature Retry on Fail added to GRUB can cause a LPM to take +longer if the SAN is slow. + +When a LPM to external site occur, the path of the disk can change +and thus the disk search function on grub can take some time since +it is used as a hint. This can cause the Retry on Fail feature to +try to access the disk 20x times (since this is hardcoded number) +and, if the SAN is slow, the boot time can increase a lot. +In some situations not acceptable. + +The following patch enables a configuration at user space of the +maximum number of retries we want for this feature. + +The variable ofdisk_retries should be set using grub2-editenv +and will be checked by retry function. If the variable is not set, +so the default number of retries will be used instead. +--- + include/grub/ieee1275/ofdisk.h | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h +index 7d2d5409305..0074d55eee4 100644 +--- a/include/grub/ieee1275/ofdisk.h ++++ b/include/grub/ieee1275/ofdisk.h +@@ -25,7 +25,12 @@ extern void grub_ofdisk_fini (void); + #define MAX_RETRIES 20 + + +-#define RETRY_IEEE1275_OFDISK_OPEN(device, last_ihandle) unsigned retry_i=0;for(retry_i=0; retry_i < MAX_RETRIES; retry_i++){ \ ++#define RETRY_IEEE1275_OFDISK_OPEN(device, last_ihandle) \ ++ unsigned max_retries = MAX_RETRIES; \ ++ if(grub_env_get("ofdisk_retries") != NULL) \ ++ max_retries = grub_strtoul(grub_env_get("ofdisk_retries"), 0, 10)+1; \ ++ grub_dprintf("ofdisk","MAX_RETRIES set to %u\n",max_retries); \ ++ unsigned retry_i=0;for(retry_i=0; retry_i < max_retries; retry_i++){ \ + if(!grub_ieee1275_open(device, last_ihandle)) \ + break; \ + grub_dprintf("ofdisk","Opening disk %s failed. Retrying...\n",device); } diff --git a/0165-misc-Make-grub_min-and-grub_max-more-resilient.patch b/0165-misc-Make-grub_min-and-grub_max-more-resilient.patch new file mode 100644 index 00000000..a9afc998 --- /dev/null +++ b/0165-misc-Make-grub_min-and-grub_max-more-resilient.patch @@ -0,0 +1,83 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 21 Mar 2022 16:06:10 -0400 +Subject: [PATCH] misc: Make grub_min() and grub_max() more resilient. + +grub_min(a,b) and grub_max(a,b) use a relatively naive implementation +which leads to several problems: +- they evaluate their parameters more than once +- the naive way to address this, to declare temporary variables in a + statement-expression, isn't resilient against nested uses, because + MIN(a,MIN(b,c)) results in the temporary variables being declared in + two nested scopes, which may result in a build warning depending on + your build options. + +This patch changes our implementation to use a statement-expression +inside a helper macro, and creates the symbols for the temporary +variables with __COUNTER__ (A GNU C cpp extension) and token pasting to +create uniquely named internal variables. + +Signed-off-by: Peter Jones +--- + grub-core/loader/multiboot_elfxx.c | 4 +--- + include/grub/misc.h | 25 +++++++++++++++++++++++-- + 2 files changed, 24 insertions(+), 5 deletions(-) + +diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c +index 1edad05948c..8d370b0b3f5 100644 +--- a/grub-core/loader/multiboot_elfxx.c ++++ b/grub-core/loader/multiboot_elfxx.c +@@ -45,9 +45,7 @@ + #endif + + #include +- +-#define CONCAT(a,b) CONCAT_(a, b) +-#define CONCAT_(a,b) a ## b ++#include + + #pragma GCC diagnostic ignored "-Wcast-align" + +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 3f5f5b61695..252bdb161eb 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -35,6 +35,14 @@ + #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) + #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } + ++#ifndef CONCAT_ ++#define CONCAT_(a, b) a ## b ++#endif ++ ++#ifndef CONCAT ++#define CONCAT(a, b) CONCAT_(a, b) ++#endif ++ + #define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__) + + void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n); +@@ -525,8 +533,21 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file, + #define grub_boot_time(...) + #endif + +-#define grub_max(a, b) (((a) > (b)) ? (a) : (b)) +-#define grub_min(a, b) (((a) < (b)) ? (a) : (b)) ++#define _grub_min(a, b, _a, _b) \ ++ ({ typeof (a) _a = (a); \ ++ typeof (b) _b = (b); \ ++ _a < _b ? _a : _b; }) ++#define grub_min(a, b) _grub_min(a, b, \ ++ CONCAT(_a_,__COUNTER__), \ ++ CONCAT(_b_,__COUNTER__)) ++ ++#define _grub_max(a, b, _a, _b) \ ++ ({ typeof (a) _a = (a); \ ++ typeof (b) _b = (b); \ ++ _a > _b ? _a : _b; }) ++#define grub_max(a, b) _grub_max(a, b, \ ++ CONCAT(_a_,__COUNTER__), \ ++ CONCAT(_b_,__COUNTER__)) + + #define grub_log2ull(n) (GRUB_TYPE_BITS (grub_uint64_t) - __builtin_clzll (n) - 1) + diff --git a/0166-ReiserFS-switch-to-using-grub_min-grub_max.patch b/0166-ReiserFS-switch-to-using-grub_min-grub_max.patch new file mode 100644 index 00000000..76d44ac3 --- /dev/null +++ b/0166-ReiserFS-switch-to-using-grub_min-grub_max.patch @@ -0,0 +1,92 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Apr 2022 16:31:17 -0400 +Subject: [PATCH] ReiserFS: switch to using grub_min()/grub_max() + +This is a minor cleanup patch to remove the bespoke MIN() and MAX() +definitions from the reiserfs driver, and uses grub_min() / grub_max() +instead. + +Signed-off-by: Peter Jones +--- + grub-core/fs/reiserfs.c | 28 +++++++++------------------- + 1 file changed, 9 insertions(+), 19 deletions(-) + +diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c +index 36b26ac98a0..42818c37622 100644 +--- a/grub-core/fs/reiserfs.c ++++ b/grub-core/fs/reiserfs.c +@@ -42,16 +42,6 @@ + + GRUB_MOD_LICENSE ("GPLv3+"); + +-#define MIN(a, b) \ +- ({ typeof (a) _a = (a); \ +- typeof (b) _b = (b); \ +- _a < _b ? _a : _b; }) +- +-#define MAX(a, b) \ +- ({ typeof (a) _a = (a); \ +- typeof (b) _b = (b); \ +- _a > _b ? _a : _b; }) +- + #define REISERFS_SUPER_BLOCK_OFFSET 0x10000 + #define REISERFS_MAGIC_LEN 12 + #define REISERFS_MAGIC_STRING "ReIsEr" +@@ -1076,7 +1066,7 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node, + grub_reiserfs_set_key_type (&key, GRUB_REISERFS_ANY, 2); + initial_position = off; + current_position = 0; +- final_position = MIN (len + initial_position, node->size); ++ final_position = grub_min (len + initial_position, node->size); + grub_dprintf ("reiserfs", + "Reading from %lld to %lld (%lld instead of requested %ld)\n", + (unsigned long long) initial_position, +@@ -1115,8 +1105,8 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node, + grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block); + if (initial_position < current_position + item_size) + { +- offset = MAX ((signed) (initial_position - current_position), 0); +- length = (MIN (item_size, final_position - current_position) ++ offset = grub_max ((signed) (initial_position - current_position), 0); ++ length = (grub_min (item_size, final_position - current_position) + - offset); + grub_dprintf ("reiserfs", + "Reading direct block %u from %u to %u...\n", +@@ -1161,9 +1151,9 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node, + grub_dprintf ("reiserfs_blocktype", "I: %u\n", (unsigned) block); + if (current_position + block_size >= initial_position) + { +- offset = MAX ((signed) (initial_position - current_position), +- 0); +- length = (MIN (block_size, final_position - current_position) ++ offset = grub_max ((signed) (initial_position - current_position), ++ 0); ++ length = (grub_min (block_size, final_position - current_position) + - offset); + grub_dprintf ("reiserfs", + "Reading indirect block %u from %u to %u...\n", +@@ -1205,7 +1195,7 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node, + switch (found.type) + { + case GRUB_REISERFS_DIRECT: +- read_length = MIN (len, item_size - file->offset); ++ read_length = grub_min (len, item_size - file->offset); + grub_disk_read (found.data->disk, + (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE, + grub_le_to_cpu16 (found.header.item_location) + file->offset, +@@ -1224,12 +1214,12 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node, + item_size, (char *) indirect_block_ptr); + if (grub_errno) + goto fail; +- len = MIN (len, file->size - file->offset); ++ len = grub_min (len, file->size - file->offset); + for (indirect_block = file->offset / block_size; + indirect_block < indirect_block_count && read_length < len; + indirect_block++) + { +- read = MIN (block_size, len - read_length); ++ read = grub_min (block_size, len - read_length); + grub_disk_read (found.data->disk, + (grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) * block_size) / GRUB_DISK_SECTOR_SIZE, + file->offset % block_size, read, diff --git a/0167-misc-make-grub_boot_time-also-call-grub_dprintf-boot.patch b/0167-misc-make-grub_boot_time-also-call-grub_dprintf-boot.patch new file mode 100644 index 00000000..9293ba93 --- /dev/null +++ b/0167-misc-make-grub_boot_time-also-call-grub_dprintf-boot.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 24 Mar 2022 14:40:01 -0400 +Subject: [PATCH] misc: make grub_boot_time() also call + grub_dprintf("boot",...) + +Currently grub_boot_time() includes valuable debugging messages, but if +you build without BOOT_TIME_STATS enabled, they are silently and +confusingly compiled away. + +This patch changes grub_boot_time() to also log when "boot" is enabled +in DEBUG, regardless of BOOT_TIME_STATS. + +Signed-off-by: Peter Jones +--- + grub-core/kern/misc.c | 1 + + include/grub/misc.h | 2 +- + 2 files changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index d3a493e3552..f607244e7ae 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -1438,6 +1438,7 @@ grub_real_boot_time (const char *file, + + va_start (args, fmt); + n->msg = grub_xvasprintf (fmt, args); ++ grub_dprintf ("boot", "%s\n", n->msg); + va_end (args); + + *boot_time_last = n; +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 252bdb161eb..c3c735371dc 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -530,7 +530,7 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file, + const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 3, 4))); + #define grub_boot_time(...) grub_real_boot_time(GRUB_FILE, __LINE__, __VA_ARGS__) + #else +-#define grub_boot_time(...) ++#define grub_boot_time(fmt, ...) grub_dprintf("boot", fmt "\n", ##__VA_ARGS__) + #endif + + #define _grub_min(a, b, _a, _b) \ diff --git a/0168-modules-make-.module_license-read-only.patch b/0168-modules-make-.module_license-read-only.patch new file mode 100644 index 00000000..368386d0 --- /dev/null +++ b/0168-modules-make-.module_license-read-only.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 24 Feb 2022 16:32:51 -0500 +Subject: [PATCH] modules: make .module_license read-only + +Currently .module_license is set writable (that is, the section has the +SHF_WRITE flag set) in the module's ELF headers. This probably never +actually matters, but it can't possibly be correct. + +This patch sets that data as "const", which causes that flag not to be +set. + +Signed-off-by: Peter Jones +--- + include/grub/dl.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/grub/dl.h b/include/grub/dl.h +index 3f10e27d62c..216f8b903ac 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -121,7 +121,7 @@ grub_mod_fini (void) + #define ATTRIBUTE_USED __unused__ + #endif + #define GRUB_MOD_LICENSE(license) \ +- static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license; ++ static const char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license; + #define GRUB_MOD_DEP(name) \ + static const char grub_module_depend_##name[] \ + __attribute__((section(GRUB_MOD_SECTION(moddeps)), ATTRIBUTE_USED)) = #name diff --git a/0169-modules-strip-.llvm_addrsig-sections-and-similar.patch b/0169-modules-strip-.llvm_addrsig-sections-and-similar.patch new file mode 100644 index 00000000..c86b9997 --- /dev/null +++ b/0169-modules-strip-.llvm_addrsig-sections-and-similar.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 24 Feb 2022 16:40:11 -0500 +Subject: [PATCH] modules: strip .llvm_addrsig sections and similar. + +Currently grub modules built with clang or gcc have several sections +which we don't actually need or support. + +We already have a list of section to skip in genmod.sh, and this patch +adds the following sections to that list (as well as a few newlines): + +.note.gnu.property +.llvm* + +Note that the glob there won't work without a new enough linker, but the +failure is just reversion to the status quo, so that's not a big problem. + +Signed-off-by: Peter Jones +--- + grub-core/genmod.sh.in | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in +index e57c4d9205c..337753c574c 100644 +--- a/grub-core/genmod.sh.in ++++ b/grub-core/genmod.sh.in +@@ -57,8 +57,11 @@ if test x@TARGET_APPLE_LINKER@ != x1; then + @TARGET_STRIP@ --strip-unneeded \ + -K grub_mod_init -K grub_mod_fini \ + -K _grub_mod_init -K _grub_mod_fini \ +- -R .note.gnu.gold-version -R .note.GNU-stack \ ++ -R .note.GNU-stack \ ++ -R .note.gnu.gold-version \ ++ -R .note.gnu.property \ + -R .gnu.build.attributes \ ++ -R '.llvm*' \ + -R .rel.gnu.build.attributes \ + -R .rela.gnu.build.attributes \ + -R .eh_frame -R .rela.eh_frame -R .rel.eh_frame \ diff --git a/0170-modules-Don-t-allocate-space-for-non-allocable-secti.patch b/0170-modules-Don-t-allocate-space-for-non-allocable-secti.patch new file mode 100644 index 00000000..19c7fdd1 --- /dev/null +++ b/0170-modules-Don-t-allocate-space-for-non-allocable-secti.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 21 Mar 2022 16:56:10 -0400 +Subject: [PATCH] modules: Don't allocate space for non-allocable sections. + +Currently when loading grub modules, we allocate space for all sections, +including those without SHF_ALLOC set. We then copy the sections that +/do/ have SHF_ALLOC set into the allocated memory, leaving some of our +allocation untouched forever. Additionally, on platforms with GOT +fixups and trampolines, we currently compute alignment round-ups for the +sections and sections with sh_size = 0. + +This patch removes the extra space from the allocation computation, and +makes the allocation computation loop skip empty sections as the loading +loop does. + +Signed-off-by: Peter Jones +--- + grub-core/kern/dl.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 931f6e41442..832c6188df4 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -281,6 +281,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + i < e->e_shnum; + i++, s = (const Elf_Shdr *)((const char *) s + e->e_shentsize)) + { ++ if (s->sh_size == 0 || !(s->sh_flags & SHF_ALLOC)) ++ continue; ++ + tsize = ALIGN_UP (tsize, s->sh_addralign) + s->sh_size; + if (talign < s->sh_addralign) + talign = s->sh_addralign; diff --git a/0171-modules-load-module-sections-at-page-aligned-address.patch b/0171-modules-load-module-sections-at-page-aligned-address.patch new file mode 100644 index 00000000..8ace83db --- /dev/null +++ b/0171-modules-load-module-sections-at-page-aligned-address.patch @@ -0,0 +1,378 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 21 Mar 2022 17:45:40 -0400 +Subject: [PATCH] modules: load module sections at page-aligned addresses + +Currently we load module sections at whatever alignment gcc+ld happened +to dump into the ELF section header, which is often pretty useless. For +example, by default time.mod has these sections on a current x86_64 +build: + +$ eu-readelf -a grub-core/time.mod |& grep ^Section -A13 +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al +[ 0] NULL 0 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0 00000040 0000015e 0 AX 0 0 1 +[ 2] .rela.text RELA 0 00000458 000001e0 24 I 8 1 8 +[ 3] .rodata.str1.1 PROGBITS 0 0000019e 000000a1 1 AMS 0 0 1 +[ 4] .module_license PROGBITS 0 00000240 0000000f 0 A 0 0 8 +[ 5] .data PROGBITS 0 0000024f 00000000 0 WA 0 0 1 +[ 6] .bss NOBITS 0 00000250 00000008 0 WA 0 0 8 +[ 7] .modname PROGBITS 0 00000250 00000005 0 0 0 1 +[ 8] .symtab SYMTAB 0 00000258 00000150 24 9 6 8 +[ 9] .strtab STRTAB 0 000003a8 000000ab 0 0 0 1 +[10] .shstrtab STRTAB 0 00000638 00000059 0 0 0 1 + +With NX protections being page based, loading sections with either a 1 +or 8 *byte* alignment does absolutely nothing to help us out. + +This patch switches most EFI platforms to load module sections at 4kB +page-aligned addresses. To do so, it adds an new per-arch function, +grub_arch_dl_min_alignment(), which returns the alignment needed for +dynamically loaded sections (in bytes). Currently it sets it to 4096 +when GRUB_MACHINE_EFI is true on x86_64, i386, arm, arm64, and emu, and +1-byte alignment on everything else. + +It then changes the allocation size computation and the loader code in +grub_dl_load_segments() to align the locations and sizes up to these +boundaries, and fills any added padding with zeros. + +All of this happens before relocations are applied, so the relocations +factor that in with no change. + +As an aside, initially Daniel Kiper and I thought that it might be a +better idea to split the modules up into top-level sections as +.text.modules, .rodata.modules, .data.modules, etc., so that their page +permissions would get set by the loader that's loading grub itself. +This turns out to have two significant downsides: 1) either in mkimage +or in grub_dl_relocate_symbols(), you wind up having to dynamically +process the relocations to accommodate the moved module sections, and 2) +you then need to change the permissions on the modules and change them +back while relocating them in grub_dl_relocate_symbols(), which means +that any loader that /does/ honor the section flags but does /not/ +generally support NX with the memory attributes API will cause grub to +fail. + +Signed-off-by: Peter Jones +--- + grub-core/kern/arm/dl.c | 13 +++++++++++++ + grub-core/kern/arm64/dl.c | 13 +++++++++++++ + grub-core/kern/dl.c | 29 +++++++++++++++++++++-------- + grub-core/kern/emu/full.c | 13 +++++++++++++ + grub-core/kern/i386/dl.c | 13 +++++++++++++ + grub-core/kern/ia64/dl.c | 9 +++++++++ + grub-core/kern/mips/dl.c | 8 ++++++++ + grub-core/kern/powerpc/dl.c | 9 +++++++++ + grub-core/kern/riscv/dl.c | 13 +++++++++++++ + grub-core/kern/sparc64/dl.c | 9 +++++++++ + grub-core/kern/x86_64/dl.c | 13 +++++++++++++ + include/grub/dl.h | 2 ++ + docs/grub-dev.texi | 6 +++--- + 13 files changed, 139 insertions(+), 11 deletions(-) + +diff --git a/grub-core/kern/arm/dl.c b/grub-core/kern/arm/dl.c +index eab9d17ff2d..92607379366 100644 +--- a/grub-core/kern/arm/dl.c ++++ b/grub-core/kern/arm/dl.c +@@ -278,3 +278,16 @@ grub_arch_dl_check_header (void *ehdr) + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ return 4096; ++#else ++ return 1; ++#endif ++} +diff --git a/grub-core/kern/arm64/dl.c b/grub-core/kern/arm64/dl.c +index a2b5789a9dd..95c6d5bf4e5 100644 +--- a/grub-core/kern/arm64/dl.c ++++ b/grub-core/kern/arm64/dl.c +@@ -196,3 +196,16 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ return 4096; ++#else ++ return 1; ++#endif ++} +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 832c6188df4..775b367287e 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -268,7 +268,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + { + unsigned i; + const Elf_Shdr *s; +- grub_size_t tsize = 0, talign = 1; ++ grub_size_t tsize = 0, talign = 1, arch_addralign = 1; + #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ + !defined (__loongarch__) + grub_size_t tramp; +@@ -277,16 +277,24 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + #endif + char *ptr; + ++ arch_addralign = grub_arch_dl_min_alignment (); ++ + for (i = 0, s = (const Elf_Shdr *)((const char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (const Elf_Shdr *)((const char *) s + e->e_shentsize)) + { ++ grub_size_t sh_addralign; ++ grub_size_t sh_size; ++ + if (s->sh_size == 0 || !(s->sh_flags & SHF_ALLOC)) + continue; + +- tsize = ALIGN_UP (tsize, s->sh_addralign) + s->sh_size; +- if (talign < s->sh_addralign) +- talign = s->sh_addralign; ++ sh_addralign = ALIGN_UP(s->sh_addralign, arch_addralign); ++ sh_size = ALIGN_UP(s->sh_size, sh_addralign); ++ ++ tsize = ALIGN_UP (tsize, sh_addralign) + sh_size; ++ if (talign < sh_addralign) ++ talign = sh_addralign; + } + + #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ +@@ -316,6 +324,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + i < e->e_shnum; + i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize)) + { ++ grub_size_t sh_addralign = ALIGN_UP(s->sh_addralign, arch_addralign); ++ grub_size_t sh_size = ALIGN_UP(s->sh_size, sh_addralign); ++ + if (s->sh_flags & SHF_ALLOC) + { + grub_dl_segment_t seg; +@@ -328,17 +339,19 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + { + void *addr; + +- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, s->sh_addralign); ++ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, sh_addralign); + addr = ptr; +- ptr += s->sh_size; ++ ptr += sh_size; + + switch (s->sh_type) + { + case SHT_PROGBITS: + grub_memcpy (addr, (char *) e + s->sh_offset, s->sh_size); ++ grub_memset ((char *)addr + s->sh_size, 0, ++ sh_size - s->sh_size); + break; + case SHT_NOBITS: +- grub_memset (addr, 0, s->sh_size); ++ grub_memset (addr, 0, sh_size); + break; + } + +@@ -347,7 +360,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + else + seg->addr = 0; + +- seg->size = s->sh_size; ++ seg->size = sh_size; + seg->section = i; + seg->next = mod->segment; + mod->segment = seg; +diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c +index e8d63b1f5f9..1de1c28eb09 100644 +--- a/grub-core/kern/emu/full.c ++++ b/grub-core/kern/emu/full.c +@@ -67,3 +67,16 @@ grub_arch_dl_init_linker (void) + } + #endif + ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ return 4096; ++#else ++ return 1; ++#endif ++} +diff --git a/grub-core/kern/i386/dl.c b/grub-core/kern/i386/dl.c +index 1346da5cc91..d6b4681fc93 100644 +--- a/grub-core/kern/i386/dl.c ++++ b/grub-core/kern/i386/dl.c +@@ -79,3 +79,16 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ return 4096; ++#else ++ return 1; ++#endif ++} +diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c +index db59300fea3..92d82c57505 100644 +--- a/grub-core/kern/ia64/dl.c ++++ b/grub-core/kern/ia64/dl.c +@@ -148,3 +148,12 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + } + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++ return 1; ++} +diff --git a/grub-core/kern/mips/dl.c b/grub-core/kern/mips/dl.c +index 5b02f97fca7..db411899dbe 100644 +--- a/grub-core/kern/mips/dl.c ++++ b/grub-core/kern/mips/dl.c +@@ -272,3 +272,11 @@ grub_arch_dl_init_linker (void) + grub_dl_register_symbol ("_gp_disp", &_gp_disp_dummy, 0, 0); + } + ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++ return 1; ++} +diff --git a/grub-core/kern/powerpc/dl.c b/grub-core/kern/powerpc/dl.c +index 7b6418eabd7..0eb8bc5bd31 100644 +--- a/grub-core/kern/powerpc/dl.c ++++ b/grub-core/kern/powerpc/dl.c +@@ -167,3 +167,12 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++ return 1; ++} +diff --git a/grub-core/kern/riscv/dl.c b/grub-core/kern/riscv/dl.c +index 896653bb41c..1fa085b4acf 100644 +--- a/grub-core/kern/riscv/dl.c ++++ b/grub-core/kern/riscv/dl.c +@@ -344,3 +344,16 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ return 4096; ++#else ++ return 1; ++#endif ++} +diff --git a/grub-core/kern/sparc64/dl.c b/grub-core/kern/sparc64/dl.c +index f3d960186ba..f054f08241d 100644 +--- a/grub-core/kern/sparc64/dl.c ++++ b/grub-core/kern/sparc64/dl.c +@@ -189,3 +189,12 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++ return 1; ++} +diff --git a/grub-core/kern/x86_64/dl.c b/grub-core/kern/x86_64/dl.c +index e5a8bdcf4f9..a105dc50cea 100644 +--- a/grub-core/kern/x86_64/dl.c ++++ b/grub-core/kern/x86_64/dl.c +@@ -119,3 +119,16 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + + return GRUB_ERR_NONE; + } ++ ++/* ++ * Tell the loader what our minimum section alignment is. ++ */ ++grub_size_t ++grub_arch_dl_min_alignment (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ return 4096; ++#else ++ return 1; ++#endif ++} +diff --git a/include/grub/dl.h b/include/grub/dl.h +index 216f8b903ac..9f86765c8e9 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -279,6 +279,8 @@ grub_err_t grub_arch_dl_check_header (void *ehdr); + grub_err_t + grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, + Elf_Shdr *s, grub_dl_segment_t seg); ++grub_size_t ++grub_arch_dl_min_alignment (void); + #endif + + #if defined (_mips) +diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi +index 04c6678cb6b..8ad5494f5ce 100644 +--- a/docs/grub-dev.texi ++++ b/docs/grub-dev.texi +@@ -996,9 +996,9 @@ declare startup asm file ($cpu_$platform_startup) as well as any other files + (e.g. init.c and callwrap.S) (e.g. $cpu_$platform = kern/$cpu/$platform/init.c). + At this stage you will also need to add dummy dl.c and cache.S with functions + grub_err_t grub_arch_dl_check_header (void *ehdr), grub_err_t +-grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) (dl.c) and +-void grub_arch_sync_caches (void *address, grub_size_t len) (cache.S). They +-won't be used for now. ++grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) (dl.c), grub_uint32_t ++grub_arch_dl_min_alignment (void), and void grub_arch_sync_caches (void ++*address, grub_size_t len) (cache.S). They won't be used for now. + + You will need to create directory include/$cpu/$platform and a file + include/$cpu/types.h. The latter following this template: diff --git a/0172-nx-add-memory-attribute-get-set-API.patch b/0172-nx-add-memory-attribute-get-set-API.patch new file mode 100644 index 00000000..6a473411 --- /dev/null +++ b/0172-nx-add-memory-attribute-get-set-API.patch @@ -0,0 +1,317 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 22 Mar 2022 10:56:21 -0400 +Subject: [PATCH] nx: add memory attribute get/set API + +For NX, we need to set the page access permission attributes for write +and execute permissions. + +This patch adds two new primitives, grub_set_mem_attrs() and +grub_clear_mem_attrs(), and associated constant definitions, to be used +for that purpose. + +For most platforms, it adds a dummy implementation that returns +GRUB_ERR_NONE. On EFI platforms, it adds a common helper function, +grub_efi_status_to_err(), which translates EFI error codes to grub error +codes, adds headers for the EFI Memory Attribute Protocol (still pending +standardization), and an implementation of the grub nx primitives using +it. + +Signed-off-by: Peter Jones +[rharwood: add pjones's none/nyi fixup] +Signed-off-by: Robbie Harwood +--- + grub-core/kern/efi/efi.c | 36 +++++++++++++ + grub-core/kern/efi/mm.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++ + include/grub/efi/api.h | 25 +++++++++ + include/grub/efi/efi.h | 2 + + include/grub/mm.h | 32 ++++++++++++ + 5 files changed, 226 insertions(+) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 412a2073f41..cdfc11565c7 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -1130,3 +1130,39 @@ grub_efi_find_configuration_table (const grub_guid_t *target_guid) + + return 0; + } ++ ++grub_err_t ++grub_efi_status_to_err (grub_efi_status_t status) ++{ ++ grub_err_t err; ++ switch (status) ++ { ++ case GRUB_EFI_SUCCESS: ++ err = GRUB_ERR_NONE; ++ break; ++ case GRUB_EFI_INVALID_PARAMETER: ++ default: ++ err = GRUB_ERR_BAD_ARGUMENT; ++ break; ++ case GRUB_EFI_OUT_OF_RESOURCES: ++ err = GRUB_ERR_OUT_OF_MEMORY; ++ break; ++ case GRUB_EFI_DEVICE_ERROR: ++ err = GRUB_ERR_IO; ++ break; ++ case GRUB_EFI_WRITE_PROTECTED: ++ err = GRUB_ERR_WRITE_ERROR; ++ break; ++ case GRUB_EFI_SECURITY_VIOLATION: ++ err = GRUB_ERR_ACCESS_DENIED; ++ break; ++ case GRUB_EFI_NOT_FOUND: ++ err = GRUB_ERR_FILE_NOT_FOUND; ++ break; ++ case GRUB_EFI_ABORTED: ++ err = GRUB_ERR_WAIT; ++ break; ++ } ++ ++ return err; ++} +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index 6a6fba89184..df443f434d4 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -687,3 +687,134 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) + return GRUB_ERR_NONE; + } + #endif ++ ++static inline grub_uint64_t ++grub_mem_attrs_to_uefi_mem_attrs (grub_uint64_t attrs) ++{ ++ grub_uint64_t ret = GRUB_EFI_MEMORY_RP | ++ GRUB_EFI_MEMORY_RO | ++ GRUB_EFI_MEMORY_XP; ++ ++ if (attrs & GRUB_MEM_ATTR_R) ++ ret &= ~GRUB_EFI_MEMORY_RP; ++ ++ if (attrs & GRUB_MEM_ATTR_W) ++ ret &= ~GRUB_EFI_MEMORY_RO; ++ ++ if (attrs & GRUB_MEM_ATTR_X) ++ ret &= ~GRUB_EFI_MEMORY_XP; ++ ++ return ret; ++} ++ ++static inline grub_uint64_t ++uefi_mem_attrs_to_grub_mem_attrs (grub_uint64_t attrs) ++{ ++ grub_uint64_t ret = GRUB_MEM_ATTR_R | ++ GRUB_MEM_ATTR_W | ++ GRUB_MEM_ATTR_X; ++ ++ if (attrs & GRUB_EFI_MEMORY_RP) ++ ret &= ~GRUB_MEM_ATTR_R; ++ ++ if (attrs & GRUB_EFI_MEMORY_RO) ++ ret &= ~GRUB_MEM_ATTR_W; ++ ++ if (attrs & GRUB_EFI_MEMORY_XP) ++ ret &= ~GRUB_MEM_ATTR_X; ++ ++ return ret; ++} ++ ++grub_err_t ++grub_get_mem_attrs (grub_addr_t addr, grub_size_t size, grub_uint64_t *attrs) ++{ ++ grub_efi_memory_attribute_protocol_t *proto; ++ grub_efi_physical_address_t physaddr = addr; ++ grub_guid_t protocol_guid = GRUB_EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID; ++ grub_efi_status_t efi_status; ++ ++ proto = grub_efi_locate_protocol (&protocol_guid, 0); ++ if (!proto) ++ return GRUB_ERR_NOT_IMPLEMENTED_YET; ++ ++ if (physaddr & 0xfff || size & 0xfff || size == 0 || attrs == NULL) ++ { ++ grub_dprintf ("nx", "%s called on 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" and attrs %p\n", ++ __func__, physaddr, physaddr+size-1, attrs); ++ return 0; ++ } ++ ++ efi_status = proto->get_memory_attributes( ++ proto, physaddr, size, attrs); ++ *attrs = uefi_mem_attrs_to_grub_mem_attrs (*attrs); ++ ++ return grub_efi_status_to_err (efi_status); ++} ++ ++grub_err_t ++grub_update_mem_attrs (grub_addr_t addr, grub_size_t size, ++ grub_uint64_t set_attrs, grub_uint64_t clear_attrs) ++{ ++ grub_efi_memory_attribute_protocol_t *proto; ++ grub_efi_physical_address_t physaddr = addr; ++ grub_guid_t protocol_guid = GRUB_EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID; ++ grub_efi_status_t efi_status = GRUB_EFI_SUCCESS; ++ grub_uint64_t before = 0, after = 0, uefi_set_attrs, uefi_clear_attrs; ++ grub_err_t err; ++ ++ proto = grub_efi_locate_protocol (&protocol_guid, 0); ++ if (!proto) ++ return GRUB_ERR_NONE; ++ ++ err = grub_get_mem_attrs (addr, size, &before); ++ if (err) ++ grub_dprintf ("nx", "grub_get_mem_attrs(0x%"PRIxGRUB_ADDR", %"PRIuGRUB_SIZE", %p) -> 0x%x\n", ++ addr, size, &before, err); ++ ++ if (physaddr & 0xfff || size & 0xfff || size == 0) ++ { ++ grub_dprintf ("nx", "%s called on 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" +%s%s%s -%s%s%s\n", ++ __func__, physaddr, physaddr + size - 1, ++ (set_attrs & GRUB_MEM_ATTR_R) ? "r" : "", ++ (set_attrs & GRUB_MEM_ATTR_W) ? "w" : "", ++ (set_attrs & GRUB_MEM_ATTR_X) ? "x" : "", ++ (clear_attrs & GRUB_MEM_ATTR_R) ? "r" : "", ++ (clear_attrs & GRUB_MEM_ATTR_W) ? "w" : "", ++ (clear_attrs & GRUB_MEM_ATTR_X) ? "x" : ""); ++ return 0; ++ } ++ ++ uefi_set_attrs = grub_mem_attrs_to_uefi_mem_attrs (set_attrs); ++ grub_dprintf ("nx", "translating set_attrs from 0x%lx to 0x%lx\n", set_attrs, uefi_set_attrs); ++ uefi_clear_attrs = grub_mem_attrs_to_uefi_mem_attrs (clear_attrs); ++ grub_dprintf ("nx", "translating clear_attrs from 0x%lx to 0x%lx\n", clear_attrs, uefi_clear_attrs); ++ if (uefi_set_attrs) ++ efi_status = proto->set_memory_attributes( ++ proto, physaddr, size, uefi_set_attrs); ++ if (efi_status == GRUB_EFI_SUCCESS && uefi_clear_attrs) ++ efi_status = proto->clear_memory_attributes( ++ proto, physaddr, size, uefi_clear_attrs); ++ ++ err = grub_get_mem_attrs (addr, size, &after); ++ if (err) ++ grub_dprintf ("nx", "grub_get_mem_attrs(0x%"PRIxGRUB_ADDR", %"PRIuGRUB_SIZE", %p) -> 0x%x\n", ++ addr, size, &after, err); ++ ++ grub_dprintf ("nx", "set +%s%s%s -%s%s%s on 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" before:%c%c%c after:%c%c%c\n", ++ (set_attrs & GRUB_MEM_ATTR_R) ? "r" : "", ++ (set_attrs & GRUB_MEM_ATTR_W) ? "w" : "", ++ (set_attrs & GRUB_MEM_ATTR_X) ? "x" : "", ++ (clear_attrs & GRUB_MEM_ATTR_R) ? "r" : "", ++ (clear_attrs & GRUB_MEM_ATTR_W) ? "w" : "", ++ (clear_attrs & GRUB_MEM_ATTR_X) ? "x" : "", ++ addr, addr + size - 1, ++ (before & GRUB_MEM_ATTR_R) ? 'r' : '-', ++ (before & GRUB_MEM_ATTR_W) ? 'w' : '-', ++ (before & GRUB_MEM_ATTR_X) ? 'x' : '-', ++ (after & GRUB_MEM_ATTR_R) ? 'r' : '-', ++ (after & GRUB_MEM_ATTR_W) ? 'w' : '-', ++ (after & GRUB_MEM_ATTR_X) ? 'x' : '-'); ++ ++ return grub_efi_status_to_err (efi_status); ++} +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 805a9d7adf9..76c88fbdcb0 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -389,6 +389,11 @@ + {0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } \ + } + ++#define GRUB_EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID \ ++ { 0xf4560cf6, 0x40ec, 0x4b4a, \ ++ { 0xa1, 0x92, 0xbf, 0x1d, 0x57, 0xd0, 0xb1, 0x89 } \ ++ } ++ + struct grub_efi_sal_system_table + { + grub_uint32_t signature; +@@ -2182,6 +2187,26 @@ struct grub_efi_ip6_config_manual_address { + }; + typedef struct grub_efi_ip6_config_manual_address grub_efi_ip6_config_manual_address_t; + ++struct grub_efi_memory_attribute_protocol ++{ ++ grub_efi_status_t (*get_memory_attributes) ( ++ struct grub_efi_memory_attribute_protocol *this, ++ grub_efi_physical_address_t base_address, ++ grub_efi_uint64_t length, ++ grub_efi_uint64_t *attributes); ++ grub_efi_status_t (*set_memory_attributes) ( ++ struct grub_efi_memory_attribute_protocol *this, ++ grub_efi_physical_address_t base_address, ++ grub_efi_uint64_t length, ++ grub_efi_uint64_t attributes); ++ grub_efi_status_t (*clear_memory_attributes) ( ++ struct grub_efi_memory_attribute_protocol *this, ++ grub_efi_physical_address_t base_address, ++ grub_efi_uint64_t length, ++ grub_efi_uint64_t attributes); ++}; ++typedef struct grub_efi_memory_attribute_protocol grub_efi_memory_attribute_protocol_t; ++ + struct initrd_media_device_path { + grub_efi_vendor_media_device_path_t vendor; + grub_efi_device_path_t end; +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 736d6f25694..3670eddc52b 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -189,4 +189,6 @@ struct grub_net_card; + grub_efi_handle_t + grub_efinet_get_device_handle (struct grub_net_card *card); + ++grub_err_t EXPORT_FUNC(grub_efi_status_to_err) (grub_efi_status_t status); ++ + #endif /* ! GRUB_EFI_EFI_HEADER */ +diff --git a/include/grub/mm.h b/include/grub/mm.h +index f3bf87fa0f9..8ee1fc7171c 100644 +--- a/include/grub/mm.h ++++ b/include/grub/mm.h +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + + #ifndef NULL +@@ -56,6 +57,37 @@ void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size); + void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size); + #endif + ++#define GRUB_MEM_ATTR_R 0x0000000000000004LLU ++#define GRUB_MEM_ATTR_W 0x0000000000000002LLU ++#define GRUB_MEM_ATTR_X 0x0000000000000001LLU ++ ++#ifdef GRUB_MACHINE_EFI ++grub_err_t EXPORT_FUNC(grub_get_mem_attrs) (grub_addr_t addr, ++ grub_size_t size, ++ grub_uint64_t *attrs); ++grub_err_t EXPORT_FUNC(grub_update_mem_attrs) (grub_addr_t addr, ++ grub_size_t size, ++ grub_uint64_t set_attrs, ++ grub_uint64_t clear_attrs); ++#else /* !GRUB_MACHINE_EFI */ ++static inline grub_err_t ++grub_get_mem_attrs (grub_addr_t addr __attribute__((__unused__)), ++ grub_size_t size __attribute__((__unused__)), ++ grub_uint64_t *attrs __attribute__((__unused__))) ++{ ++ return GRUB_ERR_NONE; ++} ++ ++static inline grub_err_t ++grub_update_mem_attrs (grub_addr_t addr __attribute__((__unused__)), ++ grub_size_t size __attribute__((__unused__)), ++ grub_uint64_t set_attrs __attribute__((__unused__)), ++ grub_uint64_t clear_attrs __attribute__((__unused__))) ++{ ++ return GRUB_ERR_NONE; ++} ++#endif /* GRUB_MACHINE_EFI */ ++ + void grub_mm_check_real (const char *file, int line); + #define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__); + diff --git a/0173-nx-set-page-permissions-for-loaded-modules.patch b/0173-nx-set-page-permissions-for-loaded-modules.patch new file mode 100644 index 00000000..416caedb --- /dev/null +++ b/0173-nx-set-page-permissions-for-loaded-modules.patch @@ -0,0 +1,236 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 21 Mar 2022 17:46:35 -0400 +Subject: [PATCH] nx: set page permissions for loaded modules. + +For NX, we need to set write and executable permissions on the sections +of grub modules when we load them. + +On sections with SHF_ALLOC set, which is typically everything except +.modname and the symbol and string tables, this patch clears the Read +Only flag on sections that have the ELF flag SHF_WRITE set, and clears +the No eXecute flag on sections with SHF_EXECINSTR set. In all other +cases it sets both flags. + +Signed-off-by: Peter Jones +[rharwood: arm tgptr -> tgaddr] +Signed-off-by: Robbie Harwood +--- + grub-core/kern/dl.c | 102 +++++++++++++++++++++++++++++++++++++++++++++------- + include/grub/dl.h | 44 +++++++++++++++++++++++ + 2 files changed, 133 insertions(+), 13 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 775b367287e..25666ae383f 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -277,6 +277,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + #endif + char *ptr; + ++ grub_dprintf ("modules", "loading segments for \"%s\"\n", mod->name); ++ + arch_addralign = grub_arch_dl_min_alignment (); + + for (i = 0, s = (const Elf_Shdr *)((const char *) e + e->e_shoff); +@@ -378,6 +380,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + ptr += got; + #endif + ++ grub_dprintf ("modules", "done loading segments for \"%s\"\n", mod->name); + return GRUB_ERR_NONE; + } + +@@ -645,6 +648,7 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) + Elf_Shdr *s; + unsigned i; + ++ grub_dprintf ("modules", "relocating symbols for \"%s\"\n", mod->name); + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) +@@ -653,22 +657,92 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) + grub_dl_segment_t seg; + grub_err_t err; + +- /* Find the target segment. */ +- for (seg = mod->segment; seg; seg = seg->next) +- if (seg->section == s->sh_info) +- break; ++ seg = grub_dl_find_segment(mod, s->sh_info); ++ if (!seg) ++ continue; + +- if (seg) +- { +- if (!mod->symtab) +- return grub_error (GRUB_ERR_BAD_MODULE, "relocation without symbol table"); ++ if (!mod->symtab) ++ return grub_error (GRUB_ERR_BAD_MODULE, "relocation without symbol table"); + +- err = grub_arch_dl_relocate_symbols (mod, ehdr, s, seg); +- if (err) +- return err; +- } ++ err = grub_arch_dl_relocate_symbols (mod, ehdr, s, seg); ++ if (err) ++ return err; + } + ++ grub_dprintf ("modules", "done relocating symbols for \"%s\"\n", mod->name); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) ++{ ++ unsigned i; ++ const Elf_Shdr *s; ++ const Elf_Ehdr *e = ehdr; ++#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) ++ grub_size_t arch_addralign = grub_arch_dl_min_alignment (); ++ grub_addr_t tgaddr; ++ grub_uint64_t tgsz; ++#endif ++ ++ grub_dprintf ("modules", "updating memory attributes for \"%s\"\n", ++ mod->name); ++ for (i = 0, s = (const Elf_Shdr *)((const char *) e + e->e_shoff); ++ i < e->e_shnum; ++ i++, s = (const Elf_Shdr *)((const char *) s + e->e_shentsize)) ++ { ++ grub_dl_segment_t seg; ++ grub_uint64_t set_attrs = GRUB_MEM_ATTR_R; ++ grub_uint64_t clear_attrs = GRUB_MEM_ATTR_W|GRUB_MEM_ATTR_X; ++ ++ seg = grub_dl_find_segment(mod, i); ++ if (!seg) ++ continue; ++ ++ if (seg->size == 0 || !(s->sh_flags & SHF_ALLOC)) ++ continue; ++ ++ if (s->sh_flags & SHF_WRITE) ++ { ++ set_attrs |= GRUB_MEM_ATTR_W; ++ clear_attrs &= ~GRUB_MEM_ATTR_W; ++ } ++ ++ if (s->sh_flags & SHF_EXECINSTR) ++ { ++ set_attrs |= GRUB_MEM_ATTR_X; ++ clear_attrs &= ~GRUB_MEM_ATTR_X; ++ } ++ ++ grub_dprintf ("modules", "setting memory attrs for section \"%s\" to -%s%s%s+%s%s%s\n", ++ grub_dl_get_section_name(e, s), ++ (clear_attrs & GRUB_MEM_ATTR_R) ? "r" : "", ++ (clear_attrs & GRUB_MEM_ATTR_W) ? "w" : "", ++ (clear_attrs & GRUB_MEM_ATTR_X) ? "x" : "", ++ (set_attrs & GRUB_MEM_ATTR_R) ? "r" : "", ++ (set_attrs & GRUB_MEM_ATTR_W) ? "w" : "", ++ (set_attrs & GRUB_MEM_ATTR_X) ? "x" : ""); ++ grub_update_mem_attrs ((grub_addr_t)(seg->addr), seg->size, set_attrs, clear_attrs); ++ } ++ ++#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) ++ tgaddr = grub_min((grub_addr_t)mod->tramp, (grub_addr_t)mod->got); ++ tgsz = grub_max((grub_addr_t)mod->trampptr, (grub_addr_t)mod->gotptr) - tgaddr; ++ ++ if (tgsz) ++ { ++ tgsz = ALIGN_UP(tgsz, arch_addralign); ++ ++ grub_dprintf ("modules", "updating attributes for GOT and trampolines\n", ++ mod->name); ++ grub_update_mem_attrs (tgaddr, tgsz, GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_X, ++ GRUB_MEM_ATTR_W); ++ } ++#endif ++ ++ grub_dprintf ("modules", "done updating module memory attributes for \"%s\"\n", ++ mod->name); ++ + return GRUB_ERR_NONE; + } + +@@ -705,6 +779,7 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) + mod->ref_count = 1; + + grub_dprintf ("modules", "relocating to %p\n", mod); ++ + /* Me, Vladimir Serbinenko, hereby I add this module check as per new + GNU module policy. Note that this license check is informative only. + Modules have to be licensed under GPLv3 or GPLv3+ (optionally +@@ -718,7 +793,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) + || grub_dl_resolve_dependencies (mod, e) + || grub_dl_load_segments (mod, e) + || grub_dl_resolve_symbols (mod, e) +- || grub_dl_relocate_symbols (mod, e)) ++ || grub_dl_relocate_symbols (mod, e) ++ || grub_dl_set_mem_attrs (mod, e)) + { + mod->fini = 0; + grub_dl_unload (mod); +diff --git a/include/grub/dl.h b/include/grub/dl.h +index 9f86765c8e9..1e1262a283b 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + #endif + + /* +@@ -267,6 +268,49 @@ grub_dl_is_persistent (grub_dl_t mod) + return mod->persistent; + } + ++static inline const char * ++grub_dl_get_section_name (const Elf_Ehdr *e, const Elf_Shdr *s) ++{ ++ Elf_Shdr *str_s; ++ const char *str; ++ ++ str_s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize); ++ str = (char *) e + str_s->sh_offset; ++ ++ return str + s->sh_name; ++} ++ ++static inline long ++grub_dl_find_section_index (Elf_Ehdr *e, const char *name) ++{ ++ Elf_Shdr *s; ++ const char *str; ++ unsigned i; ++ ++ s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize); ++ str = (char *) e + s->sh_offset; ++ ++ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); ++ i < e->e_shnum; ++ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) ++ if (grub_strcmp (str + s->sh_name, name) == 0) ++ return (long)i; ++ return -1; ++} ++ ++/* Return the segment for a section of index N */ ++static inline grub_dl_segment_t ++grub_dl_find_segment (grub_dl_t mod, unsigned n) ++{ ++ grub_dl_segment_t seg; ++ ++ for (seg = mod->segment; seg; seg = seg->next) ++ if (seg->section == n) ++ return seg; ++ ++ return NULL; ++} ++ + #endif + + void * EXPORT_FUNC(grub_resolve_symbol) (const char *name); diff --git a/0174-nx-set-the-nx-compatible-flag-in-EFI-grub-images.patch b/0174-nx-set-the-nx-compatible-flag-in-EFI-grub-images.patch new file mode 100644 index 00000000..c2a4c048 --- /dev/null +++ b/0174-nx-set-the-nx-compatible-flag-in-EFI-grub-images.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 22 Mar 2022 10:57:20 -0400 +Subject: [PATCH] nx: set the nx compatible flag in EFI grub images + +For NX, we need the grub binary to announce that it is compatible with +the NX feature. This implies that when loading the executable grub +image, several attributes are true: + +- the binary doesn't need an executable stack +- the binary doesn't need sections to be both executable and writable +- the binary knows how to use the EFI Memory Attributes protocol on code + it is loading. + +This patch adds a definition for the PE DLL Characteristics flag +GRUB_PE32_NX_COMPAT, and changes grub-mkimage to set that flag. + +Signed-off-by: Peter Jones +--- + util/mkimage.c | 1 + + include/grub/efi/pe32.h | 2 ++ + 2 files changed, 3 insertions(+) + +diff --git a/util/mkimage.c b/util/mkimage.c +index e2bb4d4cd05..425d920ff92 100644 +--- a/util/mkimage.c ++++ b/util/mkimage.c +@@ -1438,6 +1438,7 @@ grub_install_generate_image (const char *dir, const char *prefix, + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdangling-pointer" + #endif ++ PE_OHDR (o32, o64, dll_characteristics) = grub_host_to_target16 (GRUB_PE32_NX_COMPAT); + PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size); + PE_OHDR (o32, o64, entry_addr) = grub_host_to_target32 (layout.start_address); + PE_OHDR (o32, o64, image_base) = 0; +diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h +index 4e6e9d254bd..9887e14b278 100644 +--- a/include/grub/efi/pe32.h ++++ b/include/grub/efi/pe32.h +@@ -231,6 +231,8 @@ struct grub_pe64_optional_header + + #define GRUB_PE32_SUBSYSTEM_EFI_APPLICATION 10 + ++#define GRUB_PE32_NX_COMPAT 0x0100 ++ + #define GRUB_PE32_NUM_DATA_DIRECTORIES 16 + + struct grub_pe32_section_table diff --git a/0175-grub_fs_probe-dprint-errors-from-filesystems.patch b/0175-grub_fs_probe-dprint-errors-from-filesystems.patch new file mode 100644 index 00000000..fdd2932f --- /dev/null +++ b/0175-grub_fs_probe-dprint-errors-from-filesystems.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Fri, 15 Jul 2022 15:39:41 -0400 +Subject: [PATCH] grub_fs_probe(): dprint errors from filesystems + +When filesystem detection fails, all that's currently debug-logged is a +series of messages like: + + grub-core/kern/fs.c:56:fs: Detecting ntfs... + grub-core/kern/fs.c:76:fs: ntfs detection failed. + +repeated for each filesystem. Any messages provided to grub_error() by +the filesystem are lost, and one has to break out gdb to figure out what +went wrong. + +With this change, one instead sees: + + grub-core/kern/fs.c:56:fs: Detecting fat... + grub-core/osdep/hostdisk.c:357:hostdisk: reusing open device + `/path/to/device' + grub-core/kern/fs.c:77:fs: error: invalid modification timestamp for /. + grub-core/kern/fs.c:79:fs: fat detection failed. + +in the debug prints. + +Signed-off-by: Robbie Harwood +(cherry picked from commit 838c79d658797d0662ee7f9e033e38ee88059e02) +--- + grub-core/kern/fs.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c +index 7ad0aaf4e29..f25bace620b 100644 +--- a/grub-core/kern/fs.c ++++ b/grub-core/kern/fs.c +@@ -74,6 +74,7 @@ grub_fs_probe (grub_device_t device) + if (grub_errno == GRUB_ERR_NONE) + return p; + ++ grub_dprintf ("fs", _("error: %s.\n"), grub_errmsg); + grub_error_push (); + /* The grub_error_push() does not touch grub_errmsg. */ + grub_dprintf ("fs", _("error: %s.\n"), grub_errmsg); diff --git a/0176-Make-debug-file-show-which-file-filters-get-run.patch b/0176-Make-debug-file-show-which-file-filters-get-run.patch new file mode 100644 index 00000000..3bd69d83 --- /dev/null +++ b/0176-Make-debug-file-show-which-file-filters-get-run.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 29 Jul 2022 15:56:00 -0400 +Subject: [PATCH] Make debug=file show which file filters get run. + +If one of the file filters breaks things, it's hard to figure out where +it has happened. + +This makes grub log which filter is being run, which makes it easier to +figure out where you are in the sequence of events. + +Signed-off-by: Peter Jones +--- + grub-core/kern/file.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c +index 264211b1143..1794d022fb0 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -30,6 +30,14 @@ void (*EXPORT_VAR (grub_grubnet_fini)) (void); + + grub_file_filter_t grub_file_filters[GRUB_FILE_FILTER_MAX]; + ++static const char *filter_names[] = { ++ [GRUB_FILE_FILTER_VERIFY] = "GRUB_FILE_FILTER_VERIFY", ++ [GRUB_FILE_FILTER_GZIO] = "GRUB_FILE_FILTER_GZIO", ++ [GRUB_FILE_FILTER_XZIO] = "GRUB_FILE_FILTER_XZIO", ++ [GRUB_FILE_FILTER_LZOPIO] = "GRUB_FILE_FILTER_LZOPIO", ++ [GRUB_FILE_FILTER_MAX] = "GRUB_FILE_FILTER_MAX" ++}; ++ + /* Get the device part of the filename NAME. It is enclosed by parentheses. */ + char * + grub_file_get_device_name (const char *name) +@@ -124,6 +132,9 @@ grub_file_open (const char *name, enum grub_file_type type) + if (grub_file_filters[filter]) + { + last_file = file; ++ if (filter < GRUB_FILE_FILTER_MAX) ++ grub_dprintf ("file", "Running %s file filter\n", ++ filter_names[filter]); + file = grub_file_filters[filter] (file, type); + if (file && file != last_file) + { diff --git a/0177-BLS-create-etc-kernel-cmdline-during-mkconfig.patch b/0177-BLS-create-etc-kernel-cmdline-during-mkconfig.patch new file mode 100644 index 00000000..05e83252 --- /dev/null +++ b/0177-BLS-create-etc-kernel-cmdline-during-mkconfig.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Tue, 2 Aug 2022 15:56:28 -0400 +Subject: [PATCH] BLS: create /etc/kernel/cmdline during mkconfig + +Signed-off-by: Robbie Harwood +--- + util/grub.d/10_linux.in | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 360ce26e5f9..a6568caf7d1 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -163,6 +163,12 @@ update_bls_cmdline() + local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + local -a files=($(get_sorted_bls)) + ++ if [[ ! -f /etc/kernel/cmdline ]]; then ++ # anaconda has the correct information to do this during install; ++ # afterward, grubby will take care of syncing on updates. ++ echo "$cmdline rhgb quiet" > /etc/kernel/cmdline ++ fi ++ + for bls in "${files[@]}"; do + local options="${cmdline}" + if [ -z "${bls##*debug*}" ]; then diff --git a/0178-squish-don-t-dup-rhgb-quiet-check-mtimes.patch b/0178-squish-don-t-dup-rhgb-quiet-check-mtimes.patch new file mode 100644 index 00000000..fa279f1f --- /dev/null +++ b/0178-squish-don-t-dup-rhgb-quiet-check-mtimes.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Wed, 17 Aug 2022 10:26:07 -0400 +Subject: [PATCH] squish: don't dup rhgb quiet, check mtimes + +Signed-off-by: Robbie Harwood +--- + util/grub.d/10_linux.in | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index a6568caf7d1..079bb9a0961 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -163,10 +163,16 @@ update_bls_cmdline() + local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + local -a files=($(get_sorted_bls)) + +- if [[ ! -f /etc/kernel/cmdline ]]; then +- # anaconda has the correct information to do this during install; +- # afterward, grubby will take care of syncing on updates. +- echo "$cmdline rhgb quiet" > /etc/kernel/cmdline ++ if [[ ! -f /etc/kernel/cmdline ]] || ++ [[ /etc/kernel/cmdline -ot /etc/default/grub ]]; then ++ # anaconda has the correct information to create this during install; ++ # afterward, grubby will take care of syncing on updates. If the user ++ # has modified /etc/default/grub, try to cope. ++ if [[ ! "$cmdline" =~ "rhgb quiet" ]]; then ++ # ensure these only show up once ++ cmdline="$cmdline rhgb quiet" ++ fi ++ echo "$cmdline" > /etc/kernel/cmdline + fi + + for bls in "${files[@]}"; do diff --git a/0179-squish-give-up-on-rhgb-quiet.patch b/0179-squish-give-up-on-rhgb-quiet.patch new file mode 100644 index 00000000..c1cbf6da --- /dev/null +++ b/0179-squish-give-up-on-rhgb-quiet.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Wed, 17 Aug 2022 11:30:30 -0400 +Subject: [PATCH] squish: give up on rhgb quiet + +Signed-off-by: Robbie Harwood +--- + util/grub.d/10_linux.in | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 079bb9a0961..2dddc39816f 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -168,10 +168,6 @@ update_bls_cmdline() + # anaconda has the correct information to create this during install; + # afterward, grubby will take care of syncing on updates. If the user + # has modified /etc/default/grub, try to cope. +- if [[ ! "$cmdline" =~ "rhgb quiet" ]]; then +- # ensure these only show up once +- cmdline="$cmdline rhgb quiet" +- fi + echo "$cmdline" > /etc/kernel/cmdline + fi + diff --git a/0180-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch b/0180-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch new file mode 100644 index 00000000..2c5c7c54 --- /dev/null +++ b/0180-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jonathan Lebon +Date: Wed, 17 Aug 2022 10:26:03 -0400 +Subject: [PATCH] squish: BLS: only write /etc/kernel/cmdline if writable + +On OSTree systems, `grub2-mkconfig` is run with `/etc` mounted read-only +because as part of the promise of transactional updates, we want to make +sure that we're not modifying the current deployment's state (`/etc` or +`/var`). + +This conflicts with 0837dcdf1 ("BLS: create /etc/kernel/cmdline during +mkconfig") which wants to write to `/etc/kernel/cmdline`. I'm not +exactly sure on the background there, but based on the comment I think +the intent is to fulfill grubby's expectation that the file exists. + +However, in systems like Silverblue, kernel arguments are managed by the +rpm-ostree stack and grubby is not shipped at all. + +Adjust the script slightly so that we only write `/etc/kernel/cmdline` +if the parent directory is writable. + +In the future, we're hoping to simplify things further on rpm-ostree +systems by not running `grub2-mkconfig` at all since libostree already +directly writes BLS entries. Doing that would also have avoided this, +but ratcheting it into existing systems needs more careful thought. + +Signed-off-by: Jonathan Lebon + +Fixes: https://github.com/fedora-silverblue/issue-tracker/issues/322 +--- + util/grub.d/10_linux.in | 13 +++++++------ + 1 file changed, 7 insertions(+), 6 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 2dddc39816f..11c19304f8b 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -163,12 +163,13 @@ update_bls_cmdline() + local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + local -a files=($(get_sorted_bls)) + +- if [[ ! -f /etc/kernel/cmdline ]] || +- [[ /etc/kernel/cmdline -ot /etc/default/grub ]]; then +- # anaconda has the correct information to create this during install; +- # afterward, grubby will take care of syncing on updates. If the user +- # has modified /etc/default/grub, try to cope. +- echo "$cmdline" > /etc/kernel/cmdline ++ if [ -w /etc/kernel ] && ++ [[ ! -f /etc/kernel/cmdline || ++ /etc/kernel/cmdline -ot /etc/default/grub ]]; then ++ # anaconda has the correct information to create this during install; ++ # afterward, grubby will take care of syncing on updates. If the user ++ # has modified /etc/default/grub, try to cope. ++ echo "$cmdline" > /etc/kernel/cmdline + fi + + for bls in "${files[@]}"; do diff --git a/0181-blscfg-Don-t-root-device-in-emu-builds.patch b/0181-blscfg-Don-t-root-device-in-emu-builds.patch new file mode 100644 index 00000000..d61b1b23 --- /dev/null +++ b/0181-blscfg-Don-t-root-device-in-emu-builds.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Thu, 25 Aug 2022 17:57:55 -0400 +Subject: [PATCH] blscfg: Don't root device in emu builds + +Otherwise, we end up looking for kernel/initrd in /boot/boot which +doesn't work at all. Non-emu builds need to be looking in +($root)/boot/, which is what this is for. + +Signed-off-by: Robbie Harwood +--- + grub-core/commands/blscfg.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index e907a6a5d28..dbd0899acf3 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -41,7 +41,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + #define GRUB_BLS_CONFIG_PATH "/loader/entries/" + #ifdef GRUB_MACHINE_EMU +-#define GRUB_BOOT_DEVICE "/boot" ++#define GRUB_BOOT_DEVICE "" + #else + #define GRUB_BOOT_DEVICE "($root)" + #endif diff --git a/0182-ppc64le-signed-boot-media-changes.patch b/0182-ppc64le-signed-boot-media-changes.patch new file mode 100644 index 00000000..f92570e3 --- /dev/null +++ b/0182-ppc64le-signed-boot-media-changes.patch @@ -0,0 +1,123 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Wed, 25 Jan 2023 16:10:58 -0500 +Subject: [PATCH] ppc64le: signed boot media changes + +Skip mdraid < 1.1 on isos since mdraid* can't even + +Prior to this change, on ppc64le with part_msdos and the mdraid* modules +enabled, we see: + + disk/diskfilter.c:191: scanning ieee1275/cdrom + kern/disk.c:196: Opening `ieee1275/cdrom'... + disk/ieee1275/ofdisk.c:477: Opening `cdrom'. + disk/ieee1275/ofdisk.c:502: MAX_RETRIES set to 20 + kern/disk.c:288: Opening `ieee1275/cdrom' succeeded. + disk/diskfilter.c:136: Scanning for DISKFILTER devices on disk ieee1275/cdrom + partmap/msdos.c:184: partition 0: flag 0x80, type 0x96, start 0x0, len + 0x6a5d70 + disk/diskfilter.c:136: Scanning for DISKFILTER devices on disk ieee1275/cdrom + SCSI-DISK: Access beyond end of device ! + SCSI-DISK: Access beyond end of device ! + SCSI-DISK: Access beyond end of device ! + SCSI-DISK: Access beyond end of device ! + SCSI-DISK: Access beyond end of device ! + disk/ieee1275/ofdisk.c:578: MAX_RETRIES set to 20 + +These latter two lines repeat many times, eventually ending in: + + kern/disk.c:388: ieee1275/cdrom read failed + error: ../../grub-core/disk/ieee1275/ofdisk.c:608:failure reading sector + 0x1a9720 from `ieee1275/cdrom'. + +and the system drops to a "grub>" prompt. + +Prior to 1.1, mdraid stored the superblock offset from the end of the +disk, and the firmware really doesn't like reads there. Best guess was +that the firmware and the iso image appear to diagree on the blocksize +(512 vs. 2048), and the diskfilter RAID probing is too much for it. +It's tempting to just skip probing for cdroms, but unfortunately isos +can be virtualized elsewhere - such as regular disks. + +Also fix detection of root, and try the chrp path as a fallback if the +built prefix doesn't work. + +Signed-off-by: Robbie Harwood + +wip +--- + grub-core/disk/mdraid1x_linux.c | 6 ++++++ + grub-core/disk/mdraid_linux.c | 5 +++++ + grub-core/kern/ieee1275/openfw.c | 2 +- + grub-core/normal/main.c | 5 +++++ + 4 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c +index 72e5cb6f481..3b5b6c42342 100644 +--- a/grub-core/disk/mdraid1x_linux.c ++++ b/grub-core/disk/mdraid1x_linux.c +@@ -130,6 +130,12 @@ grub_mdraid_detect (grub_disk_t disk, + struct grub_diskfilter_vg *array; + char *uuid; + ++#ifdef __powerpc__ ++ /* Firmware will yell at us for reading too far. */ ++ if (minor_version == 0) ++ continue; ++#endif ++ + if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0) + continue; + +diff --git a/grub-core/disk/mdraid_linux.c b/grub-core/disk/mdraid_linux.c +index e40216f5111..98fcfb1be69 100644 +--- a/grub-core/disk/mdraid_linux.c ++++ b/grub-core/disk/mdraid_linux.c +@@ -189,6 +189,11 @@ grub_mdraid_detect (grub_disk_t disk, + grub_uint32_t level; + struct grub_diskfilter_vg *ret; + ++#ifdef __powerpc__ ++ /* Firmware will yell at us for reading too far. */ ++ return NULL; ++#endif ++ + /* The sector where the mdraid 0.90 superblock is stored, if available. */ + size = grub_disk_native_sectors (disk); + if (size == GRUB_DISK_SIZE_UNKNOWN) +diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c +index e2ecc65d2d8..65616254e02 100644 +--- a/grub-core/kern/ieee1275/openfw.c ++++ b/grub-core/kern/ieee1275/openfw.c +@@ -499,7 +499,7 @@ grub_ieee1275_encode_devname (const char *path) + *optr++ ='\\'; + *optr++ = *iptr++; + } +- if (partition && partition[0]) ++ if (partition && partition[0] >= '0' && partition[0] <= '9') + { + unsigned int partno = grub_strtoul (partition, 0, 0); + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index fc3ed551cec..e903f291732 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -372,6 +372,7 @@ grub_try_normal_prefix (const char *prefix) + file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); + if (file) + { ++ grub_env_set ("prefix", prefix); + grub_file_close (file); + err = GRUB_ERR_NONE; + } +@@ -447,6 +448,10 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + err = grub_try_normal ("fw_path"); + if (err == GRUB_ERR_FILE_NOT_FOUND) + err = grub_try_normal ("prefix"); ++#ifdef __powerpc__ ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ err = grub_try_normal_prefix ("/boot/grub"); ++#endif + if (err == GRUB_ERR_FILE_NOT_FOUND) + err = grub_try_normal_discover (); + if (err == GRUB_ERR_FILE_NOT_FOUND) diff --git a/0183-core-Fix-several-implicit-function-declarations.patch b/0183-core-Fix-several-implicit-function-declarations.patch new file mode 100644 index 00000000..a8140332 --- /dev/null +++ b/0183-core-Fix-several-implicit-function-declarations.patch @@ -0,0 +1,54 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Arjun Shankar +Date: Sun, 5 Feb 2023 11:13:55 +0100 +Subject: [PATCH] core: Fix several implicit function declarations + +These #include lines ensure that grub2 continues to build with C99 +where implicit function declarations are removed. + +Related to: + + + +--- + grub-core/commands/efi/connectefi.c | 1 + + grub-core/net/http.c | 1 + + grub-core/term/at_keyboard.c | 1 + + 3 files changed, 3 insertions(+) + +diff --git a/grub-core/commands/efi/connectefi.c b/grub-core/commands/efi/connectefi.c +index 0f840ea0575..6c397f8f508 100644 +--- a/grub-core/commands/efi/connectefi.c ++++ b/grub-core/commands/efi/connectefi.c +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + #include + #include + #include +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index ce2b492c353..40df19426c8 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c +index 378deb321d9..e667d0a862c 100644 +--- a/grub-core/term/at_keyboard.c ++++ b/grub-core/term/at_keyboard.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + diff --git a/0184-ieee1275-request-memory-with-ibm-client-architecture.patch b/0184-ieee1275-request-memory-with-ibm-client-architecture.patch new file mode 100644 index 00000000..bd598850 --- /dev/null +++ b/0184-ieee1275-request-memory-with-ibm-client-architecture.patch @@ -0,0 +1,109 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Mon, 6 Feb 2023 10:03:20 -0500 +Subject: [PATCH] ieee1275: request memory with ibm, + client-architecture-support + +On PowerVM, the first time we boot a Linux partition, we may only get +256MB of real memory area, even if the partition has more memory. + +This isn't enough to reliably verify a kernel. Fortunately, the Power +Architecture Platform Reference (PAPR) defines a method we can call to ask +for more memory: the broad and powerful ibm,client-architecture-support +(CAS) method. + +CAS can do an enormous amount of things on a PAPR platform: as well as +asking for memory, you can set the supported processor level, the interrupt +controller, hash vs radix mmu, and so on. + +If: + + - we are running under what we think is PowerVM (compatible property of / + begins with "IBM"), and + + - the full amount of RMA is less than 512MB (as determined by the reg + property of /memory) + +then call CAS as follows: (refer to the Linux on Power Architecture +Reference, LoPAR, which is public, at B.5.2.3): + + - Use the "any" PVR value and supply 2 option vectors. + + - Set option vector 1 (PowerPC Server Processor Architecture Level) + to "ignore". + + - Set option vector 2 with default or Linux-like options, including a + min-rma-size of 512MB. + + - Set option vector 3 to request Floating Point, VMX and Decimal Floating + point, but don't abort the boot if we can't get them. + + - Set option vector 4 to request a minimum VP percentage to 1%, which is + what Linux requests, and is below the default of 10%. Without this, + some systems with very large or very small configurations fail to boot. + +This will cause a CAS reboot and the partition will restart with 512MB +of RMA. Importantly, grub will notice the 512MB and not call CAS again. + +Notes about the choices of parameters: + + - A partition can be configured with only 256MB of memory, which would + mean this request couldn't be satisfied, but PFW refuses to load with + only 256MB of memory, so it's a bit moot. SLOF will run fine with 256MB, + but we will never call CAS under qemu/SLOF because /compatible won't + begin with "IBM".) + + - unspecified CAS vectors take on default values. Some of these values + might restrict the ability of certain hardware configurations to boot. + This is why we need to specify the VP percentage in vector 4, which is + in turn why we need to specify vector 3. + +Finally, we should have enough memory to verify a kernel, and we will +reach Linux. One of the first things Linux does while still running under +OpenFirmware is to call CAS with a much fuller set of options (including +asking for 512MB of memory). Linux includes a much more restrictive set of +PVR values and processor support levels, and this CAS invocation will likely +induce another reboot. On this reboot grub will again notice the higher RMA, +and not call CAS. We will get to Linux again, Linux will call CAS again, but +because the values are now set for Linux this will not induce another CAS +reboot and we will finally boot all the way to userspace. + +On all subsequent boots, everything will be configured with 512MB of RMA, +so there will be no further CAS reboots from grub. (phyp is super sticky +with the RMA size - it persists even on cold boots. So if you've ever booted +Linux in a partition, you'll probably never have grub call CAS. It'll only +ever fire the first time a partition loads grub, or if you deliberately lower +the amount of memory your partition has below 512MB.) + +Signed-off-by: Daniel Axtens +Signed-off-by: Stefan Berger +Reviewed-by: Daniel Kiper +(cherry picked from commit d5571590b7de61887efac1c298901455697ba307) +--- + grub-core/kern/ieee1275/init.c | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 8ce1a0f09ee..13e8a5b4bb8 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -850,6 +850,19 @@ grub_claim_heap (void) + } + #endif + ++#if defined(__powerpc__) ++ if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY)) ++ { ++ grub_uint64_t rma_size; ++ grub_err_t err; ++ ++ err = grub_ieee1275_total_mem (&rma_size); ++ /* if we have an error, don't call CAS, just hope for the best */ ++ if (err == GRUB_ERR_NONE && rma_size < (512 * 1024 * 1024)) ++ grub_ieee1275_ibm_cas (); ++ } ++#endif ++ + grub_machine_mmap_iterate (heap_init, &total); + } + #endif diff --git a/0185-hostdisk-work-around-proc-not-reporting-size.patch b/0185-hostdisk-work-around-proc-not-reporting-size.patch new file mode 100644 index 00000000..72715ae3 --- /dev/null +++ b/0185-hostdisk-work-around-proc-not-reporting-size.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Thu, 9 Mar 2023 11:18:19 -0500 +Subject: [PATCH] hostdisk: work around /proc not reporting size + +fstat(2) of files in /proc will yield st_size == 0 regardless of file +contents. Use a negative value in grub_file_t's size to denote "ignore" +and plumb through. + +Signed-off-by: Robbie Harwood +--- + grub-core/kern/file.c | 28 ++++++++++++++++------------ + grub-core/lib/progress.c | 2 +- + grub-core/osdep/unix/hostdisk.c | 6 ++++++ + 3 files changed, 23 insertions(+), 13 deletions(-) + +diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c +index 1794d022fb0..75510df7c92 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -172,26 +172,30 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) + grub_disk_read_hook_t read_hook; + void *read_hook_data; + +- if (file->offset > file->size) +- { +- grub_error (GRUB_ERR_OUT_OF_RANGE, +- N_("attempt to read past the end of file")); +- return -1; +- } +- + if (len == 0) + return 0; + +- if (len > file->size - file->offset) +- len = file->size - file->offset; ++#ifdef GRUB_MACHINE_EMU ++ if (file->size >= 0) ++ { ++#endif ++ if (file->offset > file->size) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ N_("attempt to read past the end of file")); ++ return -1; ++ } ++ ++ if (len > file->size - file->offset) ++ len = file->size - file->offset; ++#ifdef GRUB_MACHINE_EMU ++ } ++#endif + + /* Prevent an overflow. */ + if ((grub_ssize_t) len < 0) + len >>= 1; + +- if (len == 0) +- return 0; +- + read_hook = file->read_hook; + read_hook_data = file->read_hook_data; + if (!file->read_hook) +diff --git a/grub-core/lib/progress.c b/grub-core/lib/progress.c +index 4f4389dd586..eb1b7d13cfd 100644 +--- a/grub-core/lib/progress.c ++++ b/grub-core/lib/progress.c +@@ -72,7 +72,7 @@ grub_file_progress_hook_real (grub_disk_addr_t sector __attribute__ ((unused)), + * 100ULL * 1000ULL, + now - file->last_progress_time, 0); + +- if (file->size == 0) ++ if (file->size <= 0) + percent = 100; + else + percent = grub_divmod64 (100 * file->progress_offset, +diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c +index 3a00d7451a5..e5f4b4d5f9c 100644 +--- a/grub-core/osdep/unix/hostdisk.c ++++ b/grub-core/osdep/unix/hostdisk.c +@@ -71,6 +71,12 @@ grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsiz + if (log_secsize) + *log_secsize = 9; + ++#ifdef GRUB_MACHINE_EMU ++ /* /proc doesn't behave itself and gives 0 for file sizes to stat. */ ++ if (st.st_size == 0 && !grub_strncmp ("/proc", name, 5)) ++ return -1; ++#endif ++ + return st.st_size; + } + diff --git a/0186-blscfg-check-for-mounted-boot-in-emu.patch b/0186-blscfg-check-for-mounted-boot-in-emu.patch new file mode 100644 index 00000000..54b3cf01 --- /dev/null +++ b/0186-blscfg-check-for-mounted-boot-in-emu.patch @@ -0,0 +1,118 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Tue, 7 Mar 2023 18:59:40 -0500 +Subject: [PATCH] blscfg: check for mounted /boot in emu + +Irritatingly, BLS defines paths relatives to the mountpoint of the +filesystem which contains its snippets, not / or any other fixed +location. So grub2-emu needs to know whether /boot is a separate +filesysem from / and conditionally prepend a path. + +Signed-off-by: Robbie Harwood +--- + grub-core/commands/blscfg.c | 54 ++++++++++++++++++++++++++++++++++++++++----- + 1 file changed, 49 insertions(+), 5 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index dbd0899acf3..6e398fc1757 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -40,8 +40,9 @@ GRUB_MOD_LICENSE ("GPLv3+"); + #include "loadenv.h" + + #define GRUB_BLS_CONFIG_PATH "/loader/entries/" ++ + #ifdef GRUB_MACHINE_EMU +-#define GRUB_BOOT_DEVICE "" ++#define GRUB_BOOT_DEVICE "/boot" + #else + #define GRUB_BOOT_DEVICE "($root)" + #endif +@@ -54,8 +55,50 @@ struct keyval + + static struct bls_entry *entries = NULL; + ++/* Cache probing in frob_boot_device(). Used for linux entry also. ++ * Always true in non-emu, meaning to prefix things with GRUB_BOOT_DEVICE. */ ++static int separate_boot = -1; ++ + #define FOR_BLS_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries) + ++/* BLS appears to make paths relative to the filesystem that snippets are ++ * on, not /. Attempt to cope. */ ++static char *frob_boot_device(char *tmp) ++{ ++#ifdef GRUB_MACHINE_EMU ++ grub_file_t f; ++ char *line = NULL; ++ ++ if (separate_boot != -1) ++ goto probed; ++ ++ separate_boot = 0; ++ ++ f = grub_file_open ("/proc/mounts", GRUB_FILE_TYPE_CONFIG); ++ if (f == NULL) ++ goto probed; ++ ++ while ((line = grub_file_getline (f))) ++ { ++ if (grub_strstr (line, " " GRUB_BOOT_DEVICE " ")) ++ { ++ separate_boot = 1; ++ grub_free (line); ++ break; ++ } ++ ++ grub_free(line); ++ } ++ ++ grub_file_close (f); ++ probed: ++ if (!separate_boot) ++ return grub_stpcpy (tmp, " "); ++#endif ++ ++ return grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++} ++ + static int bls_add_keyval(struct bls_entry *entry, char *key, char *val) + { + char *k, *v; +@@ -842,7 +885,7 @@ static void create_entry (struct bls_entry *entry) + for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++) + { + grub_dprintf ("blscfg", "adding early initrd %s\n", early_initrds[i]); +- tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++ tmp = frob_boot_device (tmp); + tmp = grub_stpcpy (tmp, initrd_prefix); + tmp = grub_stpcpy (tmp, early_initrds[i]); + grub_free(early_initrds[i]); +@@ -851,7 +894,7 @@ static void create_entry (struct bls_entry *entry) + for (i = 0; initrds != NULL && initrds[i] != NULL; i++) + { + grub_dprintf ("blscfg", "adding initrd %s\n", initrds[i]); +- tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++ tmp = frob_boot_device (tmp); + tmp = grub_stpcpy (tmp, initrds[i]); + } + tmp = grub_stpcpy (tmp, "\n"); +@@ -888,7 +931,7 @@ static void create_entry (struct bls_entry *entry) + } + char *tmp = dt; + tmp = grub_stpcpy (dt, "devicetree"); +- tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++ tmp = frob_boot_device (tmp); + if (add_dt_prefix) + tmp = grub_stpcpy (tmp, prefix); + tmp = grub_stpcpy (tmp, devicetree); +@@ -907,7 +950,8 @@ static void create_entry (struct bls_entry *entry) + "linux %s%s%s%s\n" + "%s%s", + savedefault ? "savedefault\n" : "", +- GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", ++ separate_boot ? GRUB_BOOT_DEVICE : "", ++ clinux, options ? " " : "", options ? options : "", + initrd ? initrd : "", dt ? dt : ""); + + grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index, entry); diff --git a/0187-grub_dl_set_mem_attrs-fix-format-string.patch b/0187-grub_dl_set_mem_attrs-fix-format-string.patch new file mode 100644 index 00000000..646c609d --- /dev/null +++ b/0187-grub_dl_set_mem_attrs-fix-format-string.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Laszlo Ersek +Date: Fri, 7 Apr 2023 14:54:35 +0200 +Subject: [PATCH] grub_dl_set_mem_attrs(): fix format string + +The grub_dprintf() call for printing the message + + updating attributes for GOT and trampolines + +passes the argument "mod->name", but the format string doesn't accept that +argument. + +Print the module name too. + +Example output: + +> kern/dl.c:736: updating attributes for GOT and trampolines ("video_fb") + +Fixes: ad1b904d325b (nx: set page permissions for loaded modules.) +Signed-off-by: Laszlo Ersek +--- + grub-core/kern/dl.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 25666ae383f..101e0794dd8 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -733,7 +733,8 @@ grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) + { + tgsz = ALIGN_UP(tgsz, arch_addralign); + +- grub_dprintf ("modules", "updating attributes for GOT and trampolines\n", ++ grub_dprintf ("modules", ++ "updating attributes for GOT and trampolines (\"%s\")\n", + mod->name); + grub_update_mem_attrs (tgaddr, tgsz, GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_X, + GRUB_MEM_ATTR_W); diff --git a/0188-grub_dl_set_mem_attrs-add-self-check-for-the-tramp-G.patch b/0188-grub_dl_set_mem_attrs-add-self-check-for-the-tramp-G.patch new file mode 100644 index 00000000..6543a9e2 --- /dev/null +++ b/0188-grub_dl_set_mem_attrs-add-self-check-for-the-tramp-G.patch @@ -0,0 +1,140 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Laszlo Ersek +Date: Fri, 7 Apr 2023 16:21:54 +0200 +Subject: [PATCH] grub_dl_set_mem_attrs(): add self-check for the tramp/GOT + sizes + +On aarch64 UEFI, we currently have a crasher: + + grub_dl_load_core() + grub_dl_load_core_noinit() + + /* independent allocation: must remain writable */ + mod = grub_zalloc(); + + /* allocates module image with incorrect tail alignment */ + grub_dl_load_segments() + + /* write-protecting the module image makes "mod" read-only! */ + grub_dl_set_mem_attrs() + grub_update_mem_attrs() + + grub_dl_init() + /* page fault, crash */ + mod->next = ...; + +- Commit 887f1d8fa976 ("modules: load module sections at page-aligned + addresses", 2023-02-08) forgot to page-align the allocation of the + trampolines and GOT areas of grub2 modules, in grub_dl_load_segments(). + +- Commit ad1b904d325b ("nx: set page permissions for loaded modules.", + 2023-02-08) calculated a common bounding box for the trampolines and GOT + areas in grub_dl_set_mem_attrs(), rounded the box size up to a whole + multiple of EFI page size ("arch_addralign"), and write-protected the + resultant page range. + +Consequently, grub_dl_load_segments() places the module image in memory +such that its tail -- the end of the trampolines and GOT areas -- lands at +the head of a page whose tail in turn contains independent memory +allocations, such as "mod". grub_dl_set_mem_attrs() will then unwittingly +write-protect these other allocations too. + +But "mod" must remain writable: we assign "mod->next" in grub_dl_init() +subsequently. Currently we crash there with a page fault / permission +fault. + +(The crash is not trivial to hit: the tramp/GOT areas are irrelevant on +x86_64, plus the page protection depends on the UEFI platform firmware +providing EFI_MEMORY_ATTRIBUTE_PROTOCOL. In practice, the crash is +restricted to aarch64 edk2 (ArmVirtQemu) builds containing commit +1c4dfadb4611, "ArmPkg/CpuDxe: Implement EFI memory attributes protocol", +2023-03-16.) + +Example log before the patch: + +> kern/dl.c:736: updating attributes for GOT and trampolines ("video_fb") +> kern/efi/mm.c:927: set +rx -w on 0x13b88b000-0x13b88bfff before:rwx after:r-x +> kern/dl.c:744: done updating module memory attributes for "video_fb" +> kern/dl.c:639: flushing 0xe4f0 bytes at 0x13b87d000 +> kern/arm64/cache.c:42: D$ line size: 64 +> kern/arm64/cache.c:43: I$ line size: 64 +> kern/dl.c:839: module name: video_fb +> kern/dl.c:840: init function: 0x0 +> kern/dl.c:865: Initing module video_fb +> +> Synchronous Exception at 0x000000013B8A76EC +> PC 0x00013B8A76EC +> +> X0 0x000000013B88B960 X1 0x0000000000000000 X2 0x000000013F93587C X3 0x0000000000000075 +> +> SP 0x00000000470745C0 ELR 0x000000013B8A76EC SPSR 0x60000205 FPSR 0x00000000 +> ESR 0x9600004F FAR 0x000000013B88B9D0 +> +> ESR : EC 0x25 IL 0x1 ISS 0x0000004F +> +> Data abort: Permission fault, third level + +Note the following: + +- The whole 4K page at 0x1_3B88_B000 is write-protected. + +- The "video_fb" module actually lives at [0x1_3B87_D000, 0x1_3B88_B4F0) + -- left-inclusive, right-exclusive --; that is, in the last page (at + 0x1_3B88_B000), it only occupies the first 0x4F0 bytes. + +- The instruction at 0x1_3B8A_76EC faults. Not shown here, but it is a + store instruction, which writes to the field at offset 0x70 of the + structure pointed-to by the X0 register. This is the "mod->next" + assignment from grub_dl_init(). + +- The faulting address is therefore (X0 + 0x70), i.e., 0x1_3B88_B9D0. This + is indeed the value held in the FAR register. + +- The faulting address 0x1_3B88_B9D0 falls in the above-noted page (at + 0x1_3B88_B000), namely at offset 0x9D0. This is *beyond* the first 0x4F0 + bytes that the very tail of the "video_fb" module occupies at the front + of that page. + +For now, add a self-check that reports this bug (and prevents the crash by +skipping the write protection). + +Example log after the patch: + +> kern/dl.c:742:BUG: trying to protect pages outside of module allocation +> ("video_fb"): module base 0x13b87d000, size 0xe4f0; tramp/GOT base +> 0x13b88b000, size 0x1000 + +Signed-off-by: Laszlo Ersek +--- + grub-core/kern/dl.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 101e0794dd8..bad0ad4b945 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -682,7 +682,7 @@ grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) + #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) + grub_size_t arch_addralign = grub_arch_dl_min_alignment (); + grub_addr_t tgaddr; +- grub_uint64_t tgsz; ++ grub_size_t tgsz; + #endif + + grub_dprintf ("modules", "updating memory attributes for \"%s\"\n", +@@ -736,6 +736,15 @@ grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) + grub_dprintf ("modules", + "updating attributes for GOT and trampolines (\"%s\")\n", + mod->name); ++ if (tgaddr < (grub_addr_t)mod->base || ++ tgsz > (grub_addr_t)-1 - tgaddr || ++ tgaddr + tgsz > (grub_addr_t)mod->base + mod->sz) ++ return grub_error (GRUB_ERR_BUG, ++ "BUG: trying to protect pages outside of module " ++ "allocation (\"%s\"): module base %p, size 0x%" ++ PRIxGRUB_SIZE "; tramp/GOT base 0x%" PRIxGRUB_ADDR ++ ", size 0x%" PRIxGRUB_SIZE, ++ mod->name, mod->base, mod->sz, tgaddr, tgsz); + grub_update_mem_attrs (tgaddr, tgsz, GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_X, + GRUB_MEM_ATTR_W); + } diff --git a/0189-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch b/0189-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch new file mode 100644 index 00000000..9ccf4122 --- /dev/null +++ b/0189-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch @@ -0,0 +1,70 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Laszlo Ersek +Date: Fri, 7 Apr 2023 16:56:09 +0200 +Subject: [PATCH] grub_dl_load_segments(): page-align the tramp/GOT areas too + +The tramp/GOT write-protection in grub_dl_set_mem_attrs() requires that +the tramp/GOT areas of the module image *not* share a page with any other +memory allocations. Page-align the tramp/GOT areas, while satisfying their +intrinsic alignment requirements too. + +Fixes: 887f1d8fa976 (modules: load module sections at page-aligned addresses) +Fixes: ad1b904d325b (nx: set page permissions for loaded modules.) +Signed-off-by: Laszlo Ersek +--- + grub-core/kern/dl.c | 24 ++++++++++++++++-------- + 1 file changed, 16 insertions(+), 8 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index bad0ad4b945..c55f0ecf931 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -272,7 +272,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ + !defined (__loongarch__) + grub_size_t tramp; ++ grub_size_t tramp_align; + grub_size_t got; ++ grub_size_t got_align; + grub_err_t err; + #endif + char *ptr; +@@ -304,12 +306,18 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + err = grub_arch_dl_get_tramp_got_size (e, &tramp, &got); + if (err) + return err; +- tsize += ALIGN_UP (tramp, GRUB_ARCH_DL_TRAMP_ALIGN); +- if (talign < GRUB_ARCH_DL_TRAMP_ALIGN) +- talign = GRUB_ARCH_DL_TRAMP_ALIGN; +- tsize += ALIGN_UP (got, GRUB_ARCH_DL_GOT_ALIGN); +- if (talign < GRUB_ARCH_DL_GOT_ALIGN) +- talign = GRUB_ARCH_DL_GOT_ALIGN; ++ tramp_align = GRUB_ARCH_DL_TRAMP_ALIGN; ++ if (tramp_align < arch_addralign) ++ tramp_align = arch_addralign; ++ tsize += ALIGN_UP (tramp, tramp_align); ++ if (talign < tramp_align) ++ talign = tramp_align; ++ got_align = GRUB_ARCH_DL_GOT_ALIGN; ++ if (got_align < arch_addralign) ++ got_align = arch_addralign; ++ tsize += ALIGN_UP (got, got_align); ++ if (talign < got_align) ++ talign = got_align; + #endif + + #ifdef GRUB_MACHINE_EMU +@@ -370,11 +378,11 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) + } + #if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \ + !defined (__loongarch__) +- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN); ++ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, tramp_align); + mod->tramp = ptr; + mod->trampptr = ptr; + ptr += tramp; +- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_GOT_ALIGN); ++ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, got_align); + mod->got = ptr; + mod->gotptr = ptr; + ptr += got; diff --git a/0190-emu-Add-switch-root-to-grub-emu.patch b/0190-emu-Add-switch-root-to-grub-emu.patch new file mode 100644 index 00000000..3fabaae5 --- /dev/null +++ b/0190-emu-Add-switch-root-to-grub-emu.patch @@ -0,0 +1,330 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Fri, 31 Mar 2023 20:47:58 +0200 +Subject: [PATCH] emu: Add switch-root to grub-emu + +If the kernel running grub emu is the same as the one we want to +boot, it makes sense that we just switch-root instead of kexec +the same kernel again by doing grub2-emu --switch-root + +Signed-off-by: Nicolas Frayer +--- + grub-core/kern/emu/main.c | 5 +- + grub-core/kern/emu/misc.c | 13 +++ + grub-core/loader/emu/linux.c | 209 +++++++++++++++++++++++++++++++++++++++++-- + include/grub/emu/exec.h | 2 +- + include/grub/emu/misc.h | 2 + + 5 files changed, 223 insertions(+), 8 deletions(-) + +diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c +index 38c1576a2ef..61b3181775b 100644 +--- a/grub-core/kern/emu/main.c ++++ b/grub-core/kern/emu/main.c +@@ -108,6 +108,7 @@ static struct argp_option options[] = { + {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, + {"hold", 'H', N_("SECS"), OPTION_ARG_OPTIONAL, N_("wait until a debugger will attach"), 0}, + {"kexec", 'X', 0, 0, N_("use kexec to boot Linux kernels via systemctl (pass twice to enable dangerous fallback to non-systemctl)."), 0}, ++ {"switch-root", 'W', 0, 0, N_("use switch-root to only switch root filesystem without restarting the kernel."), 0}, + { 0, 0, 0, 0, 0, 0 } + }; + +@@ -168,7 +169,9 @@ argp_parser (int key, char *arg, struct argp_state *state) + case 'X': + grub_util_set_kexecute (); + break; +- ++ case 'W': ++ grub_util_set_switch_root (); ++ break; + case ARGP_KEY_ARG: + { + /* Too many arguments. */ +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index d145e5796b3..7b9731b7efa 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -40,6 +40,7 @@ + + int verbosity; + int kexecute; ++int switchroot = 0; + + void + grub_util_warn (const char *fmt, ...) +@@ -231,3 +232,15 @@ grub_util_get_kexecute (void) + { + return kexecute; + } ++ ++void ++grub_util_set_switch_root (void) ++{ ++ switchroot = 1; ++} ++ ++int ++grub_util_get_switch_root (void) ++{ ++ return switchroot; ++} +diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c +index 7de3f7f8610..6feb0412c58 100644 +--- a/grub-core/loader/emu/linux.c ++++ b/grub-core/loader/emu/linux.c +@@ -15,7 +15,6 @@ + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ +- + #include + #include + #include +@@ -33,6 +32,196 @@ static char *kernel_path; + static char *initrd_path; + static char *boot_cmdline; + ++static grub_err_t ++grub_switch_root (void) ++{ ++ char *tmp = NULL; ++ char *options_cmd = NULL; ++ char *options = NULL; ++ char *subvol = NULL; ++ char *root_uuid = NULL; ++ char *kernel_release = NULL; ++ grub_err_t rc = GRUB_ERR_NONE; ++ const char *subvol_param = "subvol="; ++ const char *kernel_release_prefix = "/boot/vmlinuz-"; ++ const char *root_prefix = "root="; ++ const char *systemctl[] = {"systemctl", "--force", "switch-root", "/sysroot", NULL}; ++ const char *mountrootfs[] = {"mount", root_uuid, "/sysroot", options_cmd, options, NULL}; ++ const char *unamer[] = {"uname", "-r", NULL}; ++ char *uname_buf = NULL; ++ int i = 0; ++ ++ /* Extract the kernel release tag from kernel_path */ ++ if (!kernel_path) ++ { ++ rc = GRUB_ERR_BAD_ARGUMENT; ++ grub_dprintf ("linux", "switch_root: No kernel_path found\n"); ++ goto out; ++ } ++ ++ if ((kernel_release = grub_xasprintf ("%s", (kernel_path + grub_strlen (kernel_release_prefix)))) == NULL) ++ { ++ grub_dprintf ("linux", "switch_root: Failed to allocate memory\n"); ++ rc = GRUB_ERR_BAD_ARGUMENT; ++ goto out; ++ } ++ ++ ++ /* Check for kernel mismatch */ ++ /* Retrieve the current kernel relase tag */ ++ grub_util_exec_redirect (unamer, NULL, "/tmp/version"); ++ ++ grub_file_t f = grub_file_open ("/tmp/version", GRUB_FILE_TYPE_FS_SEARCH); ++ ++ if (f == NULL) ++ { ++ grub_dprintf ("linux", "failed opening file.\n"); ++ rc = GRUB_ERR_FILE_NOT_FOUND; ++ goto out; ++ } ++ ++ if ((uname_buf = grub_malloc (f->size)) == NULL) ++ { ++ grub_dprintf ("linux", "switch_root: Failed to allocate memory\n"); ++ rc = GRUB_ERR_OUT_OF_MEMORY; ++ goto out; ++ } ++ ++ if (grub_file_read (f, uname_buf, f->size) < 0) ++ { ++ grub_dprintf ("linux", "switch_root: failed to read from file\n"); ++ rc = GRUB_ERR_FILE_READ_ERROR; ++ goto out; ++ } ++ ++ grub_file_close (f); ++ ++ if (grub_strstr (uname_buf, kernel_release) == NULL) ++ { ++ grub_dprintf ("linux", "switch_root: kernel mismatch, not performing switch-root ...\n"); ++ rc = GRUB_ERR_NO_KERNEL; ++ goto out; ++ } ++ ++ /* Extract the root partition from boot_cmdline */ ++ if (!boot_cmdline) ++ { ++ rc = GRUB_ERR_BAD_ARGUMENT; ++ goto out; ++ } ++ ++ tmp = grub_strdup (boot_cmdline); ++ ++ if (tmp == NULL) ++ { ++ rc = GRUB_ERR_OUT_OF_MEMORY; ++ goto out; ++ } ++ ++ if ((root_uuid = grub_strstr (tmp, root_prefix)) == NULL) ++ { ++ rc = GRUB_ERR_BAD_ARGUMENT; ++ grub_dprintf ("linux", "switch_root: Can't find rootfs\n"); ++ goto out; ++ } ++ ++ root_uuid += grub_strlen (root_prefix); ++ ++ while (root_uuid[i] != ' ' && root_uuid[i] != '\0') ++ i++; ++ ++ root_uuid[i] = '\0'; ++ ++ /* Allocate a new buffer holding root_uuid */ ++ root_uuid = grub_xasprintf ("%s", root_uuid); ++ ++ if (root_uuid == NULL) ++ { ++ grub_dprintf ("linux", "switch_root: Failed to allocated memory\n"); ++ rc = GRUB_ERR_OUT_OF_MEMORY; ++ goto out; ++ } ++ ++ /* Check for subvol parameter */ ++ grub_strcpy (tmp, boot_cmdline); ++ ++ if ((subvol = grub_strstr(tmp, subvol_param)) != NULL) ++ { ++ i = 0; ++ ++ while (subvol[i] != ' ' && subvol[i] != '\0') ++ i++; ++ ++ subvol[i] = '\0'; ++ ++ /* Allocate a new buffer holding subvol */ ++ subvol = grub_xasprintf("%s", subvol); ++ ++ if (subvol == NULL) ++ { ++ grub_dprintf ("linux", "switch_root: Failed to allocated memory\n"); ++ rc = GRUB_ERR_OUT_OF_MEMORY; ++ goto out; ++ } ++ ++ options_cmd = grub_xasprintf("%s", "-o"); ++ options = grub_xasprintf("%s", subvol); ++ } ++ ++ if (options == NULL) ++ { ++ mountrootfs[3] = NULL; ++ } ++ else ++ { ++ mountrootfs[3] = options_cmd; ++ mountrootfs[4] = options; ++ } ++ ++ mountrootfs[1] = root_uuid; ++ ++ grub_dprintf ("linux", "Executing:\n"); ++ grub_dprintf ("linux", "%s %s %s %s %s\n", mountrootfs[0], mountrootfs[1], ++ mountrootfs[2], mountrootfs[3], mountrootfs[4]); ++ ++ /* Mount the rootfs */ ++ rc = grub_util_exec (mountrootfs); ++ ++ if (rc != GRUB_ERR_NONE) ++ { ++ grub_dprintf ("linux", "switch_root: Failed.\n"); ++ rc = GRUB_ERR_INVALID_COMMAND; ++ goto out; ++ } ++ ++ grub_dprintf ("linux", "Done.\n"); ++ ++ grub_dprintf ("linux", "%s %s %s %s\n", systemctl[0], systemctl[1], ++ systemctl[2], systemctl[3]); ++ ++ /* Switch root */ ++ rc = grub_util_exec (systemctl); ++ ++ if (rc != GRUB_ERR_NONE) ++ { ++ grub_dprintf ("linux", "switch_root: Failed.\n"); ++ rc = GRUB_ERR_INVALID_COMMAND; ++ goto out; ++ } ++ ++ grub_dprintf ("linux", "Done.\n"); ++ ++out: ++ grub_free (tmp); ++ grub_free (options_cmd); ++ grub_free (options); ++ grub_free (subvol); ++ grub_free (root_uuid); ++ grub_free (uname_buf); ++ grub_free (kernel_release); ++ return rc; ++} ++ + static grub_err_t + grub_linux_boot (void) + { +@@ -51,12 +240,20 @@ grub_linux_boot (void) + else + initrd_param = grub_xasprintf ("%s", ""); + +- grub_dprintf ("linux", "%serforming 'kexec -la %s %s %s'\n", +- (kexecute) ? "P" : "Not p", +- kernel_path, initrd_param, boot_cmdline); ++ if (grub_util_get_switch_root() == 1) ++ { ++ rc = grub_switch_root(); ++ if (rc != GRUB_ERR_NONE) ++ grub_fatal (N_("Failed to execute switch_root\n")); ++ } ++ else if (kexecute) ++ { ++ grub_dprintf ("linux", "%serforming 'kexec -la %s %s %s'\n", ++ (kexecute) ? "P" : "Not p", ++ kernel_path, initrd_param, boot_cmdline); + +- if (kexecute) +- rc = grub_util_exec (kexec); ++ rc = grub_util_exec (kexec); ++ } + + grub_free (initrd_param); + +diff --git a/include/grub/emu/exec.h b/include/grub/emu/exec.h +index 1b61b4a2e5d..e82f13215e0 100644 +--- a/include/grub/emu/exec.h ++++ b/include/grub/emu/exec.h +@@ -36,7 +36,7 @@ grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, + int + EXPORT_FUNC(grub_util_exec) (const char *const *argv); + int +-grub_util_exec_redirect (const char *const *argv, const char *stdin_file, ++EXPORT_FUNC(grub_util_exec_redirect) (const char *const *argv, const char *stdin_file, + const char *stdout_file); + int + grub_util_exec_redirect_null (const char *const *argv); +diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h +index 01056954b96..f3a712a8b2f 100644 +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -59,6 +59,8 @@ void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format + + void EXPORT_FUNC(grub_util_set_kexecute) (void); + int EXPORT_FUNC(grub_util_get_kexecute) (void) WARN_UNUSED_RESULT; ++void EXPORT_FUNC(grub_util_set_switch_root) (void); ++int EXPORT_FUNC(grub_util_get_switch_root) (void); + + grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void); + diff --git a/0191-util-Enable-default-kernel-for-updates.patch b/0191-util-Enable-default-kernel-for-updates.patch new file mode 100644 index 00000000..5682df04 --- /dev/null +++ b/0191-util-Enable-default-kernel-for-updates.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Marta Lewandowska +Date: Wed, 24 May 2023 11:22:47 +0200 +Subject: [PATCH] util: Enable default kernel for updates + +Several kernel variants can be installed on a system in parallel. +In order to allow the user to choose which kernel will be set to +default after an update, re-enable grub's usage of DEFAULTKERNEL as +set in /etc/sysconfig/kernel + +Signed-off-by: Marta Lewandowska +--- + util/grub-get-kernel-settings.in | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in +index 7e87dfccc0e..f71bc64360b 100644 +--- a/util/grub-get-kernel-settings.in ++++ b/util/grub-get-kernel-settings.in +@@ -68,6 +68,14 @@ if test -f /etc/sysconfig/kernel ; then + . /etc/sysconfig/kernel + fi + ++GRUB_DEFAULT_KERNEL_TYPE=${DEFAULTKERNEL/-core/} ++if [ "$GRUB_DEFAULT_KERNEL_TYPE" != "kernel" ]; then ++ echo GRUB_NON_STANDARD_KERNEL=true ++ echo export GRUB_NON_STANDARD_KERNEL ++ GRUB_DEFAULT_KERNEL_TYPE=${GRUB_DEFAULT_KERNEL_TYPE/kernel-/} ++fi ++echo GRUB_DEFAULT_KERNEL_TYPE=$GRUB_DEFAULT_KERNEL_TYPE ++echo export GRUB_DEFAULT_KERNEL_TYPE + if [ "$MAKEDEBUG" = "yes" ]; then + echo GRUB_LINUX_MAKE_DEBUG=true + echo export GRUB_LINUX_MAKE_DEBUG diff --git a/0192-efi-http-change-uint32_t-to-uintn_t.patch b/0192-efi-http-change-uint32_t-to-uintn_t.patch new file mode 100644 index 00000000..ec22c360 --- /dev/null +++ b/0192-efi-http-change-uint32_t-to-uintn_t.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Keng-Yu Lin +Date: Wed, 26 Apr 2023 01:43:16 -0400 +Subject: [PATCH] efi/http: change uint32_t to uintn_t + +Modify UINT32 to UINTN in EFI_HTTP_MESSAGE to +be UEFI 2.9 compliant. + +Signed-off-by: Keng-Yu Lin +Signed-off-by: Nicolas Frayer +--- + include/grub/efi/http.h | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/include/grub/efi/http.h b/include/grub/efi/http.h +index c5e9a89f505..ad164ba1913 100644 +--- a/include/grub/efi/http.h ++++ b/include/grub/efi/http.h +@@ -171,9 +171,9 @@ typedef struct { + grub_efi_http_request_data_t *request; + grub_efi_http_response_data_t *response; + } data; +- grub_efi_uint32_t header_count; ++ grub_efi_uintn_t header_count; + grub_efi_http_header_t *headers; +- grub_efi_uint32_t body_length; ++ grub_efi_uintn_t body_length; + void *body; + } grub_efi_http_message_t; + diff --git a/0193-Add-Install-section-to-aux-systemd-units.patch b/0193-Add-Install-section-to-aux-systemd-units.patch new file mode 100644 index 00000000..69812255 --- /dev/null +++ b/0193-Add-Install-section-to-aux-systemd-units.patch @@ -0,0 +1,52 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Christian Glombek +Date: Wed, 9 Aug 2023 18:11:25 +0200 +Subject: [PATCH] Add [Install] section to aux systemd units + +Currently in Fedora, these services are statically enabled by symlinks, +with no other way to disable them than to manually delete those symlinks. +This is problematic in Fedora IoT, where grub-boot-success.timer is +not supposed to be enabled. + +This change adds `[Install]` sections to all systemd units that are +currently enabled statically, so that they can be enabled dynamically +via presets or manually instead. +--- + docs/grub-boot-indeterminate.service | 3 +++ + docs/grub-boot-success.timer | 3 +++ + util/systemd/grub-systemd-integration.service.in | 3 +++ + 3 files changed, 9 insertions(+) + +diff --git a/docs/grub-boot-indeterminate.service b/docs/grub-boot-indeterminate.service +index 6c8dcb186b6..5bcb474a3d3 100644 +--- a/docs/grub-boot-indeterminate.service ++++ b/docs/grub-boot-indeterminate.service +@@ -9,3 +9,6 @@ Before=system-update-pre.target + [Service] + Type=oneshot + ExecStart=/usr/bin/grub2-editenv - incr boot_indeterminate ++ ++[Install] ++WantedBy=system-update.target +diff --git a/docs/grub-boot-success.timer b/docs/grub-boot-success.timer +index 406f1720056..1d124cccc14 100644 +--- a/docs/grub-boot-success.timer ++++ b/docs/grub-boot-success.timer +@@ -5,3 +5,6 @@ ConditionVirtualization=!container + + [Timer] + OnActiveSec=2min ++ ++[Install] ++WantedBy=timers.target +diff --git a/util/systemd/grub-systemd-integration.service.in b/util/systemd/grub-systemd-integration.service.in +index c81fb594ce1..22ca1ca4885 100644 +--- a/util/systemd/grub-systemd-integration.service.in ++++ b/util/systemd/grub-systemd-integration.service.in +@@ -6,3 +6,6 @@ ConditionPathExists=/run/systemd/reboot-to-boot-loader-menu + + [Service] + ExecStart=@libexecdir@/@grubdirname@/systemd-integration.sh ++ ++[Install] ++WantedBy=reboot.target diff --git a/0194-Fix-missing-include-in-ofdisk.c.patch b/0194-Fix-missing-include-in-ofdisk.c.patch new file mode 100644 index 00000000..a2b90476 --- /dev/null +++ b/0194-Fix-missing-include-in-ofdisk.c.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 29 Sep 2023 10:56:11 -0400 +Subject: [PATCH] Fix missing #include in ofdisk.c + +Recently we started building with -Werror=implicit-function-declaration, +and discovered that ofdisk.c is missing an include to declare +grub_env_get(). + +This patch adds that #include. + +Signed-off-by: Peter Jones +--- + grub-core/disk/ieee1275/ofdisk.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index b413822bb87..57624fde55c 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + static char *last_devpath; + static grub_ieee1275_ihandle_t last_ihandle; diff --git a/0195-add-flag-to-only-search-root-dev.patch b/0195-add-flag-to-only-search-root-dev.patch new file mode 100644 index 00000000..9061f39b --- /dev/null +++ b/0195-add-flag-to-only-search-root-dev.patch @@ -0,0 +1,160 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Marta Lewandowska +Date: Mon, 9 Oct 2023 08:53:18 +0200 +Subject: [PATCH] add flag to only search root dev + +fixes bz#2223437 + +Signed-off-by: Marta Lewandowska +--- + grub-core/commands/search.c | 36 ++++++++++++++++++++++++++++++++++++ + grub-core/commands/search_wrap.c | 5 +++++ + grub-core/kern/misc.c | 30 ++++++++++++++++++++++++++++++ + include/grub/misc.h | 1 + + include/grub/search.h | 3 ++- + 5 files changed, 74 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c +index 263f1501cdf..db8692ffbfb 100644 +--- a/grub-core/commands/search.c ++++ b/grub-core/commands/search.c +@@ -86,6 +86,42 @@ iterate_device (const char *name, void *data) + grub_device_close (dev); + } + ++ /* Skip it if it's not the root device when requested. */ ++ if (ctx->flags & SEARCH_FLAGS_ROOTDEV_ONLY) ++ { ++ const char *root_dev; ++ root_dev = grub_env_get ("root"); ++ if (root_dev != NULL && *root_dev != '\0') ++ { ++ char *root_disk = grub_malloc (grub_strlen(root_dev) + 1); ++ char *name_disk = grub_malloc (grub_strlen(name) + 1); ++ char *rem_1 = grub_malloc(grub_strlen(root_dev) + 1); ++ char *rem_2 = grub_malloc(grub_strlen(name) + 1); ++ ++ if (root_disk != NULL && name_disk != NULL && ++ rem_1 != NULL && rem_2 != NULL) ++ { ++ /* get just the disk name; partitions will be different. */ ++ grub_str_sep (root_dev, root_disk, ',', rem_1); ++ grub_str_sep (name, name_disk, ',', rem_2); ++ if (root_disk != NULL && *root_disk != '\0' && ++ name_disk != NULL && *name_disk != '\0') ++ if (grub_strcmp(root_disk, name_disk) != 0) ++ { ++ grub_free (root_disk); ++ grub_free (name_disk); ++ grub_free (rem_1); ++ grub_free (rem_2); ++ return 0; ++ } ++ } ++ grub_free (root_disk); ++ grub_free (name_disk); ++ grub_free (rem_1); ++ grub_free (rem_2); ++ } ++ } ++ + #ifdef DO_SEARCH_FS_UUID + #define compare_fn grub_strcasecmp + #else +diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c +index 318581f3b1e..4fe6440c65b 100644 +--- a/grub-core/commands/search_wrap.c ++++ b/grub-core/commands/search_wrap.c +@@ -41,6 +41,7 @@ static const struct grub_arg_option options[] = + ARG_TYPE_STRING}, + {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0}, + {"efidisk-only", 0, 0, N_("Only probe EFI disks."), 0, 0}, ++ {"root-dev-only", 'r', 0, N_("Only probe root device."), 0, 0}, + {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT. If HINT ends in comma, " + "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, +@@ -75,6 +76,7 @@ enum options + SEARCH_SET, + SEARCH_NO_FLOPPY, + SEARCH_EFIDISK_ONLY, ++ SEARCH_ROOTDEV_ONLY, + SEARCH_HINT, + SEARCH_HINT_IEEE1275, + SEARCH_HINT_BIOS, +@@ -189,6 +191,9 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) + if (state[SEARCH_EFIDISK_ONLY].set) + flags |= SEARCH_FLAGS_EFIDISK_ONLY; + ++ if (state[SEARCH_ROOTDEV_ONLY].set) ++ flags |= SEARCH_FLAGS_ROOTDEV_ONLY; ++ + if (state[SEARCH_LABEL].set) + grub_search_label (id, var, flags, hints, nhints); + else if (state[SEARCH_FS_UUID].set) +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index f607244e7ae..96ab7c96b52 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -645,6 +645,36 @@ grub_reverse (char *str) + } + } + ++/* Separate string into two parts, broken up by delimiter delim. */ ++void ++grub_str_sep (const char *s, char *p, char delim, char *r) ++{ ++ char* t = grub_strndup(s, grub_strlen(s)); ++ ++ if (t != NULL && *t != '\0') ++ { ++ char* tmp = t; ++ ++ while (((*p = *t) != '\0') && ((*p = *t) != delim)) ++ { ++ p++; ++ t++; ++ } ++ *p = '\0'; ++ ++ if (*t != '\0') ++ { ++ t++; ++ while ((*r++ = *t++) != '\0') ++ ; ++ *r = '\0'; ++ } ++ grub_free (tmp); ++ } ++ else ++ grub_free (t); ++} ++ + /* Divide N by D, return the quotient, and store the remainder in *R. */ + grub_uint64_t + grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) +diff --git a/include/grub/misc.h b/include/grub/misc.h +index c3c735371dc..3e9a00f0a9c 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -343,6 +343,7 @@ char *EXPORT_FUNC(grub_strdup) (const char *s) WARN_UNUSED_RESULT; + char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n) WARN_UNUSED_RESULT; + void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n); + grub_size_t EXPORT_FUNC(grub_strlen) (const char *s) WARN_UNUSED_RESULT; ++void EXPORT_FUNC(grub_str_sep) (const char *s, char *p, char delim, char *r); + + /* Replace all `ch' characters of `input' with `with' and copy the + result into `output'; return EOS address of `output'. */ +diff --git a/include/grub/search.h b/include/grub/search.h +index ffd2411ca1a..9343c66b134 100644 +--- a/include/grub/search.h ++++ b/include/grub/search.h +@@ -23,7 +23,8 @@ enum search_flags + { + SEARCH_FLAGS_NONE = 0, + SEARCH_FLAGS_NO_FLOPPY = 1, +- SEARCH_FLAGS_EFIDISK_ONLY = 2 ++ SEARCH_FLAGS_EFIDISK_ONLY = 2, ++ SEARCH_FLAGS_ROOTDEV_ONLY = 4 + }; + + void grub_search_fs_file (const char *key, const char *var, diff --git a/0196-cryptdisk-fix-incorrect-sign-comparison.patch b/0196-cryptdisk-fix-incorrect-sign-comparison.patch new file mode 100644 index 00000000..dbb4fc2e --- /dev/null +++ b/0196-cryptdisk-fix-incorrect-sign-comparison.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 15:44:27 -0500 +Subject: [PATCH] cryptdisk: fix incorrect sign comparison + +grub_util_get_fd_size() returns a signed integer, but we're assigning it +to an unsigned integer and then testing against -1. That's wrong. + +This patch makes the variable a signed integer. + +Signed-off-by: Peter Jones +--- + grub-core/disk/cryptodisk.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c +index 2246af51b6a..98e176a139c 100644 +--- a/grub-core/disk/cryptodisk.c ++++ b/grub-core/disk/cryptodisk.c +@@ -721,7 +721,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk) + #ifdef GRUB_UTIL + if (dev->cheat) + { +- grub_uint64_t cheat_dev_size; ++ grub_int64_t cheat_dev_size; + unsigned int cheat_log_sector_size; + + if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd)) diff --git a/0197-grub-install-fix-a-sign-comparison-error.patch b/0197-grub-install-fix-a-sign-comparison-error.patch new file mode 100644 index 00000000..7b63b082 --- /dev/null +++ b/0197-grub-install-fix-a-sign-comparison-error.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 15:45:57 -0500 +Subject: [PATCH] grub-install: fix a sign comparison error + +This is a trivial sign comparison fix. + +Signed-off-by: Peter Jones +--- + util/grub-install-common.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub-install-common.c b/util/grub-install-common.c +index b58539111da..67afc2eedf4 100644 +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c +@@ -368,7 +368,7 @@ char *grub_install_themes_directory = NULL; + int + grub_install_is_short_mbrgap_supported (void) + { +- int i, j; ++ unsigned int i, j; + static const char *whitelist[] = + { + "part_msdos", "biosdisk", "affs", "afs", "bfs", "archelp", diff --git a/0198-grub-mount-work-around-bad-integer-comparison.patch b/0198-grub-mount-work-around-bad-integer-comparison.patch new file mode 100644 index 00000000..d303801a --- /dev/null +++ b/0198-grub-mount-work-around-bad-integer-comparison.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 15:54:31 -0500 +Subject: [PATCH] grub-mount: work around bad integer comparison. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +gcc says: + + util/grub-mount.c: In function ‘fuse_read’: + util/grub-mount.c:273:11: error: comparison of integer expressions of different signedness: ‘off_t’ {aka ‘long int’} and ‘grub_off_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] + 273 | if (off > file->size) + | ^ + +This is happening because grub_off_t is unsigned but the system's off_t is +signed. + +That's too much work to fix today, so this patch works around it with +tests and typecasting. + +Signed-off-by: Peter Jones +--- + util/grub-mount.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/util/grub-mount.c b/util/grub-mount.c +index bf4c8b891be..d369e21666e 100644 +--- a/util/grub-mount.c ++++ b/util/grub-mount.c +@@ -269,11 +269,17 @@ fuse_read (const char *path, char *buf, size_t sz, off_t off, + { + grub_file_t file = files[fi->fh]; + grub_ssize_t size; ++ grub_off_t offset; + +- if (off > file->size) ++ if (off < 0) + return -EINVAL; + +- file->offset = off; ++ if ((grub_off_t)off > file->size) ++ return -EINVAL; ++ ++ offset = (grub_off_t)off; ++ ++ file->offset = offset; + + size = grub_file_read (file, buf, sz); + if (size < 0) diff --git a/0198-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch b/0198-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch deleted file mode 100644 index 52fa9d23..00000000 --- a/0198-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch +++ /dev/null @@ -1,75 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Wed, 14 Apr 2021 20:10:23 +1000 -Subject: [PATCH] ieee1275: drop HEAP_MAX_ADDR, HEAP_MIN_SIZE - -HEAP_MAX_ADDR is confusing. Currently it is set to 32MB, except -on ieee1275 on x86, where it is 64MB. - -There is a comment which purports to explain it: - -/* If possible, we will avoid claiming heap above this address, because it - seems to cause relocation problems with OSes that link at 4 MiB */ - -This doesn't make a lot of sense when the constants are well above 4MB -already. It was not always this way. Prior to -commit 7b5d0fe4440c ("Increase heap limit") in 2010, HEAP_MAX_SIZE and -HEAP_MAX_ADDR were indeed 4MB. However, when the constants were increased -the comment was left unchanged. - -It's been over a decade. It doesn't seem like we have problems with -claims over 4MB on powerpc or x86 ieee1275. (sparc does things completely -differently and never used the constant.) - -Drop the constant and the check. - -The only use of HEAP_MIN_SIZE was to potentially override the -HEAP_MAX_ADDR check. It is now unused. Remove it. - -Signed-off-by: Daniel Axtens ---- - grub-core/kern/ieee1275/init.c | 17 ----------------- - 1 file changed, 17 deletions(-) - -diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index fc7d9712729..0dcd114ce54 100644 ---- a/grub-core/kern/ieee1275/init.c -+++ b/grub-core/kern/ieee1275/init.c -@@ -46,9 +46,6 @@ - #endif - #include - --/* The minimal heap size we can live with. */ --#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) -- - /* The maximum heap size we're going to claim */ - #ifdef __i386__ - #define HEAP_MAX_SIZE (unsigned long) (64 * 1024 * 1024) -@@ -56,14 +53,6 @@ - #define HEAP_MAX_SIZE (unsigned long) (32 * 1024 * 1024) - #endif - --/* If possible, we will avoid claiming heap above this address, because it -- seems to cause relocation problems with OSes that link at 4 MiB */ --#ifdef __i386__ --#define HEAP_MAX_ADDR (unsigned long) (64 * 1024 * 1024) --#else --#define HEAP_MAX_ADDR (unsigned long) (32 * 1024 * 1024) --#endif -- - extern char _end[]; - - #ifdef __sparc__ -@@ -185,12 +174,6 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - if (*total + len > HEAP_MAX_SIZE) - len = HEAP_MAX_SIZE - *total; - -- /* Avoid claiming anything above HEAP_MAX_ADDR, if possible. */ -- if ((addr < HEAP_MAX_ADDR) && /* if it's too late, don't bother */ -- (addr + len > HEAP_MAX_ADDR) && /* if it wasn't available anyway, don't bother */ -- (*total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE)) /* only limit ourselves when we can afford to */ -- len = HEAP_MAX_ADDR - addr; -- - /* In theory, firmware should already prevent this from happening by not - listing our own image in /memory/available. The check below is intended - as a safeguard in case that doesn't happen. However, it doesn't protect diff --git a/0199-ieee1275-claim-more-memory.patch b/0199-ieee1275-claim-more-memory.patch deleted file mode 100644 index 001a9df0..00000000 --- a/0199-ieee1275-claim-more-memory.patch +++ /dev/null @@ -1,252 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Wed, 15 Apr 2020 23:28:29 +1000 -Subject: [PATCH] ieee1275: claim more memory - -On powerpc-ieee1275, we are running out of memory trying to verify -anything. This is because: - - - we have to load an entire file into memory to verify it. This is - extremely difficult to change with appended signatures. - - We only have 32MB of heap. - - Distro kernels are now often around 30MB. - -So we want to claim more memory from OpenFirmware for our heap. - -There are some complications: - - - The grub mm code isn't the only thing that will make claims on - memory from OpenFirmware: - - * PFW/SLOF will have claimed some for their own use. - - * The ieee1275 loader will try to find other bits of memory that we - haven't claimed to place the kernel and initrd when we go to boot. - - * Once we load Linux, it will also try to claim memory. It claims - memory without any reference to /memory/available, it just starts - at min(top of RMO, 768MB) and works down. So we need to avoid this - area. See arch/powerpc/kernel/prom_init.c as of v5.11. - - - The smallest amount of memory a ppc64 KVM guest can have is 256MB. - It doesn't work with distro kernels but can work with custom kernels. - We should maintain support for that. (ppc32 can boot with even less, - and we shouldn't break that either.) - - - Even if a VM has more memory, the memory OpenFirmware makes available - as Real Memory Area can be restricted. A freshly created LPAR on a - PowerVM machine is likely to have only 256MB available to OpenFirmware - even if it has many gigabytes of memory allocated. - -EFI systems will attempt to allocate 1/4th of the available memory, -clamped to between 1M and 1600M. That seems like a good sort of -approach, we just need to figure out if 1/4 is the right fraction -for us. - -We don't know in advance how big the kernel and initrd are going to be, -which makes figuring out how much memory we can take a bit tricky. - -To figure out how much memory we should leave unused, I looked at: - - - an Ubuntu 20.04.1 ppc64le pseries KVM guest: - vmlinux: ~30MB - initrd: ~50MB - - - a RHEL8.2 ppc64le pseries KVM guest: - vmlinux: ~30MB - initrd: ~30MB - -Ubuntu VMs struggle to boot with just 256MB under SLOF. -RHEL likewise has a higher minimum supported memory figure. -So lets first consider a distro kernel and 512MB of addressible memory. -(This is the default case for anything booting under PFW.) Say we lose -131MB to PFW (based on some tests). This leaves us 381MB. 1/4 of 381MB -is ~95MB. That should be enough to verify a 30MB vmlinux and should -leave plenty of space to load Linux and the initrd. - -If we consider 256MB of RMA under PFW, we have just 125MB remaining. 1/4 -of that is a smidge under 32MB, which gives us very poor odds of verifying -a distro-sized kernel. However, if we need 80MB just to put the kernel -and initrd in memory, we can't claim any more than 45MB anyway. So 1/4 -will do. We'll come back to this later. - -grub is always built as a 32-bit binary, even if it's loading a ppc64 -kernel. So we can't address memory beyond 4GB. This gives a natural cap -of 1GB for powerpc-ieee1275. - -Also apply this 1/4 approach to i386-ieee1275, but keep the 32MB cap. - -make check still works for both i386 and powerpc and I've booted -powerpc grub with this change under SLOF and PFW. - -Signed-off-by: Daniel Axtens ---- - grub-core/kern/ieee1275/init.c | 81 +++++++++++++++++++++++++++++++++--------- - docs/grub-dev.texi | 6 ++-- - 2 files changed, 69 insertions(+), 18 deletions(-) - -diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index 0dcd114ce54..c61d91a0285 100644 ---- a/grub-core/kern/ieee1275/init.c -+++ b/grub-core/kern/ieee1275/init.c -@@ -46,11 +46,12 @@ - #endif - #include - --/* The maximum heap size we're going to claim */ -+/* The maximum heap size we're going to claim. Not used by sparc. -+ We allocate 1/4 of the available memory under 4G, up to this limit. */ - #ifdef __i386__ - #define HEAP_MAX_SIZE (unsigned long) (64 * 1024 * 1024) --#else --#define HEAP_MAX_SIZE (unsigned long) (32 * 1024 * 1024) -+#else // __powerpc__ -+#define HEAP_MAX_SIZE (unsigned long) (1 * 1024 * 1024 * 1024) - #endif - - extern char _end[]; -@@ -147,16 +148,45 @@ grub_claim_heap (void) - + GRUB_KERNEL_MACHINE_STACK_SIZE), 0x200000); - } - #else --/* Helper for grub_claim_heap. */ -+/* Helper for grub_claim_heap on powerpc. */ -+static int -+heap_size (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, -+ void *data) -+{ -+ grub_uint32_t total = *(grub_uint32_t *)data; -+ -+ if (type != GRUB_MEMORY_AVAILABLE) -+ return 0; -+ -+ /* Do not consider memory beyond 4GB */ -+ if (addr > 0xffffffffUL) -+ return 0; -+ -+ if (addr + len > 0xffffffffUL) -+ len = 0xffffffffUL - addr; -+ -+ total += len; -+ *(grub_uint32_t *)data = total; -+ -+ return 0; -+} -+ - static int - heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - void *data) - { -- unsigned long *total = data; -+ grub_uint32_t total = *(grub_uint32_t *)data; - - if (type != GRUB_MEMORY_AVAILABLE) - return 0; - -+ /* Do not consider memory beyond 4GB */ -+ if (addr > 0xffffffffUL) -+ return 0; -+ -+ if (addr + len > 0xffffffffUL) -+ len = 0xffffffffUL - addr; -+ - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM)) - { - if (addr + len <= 0x180000) -@@ -170,10 +200,6 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - } - len -= 1; /* Required for some firmware. */ - -- /* Never exceed HEAP_MAX_SIZE */ -- if (*total + len > HEAP_MAX_SIZE) -- len = HEAP_MAX_SIZE - *total; -- - /* In theory, firmware should already prevent this from happening by not - listing our own image in /memory/available. The check below is intended - as a safeguard in case that doesn't happen. However, it doesn't protect -@@ -185,6 +211,18 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - len = 0; - } - -+ /* If this block contains 0x30000000 (768MB), do not claim below that. -+ Linux likes to claim memory at min(RMO top, 768MB) and works down -+ without reference to /memory/available. */ -+ if ((addr < 0x30000000) && ((addr + len) > 0x30000000)) -+ { -+ len = len - (0x30000000 - addr); -+ addr = 0x30000000; -+ } -+ -+ if (len > total) -+ len = total; -+ - if (len) - { - grub_err_t err; -@@ -193,10 +231,12 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - if (err) - return err; - grub_mm_init_region ((void *) (grub_addr_t) addr, len); -+ total -= len; - } - -- *total += len; -- if (*total >= HEAP_MAX_SIZE) -+ *(grub_uint32_t *)data = total; -+ -+ if (total == 0) - return 1; - - return 0; -@@ -205,13 +245,22 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - static void - grub_claim_heap (void) - { -- unsigned long total = 0; -+ grub_uint32_t total = 0; - - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM)) -- heap_init (GRUB_IEEE1275_STATIC_HEAP_START, GRUB_IEEE1275_STATIC_HEAP_LEN, -- 1, &total); -- else -- grub_machine_mmap_iterate (heap_init, &total); -+ { -+ heap_init (GRUB_IEEE1275_STATIC_HEAP_START, GRUB_IEEE1275_STATIC_HEAP_LEN, -+ 1, &total); -+ return; -+ } -+ -+ grub_machine_mmap_iterate (heap_size, &total); -+ -+ total = total / 4; -+ if (total > HEAP_MAX_SIZE) -+ total = HEAP_MAX_SIZE; -+ -+ grub_machine_mmap_iterate (heap_init, &total); - } - #endif - -diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi -index 19f708ee662..90083772c8a 100644 ---- a/docs/grub-dev.texi -+++ b/docs/grub-dev.texi -@@ -1047,7 +1047,9 @@ space is limited to 4GiB. GRUB allocates pages from EFI for its heap, at most - 1.6 GiB. - - On i386-ieee1275 and powerpc-ieee1275 GRUB uses same stack as IEEE1275. --It allocates at most 32MiB for its heap. -+ -+On i386-ieee1275, GRUB allocates at most 32MiB for its heap. On -+powerpc-ieee1275, GRUB allocates up to 1GiB. - - On sparc64-ieee1275 stack is 256KiB and heap is 2MiB. - -@@ -1075,7 +1077,7 @@ In short: - @item i386-qemu @tab 60 KiB @tab < 4 GiB - @item *-efi @tab ? @tab < 1.6 GiB - @item i386-ieee1275 @tab ? @tab < 32 MiB --@item powerpc-ieee1275 @tab ? @tab < 32 MiB -+@item powerpc-ieee1275 @tab ? @tab < 1 GiB - @item sparc64-ieee1275 @tab 256KiB @tab 2 MiB - @item arm-uboot @tab 256KiB @tab 2 MiB - @item mips(el)-qemu_mips @tab 2MiB @tab 253 MiB diff --git a/0199-power-Fix-use-after-free-in-get_slave_from_dm.patch b/0199-power-Fix-use-after-free-in-get_slave_from_dm.patch new file mode 100644 index 00000000..b4520e7d --- /dev/null +++ b/0199-power-Fix-use-after-free-in-get_slave_from_dm.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 16:03:54 -0500 +Subject: [PATCH] power: Fix use after free in get_slave_from_dm() + +Signed-off-by: Peter Jones +--- + grub-core/osdep/linux/ofpath.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c +index cc849d9c94c..72772c87a66 100644 +--- a/grub-core/osdep/linux/ofpath.c ++++ b/grub-core/osdep/linux/ofpath.c +@@ -775,6 +775,8 @@ get_slave_from_dm(const char * device){ + + device_path = grub_xasprintf ("/sys/block/%s/slaves", curr_device); + dp = opendir(device_path); ++ if (dp == NULL) ++ grub_util_warn (_("cannot open directory `%s'"), device_path); + free(device_path); + + if (dp != NULL) +@@ -800,8 +802,6 @@ get_slave_from_dm(const char * device){ + } + closedir (dp); + } +- else +- grub_util_warn (_("cannot open directory `%s'"), device_path); + } + + free (directory); diff --git a/0200-Fix-some-sign-comparison-errors.patch b/0200-Fix-some-sign-comparison-errors.patch new file mode 100644 index 00000000..a3e5b250 --- /dev/null +++ b/0200-Fix-some-sign-comparison-errors.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 19:08:33 -0500 +Subject: [PATCH] Fix some sign comparison errors + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/pc/truecrypt.c | 2 +- + grub-core/loader/multiboot_elfxx.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/i386/pc/truecrypt.c b/grub-core/loader/i386/pc/truecrypt.c +index bae1ad031b3..7bf801603f4 100644 +--- a/grub-core/loader/i386/pc/truecrypt.c ++++ b/grub-core/loader/i386/pc/truecrypt.c +@@ -176,7 +176,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)), + + edx = (dh << 8) | grub_get_root_biosnumber (); + +- destaddr = ALIGN_DOWN (grub_min (0x90000, grub_mmap_get_lower ()) ++ destaddr = ALIGN_DOWN (grub_min (0x90000ull, grub_mmap_get_lower ()) + - truecryptmemsize, 64 * 1024); + + { +diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c +index 8d370b0b3f5..24480df5053 100644 +--- a/grub-core/loader/multiboot_elfxx.c ++++ b/grub-core/loader/multiboot_elfxx.c +@@ -99,7 +99,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + return err; + + /* FIXME: Should we support program headers at strange locations? */ +- phlimit = grub_min (MULTIBOOT_SEARCH, grub_file_size (mld->file)); ++ phlimit = grub_min ((grub_off_t)MULTIBOOT_SEARCH, grub_file_size (mld->file)); + if ((grub_off_t) ehdr->e_phoff + phnum * ehdr->e_phentsize > phlimit) + return grub_error (GRUB_ERR_BAD_OS, "program header at a too high offset"); + diff --git a/0200-ieee1275-request-memory-with-ibm-client-architecture.patch b/0200-ieee1275-request-memory-with-ibm-client-architecture.patch deleted file mode 100644 index 6e6c1f0c..00000000 --- a/0200-ieee1275-request-memory-with-ibm-client-architecture.patch +++ /dev/null @@ -1,268 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Daniel Axtens -Date: Fri, 16 Apr 2021 11:48:46 +1000 -Subject: [PATCH] ieee1275: request memory with ibm,client-architecture-support - -On PowerVM, the first time we boot a Linux partition, we may only get -256MB of real memory area, even if the partition has more memory. - -This isn't really enough. Fortunately, the Power Architecture Platform -Reference (PAPR) defines a method we can call to ask for more memory. -This is part of the broad and powerful ibm,client-architecture-support -(CAS) method. - -CAS can do an enormous amount of things on a PAPR platform: as well as -asking for memory, you can set the supported processor level, the interrupt -controller, hash vs radix mmu, and so on. We want to touch as little of -this as possible because we don't want to step on the toes of the future OS. - -If: - - - we are running under what we think is PowerVM (compatible property of / - begins with "IBM"), and - - - the full amount of RMA is less than 512MB (as determined by the reg - property of /memory) - -then call CAS as follows: (refer to the Linux on Power Architecture -Reference, LoPAR, which is public, at B.5.2.3): - - - Use the "any" PVR value and supply 2 option vectors. - - - Set option vector 1 (PowerPC Server Processor Architecture Level) - to "ignore". - - - Set option vector 2 with default or Linux-like options, including a - min-rma-size of 512MB. - -This will cause a CAS reboot and the partition will restart with 512MB -of RMA. Grub will notice the 512MB and not call CAS again. - -(A partition can be configured with only 256MB of memory, which would -mean this request couldn't be satisfied, but PFW refuses to load with -only 256MB of memory, so it's a bit moot. SLOF will run fine with 256MB, -but we will never call CAS under qemu/SLOF because /compatible won't -begin with "IBM".) - -One of the first things Linux does while still running under OpenFirmware -is to call CAS with a much fuller set of options (including asking for -512MB of memory). This includes a much more restrictive set of PVR values -and processor support levels, and this will induce another reboot. On this -reboot grub will again notice the higher RMA, and not call CAS. We will get -to Linux, Linux will call CAS but because the values are now set for Linux -this will not induce another CAS reboot and we will finally boot. - -On all subsequent boots, everything will be configured with 512MB of RMA -and all the settings Linux likes, so there will be no further CAS reboots. - -(phyp is super sticky with the RMA size - it persists even on cold boots. -So if you've ever booted Linux in a partition, you'll probably never have -grub call CAS. It'll only ever fire the first time a partition loads grub, -or if you deliberately lower the amount of memory your partition has below -512MB.) - -Signed-off-by: Daniel Axtens ---- - grub-core/kern/ieee1275/cmain.c | 3 + - grub-core/kern/ieee1275/init.c | 144 ++++++++++++++++++++++++++++++++++++++- - include/grub/ieee1275/ieee1275.h | 8 ++- - 3 files changed, 152 insertions(+), 3 deletions(-) - -diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c -index 04df9d2c667..6435628ec57 100644 ---- a/grub-core/kern/ieee1275/cmain.c -+++ b/grub-core/kern/ieee1275/cmain.c -@@ -127,6 +127,9 @@ grub_ieee1275_find_options (void) - break; - } - } -+ -+ if (grub_strncmp (tmp, "IBM,", 4) == 0) -+ grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY); - } - - if (is_smartfirmware) -diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c -index c61d91a0285..9704715c837 100644 ---- a/grub-core/kern/ieee1275/init.c -+++ b/grub-core/kern/ieee1275/init.c -@@ -242,6 +242,135 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, - return 0; - } - -+/* How much memory does OF believe it has? (regardless of whether -+ it's accessible or not) */ -+static grub_err_t -+grub_ieee1275_total_mem (grub_uint64_t *total) -+{ -+ grub_ieee1275_phandle_t root; -+ grub_ieee1275_phandle_t memory; -+ grub_uint32_t reg[4]; -+ grub_ssize_t reg_size; -+ grub_uint32_t address_cells = 1; -+ grub_uint32_t size_cells = 1; -+ grub_uint64_t size; -+ -+ /* If we fail to get to the end, report 0. */ -+ *total = 0; -+ -+ /* Determine the format of each entry in `reg'. */ -+ grub_ieee1275_finddevice ("/", &root); -+ grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells, -+ sizeof address_cells, 0); -+ grub_ieee1275_get_integer_property (root, "#size-cells", &size_cells, -+ sizeof size_cells, 0); -+ -+ if (size_cells > address_cells) -+ address_cells = size_cells; -+ -+ /* Load `/memory/reg'. */ -+ if (grub_ieee1275_finddevice ("/memory", &memory)) -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, -+ "couldn't find /memory node"); -+ if (grub_ieee1275_get_integer_property (memory, "reg", reg, -+ sizeof reg, ®_size)) -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, -+ "couldn't examine /memory/reg property"); -+ if (reg_size < 0 || (grub_size_t) reg_size > sizeof (reg)) -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, -+ "/memory response buffer exceeded"); -+ -+ if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)) -+ { -+ address_cells = 1; -+ size_cells = 1; -+ } -+ -+ /* Decode only the size */ -+ size = reg[address_cells]; -+ if (size_cells == 2) -+ size = (size << 32) | reg[address_cells + 1]; -+ -+ *total = size; -+ -+ return grub_errno; -+} -+ -+/* Based on linux - arch/powerpc/kernel/prom_init.c */ -+struct option_vector2 { -+ grub_uint8_t byte1; -+ grub_uint16_t reserved; -+ grub_uint32_t real_base; -+ grub_uint32_t real_size; -+ grub_uint32_t virt_base; -+ grub_uint32_t virt_size; -+ grub_uint32_t load_base; -+ grub_uint32_t min_rma; -+ grub_uint32_t min_load; -+ grub_uint8_t min_rma_percent; -+ grub_uint8_t max_pft_size; -+} __attribute__((packed)); -+ -+struct pvr_entry { -+ grub_uint32_t mask; -+ grub_uint32_t entry; -+}; -+ -+struct cas_vector { -+ struct { -+ struct pvr_entry terminal; -+ } pvr_list; -+ grub_uint8_t num_vecs; -+ grub_uint8_t vec1_size; -+ grub_uint8_t vec1; -+ grub_uint8_t vec2_size; -+ struct option_vector2 vec2; -+} __attribute__((packed)); -+ -+/* Call ibm,client-architecture-support to try to get more RMA. -+ We ask for 512MB which should be enough to verify a distro kernel. -+ We ignore most errors: if we don't succeed we'll proceed with whatever -+ memory we have. */ -+static void -+grub_ieee1275_ibm_cas (void) -+{ -+ int rc; -+ grub_ieee1275_ihandle_t root; -+ struct cas_args { -+ struct grub_ieee1275_common_hdr common; -+ grub_ieee1275_cell_t method; -+ grub_ieee1275_ihandle_t ihandle; -+ grub_ieee1275_cell_t cas_addr; -+ grub_ieee1275_cell_t result; -+ } args; -+ struct cas_vector vector = { -+ .pvr_list = { { 0x00000000, 0xffffffff } }, /* any processor */ -+ .num_vecs = 2 - 1, -+ .vec1_size = 0, -+ .vec1 = 0x80, /* ignore */ -+ .vec2_size = 1 + sizeof(struct option_vector2) - 2, -+ .vec2 = { -+ 0, 0, -1, -1, -1, -1, -1, 512, -1, 0, 48 -+ }, -+ }; -+ -+ INIT_IEEE1275_COMMON (&args.common, "call-method", 3, 2); -+ args.method = (grub_ieee1275_cell_t)"ibm,client-architecture-support"; -+ rc = grub_ieee1275_open("/", &root); -+ if (rc) { -+ grub_error (GRUB_ERR_IO, "could not open root when trying to call CAS"); -+ return; -+ } -+ args.ihandle = root; -+ args.cas_addr = (grub_ieee1275_cell_t)&vector; -+ -+ grub_printf("Calling ibm,client-architecture-support..."); -+ IEEE1275_CALL_ENTRY_FN (&args); -+ grub_printf("done\n"); -+ -+ grub_ieee1275_close(root); -+} -+ - static void - grub_claim_heap (void) - { -@@ -249,11 +378,22 @@ grub_claim_heap (void) - - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM)) - { -- heap_init (GRUB_IEEE1275_STATIC_HEAP_START, GRUB_IEEE1275_STATIC_HEAP_LEN, -- 1, &total); -+ heap_init (GRUB_IEEE1275_STATIC_HEAP_START, -+ GRUB_IEEE1275_STATIC_HEAP_LEN, 1, &total); - return; - } - -+ if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY)) -+ { -+ grub_uint64_t rma_size; -+ grub_err_t err; -+ -+ err = grub_ieee1275_total_mem (&rma_size); -+ /* if we have an error, don't call CAS, just hope for the best */ -+ if (!err && rma_size < (512 * 1024 * 1024)) -+ grub_ieee1275_ibm_cas(); -+ } -+ - grub_machine_mmap_iterate (heap_size, &total); - - total = total / 4; -diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h -index b5a1d49bbc3..e0a6c2ce1e6 100644 ---- a/include/grub/ieee1275/ieee1275.h -+++ b/include/grub/ieee1275/ieee1275.h -@@ -149,7 +149,13 @@ enum grub_ieee1275_flag - - GRUB_IEEE1275_FLAG_RAW_DEVNAMES, - -- GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT -+ GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT, -+ -+ /* On PFW, the first time we boot a Linux partition, we may only get 256MB -+ of real memory area, even if the partition has more memory. Set this flag -+ if we think we're running under PFW. Then, if this flag is set, and the -+ RMA is only 256MB in size, try asking for more with CAS. */ -+ GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY, - }; - - extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); diff --git a/0201-normal-Fix-a-discarded-const.patch b/0201-normal-Fix-a-discarded-const.patch new file mode 100644 index 00000000..57598db1 --- /dev/null +++ b/0201-normal-Fix-a-discarded-const.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 19:12:15 -0500 +Subject: [PATCH] normal: Fix a discarded const. + +Signed-off-by: Peter Jones +--- + grub-core/normal/main.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index e903f291732..803b9656d36 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -406,7 +406,7 @@ grub_try_normal_dev (const char *name, void *data) + static grub_err_t + grub_try_normal_discover (void) + { +- char *prefix = grub_env_get ("prefix"); ++ const char *prefix = grub_env_get ("prefix"); + grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; + + if (!prefix) diff --git a/0202-at_keyboard-mark-grub_keyboard_controller_write-unus.patch b/0202-at_keyboard-mark-grub_keyboard_controller_write-unus.patch new file mode 100644 index 00000000..058340d7 --- /dev/null +++ b/0202-at_keyboard-mark-grub_keyboard_controller_write-unus.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jan 2024 19:14:06 -0500 +Subject: [PATCH] at_keyboard: mark grub_keyboard_controller_write unused + +It's used sometimes and not others by #ifdef, so mark it unused so the +compiler doesn't complain. + +Signed-off-by: Peter Jones +--- + grub-core/term/at_keyboard.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c +index e667d0a862c..d2b716b5b4f 100644 +--- a/grub-core/term/at_keyboard.c ++++ b/grub-core/term/at_keyboard.c +@@ -93,7 +93,7 @@ at_command (grub_uint8_t data) + return (i != GRUB_AT_TRIES); + } + +-static void ++static void __attribute__((__unused__)) + grub_keyboard_controller_write (grub_uint8_t c) + { + at_command (KEYBOARD_COMMAND_WRITE); +@@ -170,7 +170,7 @@ query_mode (void) + grub_uint64_t endtime; + unsigned i; + int e; +- char *envvar; ++ const char *envvar; + + for (i = 0; i < GRUB_AT_TRIES; i++) { + grub_dprintf ("atkeyb", "query_mode: sending command to controller\n"); diff --git a/0203-01_menu_auto_hide.in-fix-a-then-than-typo.patch b/0203-01_menu_auto_hide.in-fix-a-then-than-typo.patch deleted file mode 100644 index 4847ef93..00000000 --- a/0203-01_menu_auto_hide.in-fix-a-then-than-typo.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= -Date: Fri, 11 Jun 2021 12:57:56 +0200 -Subject: [PATCH] 01_menu_auto_hide.in: fix a then/than typo -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Signed-off-by: Jan Pokorný ---- - util/grub.d/10_reset_boot_success.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in -index 737e1ae5b68..e73f4137b36 100644 ---- a/util/grub.d/10_reset_boot_success.in -+++ b/util/grub.d/10_reset_boot_success.in -@@ -15,7 +15,7 @@ fi - # Reset boot_indeterminate after a successful boot - if [ "\${boot_success}" = "1" ] ; then - set boot_indeterminate=0 --# Avoid boot_indeterminate causing the menu to be hidden more then once -+# Avoid boot_indeterminate causing the menu to be hidden more than once - elif [ "\${boot_indeterminate}" = "1" ]; then - set boot_indeterminate=2 - fi diff --git a/0203-Fix-another-minor-sign-comparison-error.patch b/0203-Fix-another-minor-sign-comparison-error.patch new file mode 100644 index 00000000..24c343cc --- /dev/null +++ b/0203-Fix-another-minor-sign-comparison-error.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 9 Jan 2024 14:37:25 -0500 +Subject: [PATCH] Fix another minor sign comparison error. + +Signed-off-by: Peter Jones +--- + grub-core/kern/mm.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c +index 1aeeba9e27e..819bc5126a6 100644 +--- a/grub-core/kern/mm.c ++++ b/grub-core/kern/mm.c +@@ -505,7 +505,7 @@ grub_memalign (grub_size_t align, grub_size_t size) + goto fail; + + /* Preallocate some extra space if heap growth is small. */ +- grow = grub_max (grow, GRUB_MM_HEAP_GROW_EXTRA); ++ grow = grub_max (grow, (grub_size_t)GRUB_MM_HEAP_GROW_EXTRA); + + /* Align up heap growth to make it friendly to CPU/MMU. */ + if (grow > ~(grub_size_t) (GRUB_MM_HEAP_GROW_ALIGN - 1)) diff --git a/0204-Fix-disabling-grub-rpm-sort.patch b/0204-Fix-disabling-grub-rpm-sort.patch deleted file mode 100644 index dccde3c4..00000000 --- a/0204-Fix-disabling-grub-rpm-sort.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tim Landscheidt -Date: Fri, 11 Jun 2021 13:02:37 +0200 -Subject: [PATCH] Fix disabling grub-rpm-sort - -Currently, grub-rpm-sort is unconditionally compiled whether -./configure has been called with --disable-rpm-sort or not. This adds -the necessary logic to configure.ac and Makefile.util.def and some -debug output to ./configure and fixes #44. ---- - configure.ac | 8 ++++++++ - Makefile.util.def | 1 + - 2 files changed, 9 insertions(+) - -diff --git a/configure.ac b/configure.ac -index d5d2a28b4ef..c7842ec29d8 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1936,6 +1936,8 @@ AC_ARG_ENABLE([rpm-sort], - [enable native rpm sorting of kernels in grub (default=guessed)])]) - if test x"$enable_rpm_sort" = xno ; then - rpm_sort_excuse="explicitly disabled" -+else -+ enable_rpm_sort=yes - fi - - if test x"$rpm_sort_excuse" = x ; then -@@ -2200,6 +2202,7 @@ AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) - AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) - AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) - AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes]) -+AM_CONDITIONAL([COND_GRUB_RPM_SORT], [test x$enable_rpm_sort = xyes]) - AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) - if test x$FONT_SOURCE != x ; then - HAVE_FONT_SOURCE=1 -@@ -2328,6 +2331,11 @@ echo grub-mount: Yes - else - echo grub-mount: No "($grub_mount_excuse)" - fi -+if [ x"$rpm_sort_excuse" = x ]; then -+echo grub-rpm-sort: Yes -+else -+echo grub-rpm-sort: No "($rpm_sort_excuse)" -+fi - if [ x"$starfield_excuse" = x ]; then - echo starfield theme: Yes - echo With DejaVuSans font from $DJVU_FONT_SOURCE -diff --git a/Makefile.util.def b/Makefile.util.def -index 8cfbe69a76e..3f191aa8095 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -774,6 +774,7 @@ program = { - ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; - ldadd = '$(LIBDEVMAPPER) $(LIBRPM)'; -+ condition = COND_GRUB_RPM_SORT; - }; - - script = { diff --git a/0204-Track-explicit-module-dependencies-in-Makefile.core..patch b/0204-Track-explicit-module-dependencies-in-Makefile.core..patch new file mode 100644 index 00000000..c5311c1f --- /dev/null +++ b/0204-Track-explicit-module-dependencies-in-Makefile.core..patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Oliver Steffen +Date: Wed, 28 Feb 2024 13:36:00 +0100 +Subject: [PATCH] Track explicit module dependencies in Makefile.core.def + +Add a new keyword, "depends", to the module definition syntax +used in Makefile.core.def. This allows specifying explicit module +dependencies together with the module definition. + +Make use of this new keyword in the bli module definition. + +Signed-off-by: Oliver Steffen +Reviewed-by: Daniel Kiper +Tested-by: Oskari Pirhonen +--- + grub-core/Makefile.core.def | 1 + + .gitignore | 1 - + conf/Makefile.common | 1 + + gentpl.py | 7 +++++++ + grub-core/Makefile.am | 9 ++++++--- + grub-core/genmoddep.awk | 2 +- + 6 files changed, 16 insertions(+), 5 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index c9dcfa00e85..a5a3ee31800 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2670,6 +2670,7 @@ module = { + name = bli; + efi = commands/bli.c; + enable = efi; ++ depends = part_gpt; + }; + + module = { +diff --git a/.gitignore b/.gitignore +index f2e8e1e42d7..c603c15d66c 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -11,7 +11,6 @@ + *.img + *.log + *.lst +-!/grub-core/extra_deps.lst + *.marker + *.mod + *.o +diff --git a/conf/Makefile.common b/conf/Makefile.common +index c8756d8146f..9feac7434da 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -115,6 +115,7 @@ MOD_FILES = + MODULE_FILES = + MARKER_FILES = + KERNEL_HEADER_FILES = ++EXTRA_DEPS = + + bin_SCRIPTS = + bin_PROGRAMS = +diff --git a/gentpl.py b/gentpl.py +index 5826a6b14e8..0f8d009ef21 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -642,6 +642,9 @@ def platform_values(defn, platform, suffix): + def extra_dist(defn): + return foreach_value(defn, "extra_dist", lambda value: value + " ") + ++def extra_dep(defn): ++ return foreach_value(defn, "depends", lambda value: value + " ") ++ + def platform_sources(defn, p): return platform_values(defn, p, "") + def platform_nodist_sources(defn, p): return platform_values(defn, p, "_nodist") + +@@ -712,6 +715,10 @@ def module(defn, platform): + gvar_add("MOD_FILES", name + ".mod") + gvar_add("MARKER_FILES", name + ".marker") + gvar_add("CLEANFILES", name + ".marker") ++ ++ for dep in defn.find_all("depends"): ++ gvar_add("EXTRA_DEPS", "depends " + name + " " + dep + ":") ++ + output(""" + """ + name + """.marker: $(""" + cname(defn) + """_SOURCES) $(nodist_""" + cname(defn) + """_SOURCES) + $(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn) + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1) +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index 7953ba95399..77f8329cd43 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -456,8 +456,11 @@ crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst + platform_DATA += crypto.lst + CLEANFILES += crypto.lst + +-syminfo.lst: gensyminfo.sh kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.lst $(MODULE_FILES) +- cat kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.lst > $@.new ++extra_deps.lst: ++ @echo $(EXTRA_DEPS) | sed "s/\s*:\s*/\n/g" > $@ ++ ++syminfo.lst: gensyminfo.sh kernel_syms.lst extra_deps.lst $(MODULE_FILES) ++ cat kernel_syms.lst extra_deps.lst > $@.new + for m in $(MODULE_FILES); do \ + sh $< $$m >> $@.new || exit 1; \ + done +@@ -467,7 +470,7 @@ syminfo.lst: gensyminfo.sh kernel_syms.lst $(top_srcdir)/grub-core/extra_deps.ls + moddep.lst: syminfo.lst genmoddep.awk video.lst + cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1) + platform_DATA += moddep.lst +-CLEANFILES += config.log syminfo.lst moddep.lst ++CLEANFILES += config.log syminfo.lst moddep.lst extra_deps.lst + + $(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT) + TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@ +diff --git a/grub-core/genmoddep.awk b/grub-core/genmoddep.awk +index cc987a53aa8..ab457cb2b56 100644 +--- a/grub-core/genmoddep.awk ++++ b/grub-core/genmoddep.awk +@@ -35,7 +35,7 @@ BEGIN { + for (i = 3; i <= NF; i++) { + modtab[$2] = modtab[$2] " " $i; + } +- } ++ } else if ($1 == "") {} #Skip empty lines + else { + printf "error: %u: unrecognized input format\n", NR >"/dev/stderr"; + error++; diff --git a/0205-Don-t-check-for-rpmvercmp-in-librpm.patch b/0205-Don-t-check-for-rpmvercmp-in-librpm.patch deleted file mode 100644 index c21dca47..00000000 --- a/0205-Don-t-check-for-rpmvercmp-in-librpm.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Fri, 11 Jun 2021 13:13:27 +0200 -Subject: [PATCH] Don't check for rpmvercmp in librpm - -The rpmvercmp() function was moved from librpm to librpmio. The configure -option had some logic to first check if the symbol is in librpm and then -librpmio if this check didn't succeed. - -But the logic wasn't working and rpm sorting was always disabled. Instead -of trying to fix this logic, let's just remove since the function already -moved and there's no need to check librpm anymore. Now it's enabled again: - - GRUB2 will be compiled with following components: - ... - grub-rpm-sort: Yes - ... - -Signed-off-by: Javier Martinez Canillas ---- - configure.ac | 19 +++++-------------- - 1 file changed, 5 insertions(+), 14 deletions(-) - -diff --git a/configure.ac b/configure.ac -index c7842ec29d8..3c808a72230 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1947,24 +1947,15 @@ if test x"$rpm_sort_excuse" = x ; then - fi - - if test x"$rpm_sort_excuse" = x ; then -- # Check for rpm library. -- AC_CHECK_LIB([rpm], [rpmvercmp], [], -- [rpm_sort_excuse="rpmlib missing rpmvercmp"]) --fi -- --if test x"$rpm_sort_excuse" = x ; then -- LIBRPM="-lrpm"; -- AC_DEFINE([HAVE_RPM], [1], -- [Define to 1 if you have the rpm library.]) --fi -- --if test x"$LIBRPM" = x ; then -- # Check for rpm library. -+ # Check for rpmio library. - AC_CHECK_LIB([rpmio], [rpmvercmp], [], - [rpm_sort_excuse="rpmio missing rpmvercmp"]) -+fi -+ -+if test x"$rpm_sort_excuse" = x ; then - LIBRPM="-lrpmio"; - AC_DEFINE([HAVE_RPMIO], [1], -- [Define to 1 if you have the rpm library.]) -+ [Define to 1 if you have the rpmio library.]) - fi - - AC_SUBST([LIBRPM]) diff --git a/0205-Revert-mm-Assert-that-we-preserve-header-vs-region-a.patch b/0205-Revert-mm-Assert-that-we-preserve-header-vs-region-a.patch new file mode 100644 index 00000000..1a224b3d --- /dev/null +++ b/0205-Revert-mm-Assert-that-we-preserve-header-vs-region-a.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Fri, 8 Mar 2024 16:54:43 -0600 +Subject: [PATCH] Revert "mm: Assert that we preserve header vs region + alignment" +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This reverts commit 1df8fe66c57087eb33bd6dc69f786ed124615aa7. + +This is temporal while we find the reason for + +In file included from ../../include/grub/mm_private.h:23, + from ../../include/grub/relocator_private.h:24, + from ../../grub-core/lib/efi/relocator.c:20: +../../include/grub/mm_private.h: In function ‘grub_mm_size_sanity_check’: +../../include/grub/misc.h:36:56: error: duplicate case value + 36 | #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } + | ^~~~ +../../include/grub/mm_private.h:105:3: note: in expansion of macro ‘COMPILE_TIME_ASSERT’ + 105 | COMPILE_TIME_ASSERT ((sizeof (struct grub_mm_region) % + | ^~~~~~~~~~~~~~~~~~~ +../../include/grub/misc.h:36:48: note: previously used here + 36 | #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } + | ^~~~ +../../include/grub/mm_private.h:105:3: note: in expansion of macro ‘COMPILE_TIME_ASSERT’ + 105 | COMPILE_TIME_ASSERT ((sizeof (struct grub_mm_region) % + | ^~~~~~~~~~~~~~~~~~~ +../../include/grub/misc.h:36:56: error: duplicate case value + 36 | #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } + | ^~~~ +../../include/grub/mm_private.h:112:3: note: in expansion of macro ‘COMPILE_TIME_ASSERT’ + 112 | COMPILE_TIME_ASSERT (sizeof (struct grub_mm_header) == GRUB_MM_ALIGN); + | ^~~~~~~~~~~~~~~~~~~ +../../include/grub/misc.h:36:48: note: previously used here + 36 | #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } + | ^~~~ +../../include/grub/mm_private.h:112:3: note: in expansion of macro ‘COMPILE_TIME_ASSERT’ + 112 | COMPILE_TIME_ASSERT (sizeof (struct grub_mm_header) == GRUB_MM_ALIGN); + | ^~~~~~~~~~~~~~~~~~~ +--- + include/grub/mm_private.h | 14 -------------- + 1 file changed, 14 deletions(-) + +diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h +index 96c2d816be6..2481ee1fa20 100644 +--- a/include/grub/mm_private.h ++++ b/include/grub/mm_private.h +@@ -20,7 +20,6 @@ + #define GRUB_MM_PRIVATE_H 1 + + #include +-#include + + /* For context, see kern/mm.c */ + +@@ -99,17 +98,4 @@ typedef struct grub_mm_region + extern grub_mm_region_t EXPORT_VAR (grub_mm_base); + #endif + +-static inline void +-grub_mm_size_sanity_check (void) { +- /* Ensure we preserve alignment when doing h = (grub_mm_header_t) (r + 1). */ +- COMPILE_TIME_ASSERT ((sizeof (struct grub_mm_region) % +- sizeof (struct grub_mm_header)) == 0); +- +- /* +- * GRUB_MM_ALIGN is supposed to represent cell size, and a mm_header is +- * supposed to be 1 cell. +- */ +- COMPILE_TIME_ASSERT (sizeof (struct grub_mm_header) == GRUB_MM_ALIGN); +-} +- + #endif diff --git a/0206-make-use-the-_CPU-variety-of-build-flags-for-PROGRAM.patch b/0206-make-use-the-_CPU-variety-of-build-flags-for-PROGRAM.patch new file mode 100644 index 00000000..4f56149d --- /dev/null +++ b/0206-make-use-the-_CPU-variety-of-build-flags-for-PROGRAM.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 13 Mar 2024 15:11:15 -0600 +Subject: [PATCH] make: use the _CPU variety of build flags for PROGRAM and + LIBRARY + +Signed-off-by: Peter Jones +--- + conf/Makefile.common | 15 +++++++-------- + 1 file changed, 7 insertions(+), 8 deletions(-) + +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 9feac7434da..f8c2f6bd881 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -60,15 +60,14 @@ LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S + CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) + CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + +-CFLAGS_PROGRAM = $(UTILS_CFLAGS) +-LDFLAGS_PROGRAM = $(UTILS_LDFLAGS) +-CPPFLAGS_PROGRAM = $(UTILS_CPPFLAGS) +-CCASFLAGS_PROGRAM = $(UTILS_CCASFLAGS) ++CFLAGS_PROGRAM = $(CFLAGS_CPU) ++LDFLAGS_PROGRAM = $(LDFLAGS_CPU) ++CPPFLAGS_PROGRAM = $(CPPFLAGS_CPU) ++CCASFLAGS_PROGRAM = $(CCASFLAGS_CPU) + +-CFLAGS_LIBRARY = $(UTILS_CFLAGS) +-LDFLAGS_LIBRARY = $(UTILS_LDFLAGS) +-CPPFLAGS_LIBRARY = $(UTILS_CPPFLAGS) +-CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) ++CFLAGS_LIBRARY = $(CFLAGS_CPU) ++CPPFLAGS_LIBRARY = $(CPPFLAGS_CPU) ++CCASFLAGS_LIBRARY = $(CCASFLAGS_CPU) + + # Other variables + diff --git a/0207-Work-around-extra_deps.lst-issue.patch b/0207-Work-around-extra_deps.lst-issue.patch new file mode 100644 index 00000000..0481cd55 --- /dev/null +++ b/0207-Work-around-extra_deps.lst-issue.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 13 Mar 2024 14:06:43 -0400 +Subject: [PATCH] Work around extra_deps.lst issue + +--- + grub-core/Makefile.am | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index 77f8329cd43..aa172391fdf 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -460,6 +460,10 @@ extra_deps.lst: + @echo $(EXTRA_DEPS) | sed "s/\s*:\s*/\n/g" > $@ + + syminfo.lst: gensyminfo.sh kernel_syms.lst extra_deps.lst $(MODULE_FILES) ++ if ! [ -f extra_deps.lst ] ; then \ ++ echo Missing extra_deps.lst ; \ ++ echo $(EXTRA_DEPS) | sed "s/\s*:\s*/\n/g" > extra_deps.lst ; \ ++ fi + cat kernel_syms.lst extra_deps.lst > $@.new + for m in $(MODULE_FILES); do \ + sh $< $$m >> $@.new || exit 1; \ diff --git a/0208-fs-ext2-Ignore-checksum-seed-incompat-feature.patch b/0208-fs-ext2-Ignore-checksum-seed-incompat-feature.patch deleted file mode 100644 index b4a5fd4d..00000000 --- a/0208-fs-ext2-Ignore-checksum-seed-incompat-feature.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Fri, 11 Jun 2021 00:01:29 +0200 -Subject: [PATCH] fs/ext2: Ignore checksum seed incompat feature - -This incompat feature is used to denote that the filesystem stored its -metadata checksum seed in the superblock. This is used to allow tune2fs -to change the UUID on a mounted metadata_csum filesystem without having -to rewrite all the disk metadata. - -But GRUB doesn't use the metadata checksum in anyway, so can just ignore -this feature if is enabled. This is consistent with GRUB filesystem code -in general which just does a best effort to access the filesystem's data. - -It may be removed from the ignored list in the future if supports to do -metadata checksumming verification is added to the read-only FS driver. - -Suggested-by: Eric Sandeen -Suggested-by: Lukas Czerner -Signed-off-by: Javier Martinez Canillas ---- - grub-core/fs/ext2.c | 10 +++++++++- - 1 file changed, 9 insertions(+), 1 deletion(-) - -diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c -index e7dd78e6635..731d346f886 100644 ---- a/grub-core/fs/ext2.c -+++ b/grub-core/fs/ext2.c -@@ -103,6 +103,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); - #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 - #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 - #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 -+#define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 - #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 - - /* The set of back-incompatible features this driver DOES support. Add (OR) -@@ -123,9 +124,16 @@ GRUB_MOD_LICENSE ("GPLv3+"); - * mmp: Not really back-incompatible - was added as such to - * avoid multiple read-write mounts. Safe to ignore for this - * RO driver. -+ * checksum seed: Not really back-incompatible - was added to allow tools -+ * such as tune2fs to change the UUID on a mounted metadata -+ * checksummed filesystem. Safe to ignore for now since the -+ * driver doesn't support checksum verification. But it must -+ * be removed from this list if that support is added later. -+ * - */ - #define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ -- | EXT4_FEATURE_INCOMPAT_MMP) -+ | EXT4_FEATURE_INCOMPAT_MMP \ -+ | EXT4_FEATURE_INCOMPAT_CSUM_SEED) - - - #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U diff --git a/0208-include-proper-attribute-for-an-EFI-API-call-definit.patch b/0208-include-proper-attribute-for-an-EFI-API-call-definit.patch new file mode 100644 index 00000000..ad965b6c --- /dev/null +++ b/0208-include-proper-attribute-for-an-EFI-API-call-definit.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Thu, 21 Mar 2024 16:27:25 -0600 +Subject: [PATCH] include proper attribute for an EFI API call definition +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Otherwise we observe the following issue + +../../grub-core/net/efi/http.c: In function ‘efihttp_request’: +../../grub-core/net/efi/http.c:233:28: error: passing argument 3 of ‘b->create_event’ from incompatible pointer type [-Wincompatible-pointer-types] + 233 | grub_efi_http_request_callback, NULL, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | | + | void (*)(void *, void *) +../../grub-core/net/efi/http.c:233:28: note: expected ‘void (__attribute__((ms_abi)) *)(void *, void *)’ but argument is of type ‘void (*)(void *, void *)’ +--- + grub-core/net/efi/http.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index 0568ea5d43e..6fecb261c55 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -131,14 +131,14 @@ static grub_efi_boolean_t request_callback_done; + static grub_efi_boolean_t response_callback_done; + + static void +-grub_efi_http_request_callback (grub_efi_event_t event __attribute__ ((unused)), ++__grub_efi_api grub_efi_http_request_callback (grub_efi_event_t event __attribute__ ((unused)), + void *context __attribute__ ((unused))) + { + request_callback_done = 1; + } + + static void +-grub_efi_http_response_callback (grub_efi_event_t event __attribute__ ((unused)), ++__grub_efi_api grub_efi_http_response_callback (grub_efi_event_t event __attribute__ ((unused)), + void *context __attribute__ ((unused))) + { + response_callback_done = 1; diff --git a/0209-cast-grub_error-status-parameter.patch b/0209-cast-grub_error-status-parameter.patch new file mode 100644 index 00000000..0cea65b2 --- /dev/null +++ b/0209-cast-grub_error-status-parameter.patch @@ -0,0 +1,67 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Fri, 22 Mar 2024 12:12:02 -0600 +Subject: [PATCH] cast grub_error status parameter +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +For some reason, the compiler concludes that the status variable is +ultimately a 'long unsigned int' but status is a 'unsigned' (not a +long) so temporally cast it to unsigned otherwise we see the following + +../../grub-core/net/efi/http.c: In function ‘efihttp_request’: +../../grub-core/net/efi/http.c:251:39: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 5 has type ‘grub_efi_status_t’ {aka ‘long unsigned int’} [-Wformat=] + 251 | return grub_error (GRUB_ERR_IO, "Fail to send a request! status=0x%x\n", status); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ + | | + | grub_efi_status_t {aka long unsigned int} +--- + grub-core/net/efi/http.c | 6 +++--- + grub-core/net/efi/net.c | 2 +- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index 6fecb261c55..5bdb47548f8 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -236,7 +236,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + if (status != GRUB_EFI_SUCCESS) + { + grub_free (request_data.url); +- return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", status); ++ return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", (unsigned) status); + } + + status = http->request(http, &request_token); +@@ -248,7 +248,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + { + b->close_event(request_token.event); + grub_free (request_data.url); +- return grub_error (GRUB_ERR_IO, "Fail to send a request! status=0x%x\n", status); ++ return grub_error (GRUB_ERR_IO, "Fail to send a request! status=0x%x\n", (unsigned) status); + } + /* TODO: Add Timeout */ + while (!request_callback_done) +@@ -273,7 +273,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + { + b->close_event(request_token.event); + grub_free (request_data.url); +- return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", status); ++ return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", (unsigned) status); + } + + response_token.status = GRUB_EFI_SUCCESS; +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 0a1e604b5bd..1b13603a63c 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -706,7 +706,7 @@ grub_efi_service_binding (grub_efi_handle_t dev, grub_guid_t *service_binding_gu + status = service->create_child(service, &child_dev); + if (status != GRUB_EFI_SUCCESS) + { +- grub_error (GRUB_ERR_IO, N_("Failed to create child device of http service %x"), status); ++ grub_error (GRUB_ERR_IO, N_("Failed to create child device of http service %x"), (unsigned) status); + return NULL; + } + diff --git a/0210-remove-unused-varible.patch b/0210-remove-unused-varible.patch new file mode 100644 index 00000000..2a10b101 --- /dev/null +++ b/0210-remove-unused-varible.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Fri, 22 Mar 2024 14:20:06 -0600 +Subject: [PATCH] remove unused varible +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Otherwise compiler complains with: + +../../grub-core/commands/efi/connectefi.c:143:20: error: unused variable ‘j’ [-Werror=unused-variable] + 143 | unsigned j; + | ^ + +Signed-off-by: Leo Sandoval +--- + grub-core/commands/efi/connectefi.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/grub-core/commands/efi/connectefi.c b/grub-core/commands/efi/connectefi.c +index 6c397f8f508..9d02f2780f6 100644 +--- a/grub-core/commands/efi/connectefi.c ++++ b/grub-core/commands/efi/connectefi.c +@@ -140,7 +140,6 @@ loop: + { + grub_efi_handle_t handle = handles[i]; + grub_efi_status_t status; +- unsigned j; + + /* Skip already handled handles */ + if (is_in_list (handle)) diff --git a/0211-cast-grub_net_bootp_packet-pointer.patch b/0211-cast-grub_net_bootp_packet-pointer.patch new file mode 100644 index 00000000..b98d9b21 --- /dev/null +++ b/0211-cast-grub_net_bootp_packet-pointer.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Fri, 22 Mar 2024 18:28:17 -0600 +Subject: [PATCH] cast grub_net_bootp_packet pointer +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Otherwise compiler complains with: + +../../grub-core/net/drivers/efi/efinet.c: In function ‘grub_efi_net_config_real’: +../../grub-core/net/drivers/efi/efinet.c:876:28: error: cannot convert to a pointer type + 876 | dhcp_ack = (struct grub_net_bootp_packet *) pxe_mode->dhcp_ack; + | ^~~~~~~~~~~~~~~~~~~~~ +../../grub-core/net/drivers/efi/efinet.c:881:57: error: initialization of ‘struct grub_net_bootp_packet *’ from incompatible pointer type ‘grub_efi_pxe_packet_t *’ [-Wincompatible-pointer-types] + 881 | struct grub_net_bootp_packet *proxy_offer = &pxe_mode->proxy_offer; + | ^ + +Signed-off-by: Leo Sandoval +--- + grub-core/net/drivers/efi/efinet.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 83005ea9f88..4591d0757ec 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -872,12 +872,12 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + { + grub_dprintf ("efinet", "using ipv4 and dhcp\n"); + +- struct grub_net_bootp_packet *dhcp_ack = &pxe_mode->dhcp_ack; ++ struct grub_net_bootp_packet *dhcp_ack = (struct grub_net_bootp_packet *) &pxe_mode->dhcp_ack; + + if (pxe_mode->proxy_offer_received) + { + grub_dprintf ("efinet", "proxy offer receive"); +- struct grub_net_bootp_packet *proxy_offer = &pxe_mode->proxy_offer; ++ struct grub_net_bootp_packet *proxy_offer = (struct grub_net_bootp_packet *) &pxe_mode->proxy_offer; + + if (proxy_offer && dhcp_ack->boot_file[0] == '\0') + { diff --git a/0211-grub-boot-success.timer-Only-run-if-not-in-a-contain.patch b/0211-grub-boot-success.timer-Only-run-if-not-in-a-contain.patch deleted file mode 100644 index 61d0f6d9..00000000 --- a/0211-grub-boot-success.timer-Only-run-if-not-in-a-contain.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Gena Makhomed -Date: Thu, 1 Jul 2021 01:07:46 +0200 -Subject: [PATCH] grub-boot-success.timer: Only run if not in a container - -The grub-boot-success.timer should be disabled inside a container since it -leads to the following error: - -Jan 09 22:56:38 test sshd[8786]: pam_unix(sshd:session): session opened for user www(uid=1000) by (uid=0) -Jan 09 22:58:39 test systemd[8857]: Starting Mark boot as successful... -Jan 09 22:58:39 test systemd[8857]: grub-boot-success.service: Main process exited, code=exited, status=1/FAILURE -Jan 09 22:58:39 test systemd[8857]: grub-boot-success.service: Failed with result 'exit-code'. -Jan 09 22:58:39 test systemd[8857]: Failed to start Mark boot as successful. -Jan 09 22:58:39 test grub2-set-bootflag[10034]: Error canonicalizing /boot/grub2/grubenv filename: No such file or directory - -Resolves: rhbz#1914571 ---- - docs/grub-boot-success.timer | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/docs/grub-boot-success.timer b/docs/grub-boot-success.timer -index 5d8fcba21aa..406f1720056 100644 ---- a/docs/grub-boot-success.timer -+++ b/docs/grub-boot-success.timer -@@ -1,6 +1,7 @@ - [Unit] - Description=Mark boot as successful after the user session has run 2 minutes - ConditionUser=!@system -+ConditionVirtualization=!container - - [Timer] - OnActiveSec=2min diff --git a/0212-libtasn1-fix-string-overflow-warning.patch b/0212-libtasn1-fix-string-overflow-warning.patch new file mode 100644 index 00000000..50d151ab --- /dev/null +++ b/0212-libtasn1-fix-string-overflow-warning.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Thu, 11 Jan 2024 12:05:20 -0600 +Subject: [PATCH] libtasn1: fix string overflow warning + +Patched also at the libtasn1 project with commit + + c54e523d9dacdb7eec7f20964df12df9b80f467c + Author: Simo Sorce + AuthorDate: Tue May 11 14:18:10 2021 -0400 + Commit: Simo Sorce + CommitDate: Tue May 11 14:26:04 2021 -0400 + + Parent: 890a8a9 Fix resource leak (node) + Contained: master + Follows: v4.16.0 (48) + Precedes: v4.17.0 (5) + + Fix String overflow warning + + Scanner Output + -------------- + rror: COMPILER_WARNING (CWE-758): [#def2] + libtasn1-4.16.0/lib/element.c: scope_hint: In function '_asn1_append_sequence_set' + libtasn1-4.16.0/lib/element.c:186:7: warning[-Wstringop-overflow=]: '_asn1_ltostr' accessing 22 bytes in a region of size 21 + # 186 | _asn1_ltostr (n, temp + 1); + # | ^~~~~~~~~~~~~~~~~~~~~~~~~~ + libtasn1-4.16.0/lib/element.c:186:7: note: referencing argument 2 of type 'char *' + libtasn1-4.16.0/lib/element.c:30: included_from: Included from here. + libtasn1-4.16.0/lib/parser_aux.h:70:7: note: in a call to function '_asn1_ltostr' + # 70 | char *_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]); + # | ^~~~~~~~~~~~ + # 184| n++; + # 185| temp[0] = '?'; + # 186|-> _asn1_ltostr (n, temp + 1); + # 187| } + # 188| _asn1_set_name (p2, temp); + +Signed-off-by: Leo Sandoval +--- + grub-core/lib/libtasn1/lib/element.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c +index ed761ff56bd..8cc73455aee 100644 +--- a/grub-core/lib/libtasn1/lib/element.c ++++ b/grub-core/lib/libtasn1/lib/element.c +@@ -143,7 +143,7 @@ int + _asn1_append_sequence_set (asn1_node node, struct node_tail_cache_st *pcache) + { + asn1_node p, p2; +- char temp[LTOSTR_MAX_SIZE]; ++ char temp[LTOSTR_MAX_SIZE + 1]; + long n; + + if (!node || !(node->down)) diff --git a/0004-Add-support-for-Linux-EFI-stub-loading.patch b/0213-Add-support-for-Linux-EFI-stub-loading.patch similarity index 55% rename from 0004-Add-support-for-Linux-EFI-stub-loading.patch rename to 0213-Add-support-for-Linux-EFI-stub-loading.patch index 73d231a2..c930f1c3 100644 --- a/0004-Add-support-for-Linux-EFI-stub-loading.patch +++ b/0213-Add-support-for-Linux-EFI-stub-loading.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Matthew Garrett -Date: Tue, 10 Jul 2012 11:58:52 -0400 +Date: Mon, 1 Apr 2024 13:20:18 -0600 Subject: [PATCH] Add support for Linux EFI stub loading. Also: @@ -26,32 +26,25 @@ grub-2.00-no-insmod-on-sb.patch), but this should be more correct. It moves the check into grub_dl_load_file. --- grub-core/Makefile.core.def | 16 +- - grub-core/kern/dl.c | 21 +++ - grub-core/kern/efi/efi.c | 28 ++++ + grub-core/kern/dl.c | 22 +++ grub-core/kern/efi/mm.c | 32 ++++ - grub-core/loader/arm64/linux.c | 118 +++++++------- - grub-core/loader/arm64/xen_boot.c | 1 - - grub-core/loader/efi/linux.c | 70 ++++++++ + grub-core/loader/efi/linux.c | 47 ++++++ grub-core/loader/i386/efi/linux.c | 335 ++++++++++++++++++++++++++++++++++++++ grub-core/loader/i386/pc/linux.c | 10 +- - include/grub/arm/linux.h | 9 + - include/grub/arm64/linux.h | 9 + - include/grub/efi/efi.h | 7 +- + include/grub/efi/efi.h | 3 + include/grub/efi/linux.h | 31 ++++ - 13 files changed, 618 insertions(+), 69 deletions(-) - create mode 100644 grub-core/loader/efi/linux.c + 8 files changed, 485 insertions(+), 11 deletions(-) create mode 100644 grub-core/loader/i386/efi/linux.c create mode 100644 include/grub/efi/linux.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 8022e1c0a79..45d3edaa4dc 100644 +index a5a3ee31800..3f6e944d6a5 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def -@@ -1734,13 +1734,6 @@ module = { - enable = i386_pc; +@@ -1831,12 +1831,6 @@ module = { }; -- + -module = { - name = linux16; - common = loader/i386/pc/linux.c; @@ -61,37 +54,47 @@ index 8022e1c0a79..45d3edaa4dc 100644 module = { name = ntldr; i386_pc = loader/i386/pc/ntldr.c; -@@ -1796,7 +1789,9 @@ module = { +@@ -1892,10 +1886,9 @@ module = { module = { name = linux; - x86 = loader/i386/linux.c; -+ i386_pc = loader/i386/pc/linux.c; -+ x86_64_efi = loader/i386/efi/linux.c; -+ i386_efi = loader/i386/efi/linux.c; i386_xen_pvh = loader/i386/linux.c; xen = loader/i386/xen.c; - i386_pc = lib/i386/pc/vesa_modes_table.c; -@@ -1811,9 +1806,14 @@ module = { - arm64 = loader/arm64/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; -+ emu = loader/emu/linux.c; +- i386_pc = lib/i386/pc/vesa_modes_table.c; ++ i386_pc = loader/i386/pc/linux.c; + i386_xen_pvh = lib/i386/pc/vesa_modes_table.c; + mips = loader/mips/linux.c; + powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c; +@@ -1908,11 +1901,14 @@ module = { + loongarch64 = loader/efi/linux.c; + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; +- i386_efi = loader/efi/linux.c; +- x86_64_efi = loader/efi/linux.c; ++ i386_efi = loader/i386/efi/linux.c; ++ x86_64_efi = loader/i386/efi/linux.c; + emu = loader/emu/linux.c; + fdt = lib/fdt.c; -+ common = loader/linux.c; common = lib/cmdline.c; - enable = noemu; -+ + efi = loader/efi/linux.c; ++ efi = loader/i386/linux.c; }; module = { diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 48f8a79073d..b7149370950 100644 +index c55f0ecf931..d48d4131ba7 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c -@@ -38,6 +38,14 @@ +@@ -32,12 +32,21 @@ + #include + #include + #include ++#include + + /* Platforms where modules are in a readonly area of memory. */ + #if defined(GRUB_MACHINE_QEMU) #define GRUB_MODULES_MACHINE_READONLY #endif @@ -106,12 +109,12 @@ index 48f8a79073d..b7149370950 100644 #pragma GCC diagnostic ignored "-Wcast-align" -@@ -695,6 +703,19 @@ grub_dl_load_file (const char *filename) +@@ -861,6 +870,19 @@ grub_dl_load_file (const char *filename) void *core = 0; grub_dl_t mod = 0; +#ifdef GRUB_MACHINE_EFI -+ if (grub_efi_secure_boot ()) ++ if (grub_efi_get_secureboot ()) + { +#if 0 + /* This is an error, but grub2-mkconfig still generates a pile of @@ -126,50 +129,11 @@ index 48f8a79073d..b7149370950 100644 grub_boot_time ("Loading module %s", filename); file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE); -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 8cff7be0289..35b8f670602 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -286,6 +286,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL); - } - -+grub_efi_boolean_t -+grub_efi_secure_boot (void) -+{ -+ grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; -+ grub_size_t datasize; -+ char *secure_boot = NULL; -+ char *setup_mode = NULL; -+ grub_efi_boolean_t ret = 0; -+ -+ secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); -+ -+ if (datasize != 1 || !secure_boot) -+ goto out; -+ -+ setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); -+ -+ if (datasize != 1 || !setup_mode) -+ goto out; -+ -+ if (*secure_boot && !*setup_mode) -+ ret = 1; -+ -+ out: -+ grub_free (secure_boot); -+ grub_free (setup_mode); -+ return ret; -+} -+ - #pragma GCC diagnostic ignored "-Wcast-align" - - /* Search the mods section from the PE32/PE32+ image. This code uses diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index 9838fb2f50d..f6aef0ef649 100644 +index df443f434d4..fb9dbf52528 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c -@@ -113,6 +113,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address, +@@ -112,6 +112,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address, } } @@ -186,7 +150,7 @@ index 9838fb2f50d..f6aef0ef649 100644 + return 0; + + b = grub_efi_system_table->boot_services; -+ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); ++ status = b->allocate_pages (GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); + + if (status != GRUB_EFI_SUCCESS) + return 0; @@ -196,7 +160,7 @@ index 9838fb2f50d..f6aef0ef649 100644 + /* Uggh, the address 0 was allocated... This is too annoying, + so reallocate another one. */ + address = max; -+ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); ++ status = b->allocate_pages (GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); + grub_efi_free_pages (0, pages); + if (status != GRUB_EFI_SUCCESS) + return 0; @@ -208,231 +172,27 @@ index 9838fb2f50d..f6aef0ef649 100644 /* Allocate pages. Return the pointer to the first of allocated pages. */ void * grub_efi_allocate_pages_real (grub_efi_physical_address_t address, -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index ef3e9f9444c..a312c668685 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -29,6 +29,7 @@ +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index bfbd95aeef0..925394d1767 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -25,10 +25,12 @@ + #include + #include + #include ++#include #include #include #include -+#include #include ++#include + #include #include #include -@@ -41,6 +42,7 @@ static int loaded; +@@ -87,6 +89,51 @@ static grub_efi_load_file2_t initrd_lf2 = { + grub_efi_initrd_load_file2 + }; - static void *kernel_addr; - static grub_uint64_t kernel_size; -+static grub_uint32_t handover_offset; - - static char *linux_args; - static grub_uint32_t cmdline_size; -@@ -67,7 +69,8 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) - static grub_err_t - finalize_params_linux (void) - { -- int node, retval; -+ grub_efi_loaded_image_t *loaded_image = NULL; -+ int node, retval, len; - - void *fdt; - -@@ -102,79 +105,70 @@ finalize_params_linux (void) - if (grub_fdt_install() != GRUB_ERR_NONE) - goto failure; - -- return GRUB_ERR_NONE; -- --failure: -- grub_fdt_unload(); -- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); --} -- --grub_err_t --grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) --{ -- grub_efi_memory_mapped_device_path_t *mempath; -- grub_efi_handle_t image_handle; -- grub_efi_boot_services_t *b; -- grub_efi_status_t status; -- grub_efi_loaded_image_t *loaded_image; -- int len; -- -- mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); -- if (!mempath) -- return grub_errno; -- -- mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE; -- mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; -- mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); -- mempath[0].memory_type = GRUB_EFI_LOADER_DATA; -- mempath[0].start_address = addr; -- mempath[0].end_address = addr + size; -- -- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; -- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; -- mempath[1].header.length = sizeof (grub_efi_device_path_t); -- -- b = grub_efi_system_table->boot_services; -- status = b->load_image (0, grub_efi_image_handle, -- (grub_efi_device_path_t *) mempath, -- (void *) addr, size, &image_handle); -- if (status != GRUB_EFI_SUCCESS) -- return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); -- -- grub_dprintf ("linux", "linux command line: '%s'\n", args); -+ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", -+ fdt); - - /* Convert command line to UCS-2 */ -- loaded_image = grub_efi_get_loaded_image (image_handle); -+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); -+ if (!loaded_image) -+ goto failure; -+ - loaded_image->load_options_size = len = -- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); -+ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); - loaded_image->load_options = - grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); - if (!loaded_image->load_options) -- return grub_errno; -+ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); - - loaded_image->load_options_size = - 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, -- (grub_uint8_t *) args, len, NULL); -+ (grub_uint8_t *) linux_args, len, NULL); - -- grub_dprintf ("linux", "starting image %p\n", image_handle); -- status = b->start_image (image_handle, 0, NULL); -+ return GRUB_ERR_NONE; - -- /* When successful, not reached */ -- b->unload_image (image_handle); -- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, -- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); -+failure: -+ grub_fdt_unload(); -+ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); -+} - -- return grub_errno; -+static void -+free_params (void) -+{ -+ grub_efi_loaded_image_t *loaded_image = NULL; -+ -+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); -+ if (loaded_image) -+ { -+ if (loaded_image->load_options) -+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options, -+ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); -+ loaded_image->load_options = NULL; -+ loaded_image->load_options_size = 0; -+ } -+} -+ -+grub_err_t -+grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args) -+{ -+ grub_err_t retval; -+ -+ retval = finalize_params_linux (); -+ if (retval != GRUB_ERR_NONE) -+ return grub_errno; -+ -+ grub_dprintf ("linux", "linux command line: '%s'\n", args); -+ -+ retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr); -+ -+ /* Never reached... */ -+ free_params(); -+ return retval; - } - - static grub_err_t - grub_linux_boot (void) - { -- if (finalize_params_linux () != GRUB_ERR_NONE) -- return grub_errno; -- -- return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, -- kernel_size, linux_args)); -+ return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, linux_args)); - } - - static grub_err_t -@@ -288,6 +282,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - { - grub_file_t file = 0; - struct linux_arch_kernel_header lh; -+ struct grub_armxx_linux_pe_header *pe; - grub_err_t err; - - grub_dl_ref (my_mod); -@@ -333,6 +328,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); - -+ if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size)) -+ { -+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); -+ goto fail; -+ } -+ -+ pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); -+ handover_offset = pe->opt.entry_addr; -+ - cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); - linux_args = grub_malloc (cmdline_size); - if (!linux_args) -diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c -index 22cc25eccd9..d9b7a9ba400 100644 ---- a/grub-core/loader/arm64/xen_boot.c -+++ b/grub-core/loader/arm64/xen_boot.c -@@ -266,7 +266,6 @@ xen_boot (void) - return err; - - return grub_arch_efi_linux_boot_image (xen_hypervisor->start, -- xen_hypervisor->size, - xen_hypervisor->cmdline); - } - -diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -new file mode 100644 -index 00000000000..c24202a5dd1 ---- /dev/null -+++ b/grub-core/loader/efi/linux.c -@@ -0,0 +1,70 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2014 Free Software Foundation, Inc. -+ * -+ * GRUB is free software: you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation, either version 3 of the License, or -+ * (at your option) any later version. -+ * -+ * GRUB is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with GRUB. If not, see . -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ +#define SHIM_LOCK_GUID \ + { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} } + @@ -445,7 +205,7 @@ index 00000000000..c24202a5dd1 +grub_efi_boolean_t +grub_linuxefi_secure_validate (void *data, grub_uint32_t size) +{ -+ grub_efi_guid_t guid = SHIM_LOCK_GUID; ++ grub_guid_t guid = SHIM_LOCK_GUID; + grub_efi_shim_lock_t *shim_lock; + + shim_lock = grub_efi_locate_protocol(&guid, NULL); @@ -465,21 +225,25 @@ index 00000000000..c24202a5dd1 +typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); + +grub_err_t -+grub_efi_linux_boot (void *kernel_addr, grub_off_t offset, ++grub_efi_linux_boot (void *kernel_address, grub_off_t offset, + void *kernel_params) +{ + handover_func hf; + -+ hf = (handover_func)((char *)kernel_addr + offset); ++ hf = (handover_func)((char *)kernel_address + offset); + hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); + + return GRUB_ERR_BUG; +} + +#pragma GCC diagnostic pop ++ + grub_err_t + grub_arch_efi_linux_load_image_header (grub_file_t file, + struct linux_arch_kernel_header * lh) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c new file mode 100644 -index 00000000000..bb2616a8092 +index 00000000000..9bfb4ab9e3e --- /dev/null +++ b/grub-core/loader/i386/efi/linux.c @@ -0,0 +1,335 @@ @@ -537,7 +301,7 @@ index 00000000000..bb2616a8092 + asm volatile ("cli"); + + return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset, -+ params); ++ params); +} + +static grub_err_t @@ -547,17 +311,17 @@ index 00000000000..bb2616a8092 + loaded = 0; + if (initrd_mem) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, -+ BYTES_TO_PAGES(params->ramdisk_size)); ++ BYTES_TO_PAGES(params->ramdisk_size)); + if (linux_cmdline) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) -+ linux_cmdline, -+ BYTES_TO_PAGES(params->cmdline_size + 1)); ++ linux_cmdline, ++ BYTES_TO_PAGES(params->cmdline_size + 1)); + if (kernel_mem) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, -+ BYTES_TO_PAGES(kernel_size)); ++ BYTES_TO_PAGES(kernel_size)); + if (params) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, -+ BYTES_TO_PAGES(16384)); ++ BYTES_TO_PAGES(16384)); + return GRUB_ERR_NONE; +} + @@ -631,14 +395,14 @@ index 00000000000..bb2616a8092 + + if (initrd_mem && grub_errno) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, -+ BYTES_TO_PAGES(size)); ++ BYTES_TO_PAGES(size)); + + return grub_errno; +} + +static grub_err_t +grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), -+ int argc, char *argv[]) ++ int argc, char *argv[]) +{ + grub_file_t file = 0; + struct linux_i386_kernel_header lh; @@ -676,7 +440,7 @@ index 00000000000..bb2616a8092 + if (! grub_linuxefi_secure_validate (kernel, filelen)) + { + grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), -+ argv[0]); ++ argv[0]); + goto fail; + } + @@ -718,7 +482,7 @@ index 00000000000..bb2616a8092 + + grub_dprintf ("linux", "setting up cmdline\n"); + linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff, -+ BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ BYTES_TO_PAGES(lh.cmdline_size + 1)); + + if (!linux_cmdline) + { @@ -729,8 +493,8 @@ index 00000000000..bb2616a8092 + grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, + linux_cmdline + sizeof (LINUX_IMAGE) - 1, -+ lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1), -+ GRUB_VERIFY_KERNEL_CMDLINE); ++ lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1), ++ GRUB_VERIFY_KERNEL_CMDLINE); + + lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; + @@ -740,11 +504,11 @@ index 00000000000..bb2616a8092 + len = grub_file_size(file) - start; + + kernel_mem = grub_efi_allocate_pages_max(lh.pref_address, -+ BYTES_TO_PAGES(lh.init_size)); ++ BYTES_TO_PAGES(lh.init_size)); + + if (!kernel_mem) + kernel_mem = grub_efi_allocate_pages_max(0x3fffffff, -+ BYTES_TO_PAGES(lh.init_size)); ++ BYTES_TO_PAGES(lh.init_size)); + + if (!kernel_mem) + { @@ -777,16 +541,16 @@ index 00000000000..bb2616a8092 + + if (linux_cmdline && !loaded) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) -+ linux_cmdline, -+ BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ linux_cmdline, ++ BYTES_TO_PAGES(lh.cmdline_size + 1)); + + if (kernel_mem && !loaded) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, -+ BYTES_TO_PAGES(kernel_size)); ++ BYTES_TO_PAGES(kernel_size)); + + if (params && !loaded) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, -+ BYTES_TO_PAGES(16384)); ++ BYTES_TO_PAGES(16384)); + + return grub_errno; +} @@ -819,10 +583,10 @@ index 00000000000..bb2616a8092 + grub_unregister_command (cmd_initrdefi); +} diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 2a299520160..8be4c3b3f48 100644 +index 600530a742b..8593d74737f 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c -@@ -474,14 +474,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), +@@ -483,14 +483,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } @@ -844,7 +608,7 @@ index 2a299520160..8be4c3b3f48 100644 grub_register_command ("initrd16", grub_cmd_initrd, 0, N_("Load initrd.")); my_mod = mod; -@@ -490,5 +496,7 @@ GRUB_MOD_INIT(linux16) +@@ -499,5 +505,7 @@ GRUB_MOD_INIT(linux16) GRUB_MOD_FINI(linux16) { grub_unregister_command (cmd_linux); @@ -852,71 +616,11 @@ index 2a299520160..8be4c3b3f48 100644 grub_unregister_command (cmd_initrd); + grub_unregister_command (cmd_initrd16); } -diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h -index bcd5a7eb186..b582f67f661 100644 ---- a/include/grub/arm/linux.h -+++ b/include/grub/arm/linux.h -@@ -20,6 +20,7 @@ - #ifndef GRUB_ARM_LINUX_HEADER - #define GRUB_ARM_LINUX_HEADER 1 - -+#include - #include "system.h" - - #define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 -@@ -34,9 +35,17 @@ struct linux_arm_kernel_header { - grub_uint32_t hdr_offset; - }; - -+struct grub_arm_linux_pe_header -+{ -+ grub_uint32_t magic; -+ struct grub_pe32_coff_header coff; -+ struct grub_pe32_optional_header opt; -+}; -+ - #if defined(__arm__) - # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE - # define linux_arch_kernel_header linux_arm_kernel_header -+# define grub_armxx_linux_pe_header grub_arm_linux_pe_header - #endif - - #if defined GRUB_MACHINE_UBOOT -diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h -index 7e22b4ab699..ea030312df3 100644 ---- a/include/grub/arm64/linux.h -+++ b/include/grub/arm64/linux.h -@@ -19,6 +19,7 @@ - #ifndef GRUB_ARM64_LINUX_HEADER - #define GRUB_ARM64_LINUX_HEADER 1 - -+#include - #include - - #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ -@@ -38,9 +39,17 @@ struct linux_arm64_kernel_header - grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ - }; - -+struct grub_arm64_linux_pe_header -+{ -+ grub_uint32_t magic; -+ struct grub_pe32_coff_header coff; -+ struct grub_pe64_optional_header opt; -+}; -+ - #if defined(__aarch64__) - # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE - # define linux_arch_kernel_header linux_arm64_kernel_header -+# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header - #endif - - #endif /* ! GRUB_ARM64_LINUX_HEADER */ diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 83d958f9945..6295df85f3f 100644 +index 3670eddc52b..83ddbe26e57 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h -@@ -47,6 +47,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, +@@ -75,6 +75,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); void * EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages); @@ -926,27 +630,9 @@ index 83d958f9945..6295df85f3f 100644 void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); -@@ -88,6 +91,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, - const grub_efi_guid_t *guid, - void *data, - grub_size_t datasize); -+grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void); - int - EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, - const grub_efi_device_path_t *dp2); -@@ -101,8 +105,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); - grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); - #include - grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); --grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, -- char *args); -+grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); - #endif - - grub_addr_t grub_efi_modules_addr (void); diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h new file mode 100644 -index 00000000000..d9ede36773b +index 00000000000..d224daafa4f --- /dev/null +++ b/include/grub/efi/linux.h @@ -0,0 +1,31 @@ @@ -978,6 +664,6 @@ index 00000000000..d9ede36773b +EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size); +grub_err_t +EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, -+ void *kernel_param); ++ void *kernel_param); + +#endif /* ! GRUB_EFI_LINUX_HEADER */ diff --git a/0213-Remove-outdated-URL-for-BLS-document.patch b/0213-Remove-outdated-URL-for-BLS-document.patch deleted file mode 100644 index d380fe88..00000000 --- a/0213-Remove-outdated-URL-for-BLS-document.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 5 Jul 2021 19:00:25 +0200 -Subject: [PATCH] Remove outdated URL for BLS document - -The document was moved to https://systemd.io/BOOT_LOADER_SPECIFICATION/, -update the URL accordingly to point to the current location. - -Resolves: rhbz#1926453 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index c9296154f51..6ee0a2cf3d0 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -96,7 +96,7 @@ cat < +Date: Tue, 2 Apr 2024 12:59:10 -0600 +Subject: [PATCH] fix i386_pc on legacycfg module + +--- + grub-core/Makefile.core.def | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 3f6e944d6a5..b045aac7c91 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2459,6 +2459,7 @@ module = { + common = commands/legacycfg.c; + common = lib/legacy_parse.c; + emu = lib/i386/pc/vesa_modes_table.c; ++ i386_pc = lib/i386/pc/vesa_modes_table.c; + i386_efi = lib/i386/pc/vesa_modes_table.c; + x86_64_efi = lib/i386/pc/vesa_modes_table.c; + xen = lib/i386/pc/vesa_modes_table.c; diff --git a/0214-templates-Check-for-EFI-at-runtime-instead-of-config.patch b/0214-templates-Check-for-EFI-at-runtime-instead-of-config.patch deleted file mode 100644 index e36afa11..00000000 --- a/0214-templates-Check-for-EFI-at-runtime-instead-of-config.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 6 Jul 2021 00:38:40 +0200 -Subject: [PATCH] templates: Check for EFI at runtime instead of config - generation time - -The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var -exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether -a "fwsetup" menu entry would be added or not to the GRUB menu. - -But this has the problem that it will only work if the configuration file -was created on an UEFI machine that supports booting to a firmware UI. - -This for example doesn't support creating GRUB config files when executing -on systems that support both UEFI and legacy BIOS booting. Since creating -the config file from legacy BIOS wouldn't allow to access the firmware UI. - -To prevent this, make the template to unconditionally create the grub.cfg -snippet but check at runtime if was booted through UEFI to decide if this -entry should be added. That way it won't be added when booting with BIOS. - -There's no need to check if EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, -since that's already done by the "fwsetup" command when is executed. - -Resolves: rhbz#1823864 - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/30_uefi-firmware.in | 21 ++++++++------------- - 1 file changed, 8 insertions(+), 13 deletions(-) - -diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in -index d344d3883d7..b6041b55e2a 100644 ---- a/util/grub.d/30_uefi-firmware.in -+++ b/util/grub.d/30_uefi-firmware.in -@@ -26,19 +26,14 @@ export TEXTDOMAINDIR="@localedir@" - - . "$pkgdatadir/grub-mkconfig_lib" - --EFI_VARS_DIR=/sys/firmware/efi/efivars --EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c --OS_INDICATIONS="$EFI_VARS_DIR/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" -+LABEL="UEFI Firmware Settings" - --if [ -e "$OS_INDICATIONS" ] && \ -- [ "$(( $(printf 0x%x \'"$(cat $OS_INDICATIONS | cut -b5)"\') & 1 ))" = 1 ]; then -- LABEL="UEFI Firmware Settings" -+gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 - -- gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 -- -- cat << EOF --menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { -- fwsetup --} --EOF -+cat << EOF -+if [ "\$grub_platform" = "efi" ]; then -+ menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { -+ fwsetup -+ } - fi -+EOF diff --git a/0007-Add-secureboot-support-on-efi-chainloader.patch b/0215-Add-secureboot-support-on-efi-chainloader.patch similarity index 87% rename from 0007-Add-secureboot-support-on-efi-chainloader.patch rename to 0215-Add-secureboot-support-on-efi-chainloader.patch index bfb5a9b6..2e993cb6 100644 --- a/0007-Add-secureboot-support-on-efi-chainloader.patch +++ b/0215-Add-secureboot-support-on-efi-chainloader.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Raymund Will -Date: Mon, 8 Jul 2019 11:55:18 +0200 +Date: Tue, 2 Apr 2024 16:39:53 -0600 Subject: [PATCH] Add secureboot support on efi chainloader Expand the chainloader to be able to verify the image by means of shim @@ -164,104 +164,93 @@ following branches: Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1347291 Signed-off-by: Laszlo Ersek + +Also: + +commit cc06f149fbd2d8c1da1e83173d21629ba97e0d92 +Author: Raymund Will + +chainloader: Define machine types for RISC-V + +The commit "Add secureboot support on efi chainloader" didn't add machine +types for RISC-V, so this patch adds them. + +Note, that grub-core/loader/riscv/linux.c is skipped because Linux is not +supported yet. This patch might need a new revision once that's the case. + +Signed-off-by: David Abdurachmanov --- - grub-core/kern/efi/efi.c | 14 +- - grub-core/loader/arm64/linux.c | 4 +- - grub-core/loader/efi/chainloader.c | 816 +++++++++++++++++++++++++++++++++---- + grub-core/loader/efi/chainloader.c | 849 +++++++++++++++++++++++++++++++++---- grub-core/loader/efi/linux.c | 25 +- grub-core/loader/i386/efi/linux.c | 17 +- include/grub/efi/linux.h | 2 +- - include/grub/efi/pe32.h | 52 ++- - 7 files changed, 840 insertions(+), 90 deletions(-) + include/grub/efi/pe32.h | 51 ++- + 5 files changed, 848 insertions(+), 96 deletions(-) -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 35b8f670602..4a2259aa1c7 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -296,14 +296,20 @@ grub_efi_secure_boot (void) - grub_efi_boolean_t ret = 0; - - secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); -- - if (datasize != 1 || !secure_boot) -- goto out; -+ { -+ grub_dprintf ("secureboot", "No SecureBoot variable\n"); -+ goto out; -+ } -+ grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot); - - setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); -- - if (datasize != 1 || !setup_mode) -- goto out; -+ { -+ grub_dprintf ("secureboot", "No SetupMode variable\n"); -+ goto out; -+ } -+ grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode); - - if (*secure_boot && !*setup_mode) - ret = 1; -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index a312c668685..04994d5c67d 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -284,6 +284,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - struct linux_arch_kernel_header lh; - struct grub_armxx_linux_pe_header *pe; - grub_err_t err; -+ int rc; - - grub_dl_ref (my_mod); - -@@ -328,7 +329,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); - -- if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size)) -+ rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); -+ if (rc < 0) - { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); - goto fail; diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 2bd80f4db3d..b54cf6986fc 100644 +index 2036924504b..e4ac39c87b4 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c -@@ -32,6 +32,8 @@ +@@ -32,6 +32,9 @@ #include #include #include +#include ++#include +#include + #include #include #include - #include -@@ -46,9 +48,14 @@ static grub_dl_t my_mod; +@@ -45,13 +48,24 @@ GRUB_MOD_LICENSE ("GPLv3+"); - static grub_efi_physical_address_t address; - static grub_efi_uintn_t pages; + static grub_dl_t my_mod; + ++static grub_efi_physical_address_t address; ++static grub_efi_uintn_t pages; +static grub_ssize_t fsize; - static grub_efi_device_path_t *file_path; - static grub_efi_handle_t image_handle; - static grub_efi_char16_t *cmdline; ++static grub_efi_device_path_t *file_path; ++static grub_efi_handle_t image_handle; ++static grub_efi_char16_t *cmdline; +static grub_ssize_t cmdline_len; +static grub_efi_handle_t dev_handle; + -+static grub_efi_status_t (*entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); - ++static grub_efi_status_t (__grub_efi_api *entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); ++ static grub_err_t - grub_chainloader_unload (void) -@@ -63,6 +70,7 @@ grub_chainloader_unload (void) - grub_free (cmdline); - cmdline = 0; - file_path = 0; -+ dev_handle = 0; + grub_chainloader_unload (void *context) + { +- grub_efi_handle_t image_handle = (grub_efi_handle_t) context; + grub_efi_loaded_image_t *loaded_image; + grub_efi_boot_services_t *b; - grub_dl_unref (my_mod); - return GRUB_ERR_NONE; -@@ -213,20 +221,690 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) ++ image_handle = (grub_efi_handle_t) context; + loaded_image = grub_efi_get_loaded_image (image_handle); + if (loaded_image != NULL) + grub_free (loaded_image->load_options); +@@ -66,12 +80,12 @@ grub_chainloader_unload (void *context) + static grub_err_t + grub_chainloader_boot (void *context) + { +- grub_efi_handle_t image_handle = (grub_efi_handle_t) context; + grub_efi_boot_services_t *b; + grub_efi_status_t status; + grub_efi_uintn_t exit_data_size; + grub_efi_char16_t *exit_data = NULL; + ++ image_handle = (grub_efi_handle_t) context; + b = grub_efi_system_table->boot_services; + status = b->start_image (image_handle, &exit_data_size, &exit_data); + if (status != GRUB_EFI_SUCCESS) +@@ -136,7 +150,7 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + char *dir_start; + char *dir_end; + grub_size_t size; +- grub_efi_device_path_t *d, *file_path; ++ grub_efi_device_path_t *d; + + dir_start = grub_strchr (filename, ')'); + if (! dir_start) +@@ -209,24 +223,701 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) return file_path; } @@ -312,7 +301,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 +read_header (void *data, grub_efi_uint32_t size, + pe_coff_loader_image_context_t *context) +{ -+ grub_efi_guid_t guid = SHIM_LOCK_GUID; ++ grub_guid_t guid = SHIM_LOCK_GUID; + grub_efi_shim_lock_t *shim_lock; + grub_efi_status_t status; + @@ -376,6 +365,10 @@ index 2bd80f4db3d..b54cf6986fc 100644 + GRUB_PE32_MACHINE_I386; +#elif defined(__ia64__) + GRUB_PE32_MACHINE_IA64; ++#elif defined(__riscv) && (__riscv_xlen == 32) ++ GRUB_PE32_MACHINE_RISCV32; ++#elif defined(__riscv) && (__riscv_xlen == 64) ++ GRUB_PE32_MACHINE_RISCV64; +#else +#error this architecture is not supported by grub2 +#endif @@ -621,8 +614,8 @@ index 2bd80f4db3d..b54cf6986fc 100644 + grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n", + context.image_size, datasize); + -+ efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, -+ buffer_size, &buffer); ++ efi_status = b->allocate_pool (GRUB_EFI_LOADER_DATA, ++ buffer_size, (void**)&buffer); + + if (efi_status != GRUB_EFI_SUCCESS) + { @@ -849,19 +842,19 @@ index 2bd80f4db3d..b54cf6986fc 100644 + } + + grub_dprintf ("chain", "booting via entry point\n"); -+ efi_status = efi_call_2 (entry_point, grub_efi_image_handle, -+ grub_efi_system_table); ++ efi_status = entry_point (grub_efi_image_handle, ++ grub_efi_system_table); + + grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); + grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); -+ efi_status = efi_call_1 (b->free_pool, buffer); ++ efi_status = b->free_pool (buffer); + + return 1; + +error_exit: + grub_dprintf ("chain", "error_exit: grub_errno: %d\n", grub_errno); + if (buffer) -+ efi_call_1 (b->free_pool, buffer); ++ b->free_pool (buffer); + + return 0; +} @@ -872,7 +865,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 + grub_efi_boot_services_t *b; + + b = grub_efi_system_table->boot_services; -+ efi_call_2 (b->free_pages, address, pages); ++ b->free_pages (address, pages); + grub_free (file_path); + grub_free (cmdline); + cmdline = 0; @@ -892,8 +885,8 @@ index 2bd80f4db3d..b54cf6986fc 100644 + + b = grub_efi_system_table->boot_services; + -+ status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, -+ boot_image, fsize, &image_handle); ++ status = b->load_image (0, grub_efi_image_handle, file_path, ++ boot_image, fsize, &image_handle); + if (status != GRUB_EFI_SUCCESS) + { + if (status == GRUB_EFI_OUT_OF_RESOURCES) @@ -946,20 +939,28 @@ index 2bd80f4db3d..b54cf6986fc 100644 grub_efi_status_t status; grub_efi_boot_services_t *b; grub_device_t dev = 0; - grub_efi_device_path_t *dp = 0; +- grub_efi_device_path_t *dp = NULL, *file_path = NULL; - grub_efi_loaded_image_t *loaded_image; ++ grub_efi_device_path_t *dp = NULL; char *filename; void *boot_image = 0; - grub_efi_handle_t dev_handle = 0; +- grub_efi_physical_address_t address = 0; +- grub_efi_uintn_t pages = 0; +- grub_efi_char16_t *cmdline = NULL; +- grub_efi_handle_t image_handle = NULL; + int rc; ++ ++ file_path = NULL; ++ address = 0; ++ pages = 0; ++ cmdline = NULL; ++ image_handle = NULL; ++ dev_handle = 0; if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -@@ -238,15 +916,45 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - address = 0; - image_handle = 0; - file_path = 0; -+ dev_handle = 0; +@@ -236,12 +927,42 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), b = grub_efi_system_table->boot_services; @@ -988,6 +989,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 + } + *(--p16) = 0; + } ++ + file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE); if (! file) @@ -1000,16 +1002,18 @@ index 2bd80f4db3d..b54cf6986fc 100644 + dev = grub_device_open (devname); + if (devname) + grub_free (devname); - if (! dev) - goto fail; - -@@ -283,17 +991,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - if (! file_path) - goto fail; - -- grub_printf ("file path: "); -- grub_efi_print_device_path (file_path); + if (dev == NULL) + ; + else if (dev->disk) +@@ -272,19 +993,16 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + file_path = make_file_path (dp, filename); + if (file_path == NULL) + goto fail; - +- grub_printf ("file path: "); +- grub_efi_print_device_path (file_path); + } + - size = grub_file_size (file); - if (!size) + fsize = grub_file_size (file); @@ -1019,12 +1023,12 @@ index 2bd80f4db3d..b54cf6986fc 100644 filename); goto fail; } -- pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12); -+ pages = (((grub_efi_uintn_t) fsize + ((1 << 12) - 1)) >> 12); +- pages = (grub_efi_uintn_t) GRUB_EFI_BYTES_TO_PAGES (size); ++ pages = (grub_efi_uintn_t) GRUB_EFI_BYTES_TO_PAGES (fsize); - 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, -@@ -307,7 +1012,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -298,7 +1016,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } boot_image = (void *) ((grub_addr_t) address); @@ -1033,7 +1037,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 { if (grub_errno == GRUB_ERR_NONE) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -@@ -317,7 +1022,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -308,7 +1026,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } #if defined (__i386__) || defined (__x86_64__) @@ -1042,7 +1046,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 { struct grub_macho_fat_header *head = boot_image; if (head->magic -@@ -326,6 +1031,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -317,6 +1035,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), grub_uint32_t i; struct grub_macho_fat_arch *archs = (struct grub_macho_fat_arch *) (head + 1); @@ -1057,7 +1061,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 for (i = 0; i < grub_cpu_to_le32 (head->nfat_arch); i++) { if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype)) -@@ -340,79 +1053,39 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -331,83 +1057,39 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), > ~grub_cpu_to_le32 (archs[i].size) || grub_cpu_to_le32 (archs[i].offset) + grub_cpu_to_le32 (archs[i].size) @@ -1075,9 +1079,9 @@ index 2bd80f4db3d..b54cf6986fc 100644 } #endif -- status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, -- boot_image, size, -- &image_handle); +- status = b->load_image (0, grub_efi_image_handle, file_path, +- boot_image, size, +- &image_handle); - if (status != GRUB_EFI_SUCCESS) + rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); + grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); @@ -1108,6 +1112,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 - } - loaded_image->device_handle = dev_handle; - +- /* Build load options with arguments from chainloader command line. */ - if (argc > 1) - { - int i, len; @@ -1123,7 +1128,7 @@ index 2bd80f4db3d..b54cf6986fc 100644 + grub_load_and_start_image(boot_image); + grub_file_close (file); + grub_device_close (dev); -+ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); ++ grub_loader_set_ex (grub_chainloader_boot, grub_chainloader_unload, image_handle, 0); - for (i = 1; i < argc; i++) - { @@ -1145,30 +1150,33 @@ index 2bd80f4db3d..b54cf6986fc 100644 - grub_file_close (file); - grub_device_close (dev); - -- grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); +- /* We're finished with the source image buffer and file path now. */ +- b->free_pages (address, pages); +- grub_free (file_path); +- +- grub_loader_set_ex (grub_chainloader_boot, grub_chainloader_unload, image_handle, 0); - return 0; - - fail: -- +fail: + if (dev) grub_device_close (dev); - -@@ -424,6 +1097,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -421,6 +1103,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (address) - efi_call_2 (b->free_pages, address, pages); + grub_efi_free_pages (address, pages); + if (cmdline) + grub_free (cmdline); + - grub_dl_unref (my_mod); + if (image_handle != NULL) + b->unload_image (image_handle); - return grub_errno; diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index c24202a5dd1..c8ecce6dfd0 100644 +index 925394d1767..0a7f8208022 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c -@@ -33,21 +33,34 @@ struct grub_efi_shim_lock +@@ -98,21 +98,36 @@ struct grub_efi_shim_lock }; typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; @@ -1176,12 +1184,12 @@ index c24202a5dd1..c8ecce6dfd0 100644 +int grub_linuxefi_secure_validate (void *data, grub_uint32_t size) { - grub_efi_guid_t guid = SHIM_LOCK_GUID; + grub_guid_t guid = SHIM_LOCK_GUID; grub_efi_shim_lock_t *shim_lock; + grub_efi_status_t status; shim_lock = grub_efi_locate_protocol(&guid, NULL); -- + + grub_dprintf ("secureboot", "shim_lock: %p\n", shim_lock); if (!shim_lock) - return 1; @@ -1200,17 +1208,18 @@ index c24202a5dd1..c8ecce6dfd0 100644 + grub_dprintf ("secureboot", "Kernel signature verification passed\n"); + return 1; + } - -- return 0; ++ + grub_dprintf ("secureboot", "Kernel signature verification failed (0x%lx)\n", + (unsigned long) status); + + return -1; + +- return 0; } #pragma GCC diagnostic push diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index bb2616a8092..6b24cbb9483 100644 +index 9bfb4ab9e3e..b59d125286d 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -117,6 +117,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), @@ -1236,7 +1245,7 @@ index bb2616a8092..6b24cbb9483 100644 { - grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), argv[0]); + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), -+ argv[0]); ++ argv[0]); goto fail; } @@ -1245,7 +1254,7 @@ index bb2616a8092..6b24cbb9483 100644 + if (rc < 0) { grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), - argv[0]); + argv[0]); @@ -203,6 +208,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } @@ -1260,7 +1269,7 @@ index bb2616a8092..6b24cbb9483 100644 } + grub_dprintf ("linux", "linux_cmdline = %lx\n", -+ (unsigned long)linux_cmdline); ++ (unsigned long)linux_cmdline); + grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); grub_create_loader_cmdline (argc, argv, @@ -1270,7 +1279,7 @@ index bb2616a8092..6b24cbb9483 100644 params->type_of_loader = 0x21; + grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n", -+ kernel_mem, handover_offset); ++ kernel_mem, handover_offset); fail: - @@ -1278,7 +1287,7 @@ index bb2616a8092..6b24cbb9483 100644 grub_file_close (file); diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h -index d9ede36773b..0033d9305a9 100644 +index d224daafa4f..b2cfd8c1f44 100644 --- a/include/grub/efi/linux.h +++ b/include/grub/efi/linux.h @@ -22,7 +22,7 @@ @@ -1291,10 +1300,10 @@ index d9ede36773b..0033d9305a9 100644 grub_err_t EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h -index 0ed8781f037..a43adf27464 100644 +index 9887e14b278..a39743396dc 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h -@@ -223,7 +223,11 @@ struct grub_pe64_optional_header +@@ -238,7 +238,11 @@ struct grub_pe64_optional_header struct grub_pe32_section_table { char name[8]; @@ -1307,7 +1316,7 @@ index 0ed8781f037..a43adf27464 100644 grub_uint32_t virtual_address; grub_uint32_t raw_data_size; grub_uint32_t raw_data_offset; -@@ -234,12 +238,18 @@ struct grub_pe32_section_table +@@ -249,12 +253,18 @@ struct grub_pe32_section_table grub_uint32_t characteristics; }; @@ -1330,7 +1339,7 @@ index 0ed8781f037..a43adf27464 100644 #define GRUB_PE32_SCN_ALIGN_1BYTES 0x00100000 #define GRUB_PE32_SCN_ALIGN_2BYTES 0x00200000 -@@ -248,10 +258,28 @@ struct grub_pe32_section_table +@@ -263,10 +273,26 @@ struct grub_pe32_section_table #define GRUB_PE32_SCN_ALIGN_16BYTES 0x00500000 #define GRUB_PE32_SCN_ALIGN_32BYTES 0x00600000 #define GRUB_PE32_SCN_ALIGN_64BYTES 0x00700000 @@ -1353,13 +1362,11 @@ index 0ed8781f037..a43adf27464 100644 +#define GRUB_PE32_SCN_MEM_EXECUTE 0x20000000 +#define GRUB_PE32_SCN_MEM_READ 0x40000000 +#define GRUB_PE32_SCN_MEM_WRITE 0x80000000 -+ -+ + #define GRUB_PE32_SIGNATURE_SIZE 4 - struct grub_pe32_header -@@ -274,6 +302,20 @@ struct grub_pe32_header + #if GRUB_TARGET_SIZEOF_VOID_P == 8 +@@ -292,6 +318,21 @@ struct grub_pe_image_header #endif }; @@ -1376,6 +1383,7 @@ index 0ed8781f037..a43adf27464 100644 + struct grub_pe32_coff_header coff_header; + struct grub_pe64_optional_header optional_header; +}; ++ + struct grub_pe32_fixup_block { diff --git a/0215-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch b/0215-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch deleted file mode 100644 index 65b4aec5..00000000 --- a/0215-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch +++ /dev/null @@ -1,92 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 6 Jul 2021 01:10:18 +0200 -Subject: [PATCH] efi: Print an error if boot to firmware setup is not - supported - -The "fwsetup" command is only registered if the firmware supports booting -to the firmware setup UI. But it could be possible that the GRUB config -already contains a "fwsetup" entry, because it was generated in a machine -that has support for this feature. - -To prevent users getting a "can't find command `fwsetup`" error if it is -not supported by the firmware, let's just always register the command but -print a more accurate message if the firmware doesn't support this option. - -Resolves: rhbz#1823864 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/efi/efifwsetup.c | 43 ++++++++++++++++++++----------------- - 1 file changed, 23 insertions(+), 20 deletions(-) - -diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c -index eaca0328388..328c45e82e0 100644 ---- a/grub-core/commands/efi/efifwsetup.c -+++ b/grub-core/commands/efi/efifwsetup.c -@@ -27,6 +27,25 @@ - - GRUB_MOD_LICENSE ("GPLv3+"); - -+static grub_efi_boolean_t -+efifwsetup_is_supported (void) -+{ -+ grub_efi_uint64_t *os_indications_supported = NULL; -+ grub_size_t oi_size = 0; -+ grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; -+ -+ grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, -+ (void **) &os_indications_supported); -+ -+ if (!os_indications_supported) -+ return 0; -+ -+ if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI) -+ return 1; -+ -+ return 0; -+} -+ - static grub_err_t - grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), -@@ -38,6 +57,10 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), - grub_size_t oi_size; - grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; - -+ if (!efifwsetup_is_supported ()) -+ return grub_error (GRUB_ERR_INVALID_COMMAND, -+ N_("Reboot to firmware setup is not supported")); -+ - grub_efi_get_variable ("OsIndications", &global, &oi_size, - (void **) &old_os_indications); - -@@ -56,28 +79,8 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), - - static grub_command_t cmd = NULL; - --static grub_efi_boolean_t --efifwsetup_is_supported (void) --{ -- grub_efi_uint64_t *os_indications_supported = NULL; -- grub_size_t oi_size = 0; -- grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; -- -- grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, -- (void **) &os_indications_supported); -- -- if (!os_indications_supported) -- return 0; -- -- if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI) -- return 1; -- -- return 0; --} -- - GRUB_MOD_INIT (efifwsetup) - { -- if (efifwsetup_is_supported ()) - cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL, - N_("Reboot into firmware setup menu.")); - diff --git a/0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch b/0216-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch similarity index 68% rename from 0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch rename to 0216-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch index 3182fe99..8313e06c 100644 --- a/0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch +++ b/0216-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones -Date: Tue, 6 Oct 2015 16:09:25 -0400 +Date: Tue, 13 Feb 2024 16:30:24 -0600 Subject: [PATCH] Make any of the loaders that link in efi mode honor secure boot. @@ -9,23 +9,20 @@ won't register commands if SB is enabled." Signed-off-by: Peter Jones --- - grub-core/commands/iorw.c | 7 +++++++ - grub-core/commands/memrw.c | 7 +++++++ - grub-core/kern/dl.c | 3 ++- - grub-core/kern/efi/efi.c | 34 ---------------------------------- - grub-core/loader/efi/appleloader.c | 7 +++++++ - grub-core/loader/efi/chainloader.c | 1 + - grub-core/loader/i386/bsd.c | 7 +++++++ - grub-core/loader/i386/linux.c | 7 +++++++ - grub-core/loader/i386/pc/linux.c | 7 +++++++ - grub-core/loader/multiboot.c | 7 +++++++ - grub-core/loader/xnu.c | 7 +++++++ - include/grub/efi/efi.h | 1 - - include/grub/ia64/linux.h | 0 - include/grub/mips/linux.h | 0 - include/grub/powerpc/linux.h | 0 - include/grub/sparc64/linux.h | 0 - 16 files changed, 59 insertions(+), 36 deletions(-) + grub-core/commands/iorw.c | 7 +++++++ + grub-core/commands/memrw.c | 7 +++++++ + grub-core/kern/dl.c | 4 ++-- + grub-core/loader/efi/appleloader.c | 7 +++++++ + grub-core/loader/i386/bsd.c | 7 +++++++ + grub-core/loader/i386/linux.c | 7 +++++++ + grub-core/loader/i386/pc/linux.c | 7 +++++++ + grub-core/loader/multiboot.c | 7 +++++++ + grub-core/loader/xnu.c | 7 +++++++ + include/grub/ia64/linux.h | 0 + include/grub/mips/linux.h | 0 + include/grub/powerpc/linux.h | 0 + include/grub/sparc64/linux.h | 0 + 13 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 include/grub/ia64/linux.h create mode 100644 include/grub/mips/linux.h create mode 100644 include/grub/powerpc/linux.h @@ -96,73 +93,27 @@ index d401a6db0ef..39cf3a06dbd 100644 grub_unregister_extcmd (cmd_read_word); grub_unregister_extcmd (cmd_read_dword); diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index b7149370950..7afb9e6f724 100644 +index d48d4131ba7..2a9ae9fc894 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c -@@ -32,6 +32,7 @@ - #include - #include - #include -+#include - - /* Platforms where modules are in a readonly area of memory. */ - #if defined(GRUB_MACHINE_QEMU) -@@ -704,7 +705,7 @@ grub_dl_load_file (const char *filename) +@@ -871,13 +871,13 @@ grub_dl_load_file (const char *filename) grub_dl_t mod = 0; #ifdef GRUB_MACHINE_EFI -- if (grub_efi_secure_boot ()) +- if (grub_efi_get_secureboot ()) + if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) { #if 0 /* This is an error, but grub2-mkconfig still generates a pile of -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index 4a2259aa1c7..8cff7be0289 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -286,40 +286,6 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL); - } - --grub_efi_boolean_t --grub_efi_secure_boot (void) --{ -- grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; -- grub_size_t datasize; -- char *secure_boot = NULL; -- char *setup_mode = NULL; -- grub_efi_boolean_t ret = 0; -- -- secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); -- if (datasize != 1 || !secure_boot) -- { -- grub_dprintf ("secureboot", "No SecureBoot variable\n"); -- goto out; -- } -- grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot); -- -- setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); -- if (datasize != 1 || !setup_mode) -- { -- grub_dprintf ("secureboot", "No SetupMode variable\n"); -- goto out; -- } -- grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode); -- -- if (*secure_boot && !*setup_mode) -- ret = 1; -- -- out: -- grub_free (secure_boot); -- grub_free (setup_mode); -- return ret; --} -- - #pragma GCC diagnostic ignored "-Wcast-align" - - /* Search the mods section from the PE32/PE32+ image. This code uses + * insmod commands, so emitting it would be mostly just obnoxious. */ + grub_error (GRUB_ERR_ACCESS_DENIED, +- "Secure Boot forbids loading module from %s", filename); ++ "Secure Boot forbids loading module from %s", filename); + #endif + return 0; + } diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c -index 74888c463ba..585f2b57385 100644 +index a0b61a240b7..35d53c5f85d 100644 --- a/grub-core/loader/efi/appleloader.c +++ b/grub-core/loader/efi/appleloader.c @@ -24,6 +24,7 @@ @@ -192,20 +143,8 @@ index 74888c463ba..585f2b57385 100644 + grub_unregister_command (cmd); } -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index b54cf6986fc..3ff305b1d32 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -34,6 +34,7 @@ - #include - #include - #include -+#include - #include - #include - #include diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c -index 5f3290ce17b..54befc26626 100644 +index 1f9128f6f20..8075ac9b06a 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -40,6 +40,7 @@ @@ -237,7 +176,7 @@ index 5f3290ce17b..54befc26626 100644 grub_unregister_extcmd (cmd_openbsd); grub_unregister_extcmd (cmd_netbsd); diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index dccf3bb3005..4aeb0e4b9a6 100644 +index 10f967f2563..5a257552234 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -37,6 +37,7 @@ @@ -248,7 +187,7 @@ index dccf3bb3005..4aeb0e4b9a6 100644 GRUB_MOD_LICENSE ("GPLv3+"); -@@ -1138,6 +1139,9 @@ static grub_command_t cmd_linux, cmd_initrd; +@@ -1164,6 +1165,9 @@ static grub_command_t cmd_linux, cmd_initrd; GRUB_MOD_INIT(linux) { @@ -258,7 +197,7 @@ index dccf3bb3005..4aeb0e4b9a6 100644 cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, -@@ -1147,6 +1151,9 @@ GRUB_MOD_INIT(linux) +@@ -1173,6 +1177,9 @@ GRUB_MOD_INIT(linux) GRUB_MOD_FINI(linux) { @@ -269,7 +208,7 @@ index dccf3bb3005..4aeb0e4b9a6 100644 grub_unregister_command (cmd_initrd); } diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 4b1750e360e..e3fa1221e81 100644 +index 8593d74737f..54a76504a79 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -36,6 +36,7 @@ @@ -301,7 +240,7 @@ index 4b1750e360e..e3fa1221e81 100644 grub_unregister_command (cmd_linux16); grub_unregister_command (cmd_initrd); diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index facb13f3d36..47e481f4576 100644 +index 94be512c4d0..94c112a29d4 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -50,6 +50,7 @@ @@ -333,7 +272,7 @@ index facb13f3d36..47e481f4576 100644 grub_unregister_command (cmd_module); } diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c -index 1c0cf6a430a..baa54e652ab 100644 +index 4cca55df92d..f76f511ac2d 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -35,6 +35,7 @@ @@ -364,18 +303,6 @@ index 1c0cf6a430a..baa54e652ab 100644 #ifndef GRUB_MACHINE_EMU grub_unregister_command (cmd_resume); #endif -diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 6295df85f3f..585fa6662b6 100644 ---- a/include/grub/efi/efi.h -+++ b/include/grub/efi/efi.h -@@ -91,7 +91,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, - const grub_efi_guid_t *guid, - void *data, - grub_size_t datasize); --grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void); - int - EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, - const grub_efi_device_path_t *dp2); diff --git a/include/grub/ia64/linux.h b/include/grub/ia64/linux.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/0044-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch b/0217-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch similarity index 93% rename from 0044-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch rename to 0217-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch index 3e2d3ae5..428737cd 100644 --- a/0044-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch +++ b/0217-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch @@ -10,10 +10,10 @@ Signed-off-by: Peter Jones 1 file changed, 8 insertions(+) diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 301d1ac229a..0f6505bf3b6 100644 +index c2e107b41ab..4eadcba4b85 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in -@@ -253,6 +253,14 @@ version_test_gt () +@@ -299,6 +299,14 @@ version_test_gt () *.old:*.old) ;; *.old:*) version_test_gt_a="`echo "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;; *:*.old) version_test_gt_b="`echo "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;; diff --git a/0082-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch b/0218-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch similarity index 79% rename from 0082-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch rename to 0218-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch index a8a757e5..c0f17078 100644 --- a/0082-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch +++ b/0218-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch @@ -13,10 +13,10 @@ Signed-off-by: Peter Jones 2 files changed, 20 insertions(+) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index a432a6be54a..9a2fae6398e 100644 +index 96ab7c96b52..98700423d79 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c -@@ -191,6 +191,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition, +@@ -280,6 +280,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition, } } @@ -42,13 +42,13 @@ index a432a6be54a..9a2fae6398e 100644 int diff --git a/include/grub/misc.h b/include/grub/misc.h -index fd18e6320b8..3adc4036e3b 100644 +index 3e9a00f0a9c..db517acd592 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h -@@ -345,6 +345,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file, - const int line, - const char *condition, +@@ -386,6 +386,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file, const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5))); + int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); + int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); +void EXPORT_FUNC(grub_qdprintf) (const char *condition, + const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 2, 3))); int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args); diff --git a/0219-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch b/0219-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch new file mode 100644 index 00000000..c7d42e4d --- /dev/null +++ b/0219-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch @@ -0,0 +1,83 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 4 Apr 2024 11:57:54 -0600 +Subject: [PATCH] Make a "gdb" dprintf that tells us load addresses. + +This makes a grub_dprintf() call during platform init and during module +loading that tells us the virtual addresses of the .text and .data +sections of grub-core/kernel.exec and any modules it loads. + +Specifically, it displays them in the gdb "add-symbol-file" syntax, with +the presumption that there's a variable $grubdir that reflects the path +to any such binaries. + +Signed-off-by: Peter Jones +--- + grub-core/kern/dl.c | 34 ++++++++++++++++++++++++++++++++++ + grub-core/kern/efi/init.c | 1 + + 2 files changed, 35 insertions(+) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 2a9ae9fc894..2eaef7150ed 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -690,6 +690,38 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) + return GRUB_ERR_NONE; + } + ++static void ++grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e) ++{ ++ void *text, *data = NULL; ++ long idx; ++ ++ idx = grub_dl_find_section_index (e, ".text"); ++ if (idx < 0) ++ return; ++ ++ text = grub_dl_get_section_addr (mod, idx); ++ if (!text) ++ return; ++ ++ idx = grub_dl_find_section_index (e, ".data"); ++ if (idx >= 0) ++ data = grub_dl_get_section_addr (mod, idx); ++ ++ if (data) ++ grub_qdprintf ("gdb", "add-symbol-file \\\n" ++ "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug " ++ "\\\n %p -s .data %p\n", ++ GRUB_TARGET_CPU, GRUB_PLATFORM, ++ mod->name, text, data); ++ else ++ grub_qdprintf ("gdb", "add-symbol-file \\\n" ++ "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug " ++ "\\\n%p\n", ++ GRUB_TARGET_CPU, GRUB_PLATFORM, ++ mod->name, text); ++} ++ + static grub_err_t + grub_dl_set_mem_attrs (grub_dl_t mod, void *ehdr) + { +@@ -833,6 +865,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) + grub_dprintf ("modules", "module name: %s\n", mod->name); + grub_dprintf ("modules", "init function: %p\n", mod->init); + ++ grub_dl_print_gdb_info (mod, e); ++ + if (grub_dl_add (mod)) + { + grub_dl_unload (mod); +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index dee3918fd35..d35d6974734 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -157,6 +157,7 @@ grub_efi_init (void) + grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL); + + grub_efi_env_init (); ++ grub_efi_print_gdb_info (); + grub_efidisk_init (); + + grub_efi_register_debug_commands (); diff --git a/0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch b/0220-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch similarity index 84% rename from 0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch rename to 0220-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch index f3aae389..0284cc64 100644 --- a/0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch +++ b/0220-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch @@ -7,40 +7,40 @@ Allow booting 64-bit kernels on 32-bit EFI on x86. Signed-off-by: Peter Jones --- - grub-core/loader/efi/linux.c | 9 +++- - grub-core/loader/i386/efi/linux.c | 110 ++++++++++++++++++++++++++------------ - include/grub/i386/linux.h | 7 ++- - 3 files changed, 89 insertions(+), 37 deletions(-) + grub-core/loader/efi/linux.c | 9 ++- + grub-core/loader/i386/efi/linux.c | 116 ++++++++++++++++++++++++++------------ + include/grub/i386/linux.h | 5 ++ + 3 files changed, 91 insertions(+), 39 deletions(-) diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index c8ecce6dfd0..0622dfa48d4 100644 +index 0a7f8208022..742e8e9af35 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c -@@ -69,12 +69,17 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) +@@ -136,12 +136,17 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); grub_err_t --grub_efi_linux_boot (void *kernel_addr, grub_off_t offset, -+grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, +-grub_efi_linux_boot (void *kernel_address, grub_off_t offset, ++grub_efi_linux_boot (void *kernel_address, grub_off_t handover_offset, void *kernel_params) { handover_func hf; + int offset = 0; -- hf = (handover_func)((char *)kernel_addr + offset); +- hf = (handover_func)((char *)kernel_address + offset); +#ifdef __x86_64__ + offset = 512; +#endif + -+ hf = (handover_func)((char *)kernel_addr + handover_offset + offset); ++ hf = (handover_func)((char *)kernel_address + handover_offset + offset); hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); return GRUB_ERR_BUG; diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 6b24cbb9483..3017d0f3e52 100644 +index b59d125286d..3c2e30f8751 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c -@@ -44,14 +44,10 @@ static char *linux_cmdline; +@@ -44,15 +44,11 @@ static char *linux_cmdline; static grub_err_t grub_linuxefi_boot (void) { @@ -52,11 +52,13 @@ index 6b24cbb9483..3017d0f3e52 100644 asm volatile ("cli"); - return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset, +- params); + return grub_efi_linux_boot ((char *)kernel_mem, + handover_offset, - params); ++ params); } + static grub_err_t @@ -153,14 +149,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } @@ -68,7 +70,7 @@ index 6b24cbb9483..3017d0f3e52 100644 + static grub_err_t grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc, char *argv[]) + int argc, char *argv[]) { grub_file_t file = 0; - struct linux_i386_kernel_header lh; @@ -166,7 +168,7 @@ index 6b24cbb9483..3017d0f3e52 100644 + grub_dprintf ("linux", "setting up cmdline\n"); linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff, -- BYTES_TO_PAGES(lh.cmdline_size + 1)); +- BYTES_TO_PAGES(lh.cmdline_size + 1)); - + BYTES_TO_PAGES(lh->cmdline_size + 1)); if (!linux_cmdline) @@ -176,9 +178,10 @@ index 6b24cbb9483..3017d0f3e52 100644 grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); grub_create_loader_cmdline (argc, argv, linux_cmdline + sizeof (LINUX_IMAGE) - 1, -- lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1), +- lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1), +- GRUB_VERIFY_KERNEL_CMDLINE); + lh->cmdline_size - (sizeof (LINUX_IMAGE) - 1), - GRUB_VERIFY_KERNEL_CMDLINE); ++ GRUB_VERIFY_KERNEL_CMDLINE); - lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; + grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); @@ -194,13 +197,13 @@ index 6b24cbb9483..3017d0f3e52 100644 + start = (lh->setup_sects + 1) * 512; - kernel_mem = grub_efi_allocate_pages_max(lh.pref_address, -- BYTES_TO_PAGES(lh.init_size)); +- BYTES_TO_PAGES(lh.init_size)); + kernel_mem = grub_efi_allocate_pages_max(lh->pref_address, + BYTES_TO_PAGES(lh->init_size)); if (!kernel_mem) kernel_mem = grub_efi_allocate_pages_max(0x3fffffff, -- BYTES_TO_PAGES(lh.init_size)); +- BYTES_TO_PAGES(lh.init_size)); + BYTES_TO_PAGES(lh->init_size)); if (!kernel_mem) @@ -229,7 +232,7 @@ index 6b24cbb9483..3017d0f3e52 100644 + params->ext_loader_type = 0; + params->ext_loader_ver = 2; grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n", - kernel_mem, handover_offset); + kernel_mem, handover_offset); @@ -301,10 +343,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), loaded = 0; @@ -238,27 +241,26 @@ index 6b24cbb9483..3017d0f3e52 100644 - if (linux_cmdline && !loaded) + if (linux_cmdline && lh && !loaded) grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) - linux_cmdline, -- BYTES_TO_PAGES(lh.cmdline_size + 1)); +- linux_cmdline, +- BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ linux_cmdline, + BYTES_TO_PAGES(lh->cmdline_size + 1)); if (kernel_mem && !loaded) grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h -index eddf9251d9a..25ef52c04eb 100644 +index d4b55086953..4ccd9d7d9f2 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h -@@ -138,7 +138,12 @@ struct linux_i386_kernel_header +@@ -148,6 +148,11 @@ struct linux_i386_kernel_header grub_uint32_t kernel_alignment; grub_uint8_t relocatable; grub_uint8_t min_alignment; -- grub_uint8_t pad[2]; +#define LINUX_XLF_KERNEL_64 (1<<0) +#define LINUX_XLF_CAN_BE_LOADED_ABOVE_4G (1<<1) +#define LINUX_XLF_EFI_HANDOVER_32 (1<<2) +#define LINUX_XLF_EFI_HANDOVER_64 (1<<3) +#define LINUX_XLF_EFI_KEXEC (1<<4) -+ grub_uint16_t xloadflags; + grub_uint16_t xloadflags; grub_uint32_t cmdline_size; grub_uint32_t hardware_subarch; - grub_uint64_t hardware_subarch_data; diff --git a/0115-Try-to-pick-better-locations-for-kernel-and-initrd.patch b/0221-Try-to-pick-better-locations-for-kernel-and-initrd.patch similarity index 88% rename from 0115-Try-to-pick-better-locations-for-kernel-and-initrd.patch rename to 0221-Try-to-pick-better-locations-for-kernel-and-initrd.patch index ba918edf..2927f4b4 100644 --- a/0115-Try-to-pick-better-locations-for-kernel-and-initrd.patch +++ b/0221-Try-to-pick-better-locations-for-kernel-and-initrd.patch @@ -23,6 +23,9 @@ Additionally, we now try to locate kernel+initrd+cmdline+etc below we try a higher address. Signed-off-by: Peter Jones +[david.abdurachmanov: fix macro for riscv64] +Signed-off-by: David Abdurachmanov +Signed-off-by: Robbie Harwood --- grub-core/kern/efi/mm.c | 8 ++++---- grub-core/loader/i386/efi/linux.c | 24 +++++++++++++++++------- @@ -30,14 +33,15 @@ Signed-off-by: Peter Jones include/grub/arm64/efi/memory.h | 1 + include/grub/i386/efi/memory.h | 1 + include/grub/ia64/efi/memory.h | 1 + + include/grub/riscv64/efi/memory.h | 1 + include/grub/x86_64/efi/memory.h | 4 +++- - 7 files changed, 28 insertions(+), 12 deletions(-) + 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index 85ad4b4494c..e84961d078c 100644 +index fb9dbf52528..8f75205a732 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c -@@ -122,7 +122,7 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max, +@@ -121,7 +121,7 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max, grub_efi_boot_services_t *b; grub_efi_physical_address_t address = max; @@ -46,7 +50,7 @@ index 85ad4b4494c..e84961d078c 100644 return 0; b = grub_efi_system_table->boot_services; -@@ -480,7 +480,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, +@@ -477,7 +477,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, { if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY #if 1 @@ -55,7 +59,7 @@ index 85ad4b4494c..e84961d078c 100644 #endif && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000 && desc->num_pages != 0) -@@ -498,9 +498,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, +@@ -495,9 +495,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, #if 1 if (BYTES_TO_PAGES (filtered_desc->physical_start) + filtered_desc->num_pages @@ -68,7 +72,7 @@ index 85ad4b4494c..e84961d078c 100644 #endif diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 3017d0f3e52..33e981e76e7 100644 +index 3c2e30f8751..9e5dca9458a 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -27,6 +27,7 @@ @@ -176,6 +180,17 @@ index 2c64918e3f7..a4c2ec83502 100644 #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff +#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + #endif /* ! GRUB_MEMORY_CPU_HEADER */ +diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h +index c6cb3241714..acb61dca44b 100644 +--- a/include/grub/riscv64/efi/memory.h ++++ b/include/grub/riscv64/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h index 46e9145a308..e81cfb32213 100644 diff --git a/0118-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch b/0222-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch similarity index 97% rename from 0118-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch rename to 0222-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch index fdd30965..83c02c90 100644 --- a/0118-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch +++ b/0222-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch @@ -12,7 +12,7 @@ Signed-off-by: Peter Jones 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 33e981e76e7..2f0336809e7 100644 +index 9e5dca9458a..3a940bec7f6 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -35,11 +35,16 @@ static grub_dl_t my_mod; @@ -98,4 +98,4 @@ index 33e981e76e7..2f0336809e7 100644 - static grub_err_t grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc, char *argv[]) + int argc, char *argv[]) diff --git a/0119-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch b/0223-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch similarity index 98% rename from 0119-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch rename to 0223-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch index f8284ec2..e4c80fe3 100644 --- a/0119-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch +++ b/0223-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch @@ -11,7 +11,7 @@ Signed-off-by: Peter Jones 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 2f0336809e7..5f48fa55619 100644 +index 3a940bec7f6..8d0b9436011 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -243,32 +243,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), @@ -121,7 +121,7 @@ index 2f0336809e7..5f48fa55619 100644 params->ext_loader_type = 0; params->ext_loader_ver = 2; - grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n", -- kernel_mem, handover_offset); +- kernel_mem, handover_offset); + grub_dprintf ("linux", + "setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n", + params->ext_loader_type, params->ext_loader_ver); diff --git a/0120-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch b/0224-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch similarity index 90% rename from 0120-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch rename to 0224-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch index 4ad0696b..afd82c38 100644 --- a/0120-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch +++ b/0224-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch @@ -7,11 +7,11 @@ This helps enable allocations above 4GB. Signed-off-by: Peter Jones --- - grub-core/loader/i386/efi/linux.c | 167 +++++++++++++++++++++----------------- - 1 file changed, 94 insertions(+), 73 deletions(-) + grub-core/loader/i386/efi/linux.c | 166 +++++++++++++++++++++----------------- + 1 file changed, 93 insertions(+), 73 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 5f48fa55619..3e4f7ef39f4 100644 +index 8d0b9436011..039b40e321d 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -47,6 +47,65 @@ static char *linux_cmdline; @@ -86,17 +86,17 @@ index 5f48fa55619..3e4f7ef39f4 100644 loaded = 0; - if (initrd_mem) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, -- BYTES_TO_PAGES(params->ramdisk_size)); +- BYTES_TO_PAGES(params->ramdisk_size)); - if (linux_cmdline) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) -- linux_cmdline, -- BYTES_TO_PAGES(params->cmdline_size + 1)); +- linux_cmdline, +- BYTES_TO_PAGES(params->cmdline_size + 1)); - if (kernel_mem) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, -- BYTES_TO_PAGES(kernel_size)); +- BYTES_TO_PAGES(kernel_size)); - if (params) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, -- BYTES_TO_PAGES(16384)); +- BYTES_TO_PAGES(16384)); + + kernel_free(initrd_mem, params->ramdisk_size); + kernel_free(linux_cmdline, params->cmdline_size + 1); @@ -127,7 +127,7 @@ index 5f48fa55619..3e4f7ef39f4 100644 params->ramdisk_size = size; - params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; -+ params->ramdisk_image = initrd_mem; ++ params->ramdisk_image = (grub_uint64_t) initrd_mem; ptr = initrd_mem; @@ -185,21 +185,20 @@ index 5f48fa55619..3e4f7ef39f4 100644 - } - - grub_dprintf ("linux", "linux_cmdline = %lx\n", -- (unsigned long)linux_cmdline); +- (unsigned long)linux_cmdline); + goto fail; + grub_dprintf ("linux", "linux_cmdline = %p\n", linux_cmdline); grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); grub_create_loader_cmdline (argc, argv, -@@ -343,27 +371,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -343,27 +371,23 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), GRUB_VERIFY_KERNEL_CMDLINE); grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); - grub_dprintf ("linux", "setting lh->cmd_line_ptr\n"); - lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; -+ grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n", -+ linux_cmdline); -+ lh->cmd_line_ptr = linux_cmdline; ++ ++ lh->cmd_line_ptr = (grub_uint64_t) linux_cmdline; handover_offset = lh->handover_offset; - grub_dprintf("linux", "handover_offset: %08x\n", handover_offset); @@ -230,7 +229,7 @@ index 5f48fa55619..3e4f7ef39f4 100644 grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem); grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); -@@ -398,18 +423,14 @@ fail: +@@ -398,18 +422,14 @@ fail: loaded = 0; } @@ -245,11 +244,11 @@ index 5f48fa55619..3e4f7ef39f4 100644 - if (kernel_mem && !loaded) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, -- BYTES_TO_PAGES(kernel_size)); +- BYTES_TO_PAGES(kernel_size)); - - if (params && !loaded) - grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, -- BYTES_TO_PAGES(16384)); +- BYTES_TO_PAGES(16384)); + kernel_free (kernel_mem, kernel_size); + kernel_free (params, sizeof(*params)); + } diff --git a/0121-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch b/0225-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch similarity index 92% rename from 0121-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch rename to 0225-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch index b1233ce3..a3b68e66 100644 --- a/0121-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch +++ b/0225-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch @@ -11,10 +11,10 @@ Signed-off-by: Peter Jones --- grub-core/loader/i386/efi/linux.c | 67 +++++++++++++++++++++++++++++++++++---- include/grub/i386/linux.h | 6 +++- - 2 files changed, 65 insertions(+), 8 deletions(-) + 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 3e4f7ef39f4..6bc18d5aef5 100644 +index 039b40e321d..015bb01d4c4 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -52,13 +52,22 @@ struct allocation_choice { @@ -68,7 +68,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644 grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); - params->ramdisk_size = size; -- params->ramdisk_image = initrd_mem; +- params->ramdisk_image = (grub_uint64_t) initrd_mem; + params->ramdisk_size = LOW_U32(size); + params->ramdisk_image = LOW_U32(initrd_mem); +#if defined(__x86_64__) @@ -97,12 +97,12 @@ index 3e4f7ef39f4..6bc18d5aef5 100644 params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters"); if (!params) goto fail; -@@ -372,21 +405,40 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -372,20 +405,41 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); - grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n", -- linux_cmdline); -- lh->cmd_line_ptr = linux_cmdline; + +- lh->cmd_line_ptr = (grub_uint64_t) linux_cmdline; ++ grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n", + LOW_U32(linux_cmdline)); + lh->cmd_line_ptr = LOW_U32(linux_cmdline); +#if defined(__x86_64__) @@ -140,7 +140,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644 if (!kernel_mem) goto fail; grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem); -@@ -395,8 +447,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), +@@ -394,8 +448,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), loaded = 1; @@ -153,10 +153,10 @@ index 3e4f7ef39f4..6bc18d5aef5 100644 grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h -index 25ef52c04eb..fac22476cc5 100644 +index 4ccd9d7d9f2..461097781fd 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h -@@ -236,7 +236,11 @@ struct linux_kernel_params +@@ -246,7 +246,11 @@ struct linux_kernel_params grub_uint32_t ofw_cif_handler; /* b8 */ grub_uint32_t ofw_idt; /* bc */ diff --git a/0151-efi-Set-image-base-address-before-jumping-to-the-PE-.patch b/0226-efi-Set-image-base-address-before-jumping-to-the-PE-.patch similarity index 78% rename from 0151-efi-Set-image-base-address-before-jumping-to-the-PE-.patch rename to 0226-efi-Set-image-base-address-before-jumping-to-the-PE-.patch index 336bcf18..f6176ba0 100644 --- a/0151-efi-Set-image-base-address-before-jumping-to-the-PE-.patch +++ b/0226-efi-Set-image-base-address-before-jumping-to-the-PE-.patch @@ -29,18 +29,18 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 14 insertions(+) diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index 0622dfa48d4..e8b9ecb17f6 100644 +index 742e8e9af35..32766bf7b19 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c -@@ -72,6 +72,7 @@ grub_err_t - grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, +@@ -139,6 +139,7 @@ grub_err_t + grub_efi_linux_boot (void *kernel_address, grub_off_t handover_offset, void *kernel_params) { + grub_efi_loaded_image_t *loaded_image = NULL; handover_func hf; int offset = 0; -@@ -79,6 +80,19 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, +@@ -146,6 +147,19 @@ grub_efi_linux_boot (void *kernel_address, grub_off_t handover_offset, offset = 512; #endif @@ -51,12 +51,12 @@ index 0622dfa48d4..e8b9ecb17f6 100644 + */ + loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (loaded_image) -+ loaded_image->image_base = kernel_addr; ++ loaded_image->image_base = kernel_address; + else + grub_dprintf ("linux", "Loaded Image base address could not be set\n"); + -+ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n", -+ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); - hf = (handover_func)((char *)kernel_addr + handover_offset + offset); ++ grub_dprintf ("linux", "kernel_address: %p handover_offset: %p params: %p\n", ++ kernel_address, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); + hf = (handover_func)((char *)kernel_address + handover_offset + offset); hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); diff --git a/0153-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch b/0227-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch similarity index 97% rename from 0153-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch rename to 0227-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch index 825d0f7c..35c0f323 100644 --- a/0153-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch +++ b/0227-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch @@ -26,7 +26,7 @@ Signed-off-by: Javier Martinez Canillas 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 6bc18d5aef5..15d40d6e35b 100644 +index 015bb01d4c4..adfb2739ae4 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -144,7 +144,7 @@ grub_linuxefi_unload (void) diff --git a/0159-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch b/0228-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch similarity index 97% rename from 0159-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch rename to 0228-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch index 95f7e208..7b507d9c 100644 --- a/0159-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch +++ b/0228-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch @@ -13,7 +13,7 @@ Signed-off-by: Colin Watson 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 15d40d6e35b..f992ceeef20 100644 +index adfb2739ae4..325aa594db1 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -28,6 +28,8 @@ diff --git a/0160-linuxefi-fail-kernel-validation-without-shim-protoco.patch b/0229-linuxefi-fail-kernel-validation-without-shim-protoco.patch similarity index 69% rename from 0160-linuxefi-fail-kernel-validation-without-shim-protoco.patch rename to 0229-linuxefi-fail-kernel-validation-without-shim-protoco.patch index 20fc7869..0bf7b19e 100644 --- a/0160-linuxefi-fail-kernel-validation-without-shim-protoco.patch +++ b/0229-linuxefi-fail-kernel-validation-without-shim-protoco.patch @@ -16,61 +16,28 @@ CVE-2020-15705 Reported-by: Mathieu Trudel-Lapierre Signed-off-by: Dimitri John Ledkov --- - grub-core/loader/arm64/linux.c | 13 +++++++++---- grub-core/loader/efi/chainloader.c | 1 + grub-core/loader/efi/linux.c | 1 + grub-core/loader/i386/efi/linux.c | 17 +++++++++++------ - 4 files changed, 22 insertions(+), 10 deletions(-) + 3 files changed, 13 insertions(+), 6 deletions(-) -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index 70a0075ec5e..47f8cf0d84b 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -34,6 +34,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -363,11 +364,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); - -- rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); -- if (rc < 0) -+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) - { -- grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); -- goto fail; -+ rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); -+ if (rc <= 0) -+ { -+ grub_error (GRUB_ERR_INVALID_COMMAND, -+ N_("%s has invalid signature"), argv[0]); -+ goto fail; -+ } - } - - pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index ac8dfd40c61..d41e8ea14a8 100644 +index e4ac39c87b4..0ec682e2988 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c -@@ -1084,6 +1084,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -1088,6 +1088,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), return 0; } + // -1 fall-through to fail fail: - if (dev) + diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index e8b9ecb17f6..9260731c107 100644 +index 32766bf7b19..ecb6d593cef 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c -@@ -33,6 +33,7 @@ struct grub_efi_shim_lock +@@ -98,6 +98,7 @@ struct grub_efi_shim_lock }; typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; @@ -79,7 +46,7 @@ index e8b9ecb17f6..9260731c107 100644 grub_linuxefi_secure_validate (void *data, grub_uint32_t size) { diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index f992ceeef20..3cf0f9b330b 100644 +index 325aa594db1..97484bbe24d 100644 --- a/grub-core/loader/i386/efi/linux.c +++ b/grub-core/loader/i386/efi/linux.c @@ -30,6 +30,7 @@ @@ -108,7 +75,7 @@ index f992ceeef20..3cf0f9b330b 100644 + if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), -- argv[0]); +- argv[0]); - goto fail; + rc = grub_linuxefi_secure_validate (kernel, filelen); + if (rc <= 0) diff --git a/0206-Allow-chainloading-EFI-apps-from-loop-mounts.patch b/0230-Allow-chainloading-EFI-apps-from-loop-mounts.patch similarity index 80% rename from 0206-Allow-chainloading-EFI-apps-from-loop-mounts.patch rename to 0230-Allow-chainloading-EFI-apps-from-loop-mounts.patch index e48f1021..c5e44570 100644 --- a/0206-Allow-chainloading-EFI-apps-from-loop-mounts.patch +++ b/0230-Allow-chainloading-EFI-apps-from-loop-mounts.patch @@ -3,15 +3,17 @@ From: Dimitri John Ledkov Date: Fri, 11 Jun 2021 13:51:20 +0200 Subject: [PATCH] Allow chainloading EFI apps from loop mounts. +Signed-off-by: Dimitri John Ledkov +Signed-off-by: Robbie Harwood --- grub-core/disk/loopback.c | 9 +-------- - grub-core/loader/efi/chainloader.c | 23 +++++++++++++++++++++++ + grub-core/loader/efi/chainloader.c | 24 ++++++++++++++++++++++++ include/grub/loopback.h | 30 ++++++++++++++++++++++++++++++ - 3 files changed, 54 insertions(+), 8 deletions(-) + 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 include/grub/loopback.h diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c -index 41bebd14fe3..99f47924ec2 100644 +index 4635dcfdeec..11a5e0cbd02 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -21,20 +21,13 @@ @@ -37,7 +39,7 @@ index 41bebd14fe3..99f47924ec2 100644 static unsigned long last_id = 0; diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index d41e8ea14a8..3af6b122926 100644 +index 0ec682e2988..efbe2bd38aa 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -24,6 +24,7 @@ @@ -48,20 +50,21 @@ index d41e8ea14a8..3af6b122926 100644 #include #include #include -@@ -901,6 +902,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), +@@ -907,6 +908,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), grub_efi_status_t status; grub_efi_boot_services_t *b; grub_device_t dev = 0; + grub_device_t orig_dev = 0; - grub_efi_device_path_t *dp = 0; + grub_efi_device_path_t *dp = NULL; char *filename; void *boot_image = 0; -@@ -958,6 +960,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - if (! dev) - goto fail; - +@@ -963,6 +965,16 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + dev = grub_device_open (devname); + if (devname) + grub_free (devname); ++ + /* if device is loopback, use underlying dev */ -+ if (dev->disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID) ++ if (dev && dev->disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID) + { + struct grub_loopback *d; + orig_dev = dev; @@ -69,10 +72,10 @@ index d41e8ea14a8..3af6b122926 100644 + dev = d->file->device; + } + - if (dev->disk) - dev_handle = grub_efidisk_get_device_handle (dev->disk); - else if (dev->net && dev->net->server) -@@ -1065,6 +1076,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + if (dev == NULL) + ; + else if (dev->disk) +@@ -1069,6 +1081,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } #endif @@ -85,10 +88,10 @@ index d41e8ea14a8..3af6b122926 100644 rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); if (rc > 0) -@@ -1087,6 +1104,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - // -1 fall-through to fail +@@ -1092,6 +1110,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), fail: + + if (orig_dev) + { + dev = orig_dev; diff --git a/0231-grub-core-loader-i386-efi-linux.c-do-not-validate-ke.patch b/0231-grub-core-loader-i386-efi-linux.c-do-not-validate-ke.patch new file mode 100644 index 00000000..084be2f8 --- /dev/null +++ b/0231-grub-core-loader-i386-efi-linux.c-do-not-validate-ke.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dimitri John Ledkov +Date: Thu, 3 Mar 2022 13:10:56 +0100 +Subject: [PATCH] grub-core/loader/i386/efi/linux.c: do not validate kernels + twice + +On codebases that have shim-lock-verifier built into the grub core +(like 2.06 upstream), shim-lock-verifier is in enforcing mode when +booted with secureboot. It means that grub_cmd_linux() command +attempts to perform shim validate upon opening linux kernel image, +including kernel measurement. And the verifier correctly returns file +open error when shim validate protocol is not present or shim fails to +validate the kernel. + +This makes the call to grub_linuxefi_secure_validate() redundant, but +also harmful. As validating the kernel image twice, extends the PCRs +with the same measurement twice. Which breaks existing sealing +policies when upgrading from grub2.04+rhboot+sb+linuxefi to +grub2.06+rhboot+sb+linuxefi builds. It is also incorrect to measure +the kernel twice. + +This patch must not be ported to older editions of grub code bases +that do not have verifiers framework, or it is not builtin, or +shim-lock-verifier is an optional module. + +This patch is tested to ensure that unsigned kernels are not possible +to boot in secureboot mode when shim rejects kernel, or shim protocol +is missing, and that the measurements become stable once again. The +above also ensures that CVE-2020-15705 is not reintroduced. + +Signed-off-by: Dimitri John Ledkov +--- + grub-core/loader/i386/efi/linux.c | 13 ------------- + 1 file changed, 13 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 97484bbe24d..1dd787081f2 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -30,7 +30,6 @@ + #include + #include + #include +-#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -278,7 +277,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_ssize_t start, filelen; + void *kernel = NULL; + int setup_header_end_offset; +- int rc; + + grub_dl_ref (my_mod); + +@@ -308,17 +306,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) +- { +- rc = grub_linuxefi_secure_validate (kernel, filelen); +- if (rc <= 0) +- { +- grub_error (GRUB_ERR_INVALID_COMMAND, +- N_("%s has invalid signature"), argv[0]); +- goto fail; +- } +- } +- + lh = (struct linux_i386_kernel_header *)kernel; + grub_dprintf ("linux", "original lh is at %p\n", kernel); + diff --git a/0232-grub-core-loader-efi-chainloader.c-do-not-validate-c.patch b/0232-grub-core-loader-efi-chainloader.c-do-not-validate-c.patch new file mode 100644 index 00000000..1ec47877 --- /dev/null +++ b/0232-grub-core-loader-efi-chainloader.c-do-not-validate-c.patch @@ -0,0 +1,80 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dimitri John Ledkov +Date: Fri, 4 Mar 2022 09:31:43 +0100 +Subject: [PATCH] grub-core/loader/efi/chainloader.c: do not validate + chainloader twice + +On secureboot systems, with shimlock verifier, call to +grub_file_open(, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE) will already +pass the chainloader target through shim-lock protocol verify +call. And create a TPM measurement. If verification fails, +grub_cmd_chainloader will fail at file open time. + +This makes previous code paths for negative, and zero return codes +from grub_linuxefi_secure_validate unreachable under secureboot. But +also breaking measurements compatibility with 2.04+linuxefi codebases, +as the chainloader file is passed through shim_lock->verify() twice +(via verifier & direct call to grub_linuxefi_secure_validate) +extending the PCRs twice. + +This reduces grub_loader options to perform +grub_secureboot_chainloader when secureboot is on, and otherwise +attempt grub_chainloader_boot. + +It means that booting with secureboot off, yet still with shim (which +always verifies things successfully), will stop choosing +grub_secureboot_chainloader, and opting for a more regular +loadimage/startimage codepath. If we want to use the +grub_secureboot_chainloader codepath in such scenarios we should adapt +the code to simply check for shim_lock protocol presence / +shim_lock->context() success?! But I am not sure if that is necessary. + +This patch must not be ported to older editions of grub code bases +that do not have verifiers framework, or it is not builtin, or +shim-lock-verifier is an optional module. + +Signed-off-by: Dimitri John Ledkov +--- + grub-core/loader/efi/chainloader.c | 8 ++------ + 1 file changed, 2 insertions(+), 6 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index efbe2bd38aa..3a3b55c1d61 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -912,7 +912,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_efi_device_path_t *dp = NULL; + char *filename; + void *boot_image = 0; +- int rc; + + file_path = NULL; + address = 0; +@@ -1087,9 +1086,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + orig_dev = 0; + } + +- rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); +- grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); +- if (rc > 0) ++ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + { + grub_file_close (file); + grub_device_close (dev); +@@ -1097,7 +1094,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_secureboot_chainloader_unload, 0); + return 0; + } +- else if (rc == 0) ++ else + { + grub_load_and_start_image(boot_image); + grub_file_close (file); +@@ -1106,7 +1103,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + + return 0; + } +- // -1 fall-through to fail + + fail: + diff --git a/0233-grub-core-loader-efi-linux.c-drop-now-unused-grub_li.patch b/0233-grub-core-loader-efi-linux.c-drop-now-unused-grub_li.patch new file mode 100644 index 00000000..a9f78884 --- /dev/null +++ b/0233-grub-core-loader-efi-linux.c-drop-now-unused-grub_li.patch @@ -0,0 +1,85 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Mon, 8 Apr 2024 10:59:25 -0600 +Subject: [PATCH] grub-core/loader/efi/linux.c: drop now unused + grub_linuxefi_secure_validate + +Drop the now unused grub_linuxefi_secure_validate() as all prior users +of this API now rely on the shim-lock-verifier codepath instead. + +This patch must not be ported to older editions of grub code bases +that do not have verifiers framework, or it is not builtin, or +shim-lock-verifier is an optional module. + +Signed-off-by: Dimitri John Ledkov +--- + grub-core/loader/efi/linux.c | 42 ------------------------------------------ + include/grub/efi/linux.h | 2 -- + 2 files changed, 44 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index ecb6d593cef..f5ab0128991 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -89,48 +89,6 @@ static grub_efi_load_file2_t initrd_lf2 = { + grub_efi_initrd_load_file2 + }; + +-#define SHIM_LOCK_GUID \ +- { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} } +- +-struct grub_efi_shim_lock +-{ +- grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size); +-}; +-typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; +- +-// Returns 1 on success, -1 on error, 0 when not available +-int +-grub_linuxefi_secure_validate (void *data, grub_uint32_t size) +-{ +- grub_guid_t guid = SHIM_LOCK_GUID; +- grub_efi_shim_lock_t *shim_lock; +- grub_efi_status_t status; +- +- shim_lock = grub_efi_locate_protocol(&guid, NULL); +- +- grub_dprintf ("secureboot", "shim_lock: %p\n", shim_lock); +- if (!shim_lock) +- { +- grub_dprintf ("secureboot", "shim not available\n"); +- return 0; +- } +- +- grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); +- status = shim_lock->verify (data, size); +- grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", (long int)status); +- if (status == GRUB_EFI_SUCCESS) +- { +- grub_dprintf ("secureboot", "Kernel signature verification passed\n"); +- return 1; +- } +- +- grub_dprintf ("secureboot", "Kernel signature verification failed (0x%lx)\n", +- (unsigned long) status); +- +- return -1; +- +-} +- + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + +diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h +index b2cfd8c1f44..c806a7757f3 100644 +--- a/include/grub/efi/linux.h ++++ b/include/grub/efi/linux.h +@@ -22,8 +22,6 @@ + #include + #include + +-int +-EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size); + grub_err_t + EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, + void *kernel_param); diff --git a/0234-loader-efi-chainloader-grub_load_and_start_image-doe.patch b/0234-loader-efi-chainloader-grub_load_and_start_image-doe.patch new file mode 100644 index 00000000..75cb622c --- /dev/null +++ b/0234-loader-efi-chainloader-grub_load_and_start_image-doe.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Thu, 28 Apr 2022 21:53:36 +0100 +Subject: [PATCH] loader/efi/chainloader: grub_load_and_start_image doesn't + load and start + +grub_load_and_start_image only loads an image - it still requires the +caller to start it. This renames it to grub_load_image. + +It's called from 2 places: +- grub_cmd_chainloader when not using the shim protocol. +- grub_secureboot_chainloader_boot if handle_image returns an error. +In this case, the image is loaded and then nothing else happens which +seems strange. I assume the intention is that it falls back to LoadImage +and StartImage if handle_image fails, so I've made it do that. + +Signed-off-by: Chris Coulson +(cherry picked from commit b4d70820a65c00561045856b7b8355461a9545f6) +--- + grub-core/loader/efi/chainloader.c | 16 +++++++++++++--- + 1 file changed, 13 insertions(+), 3 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 3a3b55c1d61..9c6a5f92600 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -847,7 +847,7 @@ grub_secureboot_chainloader_unload (void) + } + + static grub_err_t +-grub_load_and_start_image(void *boot_image) ++grub_load_image(void *boot_image) + { + grub_efi_boot_services_t *b; + grub_efi_status_t status; +@@ -889,13 +889,23 @@ grub_load_and_start_image(void *boot_image) + static grub_err_t + grub_secureboot_chainloader_boot (void) + { ++ grub_efi_boot_services_t *b; + int rc; ++ + rc = handle_image ((void *)(unsigned long)address, fsize); + if (rc == 0) + { +- grub_load_and_start_image((void *)(unsigned long)address); ++ /* We weren't able to attempt to execute the image, so fall back ++ * to LoadImage / StartImage. ++ */ ++ rc = grub_load_image((void *)(unsigned long)address); ++ if (rc == 0) ++ grub_chainloader_boot (); + } + ++ b = grub_efi_system_table->boot_services; ++ efi_call_1 (b->unload_image, image_handle); ++ + grub_loader_unset (); + return grub_errno; + } +@@ -1096,7 +1106,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + } + else + { +- grub_load_and_start_image(boot_image); ++ grub_load_image(boot_image); + grub_file_close (file); + grub_device_close (dev); + grub_loader_set_ex (grub_chainloader_boot, grub_chainloader_unload, image_handle, 0); diff --git a/0235-loader-efi-chainloader-simplify-the-loader-state.patch b/0235-loader-efi-chainloader-simplify-the-loader-state.patch new file mode 100644 index 00000000..d9962f07 --- /dev/null +++ b/0235-loader-efi-chainloader-simplify-the-loader-state.patch @@ -0,0 +1,326 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Fri, 29 Apr 2022 21:13:08 +0100 +Subject: [PATCH] loader/efi/chainloader: simplify the loader state + +When not using the shim lock protocol, the chainloader command retains +the source buffer and device path passed to LoadImage, requiring the +unload hook passed to grub_loader_set to free them. It isn't required +to retain this state though - they aren't required by StartImage or +anything else in the boot hook, so clean them up before +grub_cmd_chainloader finishes. + +This also wraps the loader state when using the shim lock protocol +inside a struct. + +Signed-off-by: Chris Coulson +(cherry picked from commit fa39862933b3be1553a580a3a5c28073257d8046) +[rharwood: fix unitialized handle and double-frees of file/dev] +Signed-off-by: Robbie Harwood +--- + grub-core/loader/efi/chainloader.c | 161 ++++++++++++++++++++++++------------- + 1 file changed, 103 insertions(+), 58 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 9c6a5f92600..cbe028cd8af 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -49,46 +49,30 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + static grub_dl_t my_mod; + +-static grub_efi_physical_address_t address; +-static grub_efi_uintn_t pages; +-static grub_ssize_t fsize; +-static grub_efi_device_path_t *file_path; + static grub_efi_handle_t image_handle; +-static grub_efi_char16_t *cmdline; +-static grub_ssize_t cmdline_len; +-static grub_efi_handle_t dev_handle; + +-static grub_efi_status_t (__grub_efi_api *entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); ++struct grub_secureboot_chainloader_context { ++ grub_efi_physical_address_t address; ++ grub_efi_uintn_t pages; ++ grub_ssize_t fsize; ++ grub_efi_device_path_t *file_path; ++ grub_efi_char16_t *cmdline; ++ grub_ssize_t cmdline_len; ++ grub_efi_handle_t dev_handle; ++}; ++static struct grub_secureboot_chainloader_context *sb_context; + + static grub_err_t +-grub_chainloader_unload (void *context) +-{ +- grub_efi_loaded_image_t *loaded_image; +- grub_efi_boot_services_t *b; +- +- image_handle = (grub_efi_handle_t) context; +- loaded_image = grub_efi_get_loaded_image (image_handle); +- if (loaded_image != NULL) +- grub_free (loaded_image->load_options); +- +- b = grub_efi_system_table->boot_services; +- b->unload_image (image_handle); +- +- grub_dl_unref (my_mod); +- return GRUB_ERR_NONE; +-} +- +-static grub_err_t +-grub_chainloader_boot (void *context) ++grub_start_image (grub_efi_handle_t handle) + { + grub_efi_boot_services_t *b; + grub_efi_status_t status; + grub_efi_uintn_t exit_data_size; + grub_efi_char16_t *exit_data = NULL; + +- image_handle = (grub_efi_handle_t) context; + b = grub_efi_system_table->boot_services; +- status = b->start_image (image_handle, &exit_data_size, &exit_data); ++ ++ status = b->start_image (handle, &exit_data_size, &exit_data); + if (status != GRUB_EFI_SUCCESS) + { + if (exit_data) +@@ -112,11 +96,37 @@ grub_chainloader_boot (void *context) + if (exit_data) + grub_efi_free_pool (exit_data); + +- grub_loader_unset (); +- + return grub_errno; + } + ++static grub_err_t ++grub_chainloader_unload (void) ++{ ++ grub_efi_loaded_image_t *loaded_image; ++ grub_efi_boot_services_t *b; ++ ++ loaded_image = grub_efi_get_loaded_image (image_handle); ++ if (loaded_image != NULL) ++ grub_free (loaded_image->load_options); ++ ++ b = grub_efi_system_table->boot_services; ++ b->unload_image (image_handle); ++ ++ grub_dl_unref (my_mod); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_chainloader_boot (void) ++{ ++ grub_err_t err; ++ ++ err = grub_start_image (image_handle); ++ ++ grub_loader_unset (); ++ return err; ++} ++ + static grub_err_t + copy_file_path (grub_efi_file_path_device_path_t *fp, + const char *str, grub_efi_uint16_t len) +@@ -151,7 +161,7 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + char *dir_start; + char *dir_end; + grub_size_t size; +- grub_efi_device_path_t *d; ++ grub_efi_device_path_t *d, *file_path; + + dir_start = grub_strchr (filename, ')'); + if (! dir_start) +@@ -527,12 +537,14 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp) + } + + static grub_efi_boolean_t +-handle_image (void *data, grub_efi_uint32_t datasize) ++handle_image (struct grub_secureboot_chainloader_context *load_context) + { + grub_efi_boot_services_t *b; + grub_efi_loaded_image_t *li, li_bak; + grub_efi_status_t efi_status; +- char *buffer = NULL; ++ void *data = (void *)(unsigned long)load_context->address; ++ grub_efi_uint32_t datasize = load_context->fsize; ++ void *buffer = NULL; + char *buffer_aligned = NULL; + grub_efi_uint32_t i; + struct grub_pe32_section_table *section; +@@ -542,6 +554,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) + grub_uint32_t buffer_size; + int found_entry_point = 0; + int rc; ++ grub_efi_status_t (*entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); + + b = grub_efi_system_table->boot_services; + +@@ -801,10 +814,10 @@ handle_image (void *data, grub_efi_uint32_t datasize) + grub_memcpy (&li_bak, li, sizeof (grub_efi_loaded_image_t)); + li->image_base = buffer_aligned; + li->image_size = context.image_size; +- li->load_options = cmdline; +- li->load_options_size = cmdline_len; +- li->file_path = grub_efi_get_media_file_path (file_path); +- li->device_handle = dev_handle; ++ li->load_options = load_context->cmdline; ++ li->load_options_size = load_context->cmdline_len; ++ li->file_path = grub_efi_get_media_file_path (load_context->file_path); ++ li->device_handle = load_context->dev_handle; + if (!li->file_path) + { + grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching file path found"); +@@ -832,22 +845,22 @@ error_exit: + static grub_err_t + grub_secureboot_chainloader_unload (void) + { +- grub_efi_boot_services_t *b; ++ grub_efi_free_pages (sb_context->address, sb_context->pages); ++ grub_free (sb_context->file_path); ++ grub_free (sb_context->cmdline); ++ grub_free (sb_context); + +- b = grub_efi_system_table->boot_services; +- b->free_pages (address, pages); +- grub_free (file_path); +- grub_free (cmdline); +- cmdline = 0; +- file_path = 0; +- dev_handle = 0; ++ sb_context = 0; + + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; + } + + static grub_err_t +-grub_load_image(void *boot_image) ++grub_load_image(grub_efi_device_path_t *file_path, void *boot_image, ++ grub_efi_uintn_t image_size, grub_efi_handle_t dev_handle, ++ grub_efi_char16_t *cmdline, grub_ssize_t cmdline_len, ++ grub_efi_handle_t *image_handle_out) + { + grub_efi_boot_services_t *b; + grub_efi_status_t status; +@@ -856,7 +869,7 @@ grub_load_image(void *boot_image) + b = grub_efi_system_table->boot_services; + + status = b->load_image (0, grub_efi_image_handle, file_path, +- boot_image, fsize, &image_handle); ++ boot_image, image_size, image_handle_out); + if (status != GRUB_EFI_SUCCESS) + { + if (status == GRUB_EFI_OUT_OF_RESOURCES) +@@ -869,7 +882,7 @@ grub_load_image(void *boot_image) + /* LoadImage does not set a device handler when the image is + loaded from memory, so it is necessary to set it explicitly here. + This is a mess. */ +- loaded_image = grub_efi_get_loaded_image (image_handle); ++ loaded_image = grub_efi_get_loaded_image (*image_handle_out); + if (! loaded_image) + { + grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); +@@ -891,20 +904,25 @@ grub_secureboot_chainloader_boot (void) + { + grub_efi_boot_services_t *b; + int rc; ++ grub_efi_handle_t handle = 0; + +- rc = handle_image ((void *)(unsigned long)address, fsize); ++ rc = handle_image (sb_context); + if (rc == 0) + { + /* We weren't able to attempt to execute the image, so fall back + * to LoadImage / StartImage. + */ +- rc = grub_load_image((void *)(unsigned long)address); ++ rc = grub_load_image(sb_context->file_path, ++ (void *)(unsigned long)sb_context->address, ++ sb_context->fsize, sb_context->dev_handle, ++ sb_context->cmdline, sb_context->cmdline_len, ++ &handle); + if (rc == 0) +- grub_chainloader_boot (); ++ grub_start_image (handle); + } + + b = grub_efi_system_table->boot_services; +- efi_call_1 (b->unload_image, image_handle); ++ b->unload_image (handle); + + grub_loader_unset (); + return grub_errno; +@@ -919,9 +937,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_efi_boot_services_t *b; + grub_device_t dev = 0; + grub_device_t orig_dev = 0; +- grub_efi_device_path_t *dp = NULL; ++ grub_efi_device_path_t *dp = 0, *file_path = 0; + char *filename; + void *boot_image = 0; ++ grub_efi_physical_address_t address = 0; ++ grub_ssize_t fsize; ++ grub_efi_uintn_t pages = 0; ++ grub_efi_char16_t *cmdline = 0; ++ grub_ssize_t cmdline_len = 0; ++ grub_efi_handle_t dev_handle = 0; + + file_path = NULL; + address = 0; +@@ -1098,18 +1122,36 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + + if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) + { ++ sb_context = grub_malloc (sizeof (*sb_context)); ++ if (sb_context == NULL) ++ goto fail; ++ sb_context->address = address; ++ sb_context->fsize = fsize; ++ sb_context->pages = pages; ++ sb_context->file_path = file_path; ++ sb_context->cmdline = cmdline; ++ sb_context->cmdline_len = cmdline_len; ++ sb_context->dev_handle = dev_handle; ++ + grub_file_close (file); + grub_device_close (dev); ++ + grub_loader_set (grub_secureboot_chainloader_boot, + grub_secureboot_chainloader_unload, 0); + return 0; + } + else + { +- grub_load_image(boot_image); ++ grub_load_image(file_path, boot_image, fsize, dev_handle, cmdline, ++ cmdline_len, &image_handle); + grub_file_close (file); + grub_device_close (dev); +- grub_loader_set_ex (grub_chainloader_boot, grub_chainloader_unload, image_handle, 0); ++ ++ /* We're finished with the source image buffer and file path now */ ++ b->free_pages (address, pages); ++ grub_free (file_path); ++ ++ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); + + return 0; + } +@@ -1137,8 +1179,11 @@ fail: + if (cmdline) + grub_free (cmdline); + +- if (image_handle != NULL) +- b->unload_image (image_handle); ++ if (image_handle != 0) ++ { ++ b->unload_image (image_handle); ++ image_handle = 0; ++ } + + grub_dl_unref (my_mod); + diff --git a/0236-loader-efi-chainloader-Use-grub_loader_set_ex.patch b/0236-loader-efi-chainloader-Use-grub_loader_set_ex.patch new file mode 100644 index 00000000..ce98152d --- /dev/null +++ b/0236-loader-efi-chainloader-Use-grub_loader_set_ex.patch @@ -0,0 +1,148 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Fri, 29 Apr 2022 21:30:56 +0100 +Subject: [PATCH] loader/efi/chainloader: Use grub_loader_set_ex + +This ports the EFI chainloader to use grub_loader_set_ex in order to fix +a use-after-free bug that occurs when grub_cmd_chainloader is executed +more than once before a boot attempt is performed. + +Signed-off-by: Chris Coulson +(cherry picked from commit 4b7f0402b7cb0f67a93be736f2b75b818d7f44c9) +[rharwood: context sludge from other change] +Signed-off-by: Robbie Harwood +--- + grub-core/loader/efi/chainloader.c | 39 +++++++++++++++++++++----------------- + 1 file changed, 22 insertions(+), 17 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index cbe028cd8af..b40acdeda80 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -49,8 +49,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + static grub_dl_t my_mod; + +-static grub_efi_handle_t image_handle; +- + struct grub_secureboot_chainloader_context { + grub_efi_physical_address_t address; + grub_efi_uintn_t pages; +@@ -60,7 +58,6 @@ struct grub_secureboot_chainloader_context { + grub_ssize_t cmdline_len; + grub_efi_handle_t dev_handle; + }; +-static struct grub_secureboot_chainloader_context *sb_context; + + static grub_err_t + grub_start_image (grub_efi_handle_t handle) +@@ -100,11 +97,14 @@ grub_start_image (grub_efi_handle_t handle) + } + + static grub_err_t +-grub_chainloader_unload (void) ++grub_chainloader_unload (void *context) + { ++ grub_efi_handle_t image_handle; + grub_efi_loaded_image_t *loaded_image; + grub_efi_boot_services_t *b; + ++ image_handle = (grub_efi_handle_t) context; ++ + loaded_image = grub_efi_get_loaded_image (image_handle); + if (loaded_image != NULL) + grub_free (loaded_image->load_options); +@@ -117,10 +117,12 @@ grub_chainloader_unload (void) + } + + static grub_err_t +-grub_chainloader_boot (void) ++grub_chainloader_boot (void *context) + { ++ grub_efi_handle_t image_handle; + grub_err_t err; + ++ image_handle = (grub_efi_handle_t) context; + err = grub_start_image (image_handle); + + grub_loader_unset (); +@@ -843,15 +845,17 @@ error_exit: + } + + static grub_err_t +-grub_secureboot_chainloader_unload (void) ++grub_secureboot_chainloader_unload (void *context) + { ++ struct grub_secureboot_chainloader_context *sb_context; ++ ++ sb_context = (struct grub_secureboot_chainloader_context *) context; ++ + grub_efi_free_pages (sb_context->address, sb_context->pages); + grub_free (sb_context->file_path); + grub_free (sb_context->cmdline); + grub_free (sb_context); + +- sb_context = 0; +- + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; + } +@@ -900,12 +904,15 @@ grub_load_image(grub_efi_device_path_t *file_path, void *boot_image, + } + + static grub_err_t +-grub_secureboot_chainloader_boot (void) ++grub_secureboot_chainloader_boot (void *context) + { ++ struct grub_secureboot_chainloader_context *sb_context; + grub_efi_boot_services_t *b; + int rc; + grub_efi_handle_t handle = 0; + ++ sb_context = (struct grub_secureboot_chainloader_context *) context; ++ + rc = handle_image (sb_context); + if (rc == 0) + { +@@ -946,6 +953,8 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_efi_char16_t *cmdline = 0; + grub_ssize_t cmdline_len = 0; + grub_efi_handle_t dev_handle = 0; ++ grub_efi_handle_t image_handle = 0; ++ struct grub_secureboot_chainloader_context *sb_context = 0; + + file_path = NULL; + address = 0; +@@ -1136,8 +1145,8 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_file_close (file); + grub_device_close (dev); + +- grub_loader_set (grub_secureboot_chainloader_boot, +- grub_secureboot_chainloader_unload, 0); ++ grub_loader_set_ex (grub_secureboot_chainloader_boot, ++ grub_secureboot_chainloader_unload, sb_context, 0); + return 0; + } + else +@@ -1151,7 +1160,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + b->free_pages (address, pages); + grub_free (file_path); + +- grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); ++ grub_loader_set_ex (grub_chainloader_boot, grub_chainloader_unload, image_handle, 0); + + return 0; + } +@@ -1179,11 +1188,7 @@ fail: + if (cmdline) + grub_free (cmdline); + +- if (image_handle != 0) +- { +- b->unload_image (image_handle); +- image_handle = 0; +- } ++ b->unload_image (image_handle); + + grub_dl_unref (my_mod); + diff --git a/0237-loader-i386-efi-linux-Avoid-a-use-after-free-in-the-.patch b/0237-loader-i386-efi-linux-Avoid-a-use-after-free-in-the-.patch new file mode 100644 index 00000000..4d080a0b --- /dev/null +++ b/0237-loader-i386-efi-linux-Avoid-a-use-after-free-in-the-.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Mon, 2 May 2022 14:39:31 +0200 +Subject: [PATCH] loader/i386/efi/linux: Avoid a use-after-free in the linuxefi + loader + +In some error paths in grub_cmd_linux, the pointer to lh may be +dereferenced after the buffer it points to has been freed. There aren't +any security implications from this because nothing else uses the +allocator after the buffer is freed and before the pointer is +dereferenced, but fix it anyway. + +Signed-off-by: Chris Coulson +(cherry picked from commit 8224f5a71af94bec8697de17e7e579792db9f9e2) +--- + grub-core/loader/i386/efi/linux.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 1dd787081f2..8f7eddaa962 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -466,9 +466,6 @@ fail: + if (file) + grub_file_close (file); + +- if (kernel) +- grub_free (kernel); +- + if (grub_errno != GRUB_ERR_NONE) + { + grub_dl_unref (my_mod); +@@ -484,6 +481,8 @@ fail: + kernel_free (params, sizeof(*params)); + } + ++ grub_free (kernel); ++ + return grub_errno; + } + diff --git a/0238-loader-i386-efi-linux-Use-grub_loader_set_ex.patch b/0238-loader-i386-efi-linux-Use-grub_loader_set_ex.patch new file mode 100644 index 00000000..428c4981 --- /dev/null +++ b/0238-loader-i386-efi-linux-Use-grub_loader_set_ex.patch @@ -0,0 +1,299 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Mon, 2 May 2022 17:04:23 +0200 +Subject: [PATCH] loader/i386/efi/linux: Use grub_loader_set_ex + +This ports the linuxefi loader to use grub_loader_set_ex in order to fix +a use-after-fre bug that occurs when grub_cmd_linux is executed more than +once before a boot attempt is performed. + +This is more complicated than for the chainloader command, as the initrd +command needs access to the loader state. To solve this, the linuxefi +module registers a dummy initrd command at startup that returns an error. +The linuxefi command then registers a proper initrd command with a higher +priority that is passed the loader state. + +Signed-off-by: Chris Coulson +(cherry picked from commit 7cf736436b4c934df5ddfa6f44b46a7e07d99fdc) +[rharwood/pjones: set kernel_size in context] +Signed-off-by: Robbie Harwood +--- + grub-core/loader/i386/efi/linux.c | 149 ++++++++++++++++++++++---------------- + 1 file changed, 88 insertions(+), 61 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 8f7eddaa962..3aaa2e9f175 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -34,13 +34,19 @@ + GRUB_MOD_LICENSE ("GPLv3+"); + + static grub_dl_t my_mod; +-static int loaded; +-static void *kernel_mem; +-static grub_uint64_t kernel_size; +-static void *initrd_mem; +-static grub_uint32_t handover_offset; +-struct linux_kernel_params *params; +-static char *linux_cmdline; ++ ++static grub_command_t cmd_linux, cmd_initrd; ++static grub_command_t cmd_linuxefi, cmd_initrdefi; ++ ++struct grub_linuxefi_context { ++ void *kernel_mem; ++ grub_uint64_t kernel_size; ++ grub_uint32_t handover_offset; ++ struct linux_kernel_params *params; ++ char *cmdline; ++ ++ void *initrd_mem; ++}; + + #define MIN(a, b) \ + ({ typeof (a) _a = (a); \ +@@ -123,25 +129,32 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) + } + + static grub_err_t +-grub_linuxefi_boot (void) ++grub_linuxefi_boot (void *data) + { ++ struct grub_linuxefi_context *context = (struct grub_linuxefi_context *) data; ++ + asm volatile ("cli"); + +- return grub_efi_linux_boot ((char *)kernel_mem, +- handover_offset, +- params); ++ return grub_efi_linux_boot ((char *)context->kernel_mem, ++ context->handover_offset, ++ context->params); + } + + static grub_err_t +-grub_linuxefi_unload (void) ++grub_linuxefi_unload (void *data) + { ++ struct grub_linuxefi_context *context = (struct grub_linuxefi_context *) data; ++ struct linux_kernel_params *params = context->params; ++ + grub_dl_unref (my_mod); +- loaded = 0; + +- kernel_free(initrd_mem, params->ramdisk_size); +- kernel_free(linux_cmdline, params->cmdline_size + 1); +- kernel_free(kernel_mem, kernel_size); +- kernel_free(params, sizeof(*params)); ++ kernel_free (context->initrd_mem, params->ramdisk_size); ++ kernel_free (context->cmdline, params->cmdline_size + 1); ++ kernel_free (context->kernel_mem, context->kernel_size); ++ kernel_free (params, sizeof(*params)); ++ cmd_initrd->data = 0; ++ cmd_initrdefi->data = 0; ++ grub_free (context); + + return GRUB_ERR_NONE; + } +@@ -188,13 +201,14 @@ read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len) + #define HIGH_U32(val) ((grub_uint32_t)(((grub_addr_t)(val) >> 32) & 0xffffffffull)) + + static grub_err_t +-grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), +- int argc, char *argv[]) ++grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + { + grub_file_t *files = 0; + int i, nfiles = 0; + grub_size_t size = 0; + grub_uint8_t *ptr; ++ struct grub_linuxefi_context *context = (struct grub_linuxefi_context *) cmd->data; ++ struct linux_kernel_params *params; + + if (argc == 0) + { +@@ -202,12 +216,14 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- if (!loaded) ++ if (!context) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first")); + goto fail; + } + ++ params = context->params; ++ + files = grub_calloc (argc, sizeof (files[0])); + if (!files) + goto fail; +@@ -225,19 +241,19 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + } + } + +- initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); +- if (initrd_mem == NULL) ++ context->initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); ++ if (context->initrd_mem == NULL) + goto fail; +- grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); ++ grub_dprintf ("linux", "initrd_mem = %p\n", context->initrd_mem); + + params->ramdisk_size = LOW_U32(size); +- params->ramdisk_image = LOW_U32(initrd_mem); ++ params->ramdisk_image = LOW_U32(context->initrd_mem); + #if defined(__x86_64__) + params->ext_ramdisk_size = HIGH_U32(size); +- params->ext_ramdisk_image = HIGH_U32(initrd_mem); ++ params->ext_ramdisk_image = HIGH_U32(context->initrd_mem); + #endif + +- ptr = initrd_mem; ++ ptr = context->initrd_mem; + + for (i = 0; i < nfiles; i++) + { +@@ -261,9 +277,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + grub_file_close (files[i]); + grub_free (files); + +- if (initrd_mem && grub_errno) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, +- BYTES_TO_PAGES(size)); ++ if (context->initrd_mem && grub_errno) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)context->initrd_mem, ++ BYTES_TO_PAGES(size)); + + return grub_errno; + } +@@ -277,6 +293,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_ssize_t start, filelen; + void *kernel = NULL; + int setup_header_end_offset; ++ void *kernel_mem = 0; ++ grub_uint64_t kernel_size = 0; ++ grub_uint32_t handover_offset; ++ struct linux_kernel_params *params = 0; ++ char *cmdline = 0; ++ struct grub_linuxefi_context *context = 0; + + grub_dl_ref (my_mod); + +@@ -390,28 +412,27 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "new lh is at %p\n", lh); + + grub_dprintf ("linux", "setting up cmdline\n"); +- linux_cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline")); +- if (!linux_cmdline) ++ cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline")); ++ if (!cmdline) + goto fail; +- grub_dprintf ("linux", "linux_cmdline = %p\n", linux_cmdline); ++ grub_dprintf ("linux", "cmdline = %p\n", cmdline); + +- grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); ++ grub_memcpy (cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, +- linux_cmdline + sizeof (LINUX_IMAGE) - 1, ++ cmdline + sizeof (LINUX_IMAGE) - 1, + lh->cmdline_size - (sizeof (LINUX_IMAGE) - 1), + GRUB_VERIFY_KERNEL_CMDLINE); + +- grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); +- ++ grub_dprintf ("linux", "cmdline:%s\n", cmdline); + grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n", +- LOW_U32(linux_cmdline)); +- lh->cmd_line_ptr = LOW_U32(linux_cmdline); ++ LOW_U32(cmdline)); ++ lh->cmd_line_ptr = LOW_U32(cmdline); + #if defined(__x86_64__) +- if ((grub_efi_uintn_t)linux_cmdline > 0xffffffffull) ++ if ((grub_efi_uintn_t)cmdline > 0xffffffffull) + { + grub_dprintf ("linux", "setting params->ext_cmd_line_ptr to 0x%08x\n", +- HIGH_U32(linux_cmdline)); +- params->ext_cmd_line_ptr = HIGH_U32(linux_cmdline); ++ HIGH_U32(cmdline)); ++ params->ext_cmd_line_ptr = HIGH_U32(cmdline); + } + #endif + +@@ -436,16 +457,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; +- kernel_mem = kernel_alloc (lh->init_size, N_("can't allocate kernel")); ++ kernel_size = lh->init_size; ++ kernel_mem = kernel_alloc (kernel_size, N_("can't allocate kernel")); + restore_addresses(); + if (!kernel_mem) + goto fail; + grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem); + +- grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); +- +- loaded = 1; +- + grub_dprintf ("linux", "setting lh->code32_start to 0x%08x\n", + LOW_U32(kernel_mem)); + lh->code32_start = LOW_U32(kernel_mem); +@@ -462,33 +480,42 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + "setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n", + params->ext_loader_type, params->ext_loader_ver); + ++ context = grub_zalloc (sizeof (*context)); ++ if (!context) ++ goto fail; ++ context->kernel_mem = kernel_mem; ++ context->kernel_size = kernel_size; ++ context->handover_offset = handover_offset; ++ context->params = params; ++ context->cmdline = cmdline; ++ ++ grub_loader_set_ex (grub_linuxefi_boot, grub_linuxefi_unload, context, 0); ++ ++ cmd_initrd->data = context; ++ cmd_initrdefi->data = context; ++ ++ grub_file_close (file); ++ grub_free (kernel); ++ return 0; ++ + fail: + if (file) + grub_file_close (file); + +- if (grub_errno != GRUB_ERR_NONE) +- { +- grub_dl_unref (my_mod); +- loaded = 0; +- } ++ grub_dl_unref (my_mod); + +- if (!loaded) +- { +- if (lh) +- kernel_free (linux_cmdline, lh->cmdline_size + 1); ++ if (lh) ++ kernel_free (cmdline, lh->cmdline_size + 1); + +- kernel_free (kernel_mem, kernel_size); +- kernel_free (params, sizeof(*params)); +- } ++ kernel_free (kernel_mem, kernel_size); ++ kernel_free (params, sizeof(*params)); + ++ grub_free (context); + grub_free (kernel); + + return grub_errno; + } + +-static grub_command_t cmd_linux, cmd_initrd; +-static grub_command_t cmd_linuxefi, cmd_initrdefi; +- + GRUB_MOD_INIT(linux) + { + cmd_linux = diff --git a/0239-loader-i386-efi-linux-Fix-a-memory-leak-in-the-initr.patch b/0239-loader-i386-efi-linux-Fix-a-memory-leak-in-the-initr.patch new file mode 100644 index 00000000..e3b44f12 --- /dev/null +++ b/0239-loader-i386-efi-linux-Fix-a-memory-leak-in-the-initr.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Tue, 3 May 2022 09:47:35 +0200 +Subject: [PATCH] loader/i386/efi/linux: Fix a memory leak in the initrd + command + +Subsequent invocations of the initrd command result in the previous +initrd being leaked, so fix that. + +Signed-off-by: Chris Coulson +(cherry picked from commit d98af31ce1e31bb22163960d53f5eb28c66582a0) +--- + grub-core/loader/i386/efi/linux.c | 21 ++++++++++++--------- + 1 file changed, 12 insertions(+), 9 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 3aaa2e9f175..71c7ed6a76e 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -209,6 +209,7 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + grub_uint8_t *ptr; + struct grub_linuxefi_context *context = (struct grub_linuxefi_context *) cmd->data; + struct linux_kernel_params *params; ++ void *initrd_mem = 0; + + if (argc == 0) + { +@@ -241,19 +242,19 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + } + } + +- context->initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); +- if (context->initrd_mem == NULL) ++ initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); ++ if (initrd_mem == NULL) + goto fail; +- grub_dprintf ("linux", "initrd_mem = %p\n", context->initrd_mem); ++ grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); + + params->ramdisk_size = LOW_U32(size); +- params->ramdisk_image = LOW_U32(context->initrd_mem); ++ params->ramdisk_image = LOW_U32(initrd_mem); + #if defined(__x86_64__) + params->ext_ramdisk_size = HIGH_U32(size); +- params->ext_ramdisk_image = HIGH_U32(context->initrd_mem); ++ params->ext_ramdisk_image = HIGH_U32(initrd_mem); + #endif + +- ptr = context->initrd_mem; ++ ptr = initrd_mem; + + for (i = 0; i < nfiles; i++) + { +@@ -270,6 +271,9 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + ptr += ALIGN_UP_OVERHEAD (cursize, 4); + } + ++ kernel_free(context->initrd_mem, params->ramdisk_size); ++ ++ context->initrd_mem = initrd_mem; + params->ramdisk_size = size; + + fail: +@@ -277,9 +281,8 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + grub_file_close (files[i]); + grub_free (files); + +- if (context->initrd_mem && grub_errno) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)context->initrd_mem, +- BYTES_TO_PAGES(size)); ++ if (initrd_mem && grub_errno) ++ kernel_free (initrd_mem, size); + + return grub_errno; + } diff --git a/0240-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_CODE-ins.patch b/0240-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_CODE-ins.patch new file mode 100644 index 00000000..ed359158 --- /dev/null +++ b/0240-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_CODE-ins.patch @@ -0,0 +1,85 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 9 Feb 2022 16:08:20 -0500 +Subject: [PATCH] EFI: allocate kernel in EFI_RUNTIME_SERVICES_CODE instead of + EFI_LOADER_DATA. + +On some of the firmwares with more security mitigations, EFI_LOADER_DATA +doesn't get you executable memory, and we take a fault and reboot when +we enter kernel. + +This patch correctly allocates the kernel code as EFI_RUNTIME_SERVICES_CODE +rather than EFI_LOADER_DATA. + +Signed-off-by: Peter Jones +[rharwood: use kernel_size] +Signed-off-by: Robbie Harwood +--- + grub-core/loader/i386/efi/linux.c | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 71c7ed6a76e..3ec9bb09c52 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -86,7 +86,9 @@ kernel_free(void *addr, grub_efi_uintn_t size) + } + + static void * +-kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) ++kernel_alloc(grub_efi_uintn_t size, ++ grub_efi_memory_type_t memtype, ++ const char * const errmsg) + { + void *addr = 0; + unsigned int i; +@@ -112,7 +114,7 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) + prev_max = max; + addr = grub_efi_allocate_pages_real (max, pages, + max_addresses[i].alloc_type, +- GRUB_EFI_LOADER_DATA); ++ memtype); + if (addr) + grub_dprintf ("linux", "Allocated at %p\n", addr); + } +@@ -242,7 +244,8 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + } + } + +- initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); ++ initrd_mem = kernel_alloc(size, GRUB_EFI_RUNTIME_SERVICES_DATA, ++ N_("can't allocate initrd")); + if (initrd_mem == NULL) + goto fail; + grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); +@@ -393,7 +396,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + +- params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters"); ++ params = kernel_alloc (sizeof(*params), GRUB_EFI_RUNTIME_SERVICES_DATA, ++ "cannot allocate kernel parameters"); + if (!params) + goto fail; + grub_dprintf ("linux", "params = %p\n", params); +@@ -415,7 +419,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "new lh is at %p\n", lh); + + grub_dprintf ("linux", "setting up cmdline\n"); +- cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline")); ++ cmdline = kernel_alloc (lh->cmdline_size + 1, ++ GRUB_EFI_RUNTIME_SERVICES_DATA, ++ N_("can't allocate cmdline")); + if (!cmdline) + goto fail; + grub_dprintf ("linux", "cmdline = %p\n", cmdline); +@@ -461,7 +467,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + kernel_size = lh->init_size; +- kernel_mem = kernel_alloc (kernel_size, N_("can't allocate kernel")); ++ kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE, ++ N_("can't allocate kernel")); + restore_addresses(); + if (!kernel_mem) + goto fail; diff --git a/0241-efi-use-enumerated-array-positions-for-our-allocatio.patch b/0241-efi-use-enumerated-array-positions-for-our-allocatio.patch new file mode 100644 index 00000000..24f9131d --- /dev/null +++ b/0241-efi-use-enumerated-array-positions-for-our-allocatio.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 1 Aug 2022 14:06:30 -0400 +Subject: [PATCH] efi: use enumerated array positions for our allocation + choices + +In our kernel allocator on EFI systems, we currently have a growing +amount of code that references the various allocation policies by +position in the array, and of course maintenance of this code scales +very poorly. + +This patch changes them to be enumerated, so they're easier to refer to +farther along in the code without confusion. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 31 ++++++++++++++++++++----------- + 1 file changed, 20 insertions(+), 11 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 3ec9bb09c52..ef5875b7697 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -60,17 +60,26 @@ struct allocation_choice { + grub_efi_allocate_type_t alloc_type; + }; + +-static struct allocation_choice max_addresses[4] = ++enum { ++ KERNEL_PREF_ADDRESS, ++ KERNEL_4G_LIMIT, ++ KERNEL_NO_LIMIT, ++}; ++ ++static struct allocation_choice max_addresses[] = + { + /* the kernel overrides this one with pref_address and + * GRUB_EFI_ALLOCATE_ADDRESS */ +- { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ [KERNEL_PREF_ADDRESS] = ++ { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ /* If the flag in params is set, this one gets changed to be above 4GB. */ ++ [KERNEL_4G_LIMIT] = ++ { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, + /* this one is always below 4GB, which we still *prefer* even if the flag + * is set. */ +- { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, +- /* If the flag in params is set, this one gets changed to be above 4GB. */ +- { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, +- { 0, 0 } ++ [KERNEL_NO_LIMIT] = ++ { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { NO_MEM, 0, 0 } + }; + static struct allocation_choice saved_addresses[4]; + +@@ -388,7 +397,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G) + { + grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n"); +- max_addresses[2].addr = GRUB_EFI_MAX_USABLE_ADDRESS; ++ max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS; + } + else + { +@@ -461,11 +470,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "lh->pref_address: %p\n", (void *)(grub_addr_t)lh->pref_address); + if (lh->pref_address < (grub_uint64_t)GRUB_EFI_MAX_ALLOCATION_ADDRESS) + { +- max_addresses[0].addr = lh->pref_address; +- max_addresses[0].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS; ++ max_addresses[KERNEL_PREF_ADDRESS].addr = lh->pref_address; ++ max_addresses[KERNEL_PREF_ADDRESS].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS; + } +- max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; +- max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; ++ max_addresses[KERNEL_4G_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; ++ max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + kernel_size = lh->init_size; + kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE, + N_("can't allocate kernel")); diff --git a/0242-efi-split-allocation-policy-for-kernel-vs-initrd-mem.patch b/0242-efi-split-allocation-policy-for-kernel-vs-initrd-mem.patch new file mode 100644 index 00000000..20f3c660 --- /dev/null +++ b/0242-efi-split-allocation-policy-for-kernel-vs-initrd-mem.patch @@ -0,0 +1,127 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 1 Aug 2022 14:24:39 -0400 +Subject: [PATCH] efi: split allocation policy for kernel vs initrd memories. + +Currently in our kernel allocator, we use the same set of choices for +all of our various kernel and initramfs allocations, though they do not +have exactly the same constraints. + +This patch adds the concept of an allocation purpose, which currently +can be KERNEL_MEM or INITRD_MEM, and updates kernel_alloc() calls +appropriately, but does not change any current policy decision. It +also adds a few debug prints. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 35 +++++++++++++++++++++++++++-------- + 1 file changed, 27 insertions(+), 8 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index ef5875b7697..1d7ced3d1f8 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -55,7 +55,14 @@ struct grub_linuxefi_context { + + #define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) + ++typedef enum { ++ NO_MEM, ++ KERNEL_MEM, ++ INITRD_MEM, ++} kernel_alloc_purpose_t; ++ + struct allocation_choice { ++ kernel_alloc_purpose_t purpose; + grub_efi_physical_address_t addr; + grub_efi_allocate_type_t alloc_type; + }; +@@ -64,6 +71,7 @@ enum { + KERNEL_PREF_ADDRESS, + KERNEL_4G_LIMIT, + KERNEL_NO_LIMIT, ++ INITRD_MAX_ADDRESS, + }; + + static struct allocation_choice max_addresses[] = +@@ -71,14 +79,17 @@ static struct allocation_choice max_addresses[] = + /* the kernel overrides this one with pref_address and + * GRUB_EFI_ALLOCATE_ADDRESS */ + [KERNEL_PREF_ADDRESS] = +- { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { KERNEL_MEM, GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, + /* If the flag in params is set, this one gets changed to be above 4GB. */ + [KERNEL_4G_LIMIT] = +- { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { KERNEL_MEM, GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, + /* this one is always below 4GB, which we still *prefer* even if the flag + * is set. */ + [KERNEL_NO_LIMIT] = +- { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { KERNEL_MEM, GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ /* this is for the initrd */ ++ [INITRD_MAX_ADDRESS] = ++ { INITRD_MEM, GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, + { NO_MEM, 0, 0 } + }; + static struct allocation_choice saved_addresses[4]; +@@ -95,7 +106,8 @@ kernel_free(void *addr, grub_efi_uintn_t size) + } + + static void * +-kernel_alloc(grub_efi_uintn_t size, ++kernel_alloc(kernel_alloc_purpose_t purpose, ++ grub_efi_uintn_t size, + grub_efi_memory_type_t memtype, + const char * const errmsg) + { +@@ -108,6 +120,9 @@ kernel_alloc(grub_efi_uintn_t size, + grub_uint64_t max = max_addresses[i].addr; + grub_efi_uintn_t pages; + ++ if (purpose != max_addresses[i].purpose) ++ continue; ++ + /* + * When we're *not* loading the kernel, or >4GB allocations aren't + * supported, these entries are basically all the same, so don't re-try +@@ -253,7 +268,8 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + } + } + +- initrd_mem = kernel_alloc(size, GRUB_EFI_RUNTIME_SERVICES_DATA, ++ grub_dprintf ("linux", "Trying to allocate initrd mem\n"); ++ initrd_mem = kernel_alloc(INITRD_MEM, size, GRUB_EFI_RUNTIME_SERVICES_DATA, + N_("can't allocate initrd")); + if (initrd_mem == NULL) + goto fail; +@@ -405,7 +421,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + +- params = kernel_alloc (sizeof(*params), GRUB_EFI_RUNTIME_SERVICES_DATA, ++ params = kernel_alloc (KERNEL_MEM, sizeof(*params), ++ GRUB_EFI_RUNTIME_SERVICES_DATA, + "cannot allocate kernel parameters"); + if (!params) + goto fail; +@@ -428,7 +445,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "new lh is at %p\n", lh); + + grub_dprintf ("linux", "setting up cmdline\n"); +- cmdline = kernel_alloc (lh->cmdline_size + 1, ++ cmdline = kernel_alloc (KERNEL_MEM, lh->cmdline_size + 1, + GRUB_EFI_RUNTIME_SERVICES_DATA, + N_("can't allocate cmdline")); + if (!cmdline) +@@ -476,7 +493,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + max_addresses[KERNEL_4G_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + kernel_size = lh->init_size; +- kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE, ++ grub_dprintf ("linux", "Trying to allocate kernel mem\n"); ++ kernel_mem = kernel_alloc (KERNEL_MEM, kernel_size, ++ GRUB_EFI_RUNTIME_SERVICES_CODE, + N_("can't allocate kernel")); + restore_addresses(); + if (!kernel_mem) diff --git a/0243-efi-allocate-the-initrd-within-the-bounds-expressed-.patch b/0243-efi-allocate-the-initrd-within-the-bounds-expressed-.patch new file mode 100644 index 00000000..922088b3 --- /dev/null +++ b/0243-efi-allocate-the-initrd-within-the-bounds-expressed-.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 1 Aug 2022 14:07:50 -0400 +Subject: [PATCH] efi: allocate the initrd within the bounds expressed by the + kernel + +Currently on x86, only linux kernels built with CONFIG_RELOCATABLE for +x86_64 can be loaded above 4G, but the maximum address for the initramfs +is specified via a HdrS field. This allows us to utilize that value, +and unless loading the kernel above 4G, uses the value present there. +If loading kernel above 4G is allowed, we assume loading the initramfs +above 4G also works; in practice this has been true in the kernel code +for quite some time. + +Resolves: rhbz#2112134 + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 1d7ced3d1f8..a798da334ab 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -182,6 +182,8 @@ grub_linuxefi_unload (void *data) + cmd_initrdefi->data = 0; + grub_free (context); + ++ max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; ++ + return GRUB_ERR_NONE; + } + +@@ -409,11 +411,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + ++ max_addresses[INITRD_MAX_ADDRESS].addr = lh->initrd_addr_max; + #if defined(__x86_64__) + if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G) + { + grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n"); + max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS; ++ max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_USABLE_ADDRESS; + } + else + { +@@ -542,6 +546,8 @@ fail: + + grub_dl_unref (my_mod); + ++ max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; ++ + if (lh) + kernel_free (cmdline, lh->cmdline_size + 1); + diff --git a/0244-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch b/0244-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch new file mode 100644 index 00000000..914ad43f --- /dev/null +++ b/0244-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 1 Aug 2022 13:04:43 -0400 +Subject: [PATCH] efi: use EFI_LOADER_(CODE|DATA) for kernel and initrd + allocations + +At some point due to an erroneous kernel warning, we switched kernel and +initramfs to being loaded in EFI_RUNTIME_SERVICES_CODE and +EFI_RUNTIME_SERVICES_DATA memory pools. This doesn't appear to be +correct according to the spec, and that kernel warning has gone away. + +This patch puts them back in EFI_LOADER_CODE and EFI_LOADER_DATA +allocations, respectively. + +Resolves: rhbz#2108456 + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index a798da334ab..03d27c81fd3 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -271,7 +271,7 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[]) + } + + grub_dprintf ("linux", "Trying to allocate initrd mem\n"); +- initrd_mem = kernel_alloc(INITRD_MEM, size, GRUB_EFI_RUNTIME_SERVICES_DATA, ++ initrd_mem = kernel_alloc(INITRD_MEM, size, GRUB_EFI_LOADER_DATA, + N_("can't allocate initrd")); + if (initrd_mem == NULL) + goto fail; +@@ -426,7 +426,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + #endif + + params = kernel_alloc (KERNEL_MEM, sizeof(*params), +- GRUB_EFI_RUNTIME_SERVICES_DATA, ++ GRUB_EFI_LOADER_DATA, + "cannot allocate kernel parameters"); + if (!params) + goto fail; +@@ -450,7 +450,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + grub_dprintf ("linux", "setting up cmdline\n"); + cmdline = kernel_alloc (KERNEL_MEM, lh->cmdline_size + 1, +- GRUB_EFI_RUNTIME_SERVICES_DATA, ++ GRUB_EFI_LOADER_DATA, + N_("can't allocate cmdline")); + if (!cmdline) + goto fail; +@@ -499,7 +499,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + kernel_size = lh->init_size; + grub_dprintf ("linux", "Trying to allocate kernel mem\n"); + kernel_mem = kernel_alloc (KERNEL_MEM, kernel_size, +- GRUB_EFI_RUNTIME_SERVICES_CODE, ++ GRUB_EFI_LOADER_CODE, + N_("can't allocate kernel")); + restore_addresses(); + if (!kernel_mem) diff --git a/0245-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch b/0245-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch new file mode 100644 index 00000000..e19f1543 --- /dev/null +++ b/0245-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 11 Oct 2022 17:00:50 -0400 +Subject: [PATCH] x86-efi: Fix an incorrect array size in kernel allocation + +In 81a6ebf62bbe166ddc968463df2e8bd481bf697c ("efi: split allocation +policy for kernel vs initrd memories."), I introduced a split in the +kernel allocator to allow for different dynamic policies for the kernel +and the initrd allocations. + +Unfortunately, that change increased the size of the policy data used to +make decisions, but did not change the size of the temporary storage we +use to back it up and restore. This results in some of .data getting +clobbered at runtime, and hilarity ensues. + +This patch makes the size of the backup storage be based on the size of +the initial policy data. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 03d27c81fd3..f97b123a51e 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -92,7 +92,7 @@ static struct allocation_choice max_addresses[] = + { INITRD_MEM, GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, + { NO_MEM, 0, 0 } + }; +-static struct allocation_choice saved_addresses[4]; ++static struct allocation_choice saved_addresses[sizeof(max_addresses) / sizeof(max_addresses[0])]; + + #define save_addresses() grub_memcpy(saved_addresses, max_addresses, sizeof(max_addresses)) + #define restore_addresses() grub_memcpy(max_addresses, saved_addresses, sizeof(max_addresses)) diff --git a/0246-grub-install-on-EFI-if-forced.patch b/0246-grub-install-on-EFI-if-forced.patch new file mode 100644 index 00000000..e569cf16 --- /dev/null +++ b/0246-grub-install-on-EFI-if-forced.patch @@ -0,0 +1,80 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Marta Lewandowska +Date: Tue, 6 Feb 2024 17:42:47 -0600 +Subject: [PATCH] grub-install on EFI if forced + +UEFI Secure Boot requires signed grub binaries to work, so grub- +install should not be used. However, users who have Secure Boot +disabled and wish to use the command should not be prevented from +doing so if they invoke --force. + +fixes bz#1917213 / bz#2240994 + +Signed-off-by: Marta Lewandowska +--- + util/grub-install.c | 38 +++++++++++++++++++------------------- + 1 file changed, 19 insertions(+), 19 deletions(-) + +diff --git a/util/grub-install.c b/util/grub-install.c +index 828e8722ba5..314b6143b8e 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -915,25 +915,6 @@ main (int argc, char *argv[]) + + platform = grub_install_get_target (grub_install_source_directory); + +- switch (platform) +- { +- case GRUB_INSTALL_PLATFORM_ARM_EFI: +- case GRUB_INSTALL_PLATFORM_ARM64_EFI: +- case GRUB_INSTALL_PLATFORM_I386_EFI: +- case GRUB_INSTALL_PLATFORM_IA64_EFI: +- case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI: +- case GRUB_INSTALL_PLATFORM_RISCV32_EFI: +- case GRUB_INSTALL_PLATFORM_RISCV64_EFI: +- case GRUB_INSTALL_PLATFORM_X86_64_EFI: +- is_efi = 1; +- grub_util_error (_("this utility cannot be used for EFI platforms" +- " because it does not support UEFI Secure Boot")); +- break; +- default: +- is_efi = 0; +- break; +- } +- + { + char *platname = grub_install_get_platform_name (platform); + fprintf (stderr, _("Installing for %s platform.\n"), platname); +@@ -1050,6 +1031,22 @@ main (int argc, char *argv[]) + + switch (platform) + { ++ case GRUB_INSTALL_PLATFORM_ARM_EFI: ++ case GRUB_INSTALL_PLATFORM_ARM64_EFI: ++ case GRUB_INSTALL_PLATFORM_I386_EFI: ++ case GRUB_INSTALL_PLATFORM_IA64_EFI: ++ case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI: ++ case GRUB_INSTALL_PLATFORM_RISCV32_EFI: ++ case GRUB_INSTALL_PLATFORM_RISCV64_EFI: ++ case GRUB_INSTALL_PLATFORM_X86_64_EFI: ++ is_efi = 1; ++ if (!force) ++ grub_util_error (_("This utility should not be used for EFI platforms" ++ " because it does not support UEFI Secure Boot." ++ " If you really wish to proceed, invoke the --force" ++ " option.\nMake sure Secure Boot is disabled before" ++ " proceeding")); ++ break; + case GRUB_INSTALL_PLATFORM_I386_IEEE1275: + case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275: + #ifdef __linux__ +@@ -1058,6 +1055,9 @@ main (int argc, char *argv[]) + try_open ("/dev/nvram"); + #endif + break; ++ /* pacify warning. */ ++ case GRUB_INSTALL_PLATFORM_MAX: ++ break; + default: + break; + } diff --git a/0247-Remove-Install-section-from-aux-systemd-units.patch b/0247-Remove-Install-section-from-aux-systemd-units.patch new file mode 100644 index 00000000..500b9f59 --- /dev/null +++ b/0247-Remove-Install-section-from-aux-systemd-units.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Christian Glombek +Date: Tue, 14 Nov 2023 07:54:59 +0100 +Subject: [PATCH] Remove [Install] section from aux systemd units + +See https://bugzilla.redhat.com/show_bug.cgi?id=2247635#c7 +--- + docs/grub-boot-indeterminate.service | 3 --- + util/systemd/grub-systemd-integration.service.in | 3 --- + 2 files changed, 6 deletions(-) + +diff --git a/docs/grub-boot-indeterminate.service b/docs/grub-boot-indeterminate.service +index 5bcb474a3d3..6c8dcb186b6 100644 +--- a/docs/grub-boot-indeterminate.service ++++ b/docs/grub-boot-indeterminate.service +@@ -9,6 +9,3 @@ Before=system-update-pre.target + [Service] + Type=oneshot + ExecStart=/usr/bin/grub2-editenv - incr boot_indeterminate +- +-[Install] +-WantedBy=system-update.target +diff --git a/util/systemd/grub-systemd-integration.service.in b/util/systemd/grub-systemd-integration.service.in +index 22ca1ca4885..c81fb594ce1 100644 +--- a/util/systemd/grub-systemd-integration.service.in ++++ b/util/systemd/grub-systemd-integration.service.in +@@ -6,6 +6,3 @@ ConditionPathExists=/run/systemd/reboot-to-boot-loader-menu + + [Service] + ExecStart=@libexecdir@/@grubdirname@/systemd-integration.sh +- +-[Install] +-WantedBy=reboot.target diff --git a/0248-chainloader-remove-device-path-debug-message.patch b/0248-chainloader-remove-device-path-debug-message.patch new file mode 100644 index 00000000..306aad38 --- /dev/null +++ b/0248-chainloader-remove-device-path-debug-message.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: raravind +Date: Tue, 9 May 2023 11:29:35 +0200 +Subject: [PATCH] chainloader: remove device path debug message + +Remove the debug message "/EndEntire" while using GRUB chainloader command. + +Signed-off-by: raravind +(cherry picked from commit f75f5386b7a6a7cb2e10d30f817a3564c0a28dd7) +--- + grub-core/loader/efi/chainloader.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index b40acdeda80..badff5e50b5 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -212,7 +212,6 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + /* Fill the file path for the directory. */ + d = (grub_efi_device_path_t *) ((char *) file_path + + ((char *) d - (char *) dp)); +- grub_efi_print_device_path (d); + if (copy_file_path ((grub_efi_file_path_device_path_t *) d, + dir_start, dir_end - dir_start) != GRUB_ERR_NONE) + { diff --git a/0249-grub-set-bootflag-Conservative-partial-fix-for-CVE-2.patch b/0249-grub-set-bootflag-Conservative-partial-fix-for-CVE-2.patch new file mode 100644 index 00000000..995181f2 --- /dev/null +++ b/0249-grub-set-bootflag-Conservative-partial-fix-for-CVE-2.patch @@ -0,0 +1,146 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Solar Designer +Date: Tue, 6 Feb 2024 21:39:41 +0100 +Subject: [PATCH] grub-set-bootflag: Conservative partial fix for CVE-2024-1048 + +Following up on CVE-2019-14865 and taking a fresh look at +grub2-set-bootflag now (through my work at CIQ on Rocky Linux), I saw some +other ways in which users could still abuse this little program: + +1. After CVE-2019-14865 fix, grub2-set-bootflag no longer rewrites the +grubenv file in-place, but writes into a temporary file and renames it +over the original, checking for error returns from each call first. +This prevents the original file truncation vulnerability, but it can +leave the temporary file around if the program is killed before it can +rename or remove the file. There are still many ways to get the program +killed, such as through RLIMIT_FSIZE triggering SIGXFSZ (tested, +reliable) or by careful timing (tricky) of signals sent by process group +leader, pty, pre-scheduled timers, SIGXCPU (probably not an exhaustive +list). Invoking the program multiple times fills up /boot (or if /boot +is not separate, then it can fill up the root filesystem). Since the +files are tiny, the filesystem is likely to run out of free inodes +before it'd run out of blocks, but the effect is similar - can't create +new files after this point (but still can add data to existing files, +such as logs). + +2. After CVE-2019-14865 fix, grub2-set-bootflag naively tries to protect +itself from signals by becoming full root. (This does protect it from +signals sent by the user directly to the PID, but e.g. "kill -9 -1" by +the user still works.) A side effect of such "protection" is that it's +possible to invoke more concurrent instances of grub2-set-bootflag than +the user's RLIMIT_NPROC would normally permit (as specified e.g. in +/etc/security/limits.conf, or say in Apache httpd's RLimitNPROC if +grub2-set-bootflag would be abused by a website script), thereby +exhausting system resources (e.g., bypassing RAM usage limit if +RLIMIT_AS was also set). + +3. umask is inherited. Again, due to how the CVE-2019-14865 fix creates +a new file, and due to how mkstemp() works, this affects grubenv's new +file permissions. Luckily, mkstemp() forces them to be no more relaxed +than 0600, but the user ends up being able to set them e.g. to 0. +Luckily, at least in my testing GRUB still works fine even when the file +has such (lack of) permissions. + +This commit deals with the abuses above as follows: + +1. RLIMIT_FSIZE is pre-checked, so this specific way to get the process +killed should no longer work. However, this isn't a complete fix +because there are other ways to get the process killed after it has +created the temporary file. + +The commit also fixes bug 1975892 ("RFE: grub2-set-bootflag should not +write the grubenv when the flag being written is already set") and +similar for "menu_show_once", which further reduces the abuse potential. + +2. RLIMIT_NPROC bypass should be avoided by not becoming full root (aka +dropping the partial "kill protection"). + +3. A safe umask is set. + +This is a partial fix (temporary files can still accumulate, but this is +harder to trigger). + +While at it, this commit also fixes potential 1- or 2-byte over-read of +env[] if its content is malformed - this was not a security issue since the +grubenv file is trusted input, and the fix is just for robustness. + +Signed-off-by: Solar Designer +--- + util/grub-set-bootflag.c | 29 ++++++++++++++++------------- + 1 file changed, 16 insertions(+), 13 deletions(-) + +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index 3b4c25ca2ac..5bbbef80439 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -33,6 +33,8 @@ + #include + #include + #include ++#include ++#include + + #include "progname.h" + +@@ -57,12 +59,17 @@ static void usage(FILE *out) + int main(int argc, char *argv[]) + { + /* NOTE buf must be at least the longest bootflag length + 4 bytes */ +- char env[GRUBENV_SIZE + 1], buf[64], *s; ++ char env[GRUBENV_SIZE + 1 + 2], buf[64], *s; + /* +1 for 0 termination, +6 for "XXXXXX" in tmp filename */ + char env_filename[PATH_MAX + 1], tmp_filename[PATH_MAX + 6 + 1]; + const char *bootflag; + int i, fd, len, ret; + FILE *f; ++ struct rlimit rlim; ++ ++ if (getrlimit(RLIMIT_FSIZE, &rlim) || rlim.rlim_cur < GRUBENV_SIZE || rlim.rlim_max < GRUBENV_SIZE) ++ return 1; ++ umask(077); + + if (argc != 2) + { +@@ -94,20 +101,11 @@ int main(int argc, char *argv[]) + len = strlen (bootflag); + + /* +- * Really become root. setuid avoids an user killing us, possibly leaking +- * the tmpfile. setgid avoids the new grubenv's gid being that of the user. ++ * setegid avoids the new grubenv's gid being that of the user. + */ +- ret = setuid(0); +- if (ret) ++ if (setegid(0)) + { +- perror ("Error setuid(0) failed"); +- return 1; +- } +- +- ret = setgid(0); +- if (ret) +- { +- perror ("Error setgid(0) failed"); ++ perror ("Error setegid(0) failed"); + return 1; + } + +@@ -136,6 +134,9 @@ int main(int argc, char *argv[]) + + /* 0 terminate env */ + env[GRUBENV_SIZE] = 0; ++ /* not a valid flag value */ ++ env[GRUBENV_SIZE + 1] = 0; ++ env[GRUBENV_SIZE + 2] = 0; + + if (strncmp (env, GRUB_ENVBLK_SIGNATURE, strlen (GRUB_ENVBLK_SIGNATURE))) + { +@@ -171,6 +172,8 @@ int main(int argc, char *argv[]) + + /* The grubenv is not 0 terminated, so memcpy the name + '=' , '1', '\n' */ + snprintf(buf, sizeof(buf), "%s=1\n", bootflag); ++ if (!memcmp(s, buf, len + 3)) ++ return 0; /* nothing to do */ + memcpy(s, buf, len + 3); + + diff --git a/0250-grub-set-bootflag-More-complete-fix-for-CVE-2024-104.patch b/0250-grub-set-bootflag-More-complete-fix-for-CVE-2024-104.patch new file mode 100644 index 00000000..615b04de --- /dev/null +++ b/0250-grub-set-bootflag-More-complete-fix-for-CVE-2024-104.patch @@ -0,0 +1,187 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Solar Designer +Date: Tue, 6 Feb 2024 21:56:21 +0100 +Subject: [PATCH] grub-set-bootflag: More complete fix for CVE-2024-1048 + +Switch to per-user fixed temporary filenames along with a weird locking +mechanism, which is explained in source code comments. This is a more +complete fix than the previous commit (temporary files can't accumulate). +Unfortunately, it introduces new risks (by working on a temporary file +shared between the user's invocations), which are _hopefully_ avoided by +the patch's elaborate logic. I actually got it wrong at first, which +suggests that this logic is hard to reason about, and more errors or +omissions are possible. It also relies on the kernel's primitives' exact +semantics to a greater extent (nothing out of the ordinary, though). + +Remaining issues that I think cannot reasonably be fixed without a +redesign (e.g., having per-flag files with nothing else in them) and +without introducing new issues: + +A. A user can still revert a concurrent user's attempt of setting the +other flag - or of making other changes to grubenv by means other than +this program. + +B. One leftover temporary file per user is still possible. + +Signed-off-by: Solar Designer +--- + util/grub-set-bootflag.c | 95 ++++++++++++++++++++++++++++++++++++++++-------- + 1 file changed, 79 insertions(+), 16 deletions(-) + +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index 5bbbef80439..514c4f9091a 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -33,6 +33,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -60,15 +61,12 @@ int main(int argc, char *argv[]) + { + /* NOTE buf must be at least the longest bootflag length + 4 bytes */ + char env[GRUBENV_SIZE + 1 + 2], buf[64], *s; +- /* +1 for 0 termination, +6 for "XXXXXX" in tmp filename */ +- char env_filename[PATH_MAX + 1], tmp_filename[PATH_MAX + 6 + 1]; ++ /* +1 for 0 termination, +11 for ".%u" in tmp filename */ ++ char env_filename[PATH_MAX + 1], tmp_filename[PATH_MAX + 11 + 1]; + const char *bootflag; + int i, fd, len, ret; + FILE *f; +- struct rlimit rlim; + +- if (getrlimit(RLIMIT_FSIZE, &rlim) || rlim.rlim_cur < GRUBENV_SIZE || rlim.rlim_max < GRUBENV_SIZE) +- return 1; + umask(077); + + if (argc != 2) +@@ -105,7 +103,7 @@ int main(int argc, char *argv[]) + */ + if (setegid(0)) + { +- perror ("Error setegid(0) failed"); ++ perror ("setegid(0) failed"); + return 1; + } + +@@ -176,19 +174,82 @@ int main(int argc, char *argv[]) + return 0; /* nothing to do */ + memcpy(s, buf, len + 3); + ++ struct rlimit rlim; ++ if (getrlimit(RLIMIT_FSIZE, &rlim) || rlim.rlim_cur < GRUBENV_SIZE || rlim.rlim_max < GRUBENV_SIZE) ++ { ++ fprintf (stderr, "Resource limits undetermined or too low\n"); ++ return 1; ++ } ++ ++ /* ++ * Here we work under the premise that we shouldn't write into the target ++ * file directly because we might not be able to have all of our changes ++ * written completely and atomically. That was CVE-2019-14865, known to ++ * have been triggerable via RLIMIT_FSIZE. While we've dealt with that ++ * specific attack via the check above, there may be other possibilities. ++ */ + + /* + * Create a tempfile for writing the new env. Use the canonicalized filename + * for the template so that the tmpfile is in the same dir / on same fs. ++ * ++ * We now use per-user fixed temporary filenames, so that a user cannot cause ++ * multiple files to accumulate. ++ * ++ * We don't use O_EXCL so that a stale temporary file doesn't prevent further ++ * usage of the program by the user. + */ +- snprintf(tmp_filename, sizeof(tmp_filename), "%sXXXXXX", env_filename); +- fd = mkstemp(tmp_filename); ++ snprintf(tmp_filename, sizeof(tmp_filename), "%s.%u", env_filename, getuid()); ++ fd = open(tmp_filename, O_CREAT | O_WRONLY, 0600); + if (fd == -1) + { + perror ("Creating tmpfile failed"); + return 1; + } + ++ /* ++ * The lock prevents the same user from reaching further steps ending in ++ * rename() concurrently, in which case the temporary file only partially ++ * written by one invocation could be renamed to the target file by another. ++ * ++ * The lock also guards the slow fsync() from concurrent calls. After the ++ * first time that and the rename() complete, further invocations for the ++ * same flag become no-ops. ++ * ++ * We lock the temporary file rather than the target file because locking the ++ * latter would allow any user having SIGSTOP'ed their process to make all ++ * other users' invocations fail (or lock up if we'd use blocking mode). ++ * ++ * We use non-blocking mode (LOCK_NB) because the lock having been taken by ++ * another process implies that the other process would normally have already ++ * renamed the file to target by the time it releases the lock (and we could ++ * acquire it), so we'd be working directly on the target if we proceeded, ++ * which is undesirable, and we'd kind of fail on the already-done rename. ++ */ ++ if (flock(fd, LOCK_EX | LOCK_NB)) ++ { ++ perror ("Locking tmpfile failed"); ++ return 1; ++ } ++ ++ /* ++ * Deal with the potential that another invocation proceeded all the way to ++ * rename() and process exit while we were between open() and flock(). ++ */ ++ { ++ struct stat st1, st2; ++ if (fstat(fd, &st1) || stat(tmp_filename, &st2)) ++ { ++ perror ("stat of tmpfile failed"); ++ return 1; ++ } ++ if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) ++ { ++ fprintf (stderr, "Another invocation won race\n"); ++ return 1; ++ } ++ } ++ + f = fdopen (fd, "w"); + if (!f) + { +@@ -213,6 +274,14 @@ int main(int argc, char *argv[]) + return 1; + } + ++ ret = ftruncate (fileno (f), GRUBENV_SIZE); ++ if (ret) ++ { ++ perror ("Error truncating tmpfile"); ++ unlink(tmp_filename); ++ return 1; ++ } ++ + ret = fsync (fileno (f)); + if (ret) + { +@@ -221,15 +290,9 @@ int main(int argc, char *argv[]) + return 1; + } + +- ret = fclose (f); +- if (ret) +- { +- perror ("Error closing tmpfile"); +- unlink(tmp_filename); +- return 1; +- } +- + /* ++ * We must not close the file before rename() as that would remove the lock. ++ * + * And finally rename the tmpfile with the new env over the old env, the + * linux kernel guarantees that this is atomic (from a syscall pov). + */ diff --git a/0251-grub-set-bootflag-Exit-calmly-when-not-running-as-ro.patch b/0251-grub-set-bootflag-Exit-calmly-when-not-running-as-ro.patch new file mode 100644 index 00000000..5b41025b --- /dev/null +++ b/0251-grub-set-bootflag-Exit-calmly-when-not-running-as-ro.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Solar Designer +Date: Tue, 6 Feb 2024 22:05:45 +0100 +Subject: [PATCH] grub-set-bootflag: Exit calmly when not running as root + +Exit calmly when not installed SUID root and invoked by non-root. This +allows installing user/grub-boot-success.service unconditionally while +supporting non-SUID installation of the program for some limited usage. + +Signed-off-by: Solar Designer +--- + util/grub-set-bootflag.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index 514c4f9091a..31a868aeca8 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -98,6 +98,17 @@ int main(int argc, char *argv[]) + bootflag = bootflags[i]; + len = strlen (bootflag); + ++ /* ++ * Exit calmly when not installed SUID root and invoked by non-root. This ++ * allows installing user/grub-boot-success.service unconditionally while ++ * supporting non-SUID installation of the program for some limited usage. ++ */ ++ if (geteuid()) ++ { ++ printf ("grub-set-bootflag not running as root, no action taken\n"); ++ return 0; ++ } ++ + /* + * setegid avoids the new grubenv's gid being that of the user. + */ diff --git a/0252-Makefile.core.def-fix-linux-module.patch b/0252-Makefile.core.def-fix-linux-module.patch new file mode 100644 index 00000000..83d8d8e8 --- /dev/null +++ b/0252-Makefile.core.def-fix-linux-module.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Mon, 15 Apr 2024 09:24:47 -0600 +Subject: [PATCH] Makefile.core.def: fix linux module + +Set EFI source file targets specifically for i386 and x86_64 archs, +otherwise we observe build failures at aarch64 + +../../grub-core/tests/videotest_checksum.c > videotest_checksum.marker.new || (rm -f videotest_checksum.marker; exit 1) +../../grub-core/loader/efi/linux.c:28:10: fatal error: grub/cpu/linux.h: No such file or directory + 28 | #include + | ^~~~~~~~~~~~~~~~~~ +compilation terminated. +. +. +. +../../grub-core/loader/i386/linux.c:30:10: fatal error: grub/cpu/linux.h: No such file or directory + 30 | #include + | ^~~~~~~~~~~~~~~~~~ +compilation terminated. + +Signed-off-by: Leo Sandoval +--- + grub-core/Makefile.core.def | 7 ++++--- + grub-core/loader/efi/linux.c | 1 - + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index b045aac7c91..6ff4835340d 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1902,13 +1902,14 @@ module = { + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; + i386_efi = loader/i386/efi/linux.c; ++ i386_efi = loader/efi/linux.c; ++ i386_efi = loader/i386/linux.c; + x86_64_efi = loader/i386/efi/linux.c; ++ x86_64_efi = loader/efi/linux.c; ++ x86_64_efi = loader/i386/linux.c; + emu = loader/emu/linux.c; +- fdt = lib/fdt.c; + common = loader/linux.c; + common = lib/cmdline.c; +- efi = loader/efi/linux.c; +- efi = loader/i386/linux.c; + }; + + module = { +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index f5ab0128991..44587df3858 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -25,7 +25,6 @@ + #include + #include + #include +-#include + #include + #include + #include diff --git a/0253-Add-support-for-Linux-EFI-stub-loading-on-arm-archit.patch b/0253-Add-support-for-Linux-EFI-stub-loading-on-arm-archit.patch new file mode 100644 index 00000000..d9ff0b61 --- /dev/null +++ b/0253-Add-support-for-Linux-EFI-stub-loading-on-arm-archit.patch @@ -0,0 +1,270 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Mon, 15 Apr 2024 11:19:31 -0600 +Subject: [PATCH] Add support for Linux EFI stub loading on arm architectures + +--- + grub-core/loader/arm64/xen_boot.c | 1 - + grub-core/loader/efi/linux.c | 116 ++++++++++++++++++-------------------- + include/grub/efi/efi.h | 28 ++++++++- + 3 files changed, 80 insertions(+), 65 deletions(-) + +diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c +index 26e1472c9d2..9838a0f878b 100644 +--- a/grub-core/loader/arm64/xen_boot.c ++++ b/grub-core/loader/arm64/xen_boot.c +@@ -252,7 +252,6 @@ xen_boot (void) + return err; + + return grub_arch_efi_linux_boot_image (xen_hypervisor->start, +- xen_hypervisor->size, + xen_hypervisor->cmdline); + } + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 44587df3858..8742e303d85 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -42,6 +43,7 @@ static int loaded; + + static void *kernel_addr; + static grub_uint64_t kernel_size; ++static grub_uint32_t handover_offset; + + static char *linux_args; + static grub_uint32_t cmdline_size; +@@ -94,7 +96,7 @@ static grub_efi_load_file2_t initrd_lf2 = { + typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); + + grub_err_t +-grub_efi_linux_boot (void *kernel_address, grub_off_t handover_offset, ++grub_efi_linux_boot (void *kernel_address, grub_off_t ho_offset, + void *kernel_params) + { + grub_efi_loaded_image_t *loaded_image = NULL; +@@ -117,8 +119,8 @@ grub_efi_linux_boot (void *kernel_address, grub_off_t handover_offset, + grub_dprintf ("linux", "Loaded Image base address could not be set\n"); + + grub_dprintf ("linux", "kernel_address: %p handover_offset: %p params: %p\n", +- kernel_address, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); +- hf = (handover_func)((char *)kernel_address + handover_offset + offset); ++ kernel_address, (void *)(grub_efi_uintn_t)ho_offset, kernel_params); ++ hf = (handover_func)((char *)kernel_address + ho_offset + offset); + hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); + + return GRUB_ERR_BUG; +@@ -178,7 +180,8 @@ grub_arch_efi_linux_load_image_header (grub_file_t file, + static grub_err_t + finalize_params_linux (void) + { +- int node, retval; ++ grub_efi_loaded_image_t *loaded_image = NULL; ++ int node, retval, len; + + void *fdt; + +@@ -213,79 +216,65 @@ finalize_params_linux (void) + if (grub_fdt_install() != GRUB_ERR_NONE) + goto failure; + +- return GRUB_ERR_NONE; +- +-failure: +- grub_fdt_unload(); +- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); +-} +-#endif +- +-grub_err_t +-grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) +-{ +- grub_efi_memory_mapped_device_path_t *mempath; +- grub_efi_handle_t image_handle; +- grub_efi_boot_services_t *b; +- grub_efi_status_t status; +- grub_efi_loaded_image_t *loaded_image; +- int len; +- +- mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); +- if (!mempath) +- return grub_errno; +- +- mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE; +- mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; +- mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); +- mempath[0].memory_type = GRUB_EFI_LOADER_DATA; +- mempath[0].start_address = addr; +- mempath[0].end_address = addr + size; +- +- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; +- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; +- mempath[1].header.length = sizeof (grub_efi_device_path_t); +- +- b = grub_efi_system_table->boot_services; +- status = b->load_image (0, grub_efi_image_handle, +- (grub_efi_device_path_t *) mempath, +- (void *) addr, size, &image_handle); +- if (status != GRUB_EFI_SUCCESS) +- return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); +- +- grub_dprintf ("linux", "linux command line: '%s'\n", args); ++ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", ++ fdt); + + /* Convert command line to UCS-2 */ +- loaded_image = grub_efi_get_loaded_image (image_handle); ++ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (loaded_image == NULL) + { + grub_error (GRUB_ERR_BAD_FIRMWARE, "missing loaded_image proto"); +- goto unload; ++ goto failure; + } + loaded_image->load_options_size = len = +- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); ++ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); + loaded_image->load_options = + grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); + if (!loaded_image->load_options) +- return grub_errno; ++ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); + + loaded_image->load_options_size = + 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, +- (grub_uint8_t *) args, len, NULL); ++ (grub_uint8_t *) linux_args, len, NULL); + +- grub_dprintf ("linux", "starting image %p\n", image_handle); +- status = b->start_image (image_handle, 0, NULL); ++ return GRUB_ERR_NONE; + +- /* When successful, not reached */ +- grub_error (GRUB_ERR_BAD_OS, "start_image() returned 0x%" PRIxGRUB_EFI_UINTN_T, status); +- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, +- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); +-unload: +- b->unload_image (image_handle); ++failure: ++ grub_fdt_unload(); ++ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); ++} ++#endif ++ ++static void ++free_params (void) ++{ ++ grub_efi_loaded_image_t *loaded_image = NULL; + +- return grub_errno; ++ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (loaded_image) ++ { ++ if (loaded_image->load_options) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options, ++ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++ loaded_image->load_options = NULL; ++ loaded_image->load_options_size = 0; ++ } + } + ++grub_err_t ++grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args) ++{ ++ grub_err_t retval; ++ ++ grub_dprintf ("linux", "linux command line: '%s'\n", args); ++ ++ retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr); ++ ++ /* Never reached... */ ++ free_params(); ++ return retval; ++ } ++ + static grub_err_t + grub_linux_boot (void) + { +@@ -294,8 +283,7 @@ grub_linux_boot (void) + return grub_errno; + #endif + +- return grub_arch_efi_linux_boot_image ((grub_addr_t) kernel_addr, +- kernel_size, linux_args); ++ return grub_arch_efi_linux_boot_image ((grub_addr_t) kernel_addr, linux_args); + } + + static grub_err_t +@@ -572,6 +560,12 @@ fallback: + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); + ++#if !defined(__i386__) && !defined(__x86_64__) ++ struct grub_armxx_linux_pe_header *pe; ++ pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); ++ handover_offset = pe->opt.entry_addr; ++#endif ++ + cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); + linux_args = grub_malloc (cmdline_size); + if (!linux_args) +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 83ddbe26e57..bff833468ee 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -20,6 +20,7 @@ + #ifndef GRUB_EFI_EFI_HEADER + #define GRUB_EFI_EFI_HEADER 1 + ++#include + #include + #include + #include +@@ -36,7 +37,29 @@ struct linux_arch_kernel_header { + struct grub_pe_image_header pe_image_header; + }; + +-#define GRUB_EFI_GRUB_VARIABLE_GUID \ ++struct grub_arm_linux_pe_header ++{ ++ grub_uint32_t magic; ++ struct grub_pe32_coff_header coff; ++ struct grub_pe32_optional_header opt; ++}; ++ ++struct grub_arm64_linux_pe_header ++{ ++ grub_uint32_t magic; ++ struct grub_pe32_coff_header coff; ++ struct grub_pe64_optional_header opt; ++}; ++ ++#if defined(__arm__) ++# define grub_armxx_linux_pe_header grub_arm_linux_pe_header ++#endif ++ ++#if defined(__aarch64__) ++# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header ++#endif ++ ++#define GRUB_EFI_GRUB_VARIABLE_GUID \ + { 0x91376aff, 0xcba6, 0x42be, \ + { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \ + } +@@ -173,8 +196,7 @@ grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); + #include + grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file, + struct linux_arch_kernel_header *lh); +-grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, +- char *args); ++grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); + + grub_addr_t grub_efi_section_addr (const char *section); + diff --git a/0114-arm-arm64-loader-Better-memory-allocation-and-error-.patch b/0254-arm-arm64-loader-Better-memory-allocation-and-error-.patch similarity index 80% rename from 0114-arm-arm64-loader-Better-memory-allocation-and-error-.patch rename to 0254-arm-arm64-loader-Better-memory-allocation-and-error-.patch index 1fdc5528..b6c1dc91 100644 --- a/0114-arm-arm64-loader-Better-memory-allocation-and-error-.patch +++ b/0254-arm-arm64-loader-Better-memory-allocation-and-error-.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Jones -Date: Thu, 11 Jul 2019 14:38:57 +0200 +Date: Mon, 15 Apr 2024 12:58:13 -0600 Subject: [PATCH] arm/arm64 loader: Better memory allocation and error messages. @@ -66,28 +66,31 @@ per-platform constraints on its given address are maintained. Signed-off-by: Peter Jones --- - grub-core/kern/efi/mm.c | 33 +++++++++++++++----- - grub-core/loader/arm64/linux.c | 68 +++++++++++++++++++++++++++++++----------- - 2 files changed, 76 insertions(+), 25 deletions(-) + grub-core/kern/efi/mm.c | 35 ++++++++++++++++++------ + grub-core/loader/efi/linux.c | 65 +++++++++++++++++++++++++++++++++----------- + 2 files changed, 75 insertions(+), 25 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index f6aef0ef649..85ad4b4494c 100644 +index 8f75205a732..560b859b6f4 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c -@@ -154,6 +154,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, +@@ -153,8 +153,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, { grub_efi_status_t status; grub_efi_boot_services_t *b; + grub_efi_physical_address_t ret = address; - /* Limit the memory access to less than 4GB for 32-bit platforms. */ +- /* Limit the memory access to less than 4GB for 32-bit platforms. */ ++/* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address > GRUB_EFI_MAX_USABLE_ADDRESS) -@@ -170,19 +171,22 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + { + char inv_addr[17], max_addr[17]; /* log16(2^64) = 16, plus NUL. */ +@@ -169,19 +170,22 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, } b = grub_efi_system_table->boot_services; -- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); -+ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret); +- status = b->allocate_pages (alloctype, memtype, pages, &address); ++ status = b->allocate_pages (alloctype, memtype, pages, &ret); if (status != GRUB_EFI_SUCCESS) { + grub_dprintf ("efi", @@ -103,13 +106,13 @@ index f6aef0ef649..85ad4b4494c 100644 /* Uggh, the address 0 was allocated... This is too annoying, so reallocate another one. */ - address = GRUB_EFI_MAX_USABLE_ADDRESS; -- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); +- status = b->allocate_pages (alloctype, memtype, pages, &address); + ret = address; -+ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret); ++ status = b->allocate_pages (alloctype, memtype, pages, &ret); grub_efi_free_pages (0, pages); if (status != GRUB_EFI_SUCCESS) { -@@ -191,9 +195,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, +@@ -190,9 +194,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, } } @@ -121,7 +124,7 @@ index f6aef0ef649..85ad4b4494c 100644 } void * -@@ -713,8 +717,21 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) +@@ -711,8 +715,21 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS; (grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size); desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) @@ -145,11 +148,11 @@ index f6aef0ef649..85ad4b4494c 100644 grub_free(memory_map); -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index 04994d5c67d..70a0075ec5e 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -71,20 +71,25 @@ finalize_params_linux (void) +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 8742e303d85..ddb27834131 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -182,7 +182,7 @@ finalize_params_linux (void) { grub_efi_loaded_image_t *loaded_image = NULL; int node, retval, len; @@ -157,29 +160,32 @@ index 04994d5c67d..70a0075ec5e 100644 + grub_err_t err = GRUB_ERR_NONE; void *fdt; - fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); -- - if (!fdt) -- goto failure; -+ { -+ err = grub_error(GRUB_ERR_BAD_OS, "failed to load FDT"); -+ goto failure; -+ } - - node = grub_fdt_find_subnode (fdt, 0, "chosen"); - if (node < 0) - node = grub_fdt_add_subnode (fdt, 0, "chosen"); - - if (node < 1) -- goto failure; -+ { -+ err = grub_error(grub_errno, "failed to load chosen fdt node."); -+ goto failure; -+ } - /* Set initrd info */ - if (initrd_start && initrd_end > initrd_start) -@@ -95,15 +100,26 @@ finalize_params_linux (void) +@@ -191,14 +191,21 @@ finalize_params_linux (void) + fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); + + if (!fdt) +- goto failure; ++ { ++ err = grub_error(GRUB_ERR_BAD_OS, "failed to load FDT"); ++ goto failure; ++ } ++ + + node = grub_fdt_find_subnode (fdt, 0, "chosen"); + if (node < 0) + node = grub_fdt_add_subnode (fdt, 0, "chosen"); + + if (node < 1) +- goto failure; ++ { ++ err = grub_error(grub_errno, "failed to load chosen fdt node."); ++ goto failure; ++ } + + grub_dprintf ("linux", "Initrd @ %p-%p\n", + (void *) initrd_start, (void *) initrd_end); +@@ -206,15 +213,26 @@ finalize_params_linux (void) retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", initrd_start); if (retval) @@ -210,18 +216,16 @@ index 04994d5c67d..70a0075ec5e 100644 grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", fdt); -@@ -111,14 +127,20 @@ finalize_params_linux (void) - /* Convert command line to UCS-2 */ +@@ -223,7 +241,7 @@ finalize_params_linux (void) loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); - if (!loaded_image) -- goto failure; -+ { + if (loaded_image == NULL) + { +- grub_error (GRUB_ERR_BAD_FIRMWARE, "missing loaded_image proto"); + err = grub_error(grub_errno, "Failed to install fdt"); -+ goto failure; -+ } - + goto failure; + } loaded_image->load_options_size = len = - (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); +@@ -231,7 +249,10 @@ finalize_params_linux (void) loaded_image->load_options = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); if (!loaded_image->load_options) @@ -233,16 +237,16 @@ index 04994d5c67d..70a0075ec5e 100644 loaded_image->load_options_size = 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, -@@ -128,7 +150,7 @@ finalize_params_linux (void) +@@ -241,7 +262,7 @@ finalize_params_linux (void) failure: grub_fdt_unload(); - return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); + return err; } + #endif - static void -@@ -212,16 +234,28 @@ grub_linux_unload (void) +@@ -344,16 +365,28 @@ grub_linux_unload (void) static void * allocate_initrd_mem (int initrd_pages) { @@ -275,5 +279,5 @@ index 04994d5c67d..70a0075ec5e 100644 + grub_dprintf ("linux", "got 0x%016llx\n", (unsigned long long)ret); + return ret; } + #endif - static grub_err_t diff --git a/0255-arm64-Fix-EFI-loader-kernel-image-allocation.patch b/0255-arm64-Fix-EFI-loader-kernel-image-allocation.patch new file mode 100644 index 00000000..61f6d44b --- /dev/null +++ b/0255-arm64-Fix-EFI-loader-kernel-image-allocation.patch @@ -0,0 +1,209 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Benjamin Herrenschmidt +Date: Tue, 16 Apr 2024 12:22:54 -0600 +Subject: [PATCH] arm64: Fix EFI loader kernel image allocation + +We are currently allocating just enough memory for the file size, +which means that the kernel BSS is in limbo (and not even zeroed). + +We are also not honoring the alignment specified in the image +PE header. + +This makes us use the PE optional header in which the kernel puts the +actual size it needs, including BSS, and make sure we clear it, and +honors the specified alignment for the image. + +Signed-off-by: Benjamin Herrenschmidt +[pjones: arm: check for the PE magic for the compiled arch] +Signed-off-by: Peter Jones +Signed-off-by: Robbie Harwood +--- + grub-core/loader/efi/linux.c | 93 +++++++++++++++++++++++++++++++------------- + include/grub/efi/efi.h | 3 +- + 2 files changed, 68 insertions(+), 28 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index ddb27834131..cb9de5565de 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -41,6 +41,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; + static int loaded; + ++static void *kernel_alloc_addr; ++static grub_uint32_t kernel_alloc_pages; + static void *kernel_addr; + static grub_uint64_t kernel_size; + static grub_uint32_t handover_offset; +@@ -319,9 +321,8 @@ grub_linux_unload (void) + GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start)); + initrd_start = initrd_end = 0; + grub_free (linux_args); +- if (kernel_addr) +- grub_efi_free_pages ((grub_addr_t) kernel_addr, +- GRUB_EFI_BYTES_TO_PAGES (kernel_size)); ++ if (kernel_alloc_addr) ++ grub_efi_free_pages ((grub_addr_t) kernel_alloc_addr, kernel_alloc_pages); + #if !defined(__i386__) && !defined(__x86_64__) + grub_fdt_unload (); + #endif +@@ -512,12 +513,37 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + return grub_errno; + } + ++#if !defined(__i386__) && !defined(__x86_64__) ++static grub_err_t ++parse_pe_header (void *kernel, grub_uint64_t *total_size, ++ grub_uint32_t *entry_offset, ++ grub_uint32_t *alignment) ++{ ++ struct linux_arch_kernel_header *lh = kernel; ++ struct grub_armxx_linux_pe_header *pe; ++ ++ pe = (void *)((unsigned long)kernel + lh->hdr_offset); ++ ++ if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC) ++ return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic"); ++ ++ *total_size = pe->opt.image_size; ++ *entry_offset = pe->opt.entry_addr; ++ *alignment = pe->opt.section_alignment; ++ ++ return GRUB_ERR_NONE; ++} ++#endif ++ + static grub_err_t + grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) + { + grub_file_t file = 0; + struct linux_arch_kernel_header lh; ++ grub_off_t filelen; ++ grub_uint32_t align; ++ void *kernel = NULL; + grub_err_t err; + + grub_dl_ref (my_mod); +@@ -548,8 +574,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + if (!file) + goto fail; + +- kernel_size = grub_file_size (file); +- + if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE) + #if !defined(__i386__) && !defined(__x86_64__) + goto fail; +@@ -570,33 +594,46 @@ fallback: + } + #endif + ++ filelen = grub_file_size (file); ++ kernel = grub_malloc(filelen); ++ if (!kernel) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer")); ++ goto fail; ++ } ++ ++ if (grub_file_read (file, kernel, filelen) < (grub_ssize_t)filelen) ++ { ++ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), ++ argv[0]); ++ goto fail; ++ } ++ ++#if !defined(__i386__) && !defined(__x86_64__) ++ if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align) != GRUB_ERR_NONE) ++ goto fail; ++ grub_dprintf ("linux", "kernel mem size : %lld\n", (long long) kernel_size); ++ grub_dprintf ("linux", "kernel entry offset : %d\n", handover_offset); ++ grub_dprintf ("linux", "kernel alignment : 0x%x\n", align); ++ + grub_loader_unset(); + +- grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size); +- kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size)); +- grub_dprintf ("linux", "kernel numpages: %lld\n", +- (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size)); +- if (!kernel_addr) ++ kernel_alloc_pages = GRUB_EFI_BYTES_TO_PAGES (kernel_size + align - 1); ++ kernel_alloc_addr = grub_efi_allocate_any_pages (kernel_alloc_pages); ++ grub_dprintf ("linux", "kernel numpages: %d\n", kernel_alloc_pages); ++ if (!kernel_alloc_addr) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); + goto fail; + } +- +- grub_file_seek (file, 0); +- if (grub_file_read (file, kernel_addr, kernel_size) +- < (grub_int64_t) kernel_size) +- { +- if (!grub_errno) +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); +- goto fail; +- } ++ kernel_addr = (void *)ALIGN_UP((grub_uint64_t)kernel_alloc_addr, align); + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); +- +-#if !defined(__i386__) && !defined(__x86_64__) +- struct grub_armxx_linux_pe_header *pe; +- pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); +- handover_offset = pe->opt.entry_addr; ++ grub_memcpy (kernel_addr, kernel, grub_min(filelen, kernel_size)); ++ if (kernel_size > filelen) ++ grub_memset ((char *)kernel_addr + filelen, 0, kernel_size - filelen); ++ grub_free(kernel); ++ kernel = NULL; + #endif + + cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); +@@ -621,6 +658,9 @@ fallback: + } + + fail: ++ if (kernel) ++ grub_free (kernel); ++ + if (file) + grub_file_close (file); + +@@ -633,9 +673,8 @@ fail: + if (linux_args && !loaded) + grub_free (linux_args); + +- if (kernel_addr && !loaded) +- grub_efi_free_pages ((grub_addr_t) kernel_addr, +- GRUB_EFI_BYTES_TO_PAGES (kernel_size)); ++ if (kernel_alloc_addr && !loaded) ++ grub_efi_free_pages ((grub_addr_t) kernel_alloc_addr, kernel_alloc_pages); + + return grub_errno; + } +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index bff833468ee..c40684821e1 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -20,7 +20,6 @@ + #ifndef GRUB_EFI_EFI_HEADER + #define GRUB_EFI_EFI_HEADER 1 + +-#include + #include + #include + #include +@@ -52,10 +51,12 @@ struct grub_arm64_linux_pe_header + }; + + #if defined(__arm__) ++# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC + # define grub_armxx_linux_pe_header grub_arm_linux_pe_header + #endif + + #if defined(__aarch64__) ++# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC + # define grub_armxx_linux_pe_header grub_arm64_linux_pe_header + #endif + diff --git a/0256-pe-add-the-DOS-header-struct-and-fix-some-bad-naming.patch b/0256-pe-add-the-DOS-header-struct-and-fix-some-bad-naming.patch new file mode 100644 index 00000000..222a13c5 --- /dev/null +++ b/0256-pe-add-the-DOS-header-struct-and-fix-some-bad-naming.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 16 Apr 2024 12:51:50 -0600 +Subject: [PATCH] pe: add the DOS header struct and fix some bad naming. + +In order to properly validate a loaded kernel's support for being loaded +without a writable stack or executable, we need to be able to properly +parse arbitrary PE headers. + +Currently, pe32.h is written in such a way that the MS-DOS header that +tells us where to find the PE header in the binary can't be accessed. +Further, for some reason it calls the DOS MZ magic "GRUB_PE32_MAGIC". + +This patch adds the structure for the DOS header, renames the DOS magic +define, and adds defines for the actual PE magic. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/linux.c | 2 +- + include/grub/efi/pe32.h | 28 ++++++++++++++++++++++++++-- + 2 files changed, 27 insertions(+), 3 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index cb9de5565de..ecaa8c18c4d 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -138,7 +138,7 @@ grub_arch_efi_linux_load_image_header (grub_file_t file, + if (grub_file_read (file, lh, sizeof (*lh)) < (grub_ssize_t) sizeof (*lh)) + return grub_error(GRUB_ERR_FILE_READ_ERROR, "failed to read Linux image header"); + +- if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC) ++ if ((lh->code0 & 0xffff) != GRUB_DOS_MAGIC) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled")); + +diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h +index a39743396dc..13fdd0e7d98 100644 +--- a/include/grub/efi/pe32.h ++++ b/include/grub/efi/pe32.h +@@ -46,7 +46,30 @@ + + #define GRUB_PE32_MSDOS_STUB_SIZE 0x80 + +-#define GRUB_PE32_MAGIC 0x5a4d ++#define GRUB_DOS_MAGIC 0x5a4d ++ ++struct grub_dos_header ++{ ++ grub_uint16_t magic; ++ grub_uint16_t cblp; ++ grub_uint16_t cp; ++ grub_uint16_t crlc; ++ grub_uint16_t cparhdr; ++ grub_uint16_t minalloc; ++ grub_uint16_t maxalloc; ++ grub_uint16_t ss; ++ grub_uint16_t sp; ++ grub_uint16_t csum; ++ grub_uint16_t ip; ++ grub_uint16_t cs; ++ grub_uint16_t lfarlc; ++ grub_uint16_t ovno; ++ grub_uint16_t res0[4]; ++ grub_uint16_t oemid; ++ grub_uint16_t oeminfo; ++ grub_uint16_t res1[10]; ++ grub_uint32_t lfanew; ++}; + + struct grub_msdos_image_header + { +@@ -293,7 +316,8 @@ struct grub_pe32_section_table + #define GRUB_PE32_SCN_MEM_READ 0x40000000 + #define GRUB_PE32_SCN_MEM_WRITE 0x80000000 + +-#define GRUB_PE32_SIGNATURE_SIZE 4 ++#define GRUB_PE32_SIGNATURE_SIZE 4 ++#define GRUB_PE32_SIGNATURE "PE\0\0" + + #if GRUB_TARGET_SIZEOF_VOID_P == 8 + #define GRUB_PE32_NATIVE_MAGIC GRUB_PE32_PE64_MAGIC diff --git a/0257-Correct-BSS-zeroing-on-aarch64.patch b/0257-Correct-BSS-zeroing-on-aarch64.patch new file mode 100644 index 00000000..232393f7 --- /dev/null +++ b/0257-Correct-BSS-zeroing-on-aarch64.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jeremy Linton +Date: Tue, 16 Apr 2024 13:26:55 -0600 +Subject: [PATCH] Correct BSS zeroing on aarch64 + +The aarch64 loader doesn't use efi bootservices, and +therefor it has a very minimal loader which makes a lot +of assumptions about the kernel layout. With the ZBOOT +changes, the layout has changed a bit and we not should +really be parsing the PE sections to determine how much +data to copy, otherwise the BSS won't be setup properly. + +This code still makes a lot of assumptions about the +the kernel layout, so its far from ideal, but it works. + +Resolves: rhbz#2125069 + +Signed-off-by: Jeremy Linton +--- + grub-core/loader/efi/linux.c | 27 ++++++++++++++++++++++----- + 1 file changed, 22 insertions(+), 5 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index ecaa8c18c4d..55c5c8600d4 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -517,10 +517,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + static grub_err_t + parse_pe_header (void *kernel, grub_uint64_t *total_size, + grub_uint32_t *entry_offset, +- grub_uint32_t *alignment) ++ grub_uint32_t *alignment, grub_uint32_t *code_size) + { + struct linux_arch_kernel_header *lh = kernel; + struct grub_armxx_linux_pe_header *pe; ++ grub_uint16_t i; ++ struct grub_pe32_section_table *sections; + + pe = (void *)((unsigned long)kernel + lh->hdr_offset); + +@@ -530,6 +532,19 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size, + *total_size = pe->opt.image_size; + *entry_offset = pe->opt.entry_addr; + *alignment = pe->opt.section_alignment; ++ *code_size = pe->opt.section_alignment; ++ ++ sections = (struct grub_pe32_section_table *) ((char *)&pe->opt + ++ pe->coff.optional_header_size); ++ grub_dprintf ("linux", "num_sections : %d\n", pe->coff.num_sections ); ++ for (i = 0 ; i < pe->coff.num_sections; i++) ++ { ++ grub_dprintf ("linux", "raw_size : %lld\n", ++ (long long) sections[i].raw_data_size); ++ grub_dprintf ("linux", "virt_size : %lld\n", ++ (long long) sections[i].virtual_size); ++ *code_size += sections[i].raw_data_size; ++ } + + return GRUB_ERR_NONE; + } +@@ -543,6 +558,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + struct linux_arch_kernel_header lh; + grub_off_t filelen; + grub_uint32_t align; ++ grub_uint32_t code_size; + void *kernel = NULL; + grub_err_t err; + +@@ -610,11 +626,12 @@ fallback: + } + + #if !defined(__i386__) && !defined(__x86_64__) +- if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align) != GRUB_ERR_NONE) ++ if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align, &code_size) != GRUB_ERR_NONE) + goto fail; + grub_dprintf ("linux", "kernel mem size : %lld\n", (long long) kernel_size); + grub_dprintf ("linux", "kernel entry offset : %d\n", handover_offset); + grub_dprintf ("linux", "kernel alignment : 0x%x\n", align); ++ grub_dprintf ("linux", "kernel size : 0x%x\n", code_size); + + grub_loader_unset(); + +@@ -629,9 +646,9 @@ fallback: + kernel_addr = (void *)ALIGN_UP((grub_uint64_t)kernel_alloc_addr, align); + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); +- grub_memcpy (kernel_addr, kernel, grub_min(filelen, kernel_size)); +- if (kernel_size > filelen) +- grub_memset ((char *)kernel_addr + filelen, 0, kernel_size - filelen); ++ grub_memcpy (kernel_addr, kernel, grub_min(code_size, kernel_size)); ++ if (kernel_size > code_size) ++ grub_memset ((char *)kernel_addr + code_size, 0, kernel_size - code_size); + grub_free(kernel); + kernel = NULL; + #endif diff --git a/0258-arm64-Use-proper-memory-type-for-kernel-allocation.patch b/0258-arm64-Use-proper-memory-type-for-kernel-allocation.patch new file mode 100644 index 00000000..453ee578 --- /dev/null +++ b/0258-arm64-Use-proper-memory-type-for-kernel-allocation.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maximilian Luz +Date: Tue, 16 Apr 2024 14:21:49 -0600 +Subject: [PATCH] arm64: Use proper memory type for kernel allocation + +Currently, the kernel pages are allocated with type EFI_LOADER_DATA. +While the vast majority of systems will happily execute code from those +pages (i.e. don't care about memory protection), the Microsoft Surface +Pro X stalls, as this memory is not designated as "executable". + +Therefore, allocate the kernel pages as EFI_LOADER_CODE to request +memory that is actually executable. + +Signed-off-by: Maximilian Luz +--- + grub-core/loader/efi/linux.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 55c5c8600d4..d9ded7c4f12 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -25,7 +25,9 @@ + #include + #include + #include ++#include + #include ++#include + #include + #include + #include +@@ -636,7 +638,10 @@ fallback: + grub_loader_unset(); + + kernel_alloc_pages = GRUB_EFI_BYTES_TO_PAGES (kernel_size + align - 1); +- kernel_alloc_addr = grub_efi_allocate_any_pages (kernel_alloc_pages); ++ kernel_alloc_addr = grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS, ++ kernel_alloc_pages, ++ GRUB_EFI_ALLOCATE_MAX_ADDRESS, ++ GRUB_EFI_LOADER_CODE); + grub_dprintf ("linux", "kernel numpages: %d\n", kernel_alloc_pages); + if (!kernel_alloc_addr) + { diff --git a/0259-normal-Remove-grub_env_set-prefix-in-grub_try_normal.patch b/0259-normal-Remove-grub_env_set-prefix-in-grub_try_normal.patch new file mode 100644 index 00000000..af24bccb --- /dev/null +++ b/0259-normal-Remove-grub_env_set-prefix-in-grub_try_normal.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Tue, 19 Dec 2023 16:52:05 +0100 +Subject: [PATCH] normal: Remove grub_env_set prefix in grub_try_normal_prefix + +Commit de735a453aa35 added a grub_env_set where the prefix contains +the arch name in the pathname. This create issues when trying to +load modules using this prefix as the pathname contains a "doubled" +arch name in it (ie .../powerpc-ieee1275/powerpc-ieee1275/). + +Signed-off-by: Nicolas Frayer +--- + grub-core/normal/main.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 803b9656d36..26872ce9477 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -372,7 +372,6 @@ grub_try_normal_prefix (const char *prefix) + file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); + if (file) + { +- grub_env_set ("prefix", prefix); + grub_file_close (file); + err = GRUB_ERR_NONE; + } diff --git a/0260-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch b/0260-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch new file mode 100644 index 00000000..2198ce3c --- /dev/null +++ b/0260-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch @@ -0,0 +1,54 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jon DeVree +Date: Sun, 11 Feb 2024 10:34:58 -0500 +Subject: [PATCH] fs/xfs: Handle non-continuous data blocks in directory + extents + +The directory extent list does not have to be a continuous list of data +blocks. When GRUB tries to read a non-existant member of the list, +grub_xfs_read_file() will return a block of zero'ed memory. Checking for +a zero'ed magic number is sufficient to skip this non-existant data block. + +Prior to commit 07318ee7e (fs/xfs: Fix XFS directory extent parsing) +this was handled as a subtle side effect of reading the (non-existant) +tail data structure. Since the block was zero'ed the computation of the +number of directory entries in the block would return 0 as well. + +Fixes: 07318ee7e (fs/xfs: Fix XFS directory extent parsing) +Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2254370 + +Signed-off-by: Jon DeVree +Reviewed-By: Vladimir Serbinenko +Reviewed-by: Daniel Kiper +--- + grub-core/fs/xfs.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index bc2224dbb46..8e02ab4a301 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -902,6 +902,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, + grub_xfs_first_de(dir->data, dirblock); + int entries = -1; + char *end = dirblock + dirblk_size; ++ grub_uint32_t magic; + + numread = grub_xfs_read_file (dir, 0, 0, + blk << dirblk_log2, +@@ -912,6 +913,15 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, + return 0; + } + ++ /* ++ * If this data block isn't actually part of the extent list then ++ * grub_xfs_read_file() returns a block of zeros. So, if the magic ++ * number field is all zeros then this block should be skipped. ++ */ ++ magic = *(grub_uint32_t *)(void *) dirblock; ++ if (!magic) ++ continue; ++ + /* + * Leaf and tail information are only in the data block if the number + * of extents is 1. diff --git a/0261-Ignore-warnings-for-incompatible-types.patch b/0261-Ignore-warnings-for-incompatible-types.patch new file mode 100644 index 00000000..ad7dacb9 --- /dev/null +++ b/0261-Ignore-warnings-for-incompatible-types.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Wed, 17 Jan 2024 21:15:14 +0100 +Subject: [PATCH] Ignore warnings for incompatible types + +Add -Wno-incompatible-pointer-types to ignore warnings for incompatible +types + +Signed-off-by: Nicolas Frayer +--- + configure.ac | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/configure.ac b/configure.ac +index d223fe3ef6e..4788f3d6adc 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -2166,8 +2166,8 @@ if test x"$enable_wextra" != xno ; then + HOST_CFLAGS="$HOST_CFLAGS -Wextra" + fi + +-TARGET_CFLAGS="$TARGET_CFLAGS -Werror=trampolines -fno-trampolines" +-HOST_CFLAGS="$HOST_CFLAGS -Werror=trampolines -fno-trampolines" ++TARGET_CFLAGS="$TARGET_CFLAGS -Werror=trampolines -fno-trampolines -Wno-incompatible-pointer-types" ++HOST_CFLAGS="$HOST_CFLAGS -Werror=trampolines -fno-trampolines -Wno-incompatible-pointer-types" + + TARGET_CPP="$TARGET_CC -E" + TARGET_CCAS=$TARGET_CC diff --git a/0262-cmd-search-Rework-of-CVE-2023-4001-fix.patch b/0262-cmd-search-Rework-of-CVE-2023-4001-fix.patch new file mode 100644 index 00000000..c63fc3e8 --- /dev/null +++ b/0262-cmd-search-Rework-of-CVE-2023-4001-fix.patch @@ -0,0 +1,180 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Thu, 16 May 2024 10:58:32 +0200 +Subject: [PATCH] cmd/search: Rework of CVE-2023-4001 fix + +The initial fix implemented a new flag that forces the grub cfg +stub to be located on the same disk as grub. This created several +issues such as RAID machines not being able to boot as their +partition names under grub were different from the partition where +grub is located. It also simply means that any machines with the +/boot partition located on a disk other than the one containing grub +won't boot. +This commit denies booting if the grub cfg stub is located on a USB +drive with a duplicated UUID (UUID being the same as the partition +containing the actual grub cfg stub) + +Signed-off-by: Nicolas Frayer +--- + grub-core/commands/search.c | 134 +++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 126 insertions(+), 8 deletions(-) + +diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c +index db8692ffbfb..9dd937e6df4 100644 +--- a/grub-core/commands/search.c ++++ b/grub-core/commands/search.c +@@ -30,6 +30,8 @@ + #include + #include + #include ++#include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -54,6 +56,100 @@ struct search_ctx + int is_cache; + }; + ++static int ++is_device_usb (const char *name) ++{ ++ int ret = 0; ++ ++ grub_device_t dev = grub_device_open(name); ++ ++ if (dev) ++ { ++ struct grub_efidisk_data ++ { ++ grub_efi_handle_t handle; ++ grub_efi_device_path_t *device_path; ++ grub_efi_device_path_t *last_device_path; ++ grub_efi_block_io_t *block_io; ++ struct grub_efidisk_data *next; ++ }; ++ ++ if (dev->disk && dev->disk->data) ++ { ++ struct grub_efidisk_data *dp = dev->disk->data; ++ ++ if ( GRUB_EFI_DEVICE_PATH_TYPE (dp->last_device_path) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE && ++ GRUB_EFI_DEVICE_PATH_SUBTYPE (dp->last_device_path) == GRUB_EFI_USB_DEVICE_PATH_SUBTYPE) ++ { ++ ret = 1; ++ } ++ } ++ grub_device_close(dev); ++ } ++ ++ return ret; ++} ++ ++static int ++get_device_uuid(const char *name, char** quid) ++{ ++ int ret = 0; ++ ++ grub_device_t dev_part = grub_device_open(name); ++ ++ if (dev_part) ++ { ++ grub_fs_t fs; ++ ++ fs = grub_fs_probe (dev_part); ++ ++#ifdef DO_SEARCH_FS_UUID ++#define read_fn fs_uuid ++#else ++#define read_fn fs_label ++#endif ++ if (fs && fs->read_fn) ++ { ++ fs->read_fn (dev_part, quid); ++ ++ if (grub_errno == GRUB_ERR_NONE && *quid) ++ { ++ ret = 1; ++ } ++ ++ } ++ grub_device_close (dev_part); ++ } ++ ++ return ret; ++} ++struct uuid_context { ++ char* name; ++ char* uuid; ++}; ++ ++static int ++check_for_duplicate (const char *name, void *data) ++{ ++ int ret = 0; ++ struct uuid_context * uuid_ctx = (struct uuid_context *)data; ++ char *quid = 0; ++ ++ get_device_uuid(name, &quid); ++ ++ if (quid == NULL) ++ return 0; ++ ++ if (!grub_strcasecmp(quid, uuid_ctx->uuid) && grub_strcasecmp(name, uuid_ctx->name)) ++ { ++ ret = 1; ++ } ++ ++ grub_free(quid); ++ ++ return ret; ++} ++ + /* Helper for FUNC_NAME. */ + static int + iterate_device (const char *name, void *data) +@@ -106,14 +202,36 @@ iterate_device (const char *name, void *data) + grub_str_sep (name, name_disk, ',', rem_2); + if (root_disk != NULL && *root_disk != '\0' && + name_disk != NULL && *name_disk != '\0') +- if (grub_strcmp(root_disk, name_disk) != 0) +- { +- grub_free (root_disk); +- grub_free (name_disk); +- grub_free (rem_1); +- grub_free (rem_2); +- return 0; +- } ++ { ++ grub_device_t dev, dev_part; ++ ++ if (is_device_usb(name) && !is_device_usb(root_dev)) ++ { ++ char *quid_name = NULL; ++ int longlist = 0; ++ struct uuid_context uuid_ctx; ++ int ret = 0; ++ ++ get_device_uuid(name, &quid_name); ++ if (!grub_strcmp(quid_name, ctx->key)) ++ { ++ uuid_ctx.name = name; ++ uuid_ctx.uuid = quid_name; ++ ++ ret = grub_device_iterate (check_for_duplicate, &uuid_ctx); ++ ++ if (ret) ++ { ++ grub_printf("Duplicated media UUID found, rebooting ...\n"); ++ grub_sleep(10); ++ grub_reboot(); ++ } ++ } ++ ++ if (quid_name) grub_free (quid_name); ++ ++ } ++ } + } + grub_free (root_disk); + grub_free (name_disk); diff --git a/0263-loader-efi-linux.c-read-the-kernel-image-before-head.patch b/0263-loader-efi-linux.c-read-the-kernel-image-before-head.patch new file mode 100644 index 00000000..e8dc2231 --- /dev/null +++ b/0263-loader-efi-linux.c-read-the-kernel-image-before-head.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 29 May 2024 17:35:35 -0600 +Subject: [PATCH] loader/efi/linux.c: read the kernel image before header + +Signed-off-by: Leo Sandoval +--- + grub-core/loader/efi/linux.c | 34 ++++++++++++++++++++-------------- + 1 file changed, 20 insertions(+), 14 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index d9ded7c4f12..3ada50ed969 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -559,6 +559,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_file_t file = 0; + struct linux_arch_kernel_header lh; + grub_off_t filelen; ++ grub_off_t filereadlen; + grub_uint32_t align; + grub_uint32_t code_size; + void *kernel = NULL; +@@ -592,6 +593,25 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + if (!file) + goto fail; + ++ filelen = grub_file_size (file); ++ kernel = grub_malloc(filelen); ++ if (!kernel) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer")); ++ goto fail; ++ } ++ ++ filereadlen = grub_file_read (file, kernel, filelen); ++ grub_dprintf ("linux", "filelen : %lld\n", (long long) filelen); ++ grub_dprintf ("linux", "filereadlen : %lld\n", (long long) filereadlen); ++ ++ if (filereadlen < filelen) ++ { ++ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), ++ argv[0]); ++ goto fail; ++ } ++ + if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE) + #if !defined(__i386__) && !defined(__x86_64__) + goto fail; +@@ -612,20 +632,6 @@ fallback: + } + #endif + +- filelen = grub_file_size (file); +- kernel = grub_malloc(filelen); +- if (!kernel) +- { +- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer")); +- goto fail; +- } +- +- if (grub_file_read (file, kernel, filelen) < (grub_ssize_t)filelen) +- { +- grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), +- argv[0]); +- goto fail; +- } + + #if !defined(__i386__) && !defined(__x86_64__) + if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align, &code_size) != GRUB_ERR_NONE) diff --git a/0264-nx-set-attrs-in-our-kernel-loaders.patch b/0264-nx-set-attrs-in-our-kernel-loaders.patch new file mode 100644 index 00000000..6b0aa1d2 --- /dev/null +++ b/0264-nx-set-attrs-in-our-kernel-loaders.patch @@ -0,0 +1,580 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 3 Jul 2024 17:54:41 -0600 +Subject: [PATCH] nx: set attrs in our kernel loaders + +For NX, our kernel loaders need to set write and execute page +permissions on allocated pages and the stack. + +This patch adds those calls. + +Signed-off-by: Peter Jones +[rharwood: fix stack_attrs undefined, fix aarch64 callsites] +Signed-off-by: Robbie Harwood +--- + grub-core/kern/efi/mm.c | 79 ++++++++++++++++ + grub-core/loader/arm64/xen_boot.c | 5 +- + grub-core/loader/efi/chainloader.c | 11 +++ + grub-core/loader/efi/linux.c | 188 ++++++++++++++++++++++++++++++++++--- + grub-core/loader/i386/efi/linux.c | 26 ++++- + grub-core/loader/i386/linux.c | 5 + + include/grub/efi/efi.h | 6 +- + include/grub/efi/linux.h | 16 +++- + include/grub/efi/pe32.h | 2 + + 9 files changed, 319 insertions(+), 19 deletions(-) + +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index 560b859b6f4..464fe1c3c01 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -603,6 +603,83 @@ print_memory_map (grub_efi_memory_descriptor_t *memory_map, + } + #endif + ++grub_addr_t grub_stack_addr = (grub_addr_t)-1ll; ++grub_size_t grub_stack_size = 0; ++ ++static void ++grub_nx_init (void) ++{ ++ grub_uint64_t attrs, stack_attrs; ++ grub_err_t err; ++ grub_addr_t stack_current, stack_end; ++ const grub_uint64_t page_size = 4096; ++ const grub_uint64_t page_mask = ~(page_size - 1); ++ ++ /* ++ * These are to confirm that the flags are working as expected when ++ * debugging. ++ */ ++ attrs = 0; ++ stack_current = (grub_addr_t)grub_nx_init & page_mask; ++ err = grub_get_mem_attrs (stack_current, page_size, &attrs); ++ if (err) ++ { ++ grub_dprintf ("nx", ++ "grub_get_mem_attrs(0x%"PRIxGRUB_UINT64_T", ...) -> 0x%x\n", ++ stack_current, err); ++ grub_error_pop (); ++ } ++ else ++ grub_dprintf ("nx", "page attrs for grub_nx_init (%p) are %c%c%c\n", ++ grub_dl_load_core, ++ (attrs & GRUB_MEM_ATTR_R) ? 'r' : '-', ++ (attrs & GRUB_MEM_ATTR_R) ? 'w' : '-', ++ (attrs & GRUB_MEM_ATTR_R) ? 'x' : '-'); ++ ++ stack_current = (grub_addr_t)&stack_current & page_mask; ++ err = grub_get_mem_attrs (stack_current, page_size, &stack_attrs); ++ if (err) ++ { ++ grub_dprintf ("nx", ++ "grub_get_mem_attrs(0x%"PRIxGRUB_UINT64_T", ...) -> 0x%x\n", ++ stack_current, err); ++ grub_error_pop (); ++ } ++ else ++ { ++ attrs = stack_attrs; ++ grub_dprintf ("nx", "page attrs for stack (%p) are %c%c%c\n", ++ &attrs, ++ (attrs & GRUB_MEM_ATTR_R) ? 'r' : '-', ++ (attrs & GRUB_MEM_ATTR_R) ? 'w' : '-', ++ (attrs & GRUB_MEM_ATTR_R) ? 'x' : '-'); ++ } ++ for (stack_end = stack_current + page_size ; ++ !(attrs & GRUB_MEM_ATTR_R); ++ stack_end += page_size) ++ { ++ err = grub_get_mem_attrs (stack_current, page_size, &attrs); ++ if (err) ++ { ++ grub_dprintf ("nx", ++ "grub_get_mem_attrs(0x%"PRIxGRUB_UINT64_T", ...) -> 0x%x\n", ++ stack_current, err); ++ grub_error_pop (); ++ break; ++ } ++ } ++ if (stack_end > stack_current) ++ { ++ grub_stack_addr = stack_current; ++ grub_stack_size = stack_end - stack_current; ++ grub_dprintf ("nx", ++ "detected stack from 0x%"PRIxGRUB_ADDR" to 0x%"PRIxGRUB_ADDR"\n", ++ grub_stack_addr, grub_stack_addr + grub_stack_size - 1); ++ } ++} ++ ++ ++ + static grub_err_t + grub_efi_mm_add_regions (grub_size_t required_bytes, unsigned int flags) + { +@@ -615,6 +692,8 @@ grub_efi_mm_add_regions (grub_size_t required_bytes, unsigned int flags) + grub_err_t err; + int mm_status; + ++ grub_nx_init (); ++ + /* Prepare a memory region to store two memory maps. */ + memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); + if (! memory_map) +diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c +index 9838a0f878b..5d7c8603db9 100644 +--- a/grub-core/loader/arm64/xen_boot.c ++++ b/grub-core/loader/arm64/xen_boot.c +@@ -252,7 +252,10 @@ xen_boot (void) + return err; + + return grub_arch_efi_linux_boot_image (xen_hypervisor->start, +- xen_hypervisor->cmdline); ++ xen_hypervisor->size, ++ xen_hypervisor->cmdline, ++ 0); ++ + } + + static void +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index badff5e50b5..5cd6f6a5993 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -1078,6 +1078,17 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ /* ++ * The OS kernel is going to set its own permissions when it takes over ++ * paging a few million instructions from now, and load_image() will set up ++ * anything that's needed based on the section headers, so there's no point ++ * in doing anything but clearing the protection bits here. ++ */ ++ grub_dprintf("nx", "setting attributes for %p (%lu bytes) to %llx\n", ++ (void *)(grub_addr_t)address, fsize, 0llu); ++ grub_update_mem_attrs (address, fsize, ++ GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_W|GRUB_MEM_ATTR_X, 0); ++ + #if defined (__i386__) || defined (__x86_64__) + if (fsize >= (grub_ssize_t) sizeof (struct grub_macho_fat_header)) + { +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 3ada50ed969..fe48001442a 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -96,16 +96,127 @@ static grub_efi_load_file2_t initrd_lf2 = { + + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" ++#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" ++ ++grub_err_t ++grub_efi_check_nx_image_support (grub_addr_t k_add, ++ grub_size_t k_size, ++ int *nx_supported) ++{ ++ struct grub_dos_header *doshdr; ++ grub_size_t sz = sizeof (*doshdr); ++ ++ struct grub_pe32_header_32 *pe32; ++ struct grub_pe32_header_64 *pe64; ++ ++ int image_is_compatible = 0; ++ int is_64_bit; ++ ++ if (k_size < sz) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel is too small")); ++ ++ doshdr = (void *)k_add; ++ ++ if ((doshdr->magic & 0xffff) != GRUB_DOS_MAGIC) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel DOS magic is invalid")); ++ ++ sz = doshdr->lfanew + sizeof (*pe32); ++ if (k_size < sz) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel is too small")); ++ ++ pe32 = (struct grub_pe32_header_32 *)(k_add + doshdr->lfanew); ++ pe64 = (struct grub_pe32_header_64 *)pe32; ++ ++ if (grub_memcmp (pe32->signature, GRUB_PE32_SIGNATURE, ++ GRUB_PE32_SIGNATURE_SIZE) != 0) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel PE magic is invalid")); ++ ++ switch (pe32->coff_header.machine) ++ { ++ case GRUB_PE32_MACHINE_ARMTHUMB_MIXED: ++ case GRUB_PE32_MACHINE_I386: ++ case GRUB_PE32_MACHINE_RISCV32: ++ is_64_bit = 0; ++ break; ++ case GRUB_PE32_MACHINE_ARM64: ++ case GRUB_PE32_MACHINE_IA64: ++ case GRUB_PE32_MACHINE_RISCV64: ++ case GRUB_PE32_MACHINE_X86_64: ++ is_64_bit = 1; ++ break; ++ default: ++ return grub_error (GRUB_ERR_BAD_OS, N_("PE machine type 0x%04hx unknown"), ++ pe32->coff_header.machine); ++ } ++ ++ if (is_64_bit) ++ { ++ sz = doshdr->lfanew + sizeof (*pe64); ++ if (k_size < sz) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel is too small")); ++ ++ if (pe64->optional_header.dll_characteristics & GRUB_PE32_NX_COMPAT) ++ image_is_compatible = 1; ++ } ++ else ++ { ++ if (pe32->optional_header.dll_characteristics & GRUB_PE32_NX_COMPAT) ++ image_is_compatible = 1; ++ } ++ ++ *nx_supported = image_is_compatible; ++ return GRUB_ERR_NONE; ++} ++ ++grub_err_t ++grub_efi_check_nx_required (int *nx_required) ++{ ++ grub_efi_status_t status; ++ grub_guid_t guid = GRUB_EFI_SHIM_LOCK_GUID; ++ grub_size_t mok_policy_sz = 0; ++ char *mok_policy = NULL; ++ grub_uint32_t mok_policy_attrs = 0; ++ ++ status = grub_efi_get_variable_with_attributes ("MokPolicy", &guid, ++ &mok_policy_sz, ++ (void **)&mok_policy, ++ &mok_policy_attrs); ++ if (status == GRUB_EFI_NOT_FOUND || ++ mok_policy_sz == 0 || ++ mok_policy == NULL) ++ { ++ *nx_required = 0; ++ return GRUB_ERR_NONE; ++ } ++ ++ *nx_required = 0; ++ if (mok_policy_sz < 1 || ++ mok_policy_attrs != (GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS | ++ GRUB_EFI_VARIABLE_RUNTIME_ACCESS) || ++ (mok_policy[mok_policy_sz-1] & GRUB_MOK_POLICY_NX_REQUIRED)) ++ *nx_required = 1; ++ ++ return GRUB_ERR_NONE; ++} + + typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); + + grub_err_t +-grub_efi_linux_boot (void *kernel_address, grub_off_t ho_offset, +- void *kernel_params) ++grub_efi_linux_boot (grub_addr_t k_address, grub_size_t k_size, ++ grub_off_t h_offset, void *k_params, ++ int nx_supported) + { + grub_efi_loaded_image_t *loaded_image = NULL; + handover_func hf; + int offset = 0; ++ grub_uint64_t stack_set_attrs = GRUB_MEM_ATTR_R | ++ GRUB_MEM_ATTR_W | ++ GRUB_MEM_ATTR_X; ++ grub_uint64_t stack_clear_attrs = 0; ++ grub_uint64_t kernel_set_attrs = stack_set_attrs; ++ grub_uint64_t kernel_clear_attrs = stack_clear_attrs; ++ grub_uint64_t attrs; ++ int nx_required = 0; + + #ifdef __x86_64__ + offset = 512; +@@ -118,14 +229,59 @@ grub_efi_linux_boot (void *kernel_address, grub_off_t ho_offset, + */ + loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (loaded_image) +- loaded_image->image_base = kernel_address; ++ loaded_image->image_base = (void *)k_address; + else + grub_dprintf ("linux", "Loaded Image base address could not be set\n"); + + grub_dprintf ("linux", "kernel_address: %p handover_offset: %p params: %p\n", +- kernel_address, (void *)(grub_efi_uintn_t)ho_offset, kernel_params); +- hf = (handover_func)((char *)kernel_address + ho_offset + offset); +- hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); ++ (void *)k_address, (void *)h_offset, k_params); ++ ++ ++ if (nx_required && !nx_supported) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel does not support NX loading required by policy")); ++ ++ if (nx_supported) ++ { ++ kernel_set_attrs &= ~GRUB_MEM_ATTR_W; ++ kernel_clear_attrs |= GRUB_MEM_ATTR_W; ++ stack_set_attrs &= ~GRUB_MEM_ATTR_X; ++ stack_clear_attrs |= GRUB_MEM_ATTR_X; ++ } ++ ++ grub_dprintf ("nx", "Setting attributes for 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" to r%cx\n", ++ k_address, k_address + k_size - 1, ++ (kernel_set_attrs & GRUB_MEM_ATTR_W) ? 'w' : '-'); ++ grub_update_mem_attrs (k_address, k_size, ++ kernel_set_attrs, kernel_clear_attrs); ++ ++ grub_get_mem_attrs (k_address, 4096, &attrs); ++ grub_dprintf ("nx", "permissions for 0x%"PRIxGRUB_ADDR" are %s%s%s\n", ++ (grub_addr_t)k_address, ++ (attrs & GRUB_MEM_ATTR_R) ? "r" : "-", ++ (attrs & GRUB_MEM_ATTR_W) ? "w" : "-", ++ (attrs & GRUB_MEM_ATTR_X) ? "x" : "-"); ++ if (grub_stack_addr != (grub_addr_t)-1ll) ++ { ++ grub_dprintf ("nx", "Setting attributes for stack at 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" to rw%c\n", ++ grub_stack_addr, grub_stack_addr + grub_stack_size - 1, ++ (stack_set_attrs & GRUB_MEM_ATTR_X) ? 'x' : '-'); ++ grub_update_mem_attrs (grub_stack_addr, grub_stack_size, ++ stack_set_attrs, stack_clear_attrs); ++ ++ grub_get_mem_attrs (grub_stack_addr, 4096, &attrs); ++ grub_dprintf ("nx", "permissions for 0x%"PRIxGRUB_ADDR" are %s%s%s\n", ++ grub_stack_addr, ++ (attrs & GRUB_MEM_ATTR_R) ? "r" : "-", ++ (attrs & GRUB_MEM_ATTR_W) ? "w" : "-", ++ (attrs & GRUB_MEM_ATTR_X) ? "x" : "-"); ++ } ++ ++#if defined(__i386__) || defined(__x86_64__) ++ asm volatile ("cli"); ++#endif ++ ++ hf = (handover_func)((char *)k_address + h_offset + offset); ++ hf (grub_efi_image_handle, grub_efi_system_table, k_params); + + return GRUB_ERR_BUG; + } +@@ -287,13 +443,15 @@ free_params (void) + } + + grub_err_t +-grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args) ++grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args, ++ int nx_supported) + { + grub_err_t retval; + + grub_dprintf ("linux", "linux command line: '%s'\n", args); + +- retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr); ++ retval = grub_efi_linux_boot (addr, size, handover_offset, ++ (void *)addr, nx_supported); + + /* Never reached... */ + free_params(); +@@ -308,7 +466,10 @@ grub_linux_boot (void) + return grub_errno; + #endif + +- return grub_arch_efi_linux_boot_image ((grub_addr_t) kernel_addr, linux_args); ++ return grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, ++ (grub_size_t)kernel_size, ++ linux_args, ++ 0); + } + + static grub_err_t +@@ -560,10 +721,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + struct linux_arch_kernel_header lh; + grub_off_t filelen; + grub_off_t filereadlen; +- grub_uint32_t align; +- grub_uint32_t code_size; + void *kernel = NULL; + grub_err_t err; ++ int nx_supported = 1; + + grub_dl_ref (my_mod); + +@@ -634,6 +794,8 @@ fallback: + + + #if !defined(__i386__) && !defined(__x86_64__) ++ grub_uint32_t align; ++ grub_uint32_t code_size; + if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align, &code_size) != GRUB_ERR_NONE) + goto fail; + grub_dprintf ("linux", "kernel mem size : %lld\n", (long long) kernel_size); +@@ -641,6 +803,10 @@ fallback: + grub_dprintf ("linux", "kernel alignment : 0x%x\n", align); + grub_dprintf ("linux", "kernel size : 0x%x\n", code_size); + ++ err = grub_efi_check_nx_image_support((grub_addr_t)kernel, filelen, &nx_supported); ++ if (err != GRUB_ERR_NONE) ++ goto fail; ++ + grub_loader_unset(); + + kernel_alloc_pages = GRUB_EFI_BYTES_TO_PAGES (kernel_size + align - 1); +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index f97b123a51e..abbf6b24f50 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -44,7 +44,7 @@ struct grub_linuxefi_context { + grub_uint32_t handover_offset; + struct linux_kernel_params *params; + char *cmdline; +- ++ int nx_supported; + void *initrd_mem; + }; + +@@ -134,13 +134,19 @@ kernel_alloc(kernel_alloc_purpose_t purpose, + pages = BYTES_TO_PAGES(size); + grub_dprintf ("linux", "Trying to allocate %lu pages from %p\n", + (unsigned long)pages, (void *)(unsigned long)max); ++ size = pages * GRUB_EFI_PAGE_SIZE; + + prev_max = max; + addr = grub_efi_allocate_pages_real (max, pages, + max_addresses[i].alloc_type, + memtype); + if (addr) +- grub_dprintf ("linux", "Allocated at %p\n", addr); ++ { ++ grub_dprintf ("linux", "Allocated at %p\n", addr); ++ grub_update_mem_attrs ((grub_addr_t)addr, size, ++ GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_W, ++ GRUB_MEM_ATTR_X); ++ } + } + + while (grub_error_pop ()) +@@ -161,9 +167,11 @@ grub_linuxefi_boot (void *data) + + asm volatile ("cli"); + +- return grub_efi_linux_boot ((char *)context->kernel_mem, ++ return grub_efi_linux_boot ((grub_addr_t)context->kernel_mem, ++ context->kernel_size, + context->handover_offset, +- context->params); ++ context->params, ++ context->nx_supported); + } + + static grub_err_t +@@ -331,7 +339,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_uint32_t handover_offset; + struct linux_kernel_params *params = 0; + char *cmdline = 0; ++ int nx_supported = 1; + struct grub_linuxefi_context *context = 0; ++ grub_err_t err; + + grub_dl_ref (my_mod); + +@@ -361,6 +371,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ err = grub_efi_check_nx_image_support ((grub_addr_t)kernel, filelen, ++ &nx_supported); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ grub_dprintf ("linux", "nx is%s supported by this kernel\n", ++ nx_supported ? "" : " not"); ++ + lh = (struct linux_i386_kernel_header *)kernel; + grub_dprintf ("linux", "original lh is at %p\n", kernel); + +@@ -530,6 +547,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + context->handover_offset = handover_offset; + context->params = params; + context->cmdline = cmdline; ++ context->nx_supported = nx_supported; + + grub_loader_set_ex (grub_linuxefi_boot, grub_linuxefi_unload, context, 0); + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 5a257552234..90121e9bc5a 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -817,6 +817,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + kernel_offset += len; + } + ++ grub_dprintf("efi", "setting attributes for %p (%zu bytes) to +rw-x\n", ++ &linux_params, sizeof (lh) + len); ++ grub_update_mem_attrs ((grub_addr_t)&linux_params, sizeof (lh) + len, ++ GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_W, GRUB_MEM_ATTR_X); ++ + linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; + linux_params.kernel_alignment = (1 << align); + linux_params.ps_mouse = linux_params.padding11 = 0; +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index c40684821e1..2c0e7f24bda 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -190,6 +190,9 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, + void * + EXPORT_FUNC (grub_efi_find_configuration_table) (const grub_guid_t *target_guid); + ++extern grub_addr_t EXPORT_VAR(grub_stack_addr); ++extern grub_size_t EXPORT_VAR(grub_stack_size); ++ + #if defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__loongarch__) + void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); + grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); +@@ -197,7 +200,8 @@ grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); + #include + grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file, + struct linux_arch_kernel_header *lh); +-grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); ++grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, ++ char *args, int nx_enabled); + + grub_addr_t grub_efi_section_addr (const char *section); + +diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h +index c806a7757f3..5b4e626c37c 100644 +--- a/include/grub/efi/linux.h ++++ b/include/grub/efi/linux.h +@@ -22,8 +22,20 @@ + #include + #include + ++#define GRUB_MOK_POLICY_NX_REQUIRED 0x1 ++ + grub_err_t +-EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, +- void *kernel_param); ++EXPORT_FUNC(grub_efi_linux_boot) (grub_addr_t kernel_address, ++ grub_size_t kernel_size, ++ grub_off_t handover_offset, ++ void *kernel_param, int nx_enabled); ++ ++grub_err_t ++EXPORT_FUNC(grub_efi_check_nx_image_support) (grub_addr_t kernel_addr, ++ grub_size_t kernel_size, ++ int *nx_supported); ++ ++grub_err_t ++EXPORT_FUNC(grub_efi_check_nx_required) (int *nx_required); + + #endif /* ! GRUB_EFI_LINUX_HEADER */ +diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h +index 13fdd0e7d98..a4d62373cc9 100644 +--- a/include/grub/efi/pe32.h ++++ b/include/grub/efi/pe32.h +@@ -194,6 +194,8 @@ struct grub_pe32_optional_header + struct grub_pe32_data_directory reserved_entry; + }; + ++#define GRUB_PE32_NX_COMPAT 0x0100 ++ + struct grub_pe64_optional_header + { + grub_uint16_t magic; diff --git a/0265-efi-Provide-wrappers-for-load_image-start_image.patch b/0265-efi-Provide-wrappers-for-load_image-start_image.patch new file mode 100644 index 00000000..1ee0f327 --- /dev/null +++ b/0265-efi-Provide-wrappers-for-load_image-start_image.patch @@ -0,0 +1,183 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Julian Andres Klode +Date: Tue, 9 Jul 2024 16:46:05 -0600 +Subject: [PATCH] efi: Provide wrappers for load_image, start_image, + +These can be used to register a different implementation later, +for example, when shim provides a protocol with those functions. + +Signed-off-by: Mate Kukri +--- + grub-core/kern/efi/efi.c | 57 ++++++++++++++++++++++++++++++++++++++ + grub-core/loader/efi/chainloader.c | 13 ++++----- + include/grub/efi/efi.h | 37 +++++++++++++++++++++++++ + 3 files changed, 100 insertions(+), 7 deletions(-) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index cdfc11565c7..b5b8a329622 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -1131,6 +1131,63 @@ grub_efi_find_configuration_table (const grub_guid_t *target_guid) + return 0; + } + ++static const grub_efi_loader_t *override_loader = NULL; ++ ++grub_err_t ++grub_efi_register_loader (const grub_efi_loader_t *loader) ++{ ++ if (override_loader != NULL) ++ return grub_error (GRUB_ERR_BUG, "trying to register different loader"); ++ override_loader = loader; ++ return GRUB_ERR_NONE; ++} ++ ++grub_err_t ++grub_efi_unregister_loader (const grub_efi_loader_t *loader) ++{ ++ if (loader != override_loader) ++ return grub_error (GRUB_ERR_BUG, "trying to unregister different loader"); ++ ++ override_loader = NULL; ++ return GRUB_ERR_NONE; ++} ++ ++grub_efi_status_t ++grub_efi_load_image (grub_efi_boolean_t boot_policy, ++ grub_efi_handle_t parent_image_handle, ++ grub_efi_device_path_t *file_path, void *source_buffer, ++ grub_efi_uintn_t source_size, ++ grub_efi_handle_t *image_handle) ++{ ++ if (override_loader != NULL) ++ return override_loader->load_image (boot_policy, parent_image_handle, ++ file_path, source_buffer, source_size, ++ image_handle); ++ return grub_efi_system_table->boot_services->load_image ( ++ boot_policy, parent_image_handle, file_path, source_buffer, source_size, ++ image_handle); ++} ++ ++grub_efi_status_t ++grub_efi_start_image (grub_efi_handle_t image_handle, ++ grub_efi_uintn_t *exit_data_size, ++ grub_efi_char16_t **exit_data) ++{ ++ if (override_loader != NULL) ++ return override_loader->start_image (image_handle, exit_data_size, ++ exit_data); ++ return grub_efi_system_table->boot_services->start_image ( ++ image_handle, exit_data_size, exit_data); ++} ++ ++grub_efi_status_t ++grub_efi_unload_image (grub_efi_handle_t image_handle) ++{ ++ if (override_loader != NULL) ++ return override_loader->unload_image (image_handle); ++ return grub_efi_system_table->boot_services->unload_image (image_handle); ++} ++ + grub_err_t + grub_efi_status_to_err (grub_efi_status_t status) + { +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 5cd6f6a5993..9b1cc3fd41d 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -69,7 +69,7 @@ grub_start_image (grub_efi_handle_t handle) + + b = grub_efi_system_table->boot_services; + +- status = b->start_image (handle, &exit_data_size, &exit_data); ++ status = grub_efi_start_image (handle, &exit_data_size, &exit_data); + if (status != GRUB_EFI_SUCCESS) + { + if (exit_data) +@@ -101,7 +101,6 @@ grub_chainloader_unload (void *context) + { + grub_efi_handle_t image_handle; + grub_efi_loaded_image_t *loaded_image; +- grub_efi_boot_services_t *b; + + image_handle = (grub_efi_handle_t) context; + +@@ -109,8 +108,7 @@ grub_chainloader_unload (void *context) + if (loaded_image != NULL) + grub_free (loaded_image->load_options); + +- b = grub_efi_system_table->boot_services; +- b->unload_image (image_handle); ++ grub_efi_unload_image (image_handle); + + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; +@@ -871,8 +869,8 @@ grub_load_image(grub_efi_device_path_t *file_path, void *boot_image, + + b = grub_efi_system_table->boot_services; + +- status = b->load_image (0, grub_efi_image_handle, file_path, +- boot_image, image_size, image_handle_out); ++ status = grub_efi_load_image (0, grub_efi_image_handle, file_path, ++ boot_image, image_size, image_handle_out); + if (status != GRUB_EFI_SUCCESS) + { + if (status == GRUB_EFI_OUT_OF_RESOURCES) +@@ -1198,7 +1196,8 @@ fail: + if (cmdline) + grub_free (cmdline); + +- b->unload_image (image_handle); ++ if (image_handle != NULL) ++ grub_efi_unload_image (image_handle); + + grub_dl_unref (my_mod); + +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 2c0e7f24bda..7eed1bd791d 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -202,6 +202,43 @@ grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file, + struct linux_arch_kernel_header *lh); + grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, + char *args, int nx_enabled); ++grub_efi_status_t ++EXPORT_FUNC (grub_efi_load_image) (grub_efi_boolean_t boot_policy, ++ grub_efi_handle_t parent_image_handle, ++ grub_efi_device_path_t *file_path, ++ void *source_buffer, grub_efi_uintn_t source_size, ++ grub_efi_handle_t *image_handle); ++ ++grub_efi_status_t ++EXPORT_FUNC (grub_efi_start_image) (grub_efi_handle_t image_handle, ++ grub_efi_uintn_t *exit_data_size, ++ grub_efi_char16_t **exit_data); ++ ++grub_efi_status_t ++EXPORT_FUNC (grub_efi_unload_image) (grub_efi_handle_t image_handle); ++ ++typedef struct grub_efi_loader ++{ ++ grub_efi_status_t (__grub_efi_api *load_image) (grub_efi_boolean_t boot_policy, ++ grub_efi_handle_t parent_image_handle, ++ grub_efi_device_path_t *file_path, ++ void *source_buffer, ++ grub_efi_uintn_t source_size, ++ grub_efi_handle_t *image_handle); ++ ++ grub_efi_status_t (__grub_efi_api *start_image) (grub_efi_handle_t image_handle, ++ grub_efi_uintn_t *exit_data_size, ++ grub_efi_char16_t **exit_data); ++ ++ grub_efi_status_t (__grub_efi_api *unload_image) (grub_efi_handle_t image_handle); ++} grub_efi_loader_t; ++ ++grub_err_t ++EXPORT_FUNC (grub_efi_register_loader) (const grub_efi_loader_t *loader); ++ ++grub_err_t ++EXPORT_FUNC (grub_efi_unregister_loader) (const grub_efi_loader_t *loader); ++ + + grub_addr_t grub_efi_section_addr (const char *section); + diff --git a/0266-efi-Disallow-fallback-to-legacy-Linux-loader-when-sh.patch b/0266-efi-Disallow-fallback-to-legacy-Linux-loader-when-sh.patch new file mode 100644 index 00000000..9b9104f0 --- /dev/null +++ b/0266-efi-Disallow-fallback-to-legacy-Linux-loader-when-sh.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Mate Kukri +Date: Wed, 10 Jul 2024 12:07:17 -0600 +Subject: [PATCH] efi: Disallow fallback to legacy Linux loader when shim says + NX is required. + +Signed-off-by: Mate Kukri +--- + grub-core/loader/efi/linux.c | 13 ++++++++----- + include/grub/efi/api.h | 2 ++ + 2 files changed, 10 insertions(+), 5 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index da5dcafad8b..21aad881ba0 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -724,6 +724,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + void *kernel = NULL; + grub_err_t err; + int nx_supported = 1; ++ int nx_required = 0; + + grub_dl_ref (my_mod); + +@@ -756,21 +757,23 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++#if !defined(__i386__) && !defined(__x86_64__) + if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE) +-#if !defined(__i386__) && !defined(__x86_64__) + goto fail; + #else +- goto fallback; +- +- if (!initrd_use_loadfile2) ++ if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE || ++ !initrd_use_loadfile2) + { ++ /* We cannot use the legacy loader when NX is required */ ++ if (grub_efi_check_nx_required(&nx_required)) ++ goto fail; ++ + /* + * This is a EFI stub image but it is too old to implement the LoadFile2 + * based initrd loading scheme, and Linux/x86 does not support the DT + * based method either. So fall back to the x86-specific loader that + * enters Linux in EFI mode but without going through its EFI stub. + */ +-fallback: + grub_file_close (file); + return grub_cmd_linux_x86_legacy (cmd, argc, argv); + } +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index da51f57fd4a..637b1272d17 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -2011,6 +2011,8 @@ struct grub_efi_block_io + }; + typedef struct grub_efi_block_io grub_efi_block_io_t; + ++#define GRUB_MOK_POLICY_NX_REQUIRED 0x1 ++ + struct grub_efi_shim_lock_protocol + { + /* diff --git a/0267-Set-non-executable-stack-sections-on-EFI-assembly-fi.patch b/0267-Set-non-executable-stack-sections-on-EFI-assembly-fi.patch new file mode 100644 index 00000000..2f249143 --- /dev/null +++ b/0267-Set-non-executable-stack-sections-on-EFI-assembly-fi.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Mon, 5 Aug 2024 13:19:28 -0600 +Subject: [PATCH] Set non-executable stack sections on EFI assembly files + +For those manual assembly files created where no '.note.GNU-stack' +section is explicitly added, linker defaults it as executable and this +is the reason that RHEL CI rpminspect & annocheck tests are +failing. The proposed change sets the corresponding GNU-stack +sections otherwise CI detects the following security vulnerability + + $ annocheck annocheck --ignore-unknown --verbose --profile=el9 *.rpm 2>&1 | grep FAIL | grep stack + (standard input):(standard input):Hardened: ./usr/lib/grub/x86_64-efi/kernel.exec: FAIL: gnu-stack test because .note.GNU-stack section has execute permission + (standard input):(standard input):Hardened: ./usr/lib/grub/x86_64-efi/kernel.img: FAIL: gnu-stack test because .note.GNU-stack section has execute permission + +Signed-off-by: Leo Sandoval +--- + grub-core/kern/i386/efi/startup.S | 5 +++++ + grub-core/kern/x86_64/efi/startup.S | 5 +++++ + 2 files changed, 10 insertions(+) + +diff --git a/grub-core/kern/i386/efi/startup.S b/grub-core/kern/i386/efi/startup.S +index fc5ea3dac..36d1b1a68 100644 +--- a/grub-core/kern/i386/efi/startup.S ++++ b/grub-core/kern/i386/efi/startup.S +@@ -34,3 +34,8 @@ _start: + movl %eax, EXT_C(grub_efi_system_table) + call EXT_C(grub_main) + ret ++ ++/* An executable stack is not required for these functions. */ ++#if defined (__linux__) && defined (__ELF__) ++.section .note.GNU-stack,"",%progbits ++#endif +diff --git a/grub-core/kern/x86_64/efi/startup.S b/grub-core/kern/x86_64/efi/startup.S +index 9357e5c5d..f5c6bc3d8 100644 +--- a/grub-core/kern/x86_64/efi/startup.S ++++ b/grub-core/kern/x86_64/efi/startup.S +@@ -33,3 +33,8 @@ _start: + andq $~0xf, %rsp + call EXT_C(grub_main) + /* Doesn't return. */ ++ ++/* An executable stack is not required for these functions. */ ++#if defined (__linux__) && defined (__ELF__) ++.section .note.GNU-stack,"",%progbits ++#endif diff --git a/0268-grub-mkconfig.in-turn-off-executable-owner-bit.patch b/0268-grub-mkconfig.in-turn-off-executable-owner-bit.patch new file mode 100644 index 00000000..e7dd610c --- /dev/null +++ b/0268-grub-mkconfig.in-turn-off-executable-owner-bit.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Mon, 6 May 2024 15:35:41 -0600 +Subject: [PATCH] grub-mkconfig.in: turn off executable owner bit + +Stricker permissions are required on the grub.cfg file, resulting in +at most 0600 owner's file permissions. This resolves conflicting +requirement permissions on grub2-pc package's grub2.cfg file. + +Signed-off-by: Leo Sandoval +--- + util/grub-mkconfig.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index bec52e052..461df7f09 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -316,7 +316,7 @@ and /etc/grub.d/* files or please file a bug report with + else + # none of the children aborted with error, install the new grub.cfg + oldumask=$(umask) +- umask 077 ++ umask 177 + cat ${grub_cfg}.new > ${grub_cfg} + umask $oldumask + rm -f ${grub_cfg}.new diff --git a/0269-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch b/0269-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch new file mode 100644 index 00000000..619ff06b --- /dev/null +++ b/0269-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch @@ -0,0 +1,119 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Avnish Chouhan +Date: Thu, 23 May 2024 18:43:14 +0530 +Subject: [PATCH] kern/ieee1275/init: Add IEEE 1275 Radix support for KVM on + Power + +This patch adds support for Radix, Xive and Radix_gtse in Options +vector5 which is required for KVM LPARs. KVM LPARs ONLY support +Radix and not the Hash. Not enabling Radix on any PowerVM KVM LPARs +will result in boot failure. + +Signed-off-by: Avnish Chouhan +Reviewed-by: Daniel Kiper +--- + grub-core/kern/ieee1275/init.c | 63 +++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 62 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 13e8a5b4b..6c5f4fb77 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -113,6 +113,16 @@ grub_addr_t grub_ieee1275_original_stack; + #define DRC_INFO 0x40 + #define BYTE22 (DY_MEM_V2 | DRC_INFO) + ++/* For ibm,arch-vec-5-platform-support. */ ++#define XIVE_INDEX 0x17 ++#define MMU_INDEX 0x18 ++#define RADIX_GTSE_INDEX 0x1a ++#define RADIX_ENABLED 0x40 ++#define XIVE_ENABLED 0x40 ++#define HASH_ENABLED 0x00 ++#define MAX_SUPPORTED 0xC0 ++#define RADIX_GTSE_ENABLED 0x40 ++ + void + grub_exit (int rc __attribute__((unused))) + { +@@ -739,6 +749,10 @@ struct option_vector5 + grub_uint32_t platform_facilities; + grub_uint8_t sub_processors; + grub_uint8_t byte22; ++ grub_uint8_t xive; ++ grub_uint8_t mmu; ++ grub_uint8_t hpt_ext; ++ grub_uint8_t radix_gtse; + } GRUB_PACKED; + + struct pvr_entry +@@ -777,6 +791,13 @@ grub_ieee1275_ibm_cas (void) + { + int rc; + grub_ieee1275_ihandle_t root; ++ grub_uint8_t ibm_arch_platform_support[8]; ++ grub_ssize_t actual; ++ grub_uint8_t xive_support = 0; ++ grub_uint8_t mmu_support = 0; ++ grub_uint8_t radix_gtse_support = 0; ++ int i = 0; ++ int prop_len = 8; + struct cas_args + { + struct grub_ieee1275_common_hdr common; +@@ -785,6 +806,46 @@ grub_ieee1275_ibm_cas (void) + grub_ieee1275_cell_t cas_addr; + grub_ieee1275_cell_t result; + } args; ++ ++ grub_ieee1275_get_integer_property (grub_ieee1275_chosen, ++ "ibm,arch-vec-5-platform-support", ++ (grub_uint32_t *) ibm_arch_platform_support, ++ sizeof (ibm_arch_platform_support), ++ &actual); ++ ++ for (i = 0; i < prop_len; i++) ++ { ++ switch (ibm_arch_platform_support[i]) ++ { ++ case XIVE_INDEX: ++ if (ibm_arch_platform_support[i + 1] & MAX_SUPPORTED) ++ xive_support = XIVE_ENABLED; ++ else ++ xive_support = 0; ++ break; ++ ++ case MMU_INDEX: ++ if (ibm_arch_platform_support[i + 1] & MAX_SUPPORTED) ++ mmu_support = RADIX_ENABLED; ++ else ++ mmu_support = HASH_ENABLED; ++ break; ++ ++ case RADIX_GTSE_INDEX: ++ if (mmu_support == RADIX_ENABLED) ++ radix_gtse_support = ibm_arch_platform_support[i + 1] & RADIX_GTSE_ENABLED; ++ else ++ radix_gtse_support = 0; ++ break; ++ ++ default: ++ /* Ignoring the other indexes of ibm,arch-vec-5-platform-support. */ ++ break; ++ } ++ /* Skipping the property value. */ ++ i++; ++ } ++ + struct cas_vector vector = + { + .pvr_list = { { 0x00000000, 0xffffffff } }, /* any processor */ +@@ -801,7 +862,7 @@ grub_ieee1275_ibm_cas (void) + .vec4 = 0x0001, /* set required minimum capacity % to the lowest value */ + .vec5_size = 1 + sizeof (struct option_vector5) - 2, + .vec5 = { +- 0, BYTE2, 0, CMO, ASSOCIATIVITY, BIN_OPTS, 0, 0, MAX_CPU, 0, 0, PLATFORM_FACILITIES, SUB_PROCESSORS, BYTE22 ++ 0, BYTE2, 0, CMO, ASSOCIATIVITY, BIN_OPTS, 0, 0, MAX_CPU, 0, 0, PLATFORM_FACILITIES, SUB_PROCESSORS, BYTE22, xive_support, mmu_support, 0, radix_gtse_support + } + }; + diff --git a/0270-grub2-mkconfig-Ensure-grub-cfg-stub-is-not-overwritt.patch b/0270-grub2-mkconfig-Ensure-grub-cfg-stub-is-not-overwritt.patch new file mode 100644 index 00000000..60f36bce --- /dev/null +++ b/0270-grub2-mkconfig-Ensure-grub-cfg-stub-is-not-overwritt.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Tue, 16 Jul 2024 11:11:43 +0200 +Subject: [PATCH] grub2-mkconfig: Ensure grub cfg stub is not overwritten + +/boot/efi/EFI/$os_name/grub.cfg contains a grub cfg stub +that should not be overwritten by grub2-mkconfig. +Ensure that we prevent this from happening. + +Signed-off-by: Marta Lewandowska +Signed-off-by: Nicolas Frayer +--- + util/grub-mkconfig.in | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 461df7f09..b560aae6c 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -109,6 +109,20 @@ do + esac + done + ++os_name=$(grep '^ID=' /etc/os-release | sed 's/ID=//') ++if test "$os_name" = '"rhel"'; then ++ os_name=redhat ++elif test "$os_name" = '"centos"'; then ++ os_name=centos ++fi ++if test "x${grub_cfg}" = "x/boot/efi/EFI/$os_name/grub.cfg" &&\ ++ mountpoint -q /boot/efi; then ++ gettext_printf "Running \`grub2-mkconfig -o %s' will overwrite the GRUB wrapper.\n" "$grub_cfg" 1>&2 ++ gettext_printf "Please run \`grub2-mkconfig -o /boot/grub2/grub.cfg' instead to update grub.cfg.\n" 1>&2 ++ gettext_printf "GRUB configuration file was not updated.\n" 1>&2 ++ exit 1 ++fi ++ + if [ "x$EUID" = "x" ] ; then + EUID=`id -u` + fi diff --git a/0271-grub2-mkconfig-Simplify-os_name-detection.patch b/0271-grub2-mkconfig-Simplify-os_name-detection.patch new file mode 100644 index 00000000..bd7ba1b4 --- /dev/null +++ b/0271-grub2-mkconfig-Simplify-os_name-detection.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrew Lukoshko +Date: Wed, 31 Jul 2024 16:06:10 +0000 +Subject: [PATCH] grub2-mkconfig: Simplify os_name detection + +--- + util/grub-mkconfig.in | 7 +------ + 1 file changed, 1 insertion(+), 6 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index efa36cc45a69..8b7883072e46 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -109,12 +109,7 @@ do + esac + done + +-os_name=$(grep '^ID=' /etc/os-release | sed 's/ID=//') +-if test "$os_name" = '"rhel"'; then +- os_name=redhat +-elif test "$os_name" = '"centos"'; then +- os_name=centos +-fi ++os_name=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g') + if test "x${grub_cfg}" = "x/boot/efi/EFI/$os_name/grub.cfg" &&\ + mountpoint -q /boot/efi; then + gettext_printf "Running \`grub2-mkconfig -o %s' will overwrite the GRUB wrapper.\n" "$grub_cfg" 1>&2 diff --git a/0272-grub-mkconfig-Remove-check-for-mount-point-for-grub-.patch b/0272-grub-mkconfig-Remove-check-for-mount-point-for-grub-.patch new file mode 100644 index 00000000..fc3ec414 --- /dev/null +++ b/0272-grub-mkconfig-Remove-check-for-mount-point-for-grub-.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Thu, 1 Aug 2024 11:13:20 +0200 +Subject: [PATCH] grub/mkconfig: Remove check for mount point for grub cfg stub + +Remove mountpoint when checking whether or not the grub cfg stub +exists and add -s to the test. This should cover scenarios where +the ESP doesn't have a seperate partition but still uses a grub +cfg stub + +Signed-off-by: Nicolas Frayer +--- + util/grub-mkconfig.in | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 8b7883072e46..31a72a39e0cf 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -110,8 +110,7 @@ do + done + + os_name=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g') +-if test "x${grub_cfg}" = "x/boot/efi/EFI/$os_name/grub.cfg" &&\ +- mountpoint -q /boot/efi; then ++if test -s "${grub_cfg}" && test "x${grub_cfg}" = "x/boot/efi/EFI/$os_name/grub.cfg"; then + gettext_printf "Running \`grub2-mkconfig -o %s' will overwrite the GRUB wrapper.\n" "$grub_cfg" 1>&2 + gettext_printf "Please run \`grub2-mkconfig -o /boot/grub2/grub.cfg' instead to update grub.cfg.\n" 1>&2 + gettext_printf "GRUB configuration file was not updated.\n" 1>&2 diff --git a/0273-efi-api.h-include-missing-__grub_efi_api-macros-on-E.patch b/0273-efi-api.h-include-missing-__grub_efi_api-macros-on-E.patch new file mode 100644 index 00000000..61ffbdcd --- /dev/null +++ b/0273-efi-api.h-include-missing-__grub_efi_api-macros-on-E.patch @@ -0,0 +1,495 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 29 Aug 2024 12:11:11 -0600 +Subject: [PATCH] efi/api.h: include missing __grub_efi_api macros on EFI + functions + +Signed-off-by: Peter Jones +Signed-off-by: Leo Sandoval +--- + grub-core/loader/efi/chainloader.c | 2 +- + include/grub/efi/api.h | 34 +++++++++++++------------- + include/grub/efi/dhcp.h | 42 ++++++++++++++++---------------- + include/grub/efi/edid.h | 2 +- + include/grub/efi/http.h | 12 ++++----- + include/grub/efi/pci.h | 50 +++++++++++++++++++------------------- + 6 files changed, 71 insertions(+), 71 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 5cd6f6a59..460a44041 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -555,7 +555,7 @@ handle_image (struct grub_secureboot_chainloader_context *load_context) + grub_uint32_t buffer_size; + int found_entry_point = 0; + int rc; +- grub_efi_status_t (*entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); ++ grub_efi_status_t (__grub_efi_api *entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); + + b = grub_efi_system_table->boot_services; + +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 2376182d7..5047ecf28 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -1094,11 +1094,11 @@ typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t; + struct grub_efi_service_binding; + + typedef grub_efi_status_t +-(*grub_efi_service_binding_create_child) (struct grub_efi_service_binding *this, ++(__grub_efi_api *grub_efi_service_binding_create_child) (struct grub_efi_service_binding *this, + grub_efi_handle_t *child_handle); + + typedef grub_efi_status_t +-(*grub_efi_service_binding_destroy_child) (struct grub_efi_service_binding *this, ++(__grub_efi_api *grub_efi_service_binding_destroy_child) (struct grub_efi_service_binding *this, + grub_efi_handle_t *child_handle); + + typedef struct grub_efi_service_binding +@@ -1754,12 +1754,12 @@ typedef struct grub_efi_pxe_mode + typedef struct grub_efi_pxe + { + grub_uint64_t rev; +- grub_efi_status_t (*start) (struct grub_efi_pxe *this, grub_efi_boolean_t use_ipv6); ++ grub_efi_status_t (__grub_efi_api *start) (struct grub_efi_pxe *this, grub_efi_boolean_t use_ipv6); + void (*stop) (void); +- grub_efi_status_t (*dhcp) (struct grub_efi_pxe *this, ++ grub_efi_status_t (__grub_efi_api *dhcp) (struct grub_efi_pxe *this, + grub_efi_boolean_t sort_offers); + void (*discover) (void); +- grub_efi_status_t (*mtftp) (struct grub_efi_pxe *this, ++ grub_efi_status_t (__grub_efi_api *mtftp) (struct grub_efi_pxe *this, + grub_efi_pxe_base_code_tftp_opcode_t operation, + void *buffer_ptr, + grub_efi_boolean_t overwrite, +@@ -1775,7 +1775,7 @@ typedef struct grub_efi_pxe + void (*setipfilter) (void); + void (*arp) (void); + void (*setparams) (void); +- grub_efi_status_t (*set_station_ip) (struct grub_efi_pxe *this, ++ grub_efi_status_t (__grub_efi_api *set_station_ip) (struct grub_efi_pxe *this, + grub_efi_pxe_ip_address_t *new_station_ip, + grub_efi_pxe_ip_address_t *new_subnet_mask); + void (*setpackets) (void); +@@ -2054,21 +2054,21 @@ typedef enum grub_efi_ip4_config2_data_type grub_efi_ip4_config2_data_type_t; + + struct grub_efi_ip4_config2_protocol + { +- grub_efi_status_t (*set_data) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_status_t (__grub_efi_api *set_data) (struct grub_efi_ip4_config2_protocol *this, + grub_efi_ip4_config2_data_type_t data_type, + grub_efi_uintn_t data_size, + void *data); + +- grub_efi_status_t (*get_data) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_status_t (__grub_efi_api *get_data) (struct grub_efi_ip4_config2_protocol *this, + grub_efi_ip4_config2_data_type_t data_type, + grub_efi_uintn_t *data_size, + void *data); + +- grub_efi_status_t (*register_data_notify) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_status_t (__grub_efi_api *register_data_notify) (struct grub_efi_ip4_config2_protocol *this, + grub_efi_ip4_config2_data_type_t data_type, + grub_efi_event_t event); + +- grub_efi_status_t (*unregister_datanotify) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_status_t (__grub_efi_api *unregister_datanotify) (struct grub_efi_ip4_config2_protocol *this, + grub_efi_ip4_config2_data_type_t data_type, + grub_efi_event_t event); + }; +@@ -2126,21 +2126,21 @@ typedef enum grub_efi_ip6_config_data_type grub_efi_ip6_config_data_type_t; + + struct grub_efi_ip6_config_protocol + { +- grub_efi_status_t (*set_data) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_status_t (__grub_efi_api *set_data) (struct grub_efi_ip6_config_protocol *this, + grub_efi_ip6_config_data_type_t data_type, + grub_efi_uintn_t data_size, + void *data); + +- grub_efi_status_t (*get_data) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_status_t (__grub_efi_api *get_data) (struct grub_efi_ip6_config_protocol *this, + grub_efi_ip6_config_data_type_t data_type, + grub_efi_uintn_t *data_size, + void *data); + +- grub_efi_status_t (*register_data_notify) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_status_t (__grub_efi_api *register_data_notify) (struct grub_efi_ip6_config_protocol *this, + grub_efi_ip6_config_data_type_t data_type, + grub_efi_event_t event); + +- grub_efi_status_t (*unregister_datanotify) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_status_t (__grub_efi_api *unregister_datanotify) (struct grub_efi_ip6_config_protocol *this, + grub_efi_ip6_config_data_type_t data_type, + grub_efi_event_t event); + }; +@@ -2191,17 +2191,17 @@ typedef struct grub_efi_ip6_config_manual_address grub_efi_ip6_config_manual_add + + struct grub_efi_memory_attribute_protocol + { +- grub_efi_status_t (*get_memory_attributes) ( ++ grub_efi_status_t (__grub_efi_api *get_memory_attributes) ( + struct grub_efi_memory_attribute_protocol *this, + grub_efi_physical_address_t base_address, + grub_efi_uint64_t length, + grub_efi_uint64_t *attributes); +- grub_efi_status_t (*set_memory_attributes) ( ++ grub_efi_status_t (__grub_efi_api *set_memory_attributes) ( + struct grub_efi_memory_attribute_protocol *this, + grub_efi_physical_address_t base_address, + grub_efi_uint64_t length, + grub_efi_uint64_t attributes); +- grub_efi_status_t (*clear_memory_attributes) ( ++ grub_efi_status_t (__grub_efi_api *clear_memory_attributes) ( + struct grub_efi_memory_attribute_protocol *this, + grub_efi_physical_address_t base_address, + grub_efi_uint64_t length, +diff --git a/include/grub/efi/dhcp.h b/include/grub/efi/dhcp.h +index fdb88eb81..d996716e4 100644 +--- a/include/grub/efi/dhcp.h ++++ b/include/grub/efi/dhcp.h +@@ -123,7 +123,7 @@ struct grub_efi_dhcp4_config_data { + grub_efi_uint32_t request_try_count; + grub_efi_uint32_t *request_timeout; + grub_efi_ipv4_address_t client_address; +- grub_efi_status_t (*dhcp4_callback) ( ++ grub_efi_status_t (__grub_efi_api *dhcp4_callback) ( + grub_efi_dhcp4_protocol_t *this, + void *context, + grub_efi_dhcp4_state_t current_state, +@@ -153,27 +153,27 @@ struct grub_efi_dhcp4_mode_data { + typedef struct grub_efi_dhcp4_mode_data grub_efi_dhcp4_mode_data_t; + + struct grub_efi_dhcp4_protocol { +- grub_efi_status_t (*get_mode_data) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *get_mode_data) (grub_efi_dhcp4_protocol_t *this, + grub_efi_dhcp4_mode_data_t *dhcp4_mode_data); +- grub_efi_status_t (*configure) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *configure) (grub_efi_dhcp4_protocol_t *this, + grub_efi_dhcp4_config_data_t *dhcp4_cfg_data); +- grub_efi_status_t (*start) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *start) (grub_efi_dhcp4_protocol_t *this, + grub_efi_event_t completion_event); +- grub_efi_status_t (*renew_rebind) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *renew_rebind) (grub_efi_dhcp4_protocol_t *this, + grub_efi_boolean_t rebind_request, + grub_efi_event_t completion_event); +- grub_efi_status_t (*release) (grub_efi_dhcp4_protocol_t *this); +- grub_efi_status_t (*stop) (grub_efi_dhcp4_protocol_t *this); +- grub_efi_status_t (*build) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *release) (grub_efi_dhcp4_protocol_t *this); ++ grub_efi_status_t (__grub_efi_api *stop) (grub_efi_dhcp4_protocol_t *this); ++ grub_efi_status_t (__grub_efi_api *build) (grub_efi_dhcp4_protocol_t *this, + grub_efi_dhcp4_packet_t *seed_packet, + grub_efi_uint32_t delete_count, + grub_efi_uint8_t *delete_list, + grub_efi_uint32_t append_count, + grub_efi_dhcp4_packet_option_t *append_list[], + grub_efi_dhcp4_packet_t **new_packet); +- grub_efi_status_t (*transmit_receive) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *transmit_receive) (grub_efi_dhcp4_protocol_t *this, + grub_efi_dhcp4_transmit_receive_token_t *token); +- grub_efi_status_t (*parse) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *parse) (grub_efi_dhcp4_protocol_t *this, + grub_efi_dhcp4_packet_t *packet, + grub_efi_uint32_t *option_count, + grub_efi_dhcp4_packet_option_t *packet_option_list[]); +@@ -289,7 +289,7 @@ struct grub_efi_dhcp6_mode_data { + typedef struct grub_efi_dhcp6_mode_data grub_efi_dhcp6_mode_data_t; + + struct grub_efi_dhcp6_config_data { +- grub_efi_status_t (*dhcp6_callback) (grub_efi_dhcp6_protocol_t this, ++ grub_efi_status_t (__grub_efi_api *dhcp6_callback) (grub_efi_dhcp6_protocol_t this, + void *context, + grub_efi_dhcp6_state_t current_state, + grub_efi_dhcp6_event_t dhcp6_event, +@@ -308,33 +308,33 @@ struct grub_efi_dhcp6_config_data { + typedef struct grub_efi_dhcp6_config_data grub_efi_dhcp6_config_data_t; + + struct grub_efi_dhcp6_protocol { +- grub_efi_status_t (*get_mode_data) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *get_mode_data) (grub_efi_dhcp6_protocol_t *this, + grub_efi_dhcp6_mode_data_t *dhcp6_mode_data, + grub_efi_dhcp6_config_data_t *dhcp6_config_data); +- grub_efi_status_t (*configure) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *configure) (grub_efi_dhcp6_protocol_t *this, + grub_efi_dhcp6_config_data_t *dhcp6_cfg_data); +- grub_efi_status_t (*start) (grub_efi_dhcp6_protocol_t *this); +- grub_efi_status_t (*info_request) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *start) (grub_efi_dhcp6_protocol_t *this); ++ grub_efi_status_t (__grub_efi_api *info_request) (grub_efi_dhcp6_protocol_t *this, + grub_efi_boolean_t send_client_id, + grub_efi_dhcp6_packet_option_t *option_request, + grub_efi_uint32_t option_count, + grub_efi_dhcp6_packet_option_t *option_list[], + grub_efi_dhcp6_retransmission_t *retransmission, + grub_efi_event_t timeout_event, +- grub_efi_status_t (*reply_callback) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *reply_callback) (grub_efi_dhcp6_protocol_t *this, + void *context, + grub_efi_dhcp6_packet_t *packet), + void *callback_context); +- grub_efi_status_t (*renew_rebind) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *renew_rebind) (grub_efi_dhcp6_protocol_t *this, + grub_efi_boolean_t rebind_request); +- grub_efi_status_t (*decline) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *decline) (grub_efi_dhcp6_protocol_t *this, + grub_efi_uint32_t address_count, + grub_efi_ipv6_address_t *addresses); +- grub_efi_status_t (*release) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *release) (grub_efi_dhcp6_protocol_t *this, + grub_efi_uint32_t address_count, + grub_efi_ipv6_address_t *addresses); +- grub_efi_status_t (*stop) (grub_efi_dhcp6_protocol_t *this); +- grub_efi_status_t (*parse) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_status_t (__grub_efi_api *stop) (grub_efi_dhcp6_protocol_t *this); ++ grub_efi_status_t (__grub_efi_api *parse) (grub_efi_dhcp6_protocol_t *this, + grub_efi_dhcp6_packet_t *packet, + grub_efi_uint32_t *option_count, + grub_efi_dhcp6_packet_option_t *packet_option_list[]); +diff --git a/include/grub/efi/edid.h b/include/grub/efi/edid.h +index 43c0c4372..ac1b8e2fd 100644 +--- a/include/grub/efi/edid.h ++++ b/include/grub/efi/edid.h +@@ -33,7 +33,7 @@ + struct grub_efi_edid_override; + + typedef grub_efi_status_t +-(*grub_efi_edid_override_get_edid) (struct grub_efi_edid_override *this, ++(__grub_efi_api *grub_efi_edid_override_get_edid) (struct grub_efi_edid_override *this, + grub_efi_handle_t *childhandle, + grub_efi_uint32_t *attributes, + grub_efi_uintn_t *edidsize, +diff --git a/include/grub/efi/http.h b/include/grub/efi/http.h +index ad164ba19..242d001b6 100644 +--- a/include/grub/efi/http.h ++++ b/include/grub/efi/http.h +@@ -188,27 +188,27 @@ typedef struct { + + struct grub_efi_http { + grub_efi_status_t +- (*get_mode_data) (struct grub_efi_http *this, ++ (__grub_efi_api *get_mode_data) (struct grub_efi_http *this, + grub_efi_http_config_data_t *http_config_data); + + grub_efi_status_t +- (*configure) (struct grub_efi_http *this, ++ (__grub_efi_api *configure) (struct grub_efi_http *this, + grub_efi_http_config_data_t *http_config_data); + + grub_efi_status_t +- (*request) (struct grub_efi_http *this, ++ (__grub_efi_api *request) (struct grub_efi_http *this, + grub_efi_http_token_t *token); + + grub_efi_status_t +- (*cancel) (struct grub_efi_http *this, ++ (__grub_efi_api *cancel) (struct grub_efi_http *this, + grub_efi_http_token_t *token); + + grub_efi_status_t +- (*response) (struct grub_efi_http *this, ++ (__grub_efi_api *response) (struct grub_efi_http *this, + grub_efi_http_token_t *token); + + grub_efi_status_t +- (*poll) (struct grub_efi_http *this); ++ (__grub_efi_api *poll) (struct grub_efi_http *this); + }; + typedef struct grub_efi_http grub_efi_http_t; + +diff --git a/include/grub/efi/pci.h b/include/grub/efi/pci.h +index b17245549..a90f61042 100644 +--- a/include/grub/efi/pci.h ++++ b/include/grub/efi/pci.h +@@ -48,7 +48,7 @@ typedef enum + struct grub_efi_pci_io; + + typedef grub_efi_status_t +-(*grub_efi_pci_io_mem_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_mem_t) (struct grub_efi_pci_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint8_t bar_index, + grub_efi_uint64_t offset, +@@ -56,7 +56,7 @@ typedef grub_efi_status_t + void *buffer); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_config_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_config_t) (struct grub_efi_pci_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint32_t offset, + grub_efi_uintn_t count, +@@ -113,7 +113,7 @@ typedef enum + grub_efi_pci_io_attribute_operation_t; + + typedef grub_efi_status_t +-(*grub_efi_pci_io_poll_io_mem_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_poll_io_mem_t) (struct grub_efi_pci_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint8_t bar_ndex, + grub_efi_uint64_t offset, +@@ -123,7 +123,7 @@ typedef grub_efi_status_t + grub_efi_uint64_t *result); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_copy_mem_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_copy_mem_t) (struct grub_efi_pci_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint8_t dest_bar_index, + grub_efi_uint64_t dest_offset, +@@ -132,7 +132,7 @@ typedef grub_efi_status_t + grub_efi_uintn_t count); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_map_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_map_t) (struct grub_efi_pci_io *this, + grub_efi_pci_io_operation_t operation, + void *host_address, + grub_efi_uintn_t *number_of_bytes, +@@ -140,11 +140,11 @@ typedef grub_efi_status_t + void **mapping); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_unmap_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_unmap_t) (struct grub_efi_pci_io *this, + void *mapping); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_allocate_buffer_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_allocate_buffer_t) (struct grub_efi_pci_io *this, + grub_efi_allocate_type_t type, + grub_efi_memory_type_t memory_type, + grub_efi_uintn_t pages, +@@ -152,7 +152,7 @@ typedef grub_efi_status_t + grub_efi_uint64_t attributes); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_free_buffer_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_free_buffer_t) (struct grub_efi_pci_io *this, + grub_efi_allocate_type_t type, + grub_efi_memory_type_t memory_type, + grub_efi_uintn_t pages, +@@ -160,29 +160,29 @@ typedef grub_efi_status_t + grub_efi_uint64_t attributes); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_flush_t) (struct grub_efi_pci_io *this); ++(__grub_efi_api *grub_efi_pci_io_flush_t) (struct grub_efi_pci_io *this); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_get_location_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_get_location_t) (struct grub_efi_pci_io *this, + grub_efi_uintn_t *segment_number, + grub_efi_uintn_t *bus_number, + grub_efi_uintn_t *device_number, + grub_efi_uintn_t *function_number); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_attributes_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_attributes_t) (struct grub_efi_pci_io *this, + grub_efi_pci_io_attribute_operation_t operation, + grub_efi_uint64_t attributes, + grub_efi_uint64_t *result); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_get_bar_attributes_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_get_bar_attributes_t) (struct grub_efi_pci_io *this, + grub_efi_uint8_t bar_index, + grub_efi_uint64_t *supports, + void **resources); + + typedef grub_efi_status_t +-(*grub_efi_pci_io_set_bar_attributes_t) (struct grub_efi_pci_io *this, ++(__grub_efi_api *grub_efi_pci_io_set_bar_attributes_t) (struct grub_efi_pci_io *this, + grub_efi_uint64_t attributes, + grub_efi_uint8_t bar_index, + grub_efi_uint64_t *offset, +@@ -212,12 +212,12 @@ struct grub_efi_pci_root_io; + + typedef struct + { +- grub_efi_status_t(*read) (struct grub_efi_pci_root_io *this, ++ grub_efi_status_t(__grub_efi_api *read) (struct grub_efi_pci_root_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint64_t address, + grub_efi_uintn_t count, + void *buffer); +- grub_efi_status_t(*write) (struct grub_efi_pci_root_io *this, ++ grub_efi_status_t(__grub_efi_api *write) (struct grub_efi_pci_root_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint64_t address, + grub_efi_uintn_t count, +@@ -237,7 +237,7 @@ typedef enum + grub_efi_pci_root_io_operation_t; + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_poll_io_mem_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_poll_io_mem_t) (struct grub_efi_pci_root_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint64_t address, + grub_efi_uint64_t mask, +@@ -246,7 +246,7 @@ typedef grub_efi_status_t + grub_efi_uint64_t *result); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_copy_mem_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_copy_mem_t) (struct grub_efi_pci_root_io *this, + grub_efi_pci_io_width_t width, + grub_efi_uint64_t dest_offset, + grub_efi_uint64_t src_offset, +@@ -254,7 +254,7 @@ typedef grub_efi_status_t + + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_map_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_map_t) (struct grub_efi_pci_root_io *this, + grub_efi_pci_root_io_operation_t operation, + void *host_address, + grub_efi_uintn_t *number_of_bytes, +@@ -262,11 +262,11 @@ typedef grub_efi_status_t + void **mapping); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_unmap_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_unmap_t) (struct grub_efi_pci_root_io *this, + void *mapping); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_allocate_buffer_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_allocate_buffer_t) (struct grub_efi_pci_root_io *this, + grub_efi_allocate_type_t type, + grub_efi_memory_type_t memory_type, + grub_efi_uintn_t pages, +@@ -274,26 +274,26 @@ typedef grub_efi_status_t + grub_efi_uint64_t attributes); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_free_buffer_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_free_buffer_t) (struct grub_efi_pci_root_io *this, + grub_efi_uintn_t pages, + void **host_address); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_flush_t) (struct grub_efi_pci_root_io *this); ++(__grub_efi_api *grub_efi_pci_root_io_flush_t) (struct grub_efi_pci_root_io *this); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_get_attributes_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_get_attributes_t) (struct grub_efi_pci_root_io *this, + grub_efi_uint64_t *supports, + void **resources); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_set_attributes_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_set_attributes_t) (struct grub_efi_pci_root_io *this, + grub_efi_uint64_t attributes, + grub_efi_uint64_t *offset, + grub_efi_uint64_t *length); + + typedef grub_efi_status_t +-(*grub_efi_pci_root_io_configuration_t) (struct grub_efi_pci_root_io *this, ++(__grub_efi_api *grub_efi_pci_root_io_configuration_t) (struct grub_efi_pci_root_io *this, + void **resources); + + struct grub_efi_pci_root_io { diff --git a/0274-grub-core-net-arp.c-fix-variable-name.patch b/0274-grub-core-net-arp.c-fix-variable-name.patch new file mode 100644 index 00000000..a94167c6 --- /dev/null +++ b/0274-grub-core-net-arp.c-fix-variable-name.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 28 Aug 2024 13:37:42 -0600 +Subject: [PATCH] grub-core/net/arp.c: fix variable name + +Signed-off-by: Leo Sandoval +--- + grub-core/net/arp.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c +index 8bf0a06e1..7adeb7447 100644 +--- a/grub-core/net/arp.c ++++ b/grub-core/net/arp.c +@@ -159,7 +159,7 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, + sender_addr.option = 0; + target_addr.option = 0; + +- grub_memcpy(&target_addr.ipv4, tmp_ptr, pln); ++ grub_memcpy(&sender_addr.ipv4, tmp_ptr, pln); + tmp_ptr += pln; + + grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); diff --git a/0275-load-EFI-commands-inside-test-expressions.patch b/0275-load-EFI-commands-inside-test-expressions.patch new file mode 100644 index 00000000..137890ef --- /dev/null +++ b/0275-load-EFI-commands-inside-test-expressions.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 4 Sep 2024 13:25:23 -0600 +Subject: [PATCH] load EFI commands inside test expressions + +These two commands may fail interrumping the normal boot process, +so placing these inside test expressions is a safer approach. + +Resolves: #2305291 +Suggested-by: Kan-Ru Chen: +Signed-off-by: Leo Sandoval +--- + util/grub.d/25_bli.in | 4 +++- + util/grub.d/30_uefi-firmware.in | 3 +-- + 2 files changed, 4 insertions(+), 3 deletions(-) + +diff --git a/util/grub.d/25_bli.in b/util/grub.d/25_bli.in +index 26e27a019..00a8d7159 100644 +--- a/util/grub.d/25_bli.in ++++ b/util/grub.d/25_bli.in +@@ -19,6 +19,8 @@ set -e + + cat << EOF + if [ "\$grub_platform" = "efi" ]; then +- insmod bli ++ if [ ! insmod bli ]; then ++ echo "bli module not available" ++ fi + fi + EOF +diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in +index 1c2365ddb..1ef31e08f 100644 +--- a/util/grub.d/30_uefi-firmware.in ++++ b/util/grub.d/30_uefi-firmware.in +@@ -32,8 +32,7 @@ gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 + + cat << EOF + if [ "\$grub_platform" = "efi" ]; then +- fwsetup --is-supported +- if [ "\$?" = 0 ]; then ++ if [ fwsetup --is-supported ]; then + menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { + fwsetup + } diff --git a/0276-efi-loader-Check-if-NX-is-required-in-grub_efi_linux.patch b/0276-efi-loader-Check-if-NX-is-required-in-grub_efi_linux.patch new file mode 100644 index 00000000..0942ea42 --- /dev/null +++ b/0276-efi-loader-Check-if-NX-is-required-in-grub_efi_linux.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Wed, 25 Sep 2024 17:23:33 +0200 +Subject: [PATCH] efi/loader: Check if NX is required in grub_efi_linux_boot() + +Call grub_efi_check_nx_required() passing it nx_required to +assign the correct value + +Signed-off-by: Nicolas Frayer +--- + grub-core/loader/efi/linux.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 0d1804b602da..5889e3f36f89 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -236,6 +236,7 @@ grub_efi_linux_boot (grub_addr_t k_address, grub_size_t k_size, + grub_dprintf ("linux", "kernel_address: %p handover_offset: %p params: %p\n", + (void *)k_address, (void *)h_offset, k_params); + ++ grub_efi_check_nx_required(&nx_required); + + if (nx_required && !nx_supported) + return grub_error (GRUB_ERR_BAD_OS, N_("kernel does not support NX loading required by policy")); diff --git a/0277-Stop-grub.efi-from-always-printing-dynamic_load_symb.patch b/0277-Stop-grub.efi-from-always-printing-dynamic_load_symb.patch new file mode 100644 index 00000000..02a64177 --- /dev/null +++ b/0277-Stop-grub.efi-from-always-printing-dynamic_load_symb.patch @@ -0,0 +1,80 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Thu, 3 Oct 2024 12:26:07 +0200 +Subject: [PATCH] Stop grub.efi from always printing "dynamic_load_symbols + %p\n" during boot + +Commit 972aa68d2bf5 ("Make a "gdb" dprintf that tells us load addresses.") +added some debug prints to help with running gdb against grub. + +Besides adding a new grub_dl_print_gdb_info () function which uses +`grub_qdprintf ("gdb", ...);` it also adds a new grub_efi_print_gdb_info () +call to grub_efi_init (). + +grub_efi_print_gdb_info () is intended for the gdbinfo command and uses +a non debug grub_printf () call leading to grub now always printing this +message during boot breaking flicker-free boot. + +Add a new "debug" parameter to grub_efi_print_gdb_info () and use +`grub_qdprintf ("gdb", ...);` when this is set to silence the printing +done from grub_efi_init () when debugging is not enabled. + +Fixes: 972aa68d2bf5 ("Make a "gdb" dprintf that tells us load addresses.") +Signed-off-by: Hans de Goede +--- + grub-core/kern/efi/debug.c | 2 +- + grub-core/kern/efi/init.c | 2 +- + include/grub/efi/debug.h | 7 +++++-- + 3 files changed, 7 insertions(+), 4 deletions(-) + +diff --git a/grub-core/kern/efi/debug.c b/grub-core/kern/efi/debug.c +index 5d2ab1a36ff4..5ac194fc8f46 100644 +--- a/grub-core/kern/efi/debug.c ++++ b/grub-core/kern/efi/debug.c +@@ -26,7 +26,7 @@ grub_cmd_gdbinfo (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) + { +- grub_efi_print_gdb_info (); ++ grub_efi_print_gdb_info (false); + return 0; + } + +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index d35d69747342..ce8a7fe7122f 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -157,7 +157,7 @@ grub_efi_init (void) + grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL); + + grub_efi_env_init (); +- grub_efi_print_gdb_info (); ++ grub_efi_print_gdb_info (true); + grub_efidisk_init (); + + grub_efi_register_debug_commands (); +diff --git a/include/grub/efi/debug.h b/include/grub/efi/debug.h +index c2d2a03b06f1..961e591afa3e 100644 +--- a/include/grub/efi/debug.h ++++ b/include/grub/efi/debug.h +@@ -27,7 +27,7 @@ + void grub_efi_register_debug_commands (void); + + static inline void +-grub_efi_print_gdb_info (void) ++grub_efi_print_gdb_info (bool debug) + { + grub_addr_t text; + +@@ -35,7 +35,10 @@ grub_efi_print_gdb_info (void) + if (!text) + return; + +- grub_printf ("dynamic_load_symbols %p\n", (void *)text); ++ if (debug) ++ grub_qdprintf ("gdb", "dynamic_load_symbols %p\n", (void *)text); ++ else ++ grub_printf ("dynamic_load_symbols %p\n", (void *)text); + } + + #endif /* ! GRUB_EFI_DEBUG_HEADER */ diff --git a/0278-acpi-Fix-out-of-bounds-access-in-grub_acpi_xsdt_find.patch b/0278-acpi-Fix-out-of-bounds-access-in-grub_acpi_xsdt_find.patch new file mode 100644 index 00000000..20d2de34 --- /dev/null +++ b/0278-acpi-Fix-out-of-bounds-access-in-grub_acpi_xsdt_find.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Benjamin Herrenschmidt +Date: Wed, 16 Oct 2024 16:20:24 +1100 +Subject: [PATCH] acpi: Fix out of bounds access in grub_acpi_xsdt_find_table() + +The calculation of the size of the table was incorrect (copy/pasta from +grub_acpi_rsdt_find_table() I assume...). The entries are 64-bit long. + +This causes us to access beyond the end of the table which is causing +crashes during boot on some systems. Typically this is causing a crash +on VMWare when using UEFI and enabling serial autodetection, as + +grub_acpi_find_table (GRUB_ACPI_SPCR_SIGNATURE); + +Will goes past the end of the table (the SPCR table doesn't exits) + +Signed-off-by: Benjamin Herrenschmidt +--- + grub-core/kern/acpi.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/acpi.c b/grub-core/kern/acpi.c +index 48ded4e2ea6e..8ff0835d501f 100644 +--- a/grub-core/kern/acpi.c ++++ b/grub-core/kern/acpi.c +@@ -75,7 +75,7 @@ grub_acpi_xsdt_find_table (struct grub_acpi_table_header *xsdt, const char *sig) + return 0; + + ptr = (grub_unaligned_uint64_t *) (xsdt + 1); +- s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t); ++ s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint64_t); + for (; s; s--, ptr++) + { + struct grub_acpi_table_header *tbl; diff --git a/0279-cmd-search-Fix-a-possible-NULL-ptr-dereference.patch b/0279-cmd-search-Fix-a-possible-NULL-ptr-dereference.patch new file mode 100644 index 00000000..7da6e10b --- /dev/null +++ b/0279-cmd-search-Fix-a-possible-NULL-ptr-dereference.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Wed, 16 Oct 2024 15:50:32 +0200 +Subject: [PATCH] cmd/search: Fix a possible NULL ptr dereference + +When querying about a partition UUID, we're not checking +for get_device_uuid() return value, which can possibly +result in dereferencing a NULL pointer. + +Signed-off-by: Nicolas Frayer +Co-authored-by: Chuong Tran +--- + grub-core/commands/search.c | 28 +++++++++++++++------------- + 1 file changed, 15 insertions(+), 13 deletions(-) + +diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c +index 9dd937e6df4e..d538b36219fb 100644 +--- a/grub-core/commands/search.c ++++ b/grub-core/commands/search.c +@@ -212,24 +212,26 @@ iterate_device (const char *name, void *data) + struct uuid_context uuid_ctx; + int ret = 0; + +- get_device_uuid(name, &quid_name); +- if (!grub_strcmp(quid_name, ctx->key)) ++ if (get_device_uuid(name, &quid_name)) + { +- uuid_ctx.name = name; +- uuid_ctx.uuid = quid_name; ++ if (!grub_strcmp(quid_name, ctx->key)) ++ { ++ uuid_ctx.name = name; ++ uuid_ctx.uuid = quid_name; + +- ret = grub_device_iterate (check_for_duplicate, &uuid_ctx); ++ ret = grub_device_iterate (check_for_duplicate, &uuid_ctx); + +- if (ret) +- { +- grub_printf("Duplicated media UUID found, rebooting ...\n"); +- grub_sleep(10); +- grub_reboot(); +- } +- } ++ if (ret) ++ { ++ grub_printf("Duplicated media UUID found, rebooting ...\n"); ++ grub_sleep(10); ++ grub_reboot(); ++ } ++ } + +- if (quid_name) grub_free (quid_name); ++ if (quid_name) grub_free (quid_name); + ++ } + } + } + } diff --git a/0280-Enable-building-blscfg-module-on-xen-and-xen_pvh.patch b/0280-Enable-building-blscfg-module-on-xen-and-xen_pvh.patch new file mode 100644 index 00000000..d1747377 --- /dev/null +++ b/0280-Enable-building-blscfg-module-on-xen-and-xen_pvh.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matyáš Kroupa +Date: Fri, 30 Aug 2024 16:28:21 +0200 +Subject: [PATCH] Enable building blscfg module on xen and xen_pvh +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Building blscfg module for Xen targets makes it possible to include them +in custom pvgrub2 and pvhgrub2 images. Those are then used to boot PV and +PVH domUs. + +Signed-off-by: Matyáš Kroupa +--- + grub-core/Makefile.core.def | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 6ff4835..95fd18d 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -880,6 +880,8 @@ module = { + enable = efi; + enable = i386_pc; + enable = emu; ++ enable = xen; ++ enable = i386_xen_pvh; + }; + + module = { +-- +2.46.0 diff --git a/0281-loader-efi-Fix-RISC-V-build.patch b/0281-loader-efi-Fix-RISC-V-build.patch new file mode 100644 index 00000000..91ccb602 --- /dev/null +++ b/0281-loader-efi-Fix-RISC-V-build.patch @@ -0,0 +1,72 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrea Bolognani +Date: Tue, 19 Nov 2024 15:42:01 +0000 +Subject: [PATCH] loader/efi: Fix RISC-V build + +Some struct definitions are currently limited to 32-bit and +64-bit Arm architectures, but they actually apply to other +architectures as well, specifically 32-bit and 64-bit RISC-V +respectively. + +Update the preprocessor checks guarding their definition, and +change their names to make them more accurate by replacing the +word "arm" with the word "efi". + +Signed-off-by: Andrea Bolognani +--- + grub-core/loader/efi/linux.c | 2 +- + include/grub/efi/efi.h | 12 ++++++------ + 2 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 5889e3f36f8..ef55556f2d9 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -684,7 +684,7 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size, + grub_uint32_t *alignment, grub_uint32_t *code_size) + { + struct linux_arch_kernel_header *lh = kernel; +- struct grub_armxx_linux_pe_header *pe; ++ struct grub_efixx_linux_pe_header *pe; + grub_uint16_t i; + struct grub_pe32_section_table *sections; + +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 7eed1bd791d..81daf6bead1 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -36,28 +36,28 @@ struct linux_arch_kernel_header { + struct grub_pe_image_header pe_image_header; + }; + +-struct grub_arm_linux_pe_header ++struct grub_efi32_linux_pe_header + { + grub_uint32_t magic; + struct grub_pe32_coff_header coff; + struct grub_pe32_optional_header opt; + }; + +-struct grub_arm64_linux_pe_header ++struct grub_efi64_linux_pe_header + { + grub_uint32_t magic; + struct grub_pe32_coff_header coff; + struct grub_pe64_optional_header opt; + }; + +-#if defined(__arm__) ++#if defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 32)) + # define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC +-# define grub_armxx_linux_pe_header grub_arm_linux_pe_header ++# define grub_efixx_linux_pe_header grub_efi32_linux_pe_header + #endif + +-#if defined(__aarch64__) ++#if defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64)) + # define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC +-# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header ++# define grub_efixx_linux_pe_header grub_efi64_linux_pe_header + #endif + + #define GRUB_EFI_GRUB_VARIABLE_GUID \ diff --git a/0282-kern-riscv-efi-init-Use-time-register-in-grub_efi_ge.patch b/0282-kern-riscv-efi-init-Use-time-register-in-grub_efi_ge.patch new file mode 100644 index 00000000..c38e333c --- /dev/null +++ b/0282-kern-riscv-efi-init-Use-time-register-in-grub_efi_ge.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Heinrich Schuchardt +Date: Mon, 12 Aug 2024 16:13:18 +0200 +Subject: [PATCH] kern/riscv/efi/init: Use time register in + grub_efi_get_time_ms() + +The cycle register is not guaranteed to count at constant frequency. +If it is counting at all depends on the state the performance monitoring +unit. Use the time register to measure time. + +Signed-off-by: Heinrich Schuchardt +Reviewed-by: Daniel Kiper +--- + grub-core/kern/riscv/efi/init.c | 15 +++++++-------- + 1 file changed, 7 insertions(+), 8 deletions(-) + +diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c +index 38795fe6741..0d7de4f541a 100644 +--- a/grub-core/kern/riscv/efi/init.c ++++ b/grub-core/kern/riscv/efi/init.c +@@ -33,16 +33,15 @@ grub_efi_get_time_ms (void) + grub_uint64_t tmr; + + #if __riscv_xlen == 64 +- asm volatile ("rdcycle %0" : "=r" (tmr)); ++ asm volatile ("rdtime %0" : "=r"(tmr)); + #else + grub_uint32_t lo, hi, tmp; +- asm volatile ( +- "1:\n" +- "rdcycleh %0\n" +- "rdcycle %1\n" +- "rdcycleh %2\n" +- "bne %0, %2, 1b" +- : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); ++ asm volatile ("1:\n" ++ "rdtimeh %0\n" ++ "rdtime %1\n" ++ "rdtimeh %2\n" ++ "bne %0, %2, 1b" ++ : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); + tmr = ((grub_uint64_t)hi << 32) | lo; + #endif + diff --git a/0283-Use-medany-instead-of-large-model-for-RISCV.patch b/0283-Use-medany-instead-of-large-model-for-RISCV.patch new file mode 100644 index 00000000..37540c47 --- /dev/null +++ b/0283-Use-medany-instead-of-large-model-for-RISCV.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jason Montleon +Date: Fri, 3 May 2024 13:18:37 -0400 +Subject: [PATCH] Use medany instead of large model for RISCV + +Signed-off-by: Jason Montleon +--- + configure.ac | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 4788f3d6adc..a6a6957fbdb 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1313,7 +1313,7 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC) + + LDFLAGS="$TARGET_LDFLAGS" + +-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then ++if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then + # Use large model to support 4G memory + AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [ + CFLAGS="$TARGET_CFLAGS -mcmodel=large" +@@ -1323,9 +1323,11 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_ + ]) + if test "x$grub_cv_cc_mcmodel" = xyes; then + TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large" +- elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then ++ elif test "$target_cpu" = sparc64; then + TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany" + fi ++elif test "$target_cpu" = riscv64 ; then ++ TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany" + fi + + if test "$target_cpu"-"$platform" = x86_64-efi; then diff --git a/0284-fs-xfs-Fix-large-extent-counters-incompat-feature-su.patch b/0284-fs-xfs-Fix-large-extent-counters-incompat-feature-su.patch new file mode 100644 index 00000000..ba641630 --- /dev/null +++ b/0284-fs-xfs-Fix-large-extent-counters-incompat-feature-su.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Eric Sandeen +Date: Wed, 4 Dec 2024 07:50:28 -0600 +Subject: [PATCH] fs/xfs: fix large extent counters incompat feature support + +When large extent counter / NREXT64 support was added to grub, it missed +a couple of direct reads of nextents which need to be changed to the new +NREXT64-aware helper as well. Without this, we'll have mis-reads of some +directories with this feature enabled. + +(The large extent counter fix likely raced on merge with +07318ee7e ("fs/xfs: Fix XFS directory extent parsing") which added the new +direct nextents reads just prior, causing this issue.) + +Fixes: aa7c1322671e ("fs/xfs: Add large extent counters incompat feature support") +Signed-off-by: Eric Sandeen +Reviewed-by: Anthony Iliopoulos +Reviewed-by: Jon DeVree +--- + grub-core/fs/xfs.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 8e02ab4a3014..92046f9bdf49 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -926,7 +926,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, + * Leaf and tail information are only in the data block if the number + * of extents is 1. + */ +- if (dir->inode.nextents == grub_cpu_to_be32_compile_time (1)) ++ if (grub_xfs_get_inode_nextents(&dir->inode) == 1) + { + struct grub_xfs_dirblock_tail *tail = grub_xfs_dir_tail (dir->data, dirblock); + +@@ -980,7 +980,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, + * The expected number of directory entries is only tracked for the + * single extent case. + */ +- if (dir->inode.nextents == grub_cpu_to_be32_compile_time (1)) ++ if (grub_xfs_get_inode_nextents(&dir->inode) == 1) + { + /* Check if last direntry in this block is reached. */ + entries--; diff --git a/0285-term-nns8250-spcr-return-if-redirection-is-disabled.patch b/0285-term-nns8250-spcr-return-if-redirection-is-disabled.patch new file mode 100644 index 00000000..4e5cdc1c --- /dev/null +++ b/0285-term-nns8250-spcr-return-if-redirection-is-disabled.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Benjamin Herrenschmidt +Date: Thu, 16 Jan 2025 10:22:48 -0600 +Subject: [PATCH] term/nns8250-spcr: return if redirection is disabled + +The Microsoft spec for SPCR says "The base address of the Serial Port register +set described using the ACPI Generic Address Structure, or 0 if console +redirection is disabled." so return if disable (base address = 0). If this check +is not done, we may get invalid ports for those particular machines that +redirection is disabled and at some point hanging the booting execution when +reading the grub.cfg configuration file. + +Signed-off-by: Benjamin Herrenschmidt +Reviewed-by: Leo Sandoval +--- + grub-core/term/ns8250-spcr.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/term/ns8250-spcr.c b/grub-core/term/ns8250-spcr.c +index d52b52c26..86f1aa078 100644 +--- a/grub-core/term/ns8250-spcr.c ++++ b/grub-core/term/ns8250-spcr.c +@@ -75,6 +75,11 @@ grub_ns8250_spcr_init (void) + config.speed = 115200; + break; + }; ++ ++ /* if base address is 0, it means redirection is disable, so return it */ ++ if (spcr->base_addr.addr == 0) ++ return NULL; ++ + switch (spcr->base_addr.space_id) + { + case GRUB_ACPI_GENADDR_MEM_SPACE: diff --git a/0286-commands-legacycfg-Avoid-closing-file-twice.patch b/0286-commands-legacycfg-Avoid-closing-file-twice.patch new file mode 100644 index 00000000..2e126ab3 --- /dev/null +++ b/0286-commands-legacycfg-Avoid-closing-file-twice.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 16 Oct 2024 11:54:38 -0600 +Subject: [PATCH] commands/legacycfg: Avoid closing file twice + +An internal (at Red Hat) static soure code scan detected an +use-after-free scenario: + + Error: USE_AFTER_FREE (CWE-416): + grub-2.06/grub-core/commands/legacycfg.c:194: freed_arg: "grub_file_close" frees "file". + grub-2.06/grub-core/commands/legacycfg.c:201: deref_arg: Calling "grub_file_close" dereferences freed pointer "file". + # 199| if (!args) + # 200| { + # 201|-> grub_file_close (file); + # 202| grub_free (suffix); + # 203| grub_free (entrysrc); + +So, remove the extra file close call. + +Signed-off-by: Leo Sandoval +Reviewed-by: Daniel Kiper +--- + grub-core/commands/legacycfg.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index 2c5d1a0ef..86bcda695 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -198,7 +198,6 @@ legacy_file (const char *filename) + const char **args = grub_malloc (sizeof (args[0])); + if (!args) + { +- grub_file_close (file); + grub_free (suffix); + grub_free (entrysrc); + return grub_errno; diff --git a/0287-disk-ahci.c-remove-conditional-operator-for-endtime.patch b/0287-disk-ahci.c-remove-conditional-operator-for-endtime.patch new file mode 100644 index 00000000..759cd4f9 --- /dev/null +++ b/0287-disk-ahci.c-remove-conditional-operator-for-endtime.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 22 Jan 2025 13:37:42 -0600 +Subject: [PATCH] disk/ahci.c: remove conditional operator for endtime + +The conditional makes no sense when the two possible expressions have the same +value, so remove it (perhaps the compiler does it for us but better to remove +it). + +Signed-off-by: Leo Sandoval +--- + grub-core/disk/ahci.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c +index e7b5dc5f2..b247161b9 100644 +--- a/grub-core/disk/ahci.c ++++ b/grub-core/disk/ahci.c +@@ -1038,7 +1038,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, + grub_dprintf ("ahci", "AHCI tfd = %x\n", + dev->hba->ports[dev->port].task_file_data); + +- endtime = grub_get_time_ms () + (spinup ? 20000 : 20000); ++ endtime = grub_get_time_ms () + 20000; + while ((dev->hba->ports[dev->port].command_issue & 1)) + if (grub_get_time_ms () > endtime || + (dev->hba->ports[dev->port].intstatus & GRUB_AHCI_HBA_PORT_IS_FATAL_MASK)) diff --git a/0288-commands-bli-Fix-crash-in-get_part_uuid.patch b/0288-commands-bli-Fix-crash-in-get_part_uuid.patch new file mode 100644 index 00000000..fe26cecb --- /dev/null +++ b/0288-commands-bli-Fix-crash-in-get_part_uuid.patch @@ -0,0 +1,80 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Wed, 17 Jul 2024 14:46:46 +0800 +Subject: [PATCH] commands/bli: Fix crash in get_part_uuid() + +The get_part_uuid() function made an assumption that the target GRUB +device is a partition device and accessed device->disk->partition +without checking for NULL. There are four situations where this +assumption is problematic: + +1. The device is a net device instead of a disk. +2. The device is an abstraction device, like LVM, RAID, or CRYPTO, which + is mostly logical "disk" ((lvmid/) and so on). +3. Firmware RAID may present the ESP to GRUB as an EFI disk (hd0) device + if it is contained within a Linux software RAID. +4. When booting from a CD-ROM, the ESP is a VFAT image indexed by the El + Torito boot catalog. The boot device is set to (cd0), corresponding + to the CD-ROM image mounted as an ISO 9660 filesystem. + +As a result, get_part_uuid() could lead to a NULL pointer dereference +and trigger a synchronous exception during boot if the ESP falls into +one of these categories. This patch fixes the problem by adding the +necessary checks to handle cases where the ESP is not a partition device. + +Additionally, to avoid disrupting the boot process, this patch relaxes +the severity of the errors in this context to non-critical. Errors will +be logged, but they will not prevent the boot process from continuing. + +Fixes: e0fa7dc84 (bli: Add a module for the Boot Loader Interface) + +Signed-off-by: Michael Chang +Reviewed-By: Oliver Steffen +Reviewed-by: Daniel Kiper +--- + grub-core/commands/bli.c | 20 +++++++++++++++++++- + 1 file changed, 19 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/bli.c b/grub-core/commands/bli.c +index e0d8a54f7bea..298c5f70a876 100644 +--- a/grub-core/commands/bli.c ++++ b/grub-core/commands/bli.c +@@ -48,6 +48,22 @@ get_part_uuid (const char *device_name, char **part_uuid) + if (device == NULL) + return grub_error (grub_errno, N_("cannot open device: %s"), device_name); + ++ if (device->disk == NULL) ++ { ++ grub_dprintf ("bli", "%s is not a disk device, partuuid skipped\n", device_name); ++ *part_uuid = NULL; ++ grub_device_close (device); ++ return GRUB_ERR_NONE; ++ } ++ ++ if (device->disk->partition == NULL) ++ { ++ grub_dprintf ("bli", "%s has no partition, partuuid skipped\n", device_name); ++ *part_uuid = NULL; ++ grub_device_close (device); ++ return GRUB_ERR_NONE; ++ } ++ + disk = grub_disk_open (device->disk->name); + if (disk == NULL) + { +@@ -99,7 +115,7 @@ set_loader_device_part_uuid (void) + + status = get_part_uuid (device_name, &part_uuid); + +- if (status == GRUB_ERR_NONE) ++ if (status == GRUB_ERR_NONE && part_uuid) + status = grub_efi_set_variable_to_string ("LoaderDevicePartUUID", &bli_vendor_guid, part_uuid, + GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS | + GRUB_EFI_VARIABLE_RUNTIME_ACCESS); +@@ -117,4 +133,6 @@ GRUB_MOD_INIT (bli) + GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS | + GRUB_EFI_VARIABLE_RUNTIME_ACCESS); + set_loader_device_part_uuid (); ++ /* No error here is critical, other than being logged */ ++ grub_print_error (); + } diff --git a/0289-misc-Implement-grub_strlcpy.patch b/0289-misc-Implement-grub_strlcpy.patch new file mode 100644 index 00000000..d6932f2e --- /dev/null +++ b/0289-misc-Implement-grub_strlcpy.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sat, 15 Jun 2024 02:33:08 +0100 +Subject: [PATCH] misc: Implement grub_strlcpy() + +grub_strlcpy() acts the same way as strlcpy() does on most *NIX, +returning the length of src and ensuring dest is always NUL +terminated except when size is 0. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + include/grub/misc.h | 39 +++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +diff --git a/include/grub/misc.h b/include/grub/misc.h +index db517acd5..6b1e084af 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -72,6 +72,45 @@ grub_stpcpy (char *dest, const char *src) + return d - 1; + } + ++static inline grub_size_t ++grub_strlcpy (char *dest, const char *src, grub_size_t size) ++{ ++ char *d = dest; ++ grub_size_t res = 0; ++ /* ++ * We do not subtract one from size here to avoid dealing with underflowing ++ * the value, which is why to_copy is always checked to be greater than one ++ * throughout this function. ++ */ ++ grub_size_t to_copy = size; ++ ++ /* Copy size - 1 bytes to dest. */ ++ if (to_copy > 1) ++ while ((*d++ = *src++) != '\0' && ++res && --to_copy > 1) ++ ; ++ ++ /* ++ * NUL terminate if size != 0. The previous step may have copied a NUL byte ++ * if it reached the end of the string, but we know dest[size - 1] must always ++ * be a NUL byte. ++ */ ++ if (size != 0) ++ dest[size - 1] = '\0'; ++ ++ /* If there is still space in dest, but are here, we reached the end of src. */ ++ if (to_copy > 1) ++ return res; ++ ++ /* ++ * If we haven't reached the end of the string, iterate through to determine ++ * the strings total length. ++ */ ++ while (*src++ != '\0' && ++res) ++ ; ++ ++ return res; ++} ++ + /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ + static inline void * + grub_memcpy (void *dest, const void *src, grub_size_t n) diff --git a/0290-fs-ufs-Fix-a-heap-OOB-write.patch b/0290-fs-ufs-Fix-a-heap-OOB-write.patch new file mode 100644 index 00000000..ed1be4cb --- /dev/null +++ b/0290-fs-ufs-Fix-a-heap-OOB-write.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 02:03:33 +0100 +Subject: [PATCH] fs/ufs: Fix a heap OOB write + +grub_strcpy() was used to copy a symlink name from the filesystem +image to a heap allocated buffer. This led to a OOB write to adjacent +heap allocations. Fix by using grub_strlcpy(). + +Fixes: CVE-2024-45781 + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ufs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c +index a354c92d9..01235101b 100644 +--- a/grub-core/fs/ufs.c ++++ b/grub-core/fs/ufs.c +@@ -463,7 +463,7 @@ grub_ufs_lookup_symlink (struct grub_ufs_data *data, int ino) + /* Check against zero is paylindromic, no need to swap. */ + if (data->inode.nblocks == 0 + && INODE_SIZE (data) <= sizeof (data->inode.symlink)) +- grub_strcpy (symlink, (char *) data->inode.symlink); ++ grub_strlcpy (symlink, (char *) data->inode.symlink, sz); + else + { + if (grub_ufs_read_file (data, 0, 0, 0, sz, symlink) < 0) diff --git a/0291-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch b/0291-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch new file mode 100644 index 00000000..5a836725 --- /dev/null +++ b/0291-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 02:48:33 +0100 +Subject: [PATCH] fs/hfs: Fix stack OOB write with grub_strcpy() + +Replaced with grub_strlcpy(). + +Fixes: CVE-2024-45782 +Fixes: CVE-2024-56737 +Fixes: https://savannah.gnu.org/bugs/?66599 + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/hfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c +index 91dc0e69c..920112b03 100644 +--- a/grub-core/fs/hfs.c ++++ b/grub-core/fs/hfs.c +@@ -379,7 +379,7 @@ grub_hfs_mount (grub_disk_t disk) + volume name. */ + key.parent_dir = grub_cpu_to_be32_compile_time (1); + key.strlen = data->sblock.volname[0]; +- grub_strcpy ((char *) key.str, (char *) (data->sblock.volname + 1)); ++ grub_strlcpy ((char *) key.str, (char *) (data->sblock.volname + 1), sizeof (key.str)); + + if (grub_hfs_find_node (data, (char *) &key, data->cat_root, + 0, (char *) &dir, sizeof (dir)) == 0) diff --git a/0292-fs-tar-Initialize-name-in-grub_cpio_find_file.patch b/0292-fs-tar-Initialize-name-in-grub_cpio_find_file.patch new file mode 100644 index 00000000..6433d2d5 --- /dev/null +++ b/0292-fs-tar-Initialize-name-in-grub_cpio_find_file.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 02:47:54 +0100 +Subject: [PATCH] fs/tar: Initialize name in grub_cpio_find_file() + +It was possible to iterate through grub_cpio_find_file() without +allocating name and not setting mode to GRUB_ARCHELP_ATTR_END, which +would cause the uninitialized value for name to be used as an argument +for canonicalize() in grub_archelp_dir(). + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/tar.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c +index c551ed6b5..646bce5eb 100644 +--- a/grub-core/fs/tar.c ++++ b/grub-core/fs/tar.c +@@ -78,6 +78,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + int reread = 0, have_longname = 0, have_longlink = 0; + + data->hofs = data->next_hofs; ++ *name = NULL; + + for (reread = 0; reread < 3; reread++) + { +@@ -202,6 +203,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + } + return GRUB_ERR_NONE; + } ++ ++ if (*name == NULL) ++ return grub_error (GRUB_ERR_BAD_FS, "invalid tar archive"); ++ + return GRUB_ERR_NONE; + } + diff --git a/0293-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch b/0293-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch new file mode 100644 index 00000000..b059e496 --- /dev/null +++ b/0293-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch @@ -0,0 +1,89 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Fri, 22 Nov 2024 06:27:58 +0000 +Subject: [PATCH] fs/tar: Integer overflow leads to heap OOB write + +Both namesize and linksize are derived from hd.size, a 12-digit octal +number parsed by read_number(). Later direct arithmetic calculation like +"namesize + 1" and "linksize + 1" may exceed the maximum value of +grub_size_t leading to heap OOB write. This patch fixes the issue by +using grub_add() and checking for an overflow. + +Fixes: CVE-2024-45780 + +Reported-by: Nils Langius +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Alec Brown +--- + grub-core/fs/tar.c | 23 ++++++++++++++++++----- + 1 file changed, 18 insertions(+), 5 deletions(-) + +diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c +index 646bce5eb..386c09022 100644 +--- a/grub-core/fs/tar.c ++++ b/grub-core/fs/tar.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -76,6 +77,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + { + struct head hd; + int reread = 0, have_longname = 0, have_longlink = 0; ++ grub_size_t sz; + + data->hofs = data->next_hofs; + *name = NULL; +@@ -98,7 +100,11 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + { + grub_err_t err; + grub_size_t namesize = read_number (hd.size, sizeof (hd.size)); +- *name = grub_malloc (namesize + 1); ++ ++ if (grub_add (namesize, 1, &sz)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("name size overflow")); ++ ++ *name = grub_malloc (sz); + if (*name == NULL) + return grub_errno; + err = grub_disk_read (data->disk, 0, +@@ -118,15 +124,19 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + { + grub_err_t err; + grub_size_t linksize = read_number (hd.size, sizeof (hd.size)); +- if (data->linkname_alloc < linksize + 1) ++ ++ if (grub_add (linksize, 1, &sz)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("link size overflow")); ++ ++ if (data->linkname_alloc < sz) + { + char *n; +- n = grub_calloc (2, linksize + 1); ++ n = grub_calloc (2, sz); + if (!n) + return grub_errno; + grub_free (data->linkname); + data->linkname = n; +- data->linkname_alloc = 2 * (linksize + 1); ++ data->linkname_alloc = 2 * (sz); + } + + err = grub_disk_read (data->disk, 0, +@@ -149,7 +159,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + while (extra_size < sizeof (hd.prefix) + && hd.prefix[extra_size]) + extra_size++; +- *name = grub_malloc (sizeof (hd.name) + extra_size + 2); ++ ++ if (grub_add (sizeof (hd.name) + 2, extra_size, &sz)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("long name size overflow")); ++ *name = grub_malloc (sz); + if (*name == NULL) + return grub_errno; + if (hd.prefix[0]) diff --git a/0294-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch b/0294-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch new file mode 100644 index 00000000..0b72b727 --- /dev/null +++ b/0294-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 06:15:03 +0100 +Subject: [PATCH] fs/f2fs: Set a grub_errno if mount fails + +It was previously possible for grub_errno to not be set when +grub_f2fs_mount() failed if nat_bitmap_ptr() returned NULL. + +This issue is solved by ensuring a grub_errno is set in the fail case. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/f2fs.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c +index 855e24618..db8a65f8d 100644 +--- a/grub-core/fs/f2fs.c ++++ b/grub-core/fs/f2fs.c +@@ -872,6 +872,9 @@ grub_f2fs_mount (grub_disk_t disk) + return data; + + fail: ++ if (grub_errno == GRUB_ERR_NONE) ++ grub_error (GRUB_ERR_BAD_FS, "not a F2FS filesystem"); ++ + grub_free (data); + + return NULL; diff --git a/0295-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch b/0295-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch new file mode 100644 index 00000000..eb36c019 --- /dev/null +++ b/0295-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 06:22:51 +0100 +Subject: [PATCH] fs/hfsplus: Set a grub_errno if mount fails + +It was possible for mount to fail but not set grub_errno. This led to +a possible double decrement of the module reference count if the NULL +page was mapped. + +Fixing in general as a similar bug was fixed in commit 61b13c187 +(fs/hfsplus: Set grub_errno to prevent NULL pointer access) and there +are likely more variants around. + +Fixes: CVE-2024-45783 + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/hfsplus.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c +index 295822f69..de71fd486 100644 +--- a/grub-core/fs/hfsplus.c ++++ b/grub-core/fs/hfsplus.c +@@ -405,7 +405,7 @@ grub_hfsplus_mount (grub_disk_t disk) + + fail: + +- if (grub_errno == GRUB_ERR_OUT_OF_RANGE) ++ if (grub_errno == GRUB_ERR_OUT_OF_RANGE || grub_errno == GRUB_ERR_NONE) + grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem"); + + grub_free (data); diff --git a/0296-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch b/0296-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch new file mode 100644 index 00000000..69470f69 --- /dev/null +++ b/0296-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 06:37:08 +0100 +Subject: [PATCH] fs/iso9660: Set a grub_errno if mount fails + +It was possible for a grub_errno to not be set if mount of an ISO 9660 +filesystem failed when set_rockridge() returned 0. + +This isn't known to be exploitable as the other filesystems due to +filesystem helper checking the requested file type. Though fixing +as a precaution. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/iso9660.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 8c348b59a..8d480e602 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -551,6 +551,9 @@ grub_iso9660_mount (grub_disk_t disk) + return data; + + fail: ++ if (grub_errno == GRUB_ERR_NONE) ++ grub_error (GRUB_ERR_BAD_FS, "not a ISO9660 filesystem"); ++ + grub_free (data); + return 0; + } diff --git a/0297-fs-iso9660-Fix-invalid-free.patch b/0297-fs-iso9660-Fix-invalid-free.patch new file mode 100644 index 00000000..61bd5cce --- /dev/null +++ b/0297-fs-iso9660-Fix-invalid-free.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Fri, 31 May 2024 15:14:42 +0800 +Subject: [PATCH] fs/iso9660: Fix invalid free + +The ctx->filename can point to either a string literal or a dynamically +allocated string. The ctx->filename_alloc field is used to indicate the +type of allocation. + +An issue has been identified where ctx->filename is reassigned to +a string literal in susp_iterate_dir() but ctx->filename_alloc is not +correctly handled. This oversight causes a memory leak and an invalid +free operation later. + +The fix involves checking ctx->filename_alloc, freeing the allocated +string if necessary and clearing ctx->filename_alloc for string literals. + +Reported-by: Daniel Axtens +Signed-off-by: Michael Chang +Reviewed-by: Daniel Kiper +--- + grub-core/fs/iso9660.c | 14 ++++++++++++-- + 1 file changed, 12 insertions(+), 2 deletions(-) + +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 8d480e602..8e3c95c4f 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -628,9 +628,19 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + filename type is stored. */ + /* FIXME: Fix this slightly improper cast. */ + if (entry->data[0] & GRUB_ISO9660_RR_DOT) +- ctx->filename = (char *) "."; ++ { ++ if (ctx->filename_alloc) ++ grub_free (ctx->filename); ++ ctx->filename_alloc = 0; ++ ctx->filename = (char *) "."; ++ } + else if (entry->data[0] & GRUB_ISO9660_RR_DOTDOT) +- ctx->filename = (char *) ".."; ++ { ++ if (ctx->filename_alloc) ++ grub_free (ctx->filename); ++ ctx->filename_alloc = 0; ++ ctx->filename = (char *) ".."; ++ } + else if (entry->len >= 5) + { + grub_size_t off = 0, csize = 1; diff --git a/0298-fs-jfs-Fix-OOB-read-in-jfs_getent.patch b/0298-fs-jfs-Fix-OOB-read-in-jfs_getent.patch new file mode 100644 index 00000000..49464e74 --- /dev/null +++ b/0298-fs-jfs-Fix-OOB-read-in-jfs_getent.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Fri, 22 Nov 2024 06:27:59 +0000 +Subject: [PATCH] fs/jfs: Fix OOB read in jfs_getent() + +The JFS fuzzing revealed an OOB read in grub_jfs_getent(). The crash +was caused by an invalid leaf nodes count, diro->dirpage->header.count, +which was larger than the maximum number of leaf nodes allowed in an +inode. This fix is to ensure that the leaf nodes count is validated in +grub_jfs_opendir() before calling grub_jfs_getent(). + +On the occasion replace existing raw numbers with newly defined constant. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Alec Brown +--- + grub-core/fs/jfs.c | 17 +++++++++++++++-- + 1 file changed, 15 insertions(+), 2 deletions(-) + +diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c +index 6f7c43904..32dec7fb7 100644 +--- a/grub-core/fs/jfs.c ++++ b/grub-core/fs/jfs.c +@@ -41,6 +41,12 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + #define GRUB_JFS_TREE_LEAF 2 + ++/* ++ * Define max entries stored in-line in an inode. ++ * https://jfs.sourceforge.net/project/pub/jfslayout.pdf ++ */ ++#define GRUB_JFS_INODE_INLINE_ENTRIES 8 ++ + struct grub_jfs_sblock + { + /* The magic for JFS. It should contain the string "JFS1". */ +@@ -203,9 +209,9 @@ struct grub_jfs_inode + grub_uint8_t freecnt; + grub_uint8_t freelist; + grub_uint32_t idotdot; +- grub_uint8_t sorted[8]; ++ grub_uint8_t sorted[GRUB_JFS_INODE_INLINE_ENTRIES]; + } header; +- struct grub_jfs_leaf_dirent dirents[8]; ++ struct grub_jfs_leaf_dirent dirents[GRUB_JFS_INODE_INLINE_ENTRIES]; + } GRUB_PACKED dir; + /* Fast symlink. */ + struct +@@ -453,6 +459,13 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode) + /* Check if the entire tree is contained within the inode. */ + if (inode->file.tree.flags & GRUB_JFS_TREE_LEAF) + { ++ if (inode->dir.header.count > GRUB_JFS_INODE_INLINE_ENTRIES) ++ { ++ grub_free (diro); ++ grub_error (GRUB_ERR_BAD_FS, N_("invalid JFS inode")); ++ return 0; ++ } ++ + diro->leaf = inode->dir.dirents; + diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de; + diro->sorted = inode->dir.header.sorted; diff --git a/0299-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch b/0299-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch new file mode 100644 index 00000000..029e8485 --- /dev/null +++ b/0299-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch @@ -0,0 +1,64 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Fri, 22 Nov 2024 06:28:00 +0000 +Subject: [PATCH] fs/jfs: Fix OOB read caused by invalid dir slot index + +While fuzz testing JFS with ASAN enabled an OOB read was detected in +grub_jfs_opendir(). The issue occurred due to an invalid directory slot +index in the first entry of the sorted directory slot array in the inode +directory header. The fix ensures the slot index is validated before +accessing it. Given that an internal or a leaf node in a directory B+ +tree is a 4 KiB in size and each directory slot is always 32 bytes, the +max number of slots in a node is 128. The validation ensures that the +slot index doesn't exceed this limit. + +[1] https://jfs.sourceforge.net/project/pub/jfslayout.pdf + + JFS will allocate 4K of disk space for an internal node of the B+ tree. + An internal node looks the same as a leaf node. + - page 10 + + Fixed number of Directory Slots depending on the size of the node. These are + the slots to be used for storing the directory slot array and the directory + entries or router entries. A directory slot is always 32 bytes. + ... + A Directory Slot Array which is a sorted array of indices to the directory + slots that are currently in use. + ... + An internal or a leaf node in the directory B+ tree is a 4K page. + - page 25 + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Alec Brown +--- + grub-core/fs/jfs.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c +index 32dec7fb7..88fb884df 100644 +--- a/grub-core/fs/jfs.c ++++ b/grub-core/fs/jfs.c +@@ -46,6 +46,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + * https://jfs.sourceforge.net/project/pub/jfslayout.pdf + */ + #define GRUB_JFS_INODE_INLINE_ENTRIES 8 ++#define GRUB_JFS_DIR_MAX_SLOTS 128 + + struct grub_jfs_sblock + { +@@ -481,6 +482,14 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode) + return 0; + } + ++ if (inode->dir.header.sorted[0] >= GRUB_JFS_DIR_MAX_SLOTS) ++ { ++ grub_error (GRUB_ERR_BAD_FS, N_("invalid directory slot index")); ++ grub_free (diro->dirpage); ++ grub_free (diro); ++ return 0; ++ } ++ + blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2); + blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS); + diff --git a/0300-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch b/0300-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch new file mode 100644 index 00000000..ed387aeb --- /dev/null +++ b/0300-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch @@ -0,0 +1,128 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Mon, 16 Dec 2024 20:22:39 +0000 +Subject: [PATCH] fs/jfs: Use full 40 bits offset and address for a data extent + +An extent's logical offset and address are represented as a 40-bit value +split into two parts: the most significant 8 bits and the least +significant 32 bits. Currently the JFS code uses only the least +significant 32 bits value for offsets and addresses assuming the data +size will never exceed the 32-bit range. This approach ignores the most +significant 8 bits potentially leading to incorrect offsets and +addresses for larger values. The patch fixes it by incorporating the +most significant 8 bits into the calculation to get the full 40-bits +value for offsets and addresses. + +https://jfs.sourceforge.net/project/pub/jfslayout.pdf + + "off1,off2 is a 40-bit field, containing the logical offset of the first + block in the extent. + ... + addr1,addr2 is a 40-bit field, containing the address of the extent." + +Signed-off-by: Lidong Chen +Reviewed-by: Alec Brown +Reviewed-by: Ross Philipson +Reviewed-by: Daniel Kiper +--- + grub-core/fs/jfs.c | 41 +++++++++++++++++++++++++++++------------ + 1 file changed, 29 insertions(+), 12 deletions(-) + +diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c +index 88fb884df..2bde48d45 100644 +--- a/grub-core/fs/jfs.c ++++ b/grub-core/fs/jfs.c +@@ -265,6 +265,20 @@ static grub_dl_t my_mod; + + static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino); + ++/* ++ * An extent's offset, physical and logical, is represented as a 40-bit value. ++ * This 40-bit value is split into two parts: ++ * - offset1: the most signficant 8 bits of the offset, ++ * - offset2: the least significant 32 bits of the offset. ++ * ++ * This function calculates and returns the 64-bit offset of an extent. ++ */ ++static grub_uint64_t ++get_ext_offset (grub_uint8_t offset1, grub_uint32_t offset2) ++{ ++ return (((grub_uint64_t) offset1 << 32) | grub_le_to_cpu32 (offset2)); ++} ++ + static grub_int64_t + getblk (struct grub_jfs_treehead *treehead, + struct grub_jfs_tree_extent *extents, +@@ -274,22 +288,25 @@ getblk (struct grub_jfs_treehead *treehead, + { + int found = -1; + int i; ++ grub_uint64_t ext_offset, ext_blk; + + for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2 && + i < max_extents; i++) + { ++ ext_offset = get_ext_offset (extents[i].offset1, extents[i].offset2); ++ ext_blk = get_ext_offset (extents[i].extent.blk1, extents[i].extent.blk2); ++ + if (treehead->flags & GRUB_JFS_TREE_LEAF) + { + /* Read the leafnode. */ +- if (grub_le_to_cpu32 (extents[i].offset2) <= blk ++ if (ext_offset <= blk + && ((grub_le_to_cpu16 (extents[i].extent.length)) + + (extents[i].extent.length2 << 16) +- + grub_le_to_cpu32 (extents[i].offset2)) > blk) +- return (blk - grub_le_to_cpu32 (extents[i].offset2) +- + grub_le_to_cpu32 (extents[i].extent.blk2)); ++ + ext_offset) > blk) ++ return (blk - ext_offset + ext_blk); + } + else +- if (blk >= grub_le_to_cpu32 (extents[i].offset2)) ++ if (blk >= ext_offset) + found = i; + } + +@@ -307,10 +324,9 @@ getblk (struct grub_jfs_treehead *treehead, + return -1; + + if (!grub_disk_read (data->disk, +- ((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2)) +- << (grub_le_to_cpu16 (data->sblock.log2_blksz) +- - GRUB_DISK_SECTOR_BITS), 0, +- sizeof (*tree), (char *) tree)) ++ (grub_disk_addr_t) ext_blk ++ << (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS), ++ 0, sizeof (*tree), (char *) tree)) + { + if (grub_memcmp (&tree->treehead, treehead, sizeof (struct grub_jfs_treehead)) || + grub_memcmp (&tree->extents, extents, 254 * sizeof (struct grub_jfs_tree_extent))) +@@ -361,7 +377,7 @@ grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino, + sizeof (iag_inodes), &iag_inodes)) + return grub_errno; + +- inoblk = grub_le_to_cpu32 (iag_inodes[inoext].blk2); ++ inoblk = get_ext_offset (iag_inodes[inoext].blk1, iag_inodes[inoext].blk2); + inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) + - GRUB_DISK_SECTOR_BITS); + inoblk += inonum; +@@ -490,7 +506,8 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode) + return 0; + } + +- blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2); ++ blk = get_ext_offset (de[inode->dir.header.sorted[0]].ex.blk1, ++ de[inode->dir.header.sorted[0]].ex.blk2); + blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS); + + /* Read in the nodes until we are on the leaf node level. */ +@@ -508,7 +525,7 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode) + + de = (struct grub_jfs_internal_dirent *) diro->dirpage->dirent; + index = diro->dirpage->sorted[diro->dirpage->header.sindex * 32]; +- blk = (grub_le_to_cpu32 (de[index].ex.blk2) ++ blk = (get_ext_offset (de[index].ex.blk1, de[index].ex.blk2) + << (grub_le_to_cpu16 (data->sblock.log2_blksz) + - GRUB_DISK_SECTOR_BITS)); + } while (!(diro->dirpage->header.flags & GRUB_JFS_TREE_LEAF)); diff --git a/0301-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch b/0301-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch new file mode 100644 index 00000000..33c684b2 --- /dev/null +++ b/0301-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch @@ -0,0 +1,85 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Mon, 16 Dec 2024 20:22:40 +0000 +Subject: [PATCH] fs/jfs: Inconsistent signed/unsigned types usage in return + values + +The getblk() returns a value of type grub_int64_t which is assigned to +iagblk and inoblk, both of type grub_uint64_t, in grub_jfs_read_inode() +via grub_jfs_blkno(). This patch fixes the type mismatch in the +functions. Additionally, the getblk() will return 0 instead of -1 on +failure cases. This change is safe because grub_errno is always set in +getblk() to indicate errors and it is later checked in the callers. + +Signed-off-by: Lidong Chen +Reviewed-by: Alec Brown +Reviewed-by: Ross Philipson +Reviewed-by: Daniel Kiper +--- + grub-core/fs/jfs.c | 15 +++++++++------ + 1 file changed, 9 insertions(+), 6 deletions(-) + +diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c +index 2bde48d45..70a2f4947 100644 +--- a/grub-core/fs/jfs.c ++++ b/grub-core/fs/jfs.c +@@ -279,7 +279,7 @@ get_ext_offset (grub_uint8_t offset1, grub_uint32_t offset2) + return (((grub_uint64_t) offset1 << 32) | grub_le_to_cpu32 (offset2)); + } + +-static grub_int64_t ++static grub_uint64_t + getblk (struct grub_jfs_treehead *treehead, + struct grub_jfs_tree_extent *extents, + int max_extents, +@@ -290,6 +290,8 @@ getblk (struct grub_jfs_treehead *treehead, + int i; + grub_uint64_t ext_offset, ext_blk; + ++ grub_errno = GRUB_ERR_NONE; ++ + for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2 && + i < max_extents; i++) + { +@@ -312,7 +314,7 @@ getblk (struct grub_jfs_treehead *treehead, + + if (found != -1) + { +- grub_int64_t ret = -1; ++ grub_uint64_t ret = 0; + struct + { + struct grub_jfs_treehead treehead; +@@ -321,7 +323,7 @@ getblk (struct grub_jfs_treehead *treehead, + + tree = grub_zalloc (sizeof (*tree)); + if (!tree) +- return -1; ++ return 0; + + if (!grub_disk_read (data->disk, + (grub_disk_addr_t) ext_blk +@@ -334,19 +336,20 @@ getblk (struct grub_jfs_treehead *treehead, + else + { + grub_error (GRUB_ERR_BAD_FS, "jfs: infinite recursion detected"); +- ret = -1; ++ ret = 0; + } + } + grub_free (tree); + return ret; + } + +- return -1; ++ grub_error (GRUB_ERR_READ_ERROR, "jfs: block %" PRIuGRUB_UINT64_T " not found", blk); ++ return 0; + } + + /* Get the block number for the block BLK in the node INODE in the + mounted filesystem DATA. */ +-static grub_int64_t ++static grub_uint64_t + grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, + grub_uint64_t blk) + { diff --git a/0302-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch b/0302-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch new file mode 100644 index 00000000..880ef764 --- /dev/null +++ b/0302-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Fri, 31 May 2024 15:14:23 +0800 +Subject: [PATCH] fs/ext2: Fix out-of-bounds read for inline extents + +When inline extents are used, i.e. the extent tree depth equals zero, +a maximum of four entries can fit into the inode's data block. If the +extent header states a number of entries greater than four the current +ext2 implementation causes an out-of-bounds read. Fix this issue by +capping the number of extents to four when reading inline extents. + +Reported-by: Daniel Axtens +Signed-off-by: Michael Chang +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ext2.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index e1cc5e62a..3f9f6b208 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -495,6 +495,8 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + struct grub_ext4_extent *ext; + int i; + grub_disk_addr_t ret; ++ grub_uint16_t nent; ++ const grub_uint16_t max_inline_ext = sizeof (inode->blocks) / sizeof (*ext) - 1; /* Minus 1 extent header. */ + + if (grub_ext4_find_leaf (data, (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, + fileblock, &leaf) != GRUB_ERR_NONE) +@@ -508,7 +510,13 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + return 0; + + ext = (struct grub_ext4_extent *) (leaf + 1); +- for (i = 0; i < grub_le_to_cpu16 (leaf->entries); i++) ++ ++ nent = grub_le_to_cpu16 (leaf->entries); ++ ++ if (leaf->depth == 0) ++ nent = grub_min (nent, max_inline_ext); ++ ++ for (i = 0; i < nent; i++) + { + if (fileblock < grub_le_to_cpu32 (ext[i].block)) + break; diff --git a/0303-fs-ntfs-Fix-out-of-bounds-read.patch b/0303-fs-ntfs-Fix-out-of-bounds-read.patch new file mode 100644 index 00000000..4d4acdce --- /dev/null +++ b/0303-fs-ntfs-Fix-out-of-bounds-read.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Mon, 3 Jun 2024 12:12:06 +0800 +Subject: [PATCH] fs/ntfs: Fix out-of-bounds read + +When parsing NTFS file records the presence of the 0xFF marker indicates +the end of the attribute list. This value signifies that there are no +more attributes to process. + +However, when the end marker is missing due to corrupted metadata the +loop continues to read beyond the attribute list resulting in out-of-bounds +reads and potentially entering an infinite loop. + +This patch adds a check to provide a stop condition for the loop ensuring +it stops at the end of the attribute list or at the end of the Master File +Table. This guards against out-of-bounds reads and prevents infinite loops. + +Reported-by: Daniel Axtens +Signed-off-by: Michael Chang +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ntfs.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index de435aa14..8a5384247 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -139,6 +139,8 @@ free_attr (struct grub_ntfs_attr *at) + static grub_uint8_t * + find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + { ++ grub_uint8_t *mft_end; ++ + if (at->flags & GRUB_NTFS_AF_ALST) + { + retry: +@@ -191,7 +193,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + return NULL; + } + at->attr_cur = at->attr_nxt; +- while (*at->attr_cur != 0xFF) ++ mft_end = at->mft->buf + (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR); ++ while (at->attr_cur < mft_end && *at->attr_cur != 0xFF) + { + at->attr_nxt += u16at (at->attr_cur, 4); + if (*at->attr_cur == GRUB_NTFS_AT_ATTRIBUTE_LIST) diff --git a/0304-fs-ntfs-Track-the-end-of-the-MFT-attribute-buffer.patch b/0304-fs-ntfs-Track-the-end-of-the-MFT-attribute-buffer.patch new file mode 100644 index 00000000..e6a5c144 --- /dev/null +++ b/0304-fs-ntfs-Track-the-end-of-the-MFT-attribute-buffer.patch @@ -0,0 +1,141 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 7 Jan 2025 11:38:34 +0000 +Subject: [PATCH] fs/ntfs: Track the end of the MFT attribute buffer + +The end of the attribute buffer should be stored alongside the rest of +the attribute struct as right now it is not possible to implement bounds +checking when accessing attributes sequentially. + +This is done via: + - updating init_attr() to set at->end and check is is not initially out of bounds, + - implementing checks as init_attr() had its type change in its callers, + - updating the value of at->end when needed. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ntfs.c | 34 ++++++++++++++++++++++++++++------ + include/grub/ntfs.h | 1 + + 2 files changed, 29 insertions(+), 6 deletions(-) + +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index 8a5384247..dbda720e1 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -119,13 +119,20 @@ static grub_err_t read_data (struct grub_ntfs_attr *at, grub_uint8_t *pa, + grub_disk_read_hook_t read_hook, + void *read_hook_data); + +-static void ++static grub_err_t + init_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft) + { + at->mft = mft; + at->flags = (mft == &mft->data->mmft) ? GRUB_NTFS_AF_MMFT : 0; + at->attr_nxt = mft->buf + first_attr_off (mft->buf); ++ at->end = mft->buf + (mft->data->mft_size << GRUB_NTFS_BLK_SHR); ++ ++ if (at->attr_nxt > at->end) ++ return grub_error (GRUB_ERR_BAD_FS, "attributes start outside the MFT"); ++ + at->attr_end = at->emft_buf = at->edat_buf = at->sbuf = NULL; ++ ++ return GRUB_ERR_NONE; + } + + static void +@@ -239,6 +246,10 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + pa_end = at->mft->buf + (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR); + } + at->flags |= GRUB_NTFS_AF_ALST; ++ ++ /* From this point on pa_end is the end of the buffer */ ++ at->end = pa_end; ++ + while (at->attr_nxt < at->attr_end) + { + if ((*at->attr_nxt == attr) || (attr == 0)) +@@ -298,7 +309,9 @@ locate_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft, + { + grub_uint8_t *pa; + +- init_attr (at, mft); ++ if (init_attr (at, mft) != GRUB_ERR_NONE) ++ return NULL; ++ + pa = find_attr (at, attr); + if (pa == NULL) + return NULL; +@@ -314,7 +327,8 @@ locate_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft, + } + grub_errno = GRUB_ERR_NONE; + free_attr (at); +- init_attr (at, mft); ++ if (init_attr (at, mft) != GRUB_ERR_NONE) ++ return NULL; + pa = find_attr (at, attr); + } + return pa; +@@ -585,7 +599,7 @@ init_file (struct grub_ntfs_file *mft, grub_uint64_t mftno) + mft->attr.attr_end = 0; /* Don't jump to attribute list */ + } + else +- init_attr (&mft->attr, mft); ++ return init_attr (&mft->attr, mft); + + return 0; + } +@@ -811,7 +825,9 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir, + bmp = NULL; + + at = &attr; +- init_attr (at, mft); ++ if (init_attr (at, mft) != GRUB_ERR_NONE) ++ return 0; ++ + while (1) + { + cur_pos = find_attr (at, GRUB_NTFS_AT_INDEX_ROOT); +@@ -842,7 +858,9 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir, + bitmap = NULL; + bitmap_len = 0; + free_attr (at); ++ /* No need to check errors here, as it will already be fine */ + init_attr (at, mft); ++ + while ((cur_pos = find_attr (at, GRUB_NTFS_AT_BITMAP)) != NULL) + { + int ofs; +@@ -1207,6 +1225,7 @@ grub_ntfs_label (grub_device_t device, char **label) + struct grub_ntfs_data *data = 0; + struct grub_fshelp_node *mft = 0; + grub_uint8_t *pa; ++ grub_err_t err; + + grub_dl_ref (my_mod); + +@@ -1232,7 +1251,10 @@ grub_ntfs_label (grub_device_t device, char **label) + goto fail; + } + +- init_attr (&mft->attr, mft); ++ err = init_attr (&mft->attr, mft); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ + pa = find_attr (&mft->attr, GRUB_NTFS_AT_VOLUME_NAME); + + if (pa >= mft->buf + (mft->data->mft_size << GRUB_NTFS_BLK_SHR)) +diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h +index d1a6af696..ec1c4db38 100644 +--- a/include/grub/ntfs.h ++++ b/include/grub/ntfs.h +@@ -134,6 +134,7 @@ struct grub_ntfs_attr + grub_uint8_t *attr_cur, *attr_nxt, *attr_end; + grub_uint32_t save_pos; + grub_uint8_t *sbuf; ++ grub_uint8_t *end; + struct grub_ntfs_file *mft; + }; + diff --git a/0305-fs-ntfs-Use-a-helper-function-to-access-attributes.patch b/0305-fs-ntfs-Use-a-helper-function-to-access-attributes.patch new file mode 100644 index 00000000..aede4b40 --- /dev/null +++ b/0305-fs-ntfs-Use-a-helper-function-to-access-attributes.patch @@ -0,0 +1,183 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 14 May 2024 12:39:56 +0100 +Subject: [PATCH] fs/ntfs: Use a helper function to access attributes + +Right now to access the next attribute the code reads the length of the +current attribute and adds that to the current pointer. This is error +prone as bounds checking needs to be performed all over the place. So, +implement a helper and ensure its used across find_attr() and read_attr(). + +This commit does *not* implement full bounds checking. It is just the +preparation work for this to be added into the helper. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ntfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++---------- + include/grub/ntfs.h | 2 ++ + 2 files changed, 58 insertions(+), 13 deletions(-) + +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index dbda720e1..1c678f3d0 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -70,6 +70,25 @@ res_attr_data_len (void *res_attr_ptr) + return u32at (res_attr_ptr, 0x10); + } + ++/* Return the next attribute if it exists, otherwise return NULL. */ ++static grub_uint8_t * ++next_attribute (grub_uint8_t *curr_attribute, void *end) ++{ ++ grub_uint8_t *next = curr_attribute; ++ ++ /* ++ * Need to verify we aren't exceeding the end of the buffer by reading the ++ * header for the current attribute ++ */ ++ if (curr_attribute + GRUB_NTFS_ATTRIBUTE_HEADER_SIZE >= (grub_uint8_t *) end) ++ return NULL; ++ ++ next += u16at (curr_attribute, 4); ++ ++ return next; ++} ++ ++ + grub_ntfscomp_func_t grub_ntfscomp_func; + + static grub_err_t +@@ -151,13 +170,13 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + if (at->flags & GRUB_NTFS_AF_ALST) + { + retry: +- while (at->attr_nxt < at->attr_end) ++ while (at->attr_nxt) + { + at->attr_cur = at->attr_nxt; +- at->attr_nxt += u16at (at->attr_cur, 4); ++ at->attr_nxt = next_attribute (at->attr_cur, at->attr_end); + if ((*at->attr_cur == attr) || (attr == 0)) + { +- grub_uint8_t *new_pos; ++ grub_uint8_t *new_pos, *end; + + if (at->flags & GRUB_NTFS_AF_MMFT) + { +@@ -181,15 +200,36 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + return NULL; + } + ++ /* ++ * Only time emft_bufs is defined is in this function, with this ++ * size. ++ */ ++ grub_size_t emft_buf_size = ++ at->mft->data->mft_size << GRUB_NTFS_BLK_SHR; ++ ++ /* ++ * Needs to be enough space for the successful case to even ++ * bother. ++ */ ++ if (first_attr_off (at->emft_buf) >= (emft_buf_size - 0x18 - 2)) ++ { ++ grub_error (GRUB_ERR_BAD_FS, ++ "can\'t find 0x%X in attribute list", ++ (unsigned char) *at->attr_cur); ++ return NULL; ++ } ++ + new_pos = &at->emft_buf[first_attr_off (at->emft_buf)]; +- while (*new_pos != 0xFF) ++ end = &at->emft_buf[emft_buf_size]; ++ ++ while (new_pos && *new_pos != 0xFF) + { + if ((*new_pos == *at->attr_cur) + && (u16at (new_pos, 0xE) == u16at (at->attr_cur, 0x18))) + { + return new_pos; + } +- new_pos += u16at (new_pos, 4); ++ new_pos = next_attribute (new_pos, end); + } + grub_error (GRUB_ERR_BAD_FS, + "can\'t find 0x%X in attribute list", +@@ -203,7 +243,7 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + mft_end = at->mft->buf + (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR); + while (at->attr_cur < mft_end && *at->attr_cur != 0xFF) + { +- at->attr_nxt += u16at (at->attr_cur, 4); ++ at->attr_nxt = next_attribute (at->attr_cur, at->end); + if (*at->attr_cur == GRUB_NTFS_AT_ATTRIBUTE_LIST) + at->attr_end = at->attr_cur; + if ((*at->attr_cur == attr) || (attr == 0)) +@@ -250,13 +290,14 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + /* From this point on pa_end is the end of the buffer */ + at->end = pa_end; + +- while (at->attr_nxt < at->attr_end) ++ while (at->attr_nxt) + { + if ((*at->attr_nxt == attr) || (attr == 0)) + break; +- at->attr_nxt += u16at (at->attr_nxt, 4); ++ at->attr_nxt = next_attribute (at->attr_nxt, pa_end); + } +- if (at->attr_nxt >= at->attr_end) ++ ++ if (at->attr_nxt >= at->attr_end || at->attr_nxt == NULL) + return NULL; + + if ((at->flags & GRUB_NTFS_AF_MMFT) && (attr == GRUB_NTFS_AT_DATA)) +@@ -277,7 +318,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + grub_cpu_to_le32 (at->mft->data->mft_start + + 1)); + pa = at->attr_nxt + u16at (pa, 4); +- while (pa < at->attr_end) ++ ++ while (pa) + { + if (*pa != attr) + break; +@@ -293,7 +335,7 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) + u32at (pa, 0x10) * (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR), + at->mft->data->mft_size << GRUB_NTFS_BLK_SHR, 0, 0, 0)) + return NULL; +- pa += u16at (pa, 4); ++ pa = next_attribute (pa, pa_end); + } + at->attr_nxt = at->attr_cur; + at->flags &= ~GRUB_NTFS_AF_GPOS; +@@ -530,14 +572,15 @@ read_attr (struct grub_ntfs_attr *at, grub_uint8_t *dest, grub_disk_addr_t ofs, + else + vcn = ofs >> (at->mft->data->log_spc + GRUB_NTFS_BLK_SHR); + pa = at->attr_nxt + u16at (at->attr_nxt, 4); +- while (pa < at->attr_end) ++ ++ while (pa) + { + if (*pa != attr) + break; + if (u32at (pa, 8) > vcn) + break; + at->attr_nxt = pa; +- pa += u16at (pa, 4); ++ pa = next_attribute (pa, at->attr_end); + } + } + pp = find_attr (at, attr); +diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h +index ec1c4db38..2c8078403 100644 +--- a/include/grub/ntfs.h ++++ b/include/grub/ntfs.h +@@ -89,6 +89,8 @@ enum + #define GRUB_NTFS_COM_SEC (GRUB_NTFS_COM_LEN >> GRUB_NTFS_BLK_SHR) + #define GRUB_NTFS_LOG_COM_SEC (GRUB_NTFS_COM_LOG_LEN - GRUB_NTFS_BLK_SHR) + ++#define GRUB_NTFS_ATTRIBUTE_HEADER_SIZE 16 ++ + enum + { + GRUB_NTFS_AF_ALST = 1, diff --git a/0307-fs-xfs-Fix-out-of-bounds-read.patch b/0307-fs-xfs-Fix-out-of-bounds-read.patch new file mode 100644 index 00000000..a71ff511 --- /dev/null +++ b/0307-fs-xfs-Fix-out-of-bounds-read.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Fri, 31 May 2024 15:14:57 +0800 +Subject: [PATCH] fs/xfs: Fix out-of-bounds read + +The number of records in the root key array read from disk was not being +validated against the size of the root node. This could lead to an +out-of-bounds read. + +This patch adds a check to ensure that the number of records in the root +key array does not exceed the expected size of a root node read from +disk. If this check detects an out-of-bounds condition the operation is +aborted to prevent random errors due to metadata corruption. + +Reported-by: Daniel Axtens +Signed-off-by: Michael Chang +Reviewed-by: Daniel Kiper +--- + grub-core/fs/xfs.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 92046f9bd..96f62c5a4 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -595,6 +595,17 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + do + { + grub_uint64_t i; ++ grub_addr_t keys_end, data_end; ++ ++ if (grub_mul (sizeof (grub_uint64_t), nrec, &keys_end) || ++ grub_add ((grub_addr_t) keys, keys_end, &keys_end) || ++ grub_add ((grub_addr_t) node->data, node->data->data_size, &data_end) || ++ keys_end > data_end) ++ { ++ grub_error (GRUB_ERR_BAD_FS, "invalid number of XFS root keys"); ++ grub_free (leaf); ++ return 0; ++ } + + for (i = 0; i < nrec; i++) + { diff --git a/0308-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch b/0308-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch new file mode 100644 index 00000000..39f0adaa --- /dev/null +++ b/0308-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 06:03:58 +0100 +Subject: [PATCH] fs/xfs: Ensuring failing to mount sets a grub_errno + +It was previously possible for grub_xfs_mount() to return NULL without +setting grub_errno if the XFS version was invalid. This resulted in it +being possible for grub_dl_unref() to be called twice allowing the XFS +module to be unloaded while there were still references to it. + +Fixing this problem in general by ensuring a grub_errno is set if the +fail label is reached. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/xfs.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 96f62c5a4..a837f9824 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -327,6 +327,8 @@ static int grub_xfs_sb_valid(struct grub_xfs_data *data) + } + return 1; + } ++ ++ grub_error (GRUB_ERR_BAD_FS, "unsupported XFS filesystem version"); + return 0; + } + +@@ -1068,7 +1070,7 @@ grub_xfs_mount (grub_disk_t disk) + return data; + fail: + +- if (grub_errno == GRUB_ERR_OUT_OF_RANGE) ++ if (grub_errno == GRUB_ERR_OUT_OF_RANGE || grub_errno == GRUB_ERR_NONE) + grub_error (GRUB_ERR_BAD_FS, "not an XFS filesystem"); + + grub_free (data); diff --git a/0309-kern-file-Ensure-file-data-is-set.patch b/0309-kern-file-Ensure-file-data-is-set.patch new file mode 100644 index 00000000..260d1b08 --- /dev/null +++ b/0309-kern-file-Ensure-file-data-is-set.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 03:01:40 +0100 +Subject: [PATCH] kern/file: Ensure file->data is set + +This is to avoid a generic issue were some filesystems would not set +data and also not set a grub_errno. This meant it was possible for many +filesystems to grub_dl_unref() themselves multiple times resulting in +it being possible to unload the filesystems while there were still +references to them, e.g., via a loopback. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/kern/file.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c +index 75510df7c..85e832bd8 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -124,6 +124,9 @@ grub_file_open (const char *name, enum grub_file_type type) + if ((file->fs->fs_open) (file, file_name) != GRUB_ERR_NONE) + goto fail; + ++ if (file->data == NULL) ++ goto fail; ++ + file->name = grub_strdup (name); + grub_errno = GRUB_ERR_NONE; + diff --git a/0310-kern-file-Implement-filesystem-reference-counting.patch b/0310-kern-file-Implement-filesystem-reference-counting.patch new file mode 100644 index 00000000..348bebed --- /dev/null +++ b/0310-kern-file-Implement-filesystem-reference-counting.patch @@ -0,0 +1,440 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 13:44:25 -0600 +Subject: [PATCH] kern/file: Implement filesystem reference counting + +The grub_file_open() and grub_file_close() should be the only places +that allow a reference to a filesystem to stay open. So, add grub_dl_t +to grub_fs_t and set this in the GRUB_MOD_INIT() for each filesystem to +avoid issues when filesystems forget to do it themselves or do not track +their own references, e.g. squash4. + +The fs_label(), fs_uuid(), fs_mtime() and fs_read() should all ref and +unref in the same function but it is essentially redundant in GRUB +single threaded model. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/fs/affs.c | 1 + + grub-core/fs/bfs.c | 1 + + grub-core/fs/btrfs.c | 1 + + grub-core/fs/cbfs.c | 1 + + grub-core/fs/cpio.c | 1 + + grub-core/fs/cpio_be.c | 1 + + grub-core/fs/ext2.c | 1 + + grub-core/fs/f2fs.c | 1 + + grub-core/fs/fat.c | 1 + + grub-core/fs/hfs.c | 1 + + grub-core/fs/hfsplus.c | 1 + + grub-core/fs/iso9660.c | 1 + + grub-core/fs/jfs.c | 1 + + grub-core/fs/minix.c | 1 + + grub-core/fs/newc.c | 1 + + grub-core/fs/nilfs2.c | 1 + + grub-core/fs/ntfs.c | 1 + + grub-core/fs/odc.c | 1 + + grub-core/fs/proc.c | 1 + + grub-core/fs/reiserfs.c | 1 + + grub-core/fs/romfs.c | 1 + + grub-core/fs/sfs.c | 1 + + grub-core/fs/squash4.c | 1 + + grub-core/fs/tar.c | 1 + + grub-core/fs/udf.c | 1 + + grub-core/fs/ufs.c | 1 + + grub-core/fs/xfs.c | 1 + + grub-core/fs/zfs/zfs.c | 1 + + grub-core/kern/file.c | 7 +++++++ + include/grub/fs.h | 4 ++++ + 30 files changed, 39 insertions(+) + +diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c +index ed606b3f1..9b0afb954 100644 +--- a/grub-core/fs/affs.c ++++ b/grub-core/fs/affs.c +@@ -703,6 +703,7 @@ static struct grub_fs grub_affs_fs = + + GRUB_MOD_INIT(affs) + { ++ grub_affs_fs.mod = mod; + grub_fs_register (&grub_affs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/bfs.c b/grub-core/fs/bfs.c +index 07cb3e3ac..f37b16895 100644 +--- a/grub-core/fs/bfs.c ++++ b/grub-core/fs/bfs.c +@@ -1106,6 +1106,7 @@ GRUB_MOD_INIT (bfs) + { + COMPILE_TIME_ASSERT (1 << LOG_EXTENT_SIZE == + sizeof (struct grub_bfs_extent)); ++ grub_bfs_fs.mod = mod; + grub_fs_register (&grub_bfs_fs); + } + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index ad35e7575..6593f5175 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -3402,6 +3402,7 @@ subvol_get_env (struct grub_env_var *var __attribute__ ((unused)), + + GRUB_MOD_INIT (btrfs) + { ++ grub_btrfs_fs.mod = mod; + grub_fs_register (&grub_btrfs_fs); + cmd_info = grub_register_command("btrfs-info", grub_cmd_btrfs_info, + "DEVICE", +diff --git a/grub-core/fs/cbfs.c b/grub-core/fs/cbfs.c +index 8ab7106af..2332745fe 100644 +--- a/grub-core/fs/cbfs.c ++++ b/grub-core/fs/cbfs.c +@@ -390,6 +390,7 @@ GRUB_MOD_INIT (cbfs) + #if (defined (__i386__) || defined (__x86_64__)) && !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_MACHINE_XEN) + init_cbfsdisk (); + #endif ++ grub_cbfs_fs.mod = mod; + grub_fs_register (&grub_cbfs_fs); + } + +diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c +index dab5f9898..1799f7ff5 100644 +--- a/grub-core/fs/cpio.c ++++ b/grub-core/fs/cpio.c +@@ -52,6 +52,7 @@ read_number (const grub_uint16_t *arr, grub_size_t size) + + GRUB_MOD_INIT (cpio) + { ++ grub_cpio_fs.mod = mod; + grub_fs_register (&grub_cpio_fs); + } + +diff --git a/grub-core/fs/cpio_be.c b/grub-core/fs/cpio_be.c +index 846548892..7bed1b848 100644 +--- a/grub-core/fs/cpio_be.c ++++ b/grub-core/fs/cpio_be.c +@@ -52,6 +52,7 @@ read_number (const grub_uint16_t *arr, grub_size_t size) + + GRUB_MOD_INIT (cpio_be) + { ++ grub_cpio_fs.mod = mod; + grub_fs_register (&grub_cpio_fs); + } + +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index 3f9f6b208..c3058f7e7 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -1131,6 +1131,7 @@ static struct grub_fs grub_ext2_fs = + + GRUB_MOD_INIT(ext2) + { ++ grub_ext2_fs.mod = mod; + grub_fs_register (&grub_ext2_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c +index db8a65f8d..f6d6beaa5 100644 +--- a/grub-core/fs/f2fs.c ++++ b/grub-core/fs/f2fs.c +@@ -1353,6 +1353,7 @@ static struct grub_fs grub_f2fs_fs = { + + GRUB_MOD_INIT (f2fs) + { ++ grub_f2fs_fs.mod = mod; + grub_fs_register (&grub_f2fs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c +index c5efed724..6e62b915d 100644 +--- a/grub-core/fs/fat.c ++++ b/grub-core/fs/fat.c +@@ -1312,6 +1312,7 @@ GRUB_MOD_INIT(fat) + #endif + { + COMPILE_TIME_ASSERT (sizeof (struct grub_fat_dir_entry) == 32); ++ grub_fat_fs.mod = mod; + grub_fs_register (&grub_fat_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c +index 920112b03..ce7581dd5 100644 +--- a/grub-core/fs/hfs.c ++++ b/grub-core/fs/hfs.c +@@ -1434,6 +1434,7 @@ static struct grub_fs grub_hfs_fs = + + GRUB_MOD_INIT(hfs) + { ++ grub_hfs_fs.mod = mod; + if (!grub_is_lockdown ()) + grub_fs_register (&grub_hfs_fs); + my_mod = mod; +diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c +index de71fd486..3f203abcc 100644 +--- a/grub-core/fs/hfsplus.c ++++ b/grub-core/fs/hfsplus.c +@@ -1176,6 +1176,7 @@ static struct grub_fs grub_hfsplus_fs = + + GRUB_MOD_INIT(hfsplus) + { ++ grub_hfsplus_fs.mod = mod; + grub_fs_register (&grub_hfsplus_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 8e3c95c4f..c73cb9ce0 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -1260,6 +1260,7 @@ static struct grub_fs grub_iso9660_fs = + + GRUB_MOD_INIT(iso9660) + { ++ grub_iso9660_fs.mod = mod; + grub_fs_register (&grub_iso9660_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c +index 70a2f4947..b0283ac00 100644 +--- a/grub-core/fs/jfs.c ++++ b/grub-core/fs/jfs.c +@@ -1005,6 +1005,7 @@ static struct grub_fs grub_jfs_fs = + + GRUB_MOD_INIT(jfs) + { ++ grub_jfs_fs.mod = mod; + grub_fs_register (&grub_jfs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c +index 5354951d1..b7679c3e2 100644 +--- a/grub-core/fs/minix.c ++++ b/grub-core/fs/minix.c +@@ -734,6 +734,7 @@ GRUB_MOD_INIT(minix) + #endif + #endif + { ++ grub_minix_fs.mod = mod; + grub_fs_register (&grub_minix_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/newc.c b/grub-core/fs/newc.c +index 4fb8b2e3d..43b7f8b64 100644 +--- a/grub-core/fs/newc.c ++++ b/grub-core/fs/newc.c +@@ -64,6 +64,7 @@ read_number (const char *str, grub_size_t size) + + GRUB_MOD_INIT (newc) + { ++ grub_cpio_fs.mod = mod; + grub_fs_register (&grub_cpio_fs); + } + +diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c +index fc7374ead..4e1e71738 100644 +--- a/grub-core/fs/nilfs2.c ++++ b/grub-core/fs/nilfs2.c +@@ -1231,6 +1231,7 @@ GRUB_MOD_INIT (nilfs2) + grub_nilfs2_dat_entry)); + COMPILE_TIME_ASSERT (1 << LOG_INODE_SIZE + == sizeof (struct grub_nilfs2_inode)); ++ grub_nilfs2_fs.mod = mod; + grub_fs_register (&grub_nilfs2_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index 64f4f2221..4e144cc3c 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -1541,6 +1541,7 @@ static struct grub_fs grub_ntfs_fs = + + GRUB_MOD_INIT (ntfs) + { ++ grub_ntfs_fs.mod = mod; + grub_fs_register (&grub_ntfs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/odc.c b/grub-core/fs/odc.c +index 790000622..8e4e8aeac 100644 +--- a/grub-core/fs/odc.c ++++ b/grub-core/fs/odc.c +@@ -52,6 +52,7 @@ read_number (const char *str, grub_size_t size) + + GRUB_MOD_INIT (odc) + { ++ grub_cpio_fs.mod = mod; + grub_fs_register (&grub_cpio_fs); + } + +diff --git a/grub-core/fs/proc.c b/grub-core/fs/proc.c +index 5f516502d..bcde43349 100644 +--- a/grub-core/fs/proc.c ++++ b/grub-core/fs/proc.c +@@ -192,6 +192,7 @@ static struct grub_fs grub_procfs_fs = + + GRUB_MOD_INIT (procfs) + { ++ grub_procfs_fs.mod = mod; + grub_disk_dev_register (&grub_procfs_dev); + grub_fs_register (&grub_procfs_fs); + } +diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c +index 42818c376..e8b0b6383 100644 +--- a/grub-core/fs/reiserfs.c ++++ b/grub-core/fs/reiserfs.c +@@ -1407,6 +1407,7 @@ static struct grub_fs grub_reiserfs_fs = + + GRUB_MOD_INIT(reiserfs) + { ++ grub_reiserfs_fs.mod = mod; + grub_fs_register (&grub_reiserfs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c +index 1f7dcfca1..56b0b2b2f 100644 +--- a/grub-core/fs/romfs.c ++++ b/grub-core/fs/romfs.c +@@ -475,6 +475,7 @@ static struct grub_fs grub_romfs_fs = + + GRUB_MOD_INIT(romfs) + { ++ grub_romfs_fs.mod = mod; + grub_fs_register (&grub_romfs_fs); + } + +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index 983e88008..f0d7cac43 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -779,6 +779,7 @@ static struct grub_fs grub_sfs_fs = + + GRUB_MOD_INIT(sfs) + { ++ grub_sfs_fs.mod = mod; + grub_fs_register (&grub_sfs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c +index a30e6ebe1..6e9d63874 100644 +--- a/grub-core/fs/squash4.c ++++ b/grub-core/fs/squash4.c +@@ -1044,6 +1044,7 @@ static struct grub_fs grub_squash_fs = + + GRUB_MOD_INIT(squash4) + { ++ grub_squash_fs.mod = mod; + grub_fs_register (&grub_squash_fs); + } + +diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c +index 386c09022..fd2ec1f74 100644 +--- a/grub-core/fs/tar.c ++++ b/grub-core/fs/tar.c +@@ -354,6 +354,7 @@ static struct grub_fs grub_cpio_fs = { + + GRUB_MOD_INIT (tar) + { ++ grub_cpio_fs.mod = mod; + grub_fs_register (&grub_cpio_fs); + } + +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index b836e6107..8765c633c 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -1455,6 +1455,7 @@ static struct grub_fs grub_udf_fs = { + + GRUB_MOD_INIT (udf) + { ++ grub_udf_fs.mod = mod; + grub_fs_register (&grub_udf_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c +index 01235101b..e82d9356d 100644 +--- a/grub-core/fs/ufs.c ++++ b/grub-core/fs/ufs.c +@@ -899,6 +899,7 @@ GRUB_MOD_INIT(ufs1) + #endif + #endif + { ++ grub_ufs_fs.mod = mod; + grub_fs_register (&grub_ufs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index a837f9824..6c952aef1 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -1304,6 +1304,7 @@ static struct grub_fs grub_xfs_fs = + + GRUB_MOD_INIT(xfs) + { ++ grub_xfs_fs.mod = mod; + grub_fs_register (&grub_xfs_fs); + my_mod = mod; + } +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index b5453e006..a497b1869 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -4424,6 +4424,7 @@ static struct grub_fs grub_zfs_fs = { + GRUB_MOD_INIT (zfs) + { + COMPILE_TIME_ASSERT (sizeof (zap_leaf_chunk_t) == ZAP_LEAF_CHUNKSIZE); ++ grub_zfs_fs.mod = mod; + grub_fs_register (&grub_zfs_fs); + #ifndef GRUB_UTIL + my_mod = mod; +diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c +index 85e832bd8..ec90a26ba 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + void (*EXPORT_VAR (grub_grubnet_fini)) (void); + +@@ -127,6 +128,9 @@ grub_file_open (const char *name, enum grub_file_type type) + if (file->data == NULL) + goto fail; + ++ if (file->fs->mod) ++ grub_dl_ref (file->fs->mod); ++ + file->name = grub_strdup (name); + grub_errno = GRUB_ERR_NONE; + +@@ -219,6 +223,9 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) + grub_err_t + grub_file_close (grub_file_t file) + { ++ if (file->fs->mod) ++ grub_dl_unref (file->fs->mod); ++ + grub_dprintf ("file", "Closing `%s' ...\n", file->name); + if (file->fs->fs_close) + (file->fs->fs_close) (file); +diff --git a/include/grub/fs.h b/include/grub/fs.h +index 026bc3bb8..df4c93b16 100644 +--- a/include/grub/fs.h ++++ b/include/grub/fs.h +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + #include + /* For embedding types. */ +@@ -57,6 +58,9 @@ struct grub_fs + /* My name. */ + const char *name; + ++ /* My module */ ++ grub_dl_t mod; ++ + /* Call HOOK with each file under DIR. */ + grub_err_t (*fs_dir) (grub_device_t device, const char *path, + grub_fs_dir_hook_t hook, void *hook_data); diff --git a/0311-cli_lock-Add-build-option-to-block-command-line-inte.patch b/0311-cli_lock-Add-build-option-to-block-command-line-inte.patch new file mode 100644 index 00000000..3c7d6414 --- /dev/null +++ b/0311-cli_lock-Add-build-option-to-block-command-line-inte.patch @@ -0,0 +1,366 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 24 Jan 2024 06:26:37 +0000 +Subject: [PATCH] cli_lock: Add build option to block command line interface + +Add functionality to disable command line interface access and editing of GRUB +menu entries if GRUB image is built with --disable-cli. + +Signed-off-by: Alec Brown +Reviewed-by: Vladimir Serbinenko +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 6 ++++-- + grub-core/kern/main.c | 28 ++++++++++++++++++++++++++++ + grub-core/kern/rescue_reader.c | 13 +++++++++++++ + grub-core/normal/auth.c | 3 +++ + grub-core/normal/menu_text.c | 31 +++++++++++++++++-------------- + include/grub/kernel.h | 1 + + include/grub/misc.h | 2 ++ + include/grub/util/install.h | 8 ++++++-- + util/grub-install-common.c | 10 ++++++++-- + util/grub-mkimage.c | 9 ++++++++- + util/mkimage.c | 15 ++++++++++++++- + 11 files changed, 104 insertions(+), 22 deletions(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 096a3cde0..9ce9c5b82 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -6520,8 +6520,10 @@ the GRUB command line, edit menu entries, and execute any menu entry. If + @samp{superusers} is set, then use of the command line and editing of menu + entries are automatically restricted to superusers. Setting @samp{superusers} + to empty string effectively disables both access to CLI and editing of menu +-entries. Note: The environment variable needs to be exported to also affect +-the section defined by the @samp{submenu} command (@pxref{submenu}). ++entries. Building a grub image with @samp{--disable-cli} option will also ++disable access to CLI and editing of menu entries, as well as disabling rescue ++mode. Note: The environment variable needs to be exported to also affect the ++section defined by the @samp{submenu} command (@pxref{submenu}). + + Other users may be allowed to execute specific menu entries by giving a list of + usernames (as above) using the @option{--users} option to the +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index 8e89763f4..0d6b8138d 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -30,11 +30,14 @@ + #include + #include + #include ++#include + + #ifdef GRUB_MACHINE_PCBIOS + #include + #endif + ++static bool cli_disabled = false; ++ + grub_addr_t + grub_modules_get_end (void) + { +@@ -299,6 +302,28 @@ grub_load_normal_mode (void) + grub_command_execute ("normal", 0, 0); + } + ++bool ++grub_is_cli_disabled (void) ++{ ++ return cli_disabled; ++} ++ ++static void ++check_is_cli_disabled (void) ++{ ++ struct grub_module_header *header; ++ header = 0; ++ ++ FOR_MODULES (header) ++ { ++ if (header->type == OBJ_TYPE_DISABLE_CLI) ++ { ++ cli_disabled = true; ++ return; ++ } ++ } ++} ++ + static void + reclaim_module_space (void) + { +@@ -356,6 +381,9 @@ grub_main (void) + + grub_boot_time ("After loading embedded modules."); + ++ /* Check if the CLI should be disabled */ ++ check_is_cli_disabled (); ++ + /* It is better to set the root device as soon as possible, + for convenience. */ + grub_set_prefix_and_root (); +diff --git a/grub-core/kern/rescue_reader.c b/grub-core/kern/rescue_reader.c +index dcd7d4439..4259857ba 100644 +--- a/grub-core/kern/rescue_reader.c ++++ b/grub-core/kern/rescue_reader.c +@@ -78,6 +78,19 @@ grub_rescue_read_line (char **line, int cont, + void __attribute__ ((noreturn)) + grub_rescue_run (void) + { ++ /* Stall if the CLI has been disabled */ ++ if (grub_is_cli_disabled ()) ++ { ++ grub_printf ("Rescue mode has been disabled...\n"); ++ ++ do ++ { ++ /* Do not optimize out the loop. */ ++ asm volatile (""); ++ } ++ while (1); ++ } ++ + grub_printf ("Entering rescue mode...\n"); + + while (1) +diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c +index 517fc623f..d94020186 100644 +--- a/grub-core/normal/auth.c ++++ b/grub-core/normal/auth.c +@@ -209,6 +209,9 @@ grub_auth_check_authentication (const char *userlist) + char entered[GRUB_AUTH_MAX_PASSLEN]; + struct grub_auth_user *user; + ++ if (grub_is_cli_disabled ()) ++ return GRUB_ACCESS_DENIED; ++ + grub_memset (login, 0, sizeof (login)); + + if (is_authenticated (userlist)) +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index b1321eb26..9c383e64a 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -178,21 +178,24 @@ command-line or ESC to discard edits and return to the GRUB menu."), + + grub_free (msg_translated); + +- if (nested) ++ if (!grub_is_cli_disabled ()) + { +- ret += grub_print_message_indented_real +- (_("Press enter to boot the selected OS, " +- "`e' to edit the commands before booting " +- "or `c' for a command-line. ESC to return previous menu."), +- STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); +- } +- else +- { +- ret += grub_print_message_indented_real +- (_("Press enter to boot the selected OS, " +- "`e' to edit the commands before booting " +- "or `c' for a command-line."), +- STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); ++ if (nested) ++ { ++ ret += grub_print_message_indented_real ++ (_("Press enter to boot the selected OS, " ++ "`e' to edit the commands before booting " ++ "or `c' for a command-line. ESC to return previous menu."), ++ STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); ++ } ++ else ++ { ++ ret += grub_print_message_indented_real ++ (_("Press enter to boot the selected OS, " ++ "`e' to edit the commands before booting " ++ "or `c' for a command-line."), ++ STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); ++ } + } + } + return ret; +diff --git a/include/grub/kernel.h b/include/grub/kernel.h +index 98edc0863..f98a780da 100644 +--- a/include/grub/kernel.h ++++ b/include/grub/kernel.h +@@ -33,6 +33,7 @@ enum + OBJ_TYPE_DISABLE_SHIM_LOCK, + OBJ_TYPE_GPG_PUBKEY, + OBJ_TYPE_X509_PUBKEY, ++ OBJ_TYPE_DISABLE_CLI + }; + + /* The module header. */ +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 6b1e084af..d6e9bae8e 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -442,6 +442,8 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, + grub_uint64_t d, + grub_uint64_t *r); + ++extern bool EXPORT_FUNC(grub_is_cli_disabled) (void); ++ + /* Must match softdiv group in gentpl.py. */ + #if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \ + (defined(__riscv) && (__riscv_xlen == 32))) +diff --git a/include/grub/util/install.h b/include/grub/util/install.h +index 59eabb9bb..dbf3c216d 100644 +--- a/include/grub/util/install.h ++++ b/include/grub/util/install.h +@@ -72,6 +72,8 @@ + { "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE,\ + "SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), \ + 1}, \ ++ { "disable-cli", GRUB_INSTALL_OPTIONS_DISABLE_CLI, 0, 0, \ ++ N_("disabled command line interface access"), 0 }, \ + { "verbose", 'v', 0, 0, \ + N_("print verbose messages."), 1 } + +@@ -135,7 +137,8 @@ enum grub_install_options { + GRUB_INSTALL_OPTIONS_DTB, + GRUB_INSTALL_OPTIONS_SBAT, + GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, +- GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE ++ GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE, ++ GRUB_INSTALL_OPTIONS_DISABLE_CLI + }; + + extern char *grub_install_source_directory; +@@ -198,7 +201,8 @@ grub_install_generate_image (const char *dir, const char *prefix, + const struct grub_install_image_target_desc *image_target, + int note, size_t appsig_size, + grub_compression_t comp, const char *dtb_file, +- const char *sbat_path, const int disable_shim_lock); ++ const char *sbat_path, const int disable_shim_lock, ++ const int disable_cli); + + const struct grub_install_image_target_desc * + grub_install_get_image_target (const char *arg); +diff --git a/util/grub-install-common.c b/util/grub-install-common.c +index 67afc2eed..42aec141e 100644 +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c +@@ -469,6 +469,7 @@ static char **x509keys; + static size_t nx509keys; + static grub_compression_t compression; + static size_t appsig_size; ++static int disable_cli; + + int + grub_install_parse (int key, char *arg) +@@ -514,6 +515,9 @@ grub_install_parse (int key, char *arg) + * (nx509keys + 1)); + x509keys[nx509keys++] = xstrdup (arg); + return 1; ++ case GRUB_INSTALL_OPTIONS_DISABLE_CLI: ++ disable_cli = 1; ++ return 1; + + case GRUB_INSTALL_OPTIONS_VERBOSITY: + verbosity++; +@@ -708,11 +712,13 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + grub_util_info ("grub-mkimage --directory '%s' --prefix '%s' --output '%s'" + " --format '%s' --compression '%s'" + " --appended-signture-size %zu %s%s%s\n", ++ " --format '%s' --compression '%s'%s%s%s%s\n", + dir, prefix, outname, + mkimage_target, compnames[compression], + appsig_size, + note ? " --note" : "", +- disable_shim_lock ? " --disable-shim-lock" : "", s); ++ disable_shim_lock ? " --disable-shim-lock" : "", ++ disable_cli ? " --disable-cli" : "", s); + free (s); + + tgt = grub_install_get_image_target (mkimage_target); +@@ -725,7 +731,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, + x509keys, nx509keys, + config_path, tgt, + note, appsig_size, compression, dtb, sbat, +- disable_shim_lock); ++ disable_shim_lock, disable_cli); + while (dc--) + grub_install_pop_module (); + } +diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c +index e1f111278..13bdc6cf0 100644 +--- a/util/grub-mkimage.c ++++ b/util/grub-mkimage.c +@@ -84,6 +84,7 @@ static struct argp_option options[] = { + {"compression", 'C', "(xz|none|auto)", 0, N_("choose the compression to use for core image"), 0}, + {"sbat", 's', N_("FILE"), 0, N_("SBAT metadata"), 0}, + {"disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, N_("disable shim_lock verifier"), 0}, ++ {"disable-cli", GRUB_INSTALL_OPTIONS_DISABLE_CLI, 0, 0, N_("disable command line interface access"), 0}, + {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, + {"appended-signature-size", 'S', N_("SIZE"), 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), 0}, + { 0, 0, 0, 0, 0, 0 } +@@ -133,6 +134,7 @@ struct arguments + int note; + int disable_shim_lock; + size_t appsig_size; ++ int disable_cli; + const struct grub_install_image_target_desc *image_target; + grub_compression_t comp; + }; +@@ -259,6 +261,10 @@ argp_parser (int key, char *arg, struct argp_state *state) + arguments->disable_shim_lock = 1; + break; + ++ case GRUB_INSTALL_OPTIONS_DISABLE_CLI: ++ arguments->disable_cli = 1; ++ break; ++ + case 'v': + verbosity++; + break; +@@ -347,7 +353,8 @@ main (int argc, char *argv[]) + arguments.image_target, arguments.note, + arguments.appsig_size, arguments.comp, + arguments.dtb, arguments.sbat, +- arguments.disable_shim_lock); ++ arguments.disable_shim_lock, ++ arguments.disable_cli); + + if (grub_util_file_sync (fp) < 0) + grub_util_error (_("cannot sync `%s': %s"), arguments.output ? : "stdout", +diff --git a/util/mkimage.c b/util/mkimage.c +index 425d920ff..f31fdefa8 100644 +--- a/util/mkimage.c ++++ b/util/mkimage.c +@@ -888,7 +888,7 @@ grub_install_generate_image (const char *dir, const char *prefix, + const struct grub_install_image_target_desc *image_target, + int note, size_t appsig_size, grub_compression_t comp, + const char *dtb_path, const char *sbat_path, +- int disable_shim_lock) ++ int disable_shim_lock, int disable_cli) + { + char *kernel_img, *core_img; + size_t total_module_size, core_size; +@@ -963,6 +963,9 @@ grub_install_generate_image (const char *dir, const char *prefix, + if (disable_shim_lock) + total_module_size += sizeof (struct grub_module_header); + ++ if (disable_cli) ++ total_module_size += sizeof (struct grub_module_header); ++ + if (config_path) + { + config_size = ALIGN_ADDR (grub_util_get_image_size (config_path) + 1); +@@ -1129,6 +1132,16 @@ grub_install_generate_image (const char *dir, const char *prefix, + offset += sizeof (*header); + } + ++ if (disable_cli) ++ { ++ struct grub_module_header *header; ++ ++ header = (struct grub_module_header *) (kernel_img + offset); ++ header->type = grub_host_to_target32 (OBJ_TYPE_DISABLE_CLI); ++ header->size = grub_host_to_target32 (sizeof (*header)); ++ offset += sizeof (*header); ++ } ++ + if (config_path) + { + struct grub_module_header *header; diff --git a/0312-disk-cryptodisk-Require-authentication-after-TPM-unl.patch b/0312-disk-cryptodisk-Require-authentication-after-TPM-unl.patch new file mode 100644 index 00000000..2c2396ad --- /dev/null +++ b/0312-disk-cryptodisk-Require-authentication-after-TPM-unl.patch @@ -0,0 +1,337 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Tue, 11 Feb 2025 15:08:06 -0600 +Subject: [PATCH] disk/cryptodisk: Require authentication after TPM unlock for + CLI access + +The GRUB may use TPM to verify the integrity of boot components and the +result can determine whether a previously sealed key can be released. If +everything checks out, showing nothing has been tampered with, the key +is released and GRUB unlocks the encrypted root partition for the next +stage of booting. + +However, the liberal Command Line Interface (CLI) can be misused by +anyone in this case to access files in the encrypted partition one way +or another. Despite efforts to keep the CLI secure by preventing utility +command output from leaking file content, many techniques in the wild +could still be used to exploit the CLI, enabling attacks or learning +methods to attack. It's nearly impossible to account for all scenarios +where a hack could be applied. + +Therefore, to mitigate potential misuse of the CLI after the root device +has been successfully unlocked via TPM, the user should be required to +authenticate using the LUKS password. This added layer of security +ensures that only authorized users can access the CLI reducing the risk +of exploitation or unauthorized access to the encrypted partition. + +Fixes: CVE-2024-49504 + +Signed-off-by: Michael Chang +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 29 +++++++++++++++ + grub-core/disk/cryptodisk.c | 87 ++++++++++++++++++++++++++++++++++++++++++- + grub-core/kern/main.c | 12 ++++++ + grub-core/normal/auth.c | 30 +++++++++++++++ + grub-core/normal/main.c | 4 ++ + grub-core/normal/menu_entry.c | 4 ++ + include/grub/auth.h | 1 + + include/grub/cryptodisk.h | 3 ++ + include/grub/misc.h | 2 + + 9 files changed, 171 insertions(+), 1 deletion(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 9ce9c5b82..2d6d73a78 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -6882,6 +6882,35 @@ sign-file SHA256 grub.key certificate.der core.elf.unsigned core.elf.signed + As with UEFI secure boot, it is necessary to build in the required modules, + or sign them separately. + ++@subsection Command line and menuentry editor protection ++ ++The TPM key protector provides full disk encryption support on servers or ++virtual machine images, meanwhile keeping the boot process unattended. This ++prevents service disruptions by eliminating the need for manual password input ++during startup, improving system uptime and continuity. It is achieved by TPM, ++which verifies the integrity of boot components by checking cryptographic ++hashes against securely stored values, to confirm the disks are unlocked in a ++trusted state. ++ ++However, for users to access the system interactively, some form of ++authentication is still required, as the disks are not unlocked by an ++authorized user. This raised concerns about using an unprotected ++@samp{command-line interface} (@pxref{Command-line interface}), as anyone could ++execute commands to access decrypted data. To address this issue, the LUKS ++password is used to ensure that only authorized users are granted access to the ++interface. Additionally, the @samp{menu entry editor} (@pxref{Menu entry ++editor}) is also safeguarded by the LUKS password, as modifying a boot entry is ++effectively the same as altering the @file{grub.cfg} file read from encrypted ++files. ++ ++It is worth mentioning that the built-in password support, as described in ++@samp{Authentication and Authorization in GRUB} (@pxref{Authentication and ++authorisation}), can also be used to protect the command-line interface from ++unauthorized access. However, it is not recommended to rely on this approach as ++it is an optional step. Setting it up requires additional manual intervention, ++which increases the risk of password leakage during the process. Moreover, the ++superuser list must be well maintained, and the password used cannot be ++synchronized with LUKS key rotation. + + @node Platform limitations + @chapter Platform limitations +diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c +index 98e176a13..06a42b2d7 100644 +--- a/grub-core/disk/cryptodisk.c ++++ b/grub-core/disk/cryptodisk.c +@@ -1144,7 +1144,9 @@ grub_cryptodisk_scan_device_real (const char *name, + ret = grub_cryptodisk_insert (dev, name, source); + if (ret != GRUB_ERR_NONE) + goto error; +- ++#ifndef GRUB_UTIL ++ grub_cli_set_auth_needed (); ++#endif + goto cleanup; + } + grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk module can handle this device"); +@@ -1576,6 +1578,89 @@ luks_script_get (grub_size_t *sz) + return ret; + } + ++#ifdef GRUB_MACHINE_EFI ++grub_err_t ++grub_cryptodisk_challenge_password (void) ++{ ++ grub_cryptodisk_t cr_dev; ++ ++ for (cr_dev = cryptodisk_list; cr_dev != NULL; cr_dev = cr_dev->next) ++ { ++ grub_cryptodisk_dev_t cr; ++ grub_disk_t source = NULL; ++ grub_err_t ret = GRUB_ERR_NONE; ++ grub_cryptodisk_t dev = NULL; ++ char *part = NULL; ++ struct grub_cryptomount_args cargs = {0}; ++ ++ cargs.check_boot = 0; ++ cargs.search_uuid = cr_dev->uuid; ++ ++ source = grub_disk_open (cr_dev->source); ++ ++ if (source == NULL) ++ { ++ ret = grub_errno; ++ goto error_out; ++ } ++ ++ FOR_CRYPTODISK_DEVS (cr) ++ { ++ dev = cr->scan (source, &cargs); ++ if (grub_errno) ++ { ++ ret = grub_errno; ++ goto error_out; ++ } ++ if (dev == NULL) ++ continue; ++ break; ++ } ++ ++ if (dev == NULL) ++ { ++ ret = grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk module can handle this device"); ++ goto error_out; ++ } ++ ++ part = grub_partition_get_name (source->partition); ++ grub_printf_ (N_("Enter passphrase for %s%s%s (%s): "), source->name, ++ source->partition != NULL ? "," : "", ++ part != NULL ? part : N_("UNKNOWN"), cr_dev->uuid); ++ grub_free (part); ++ ++ cargs.key_data = grub_malloc (GRUB_CRYPTODISK_MAX_PASSPHRASE); ++ if (cargs.key_data == NULL) ++ { ++ ret = grub_errno; ++ goto error_out; ++ } ++ ++ if (!grub_password_get ((char *) cargs.key_data, GRUB_CRYPTODISK_MAX_PASSPHRASE)) ++ { ++ ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "passphrase not supplied"); ++ goto error_out; ++ } ++ cargs.key_len = grub_strlen ((char *) cargs.key_data); ++ ret = cr->recover_key (source, dev, &cargs); ++ ++ error_out: ++ grub_disk_close (source); ++ if (dev != NULL) ++ cryptodisk_close (dev); ++ if (cargs.key_data) ++ { ++ grub_memset (cargs.key_data, 0, cargs.key_len); ++ grub_free (cargs.key_data); ++ } ++ ++ return ret; ++ } ++ ++ return GRUB_ERR_NONE; ++} ++#endif /* GRUB_MACHINE_EFI */ ++ + struct grub_procfs_entry luks_script = + { + .name = "luks_script", +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index 0d6b8138d..2e6b79ee3 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -37,6 +37,7 @@ + #endif + + static bool cli_disabled = false; ++static bool cli_need_auth = false; + + grub_addr_t + grub_modules_get_end (void) +@@ -308,6 +309,17 @@ grub_is_cli_disabled (void) + return cli_disabled; + } + ++bool ++grub_is_cli_need_auth (void) ++{ ++ return cli_need_auth; ++} ++ ++void grub_cli_set_auth_needed (void) ++{ ++ cli_need_auth = true; ++} ++ + static void + check_is_cli_disabled (void) + { +diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c +index d94020186..71b361bc0 100644 +--- a/grub-core/normal/auth.c ++++ b/grub-core/normal/auth.c +@@ -25,6 +25,10 @@ + #include + #include + ++#ifdef GRUB_MACHINE_EFI ++#include ++#endif ++ + struct grub_auth_user + { + struct grub_auth_user *next; +@@ -200,6 +204,32 @@ grub_username_get (char buf[], unsigned buf_size) + return (key != GRUB_TERM_ESC); + } + ++grub_err_t ++grub_auth_check_cli_access (void) ++{ ++ if (grub_is_cli_need_auth () == true) ++ { ++#ifdef GRUB_MACHINE_EFI ++ static bool authenticated = false; ++ ++ if (authenticated == false) ++ { ++ grub_err_t ret; ++ ++ ret = grub_cryptodisk_challenge_password (); ++ if (ret == GRUB_ERR_NONE) ++ authenticated = true; ++ return ret; ++ } ++ return GRUB_ERR_NONE; ++#else ++ return GRUB_ACCESS_DENIED; ++#endif ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ + grub_err_t + grub_auth_check_authentication (const char *userlist) + { +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 26872ce94..86ffb388d 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -557,9 +557,13 @@ grub_cmdline_run (int nested, int force_auth) + } + while (err && force_auth); + ++ if (err == GRUB_ERR_NONE) ++ err = grub_auth_check_cli_access (); ++ + if (err) + { + grub_print_error (); ++ grub_wait_after_message (); + grub_errno = GRUB_ERR_NONE; + return; + } +diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c +index ade56be2b..8b0d17e3f 100644 +--- a/grub-core/normal/menu_entry.c ++++ b/grub-core/normal/menu_entry.c +@@ -1255,9 +1255,13 @@ grub_menu_entry_run (grub_menu_entry_t entry) + + err = grub_auth_check_authentication (NULL); + ++ if (err == GRUB_ERR_NONE) ++ err = grub_auth_check_cli_access (); ++ + if (err) + { + grub_print_error (); ++ grub_wait_after_message (); + grub_errno = GRUB_ERR_NONE; + return; + } +diff --git a/include/grub/auth.h b/include/grub/auth.h +index 747334451..21d5190f0 100644 +--- a/include/grub/auth.h ++++ b/include/grub/auth.h +@@ -33,5 +33,6 @@ grub_err_t grub_auth_unregister_authentication (const char *user); + grub_err_t grub_auth_authenticate (const char *user); + grub_err_t grub_auth_deauthenticate (const char *user); + grub_err_t grub_auth_check_authentication (const char *userlist); ++grub_err_t grub_auth_check_cli_access (void); + + #endif /* ! GRUB_AUTH_HEADER */ +diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h +index d94df68b6..d2572f8b0 100644 +--- a/include/grub/cryptodisk.h ++++ b/include/grub/cryptodisk.h +@@ -187,4 +187,7 @@ grub_util_get_geli_uuid (const char *dev); + grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid); + grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk); + ++#ifdef GRUB_MACHINE_EFI ++grub_err_t grub_cryptodisk_challenge_password (void); ++#endif + #endif +diff --git a/include/grub/misc.h b/include/grub/misc.h +index d6e9bae8e..0429339ef 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -443,6 +443,8 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, + grub_uint64_t *r); + + extern bool EXPORT_FUNC(grub_is_cli_disabled) (void); ++extern bool EXPORT_FUNC(grub_is_cli_need_auth) (void); ++extern void EXPORT_FUNC(grub_cli_set_auth_needed) (void); + + /* Must match softdiv group in gentpl.py. */ + #if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \ diff --git a/0313-disk-loopback-Reference-tracking-for-the-loopback.patch b/0313-disk-loopback-Reference-tracking-for-the-loopback.patch new file mode 100644 index 00000000..5f6cd3af --- /dev/null +++ b/0313-disk-loopback-Reference-tracking-for-the-loopback.patch @@ -0,0 +1,108 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 15:22:28 -0600 +Subject: [PATCH] disk/loopback: Reference tracking for the loopback + +It was possible to delete a loopback while there were still references +to it. This led to an exploitable use-after-free. + +Fixed by implementing a reference counting in the grub_loopback struct. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/disk/loopback.c | 17 +++++++++++++++++ + include/grub/err.h | 3 ++- + include/grub/loopback.h | 1 + + 3 files changed, 20 insertions(+), 1 deletion(-) + +diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c +index 11a5e0cbd..f39281323 100644 +--- a/grub-core/disk/loopback.c ++++ b/grub-core/disk/loopback.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -57,6 +58,8 @@ delete_loopback (const char *name) + if (! dev) + return grub_error (GRUB_ERR_BAD_DEVICE, "device not found"); + ++ if (dev->refcnt > 0) ++ return grub_error (GRUB_ERR_STILL_REFERENCED, "device still referenced"); + /* Remove the device from the list. */ + *prev = dev->next; + +@@ -113,6 +116,7 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args) + + newdev->file = file; + newdev->id = last_id++; ++ newdev->refcnt = 0; + + /* Add the new entry to the list. */ + newdev->next = loopback_list; +@@ -154,6 +158,9 @@ grub_loopback_open (const char *name, grub_disk_t disk) + if (! dev) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); + ++ if (grub_add (dev->refcnt, 1, &dev->refcnt)) ++ grub_fatal ("Reference count overflow"); ++ + /* Use the filesize for the disk size, round up to a complete sector. */ + if (dev->file->size != GRUB_FILE_SIZE_UNKNOWN) + disk->total_sectors = ((dev->file->size + GRUB_DISK_SECTOR_SIZE - 1) +@@ -171,6 +178,15 @@ grub_loopback_open (const char *name, grub_disk_t disk) + return 0; + } + ++static void ++grub_loopback_close (grub_disk_t disk) ++{ ++ struct grub_loopback *dev = disk->data; ++ ++ if (grub_sub (dev->refcnt, 1, &dev->refcnt)) ++ grub_fatal ("Reference count underflow"); ++} ++ + static grub_err_t + grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_size_t size, char *buf) +@@ -213,6 +229,7 @@ static struct grub_disk_dev grub_loopback_dev = + .id = GRUB_DISK_DEVICE_LOOPBACK_ID, + .disk_iterate = grub_loopback_iterate, + .disk_open = grub_loopback_open, ++ .disk_close = grub_loopback_close, + .disk_read = grub_loopback_read, + .disk_write = grub_loopback_write, + .next = 0 +diff --git a/include/grub/err.h b/include/grub/err.h +index 3c587b9b8..29f1a73c5 100644 +--- a/include/grub/err.h ++++ b/include/grub/err.h +@@ -73,7 +73,8 @@ typedef enum + GRUB_ERR_NET_NO_DOMAIN, + GRUB_ERR_EOF, + GRUB_ERR_BAD_SIGNATURE, +- GRUB_ERR_BAD_FIRMWARE ++ GRUB_ERR_BAD_FIRMWARE, ++ GRUB_ERR_STILL_REFERENCED + } + grub_err_t; + +diff --git a/include/grub/loopback.h b/include/grub/loopback.h +index 3b9a9e32e..915ef65fc 100644 +--- a/include/grub/loopback.h ++++ b/include/grub/loopback.h +@@ -25,6 +25,7 @@ struct grub_loopback + grub_file_t file; + struct grub_loopback *next; + unsigned long id; ++ grub_uint64_t refcnt; + }; + + #endif /* ! GRUB_LOOPBACK_HEADER */ diff --git a/0314-kern-disk-Limit-recursion-depth.patch b/0314-kern-disk-Limit-recursion-depth.patch new file mode 100644 index 00000000..eba37f97 --- /dev/null +++ b/0314-kern-disk-Limit-recursion-depth.patch @@ -0,0 +1,120 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 04:09:24 +0100 +Subject: [PATCH] kern/disk: Limit recursion depth + +The grub_disk_read() may trigger other disk reads, e.g. via loopbacks. +This may lead to very deep recursion which can corrupt the heap. So, fix +the issue by limiting reads depth. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/kern/disk.c | 27 ++++++++++++++++++++------- + include/grub/err.h | 3 ++- + 2 files changed, 22 insertions(+), 8 deletions(-) + +diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c +index 355b6579d..5747ad85c 100644 +--- a/grub-core/kern/disk.c ++++ b/grub-core/kern/disk.c +@@ -28,6 +28,10 @@ + + #define GRUB_CACHE_TIMEOUT 2 + ++/* Disk reads may trigger other disk reads. So, limit recursion depth. */ ++#define MAX_READ_RECURSION_DEPTH 16 ++static unsigned int read_recursion_depth = 0; ++ + /* The last time the disk was used. */ + static grub_uint64_t grub_last_time = 0; + +@@ -421,6 +425,8 @@ grub_err_t + grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_off_t offset, grub_size_t size, void *buf) + { ++ grub_err_t err = GRUB_ERR_NONE; ++ + /* First of all, check if the region is within the disk. */ + if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) + { +@@ -431,12 +437,17 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + return grub_errno; + } + ++ if (++read_recursion_depth >= MAX_READ_RECURSION_DEPTH) ++ { ++ grub_error (GRUB_ERR_RECURSION_DEPTH, "grub_disk_read(): Maximum recursion depth exceeded"); ++ goto error; ++ } ++ + /* First read until first cache boundary. */ + if (offset || (sector & (GRUB_DISK_CACHE_SIZE - 1))) + { + grub_disk_addr_t start_sector; + grub_size_t pos; +- grub_err_t err; + grub_size_t len; + + start_sector = sector & ~((grub_disk_addr_t) GRUB_DISK_CACHE_SIZE - 1); +@@ -448,7 +459,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + err = grub_disk_read_small (disk, start_sector, + offset + pos, len, buf); + if (err) +- return err; ++ goto error; + buf = (char *) buf + len; + size -= len; + offset += len; +@@ -461,7 +472,6 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + { + char *data = NULL; + grub_disk_addr_t agglomerate; +- grub_err_t err; + + /* agglomerate read until we find a first cached entry. */ + for (agglomerate = 0; agglomerate +@@ -497,7 +507,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + - disk->log_sector_size), + buf); + if (err) +- return err; ++ goto error; + + for (i = 0; i < agglomerate; i ++) + grub_disk_cache_store (disk->dev->id, disk->id, +@@ -531,13 +541,16 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + /* And now read the last part. */ + if (size) + { +- grub_err_t err; + err = grub_disk_read_small (disk, sector, 0, size, buf); + if (err) +- return err; ++ goto error; + } + +- return grub_errno; ++ err = grub_errno; ++ ++ error: ++ read_recursion_depth--; ++ return err; + } + + grub_uint64_t +diff --git a/include/grub/err.h b/include/grub/err.h +index 29f1a73c5..7530f58b2 100644 +--- a/include/grub/err.h ++++ b/include/grub/err.h +@@ -74,7 +74,8 @@ typedef enum + GRUB_ERR_EOF, + GRUB_ERR_BAD_SIGNATURE, + GRUB_ERR_BAD_FIRMWARE, +- GRUB_ERR_STILL_REFERENCED ++ GRUB_ERR_STILL_REFERENCED, ++ GRUB_ERR_RECURSION_DEPTH + } + grub_err_t; + diff --git a/0315-kern-partition-Limit-recursion-in-part_iterate.patch b/0315-kern-partition-Limit-recursion-in-part_iterate.patch new file mode 100644 index 00000000..f51ff967 --- /dev/null +++ b/0315-kern-partition-Limit-recursion-in-part_iterate.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sat, 16 Nov 2024 21:24:19 +0000 +Subject: [PATCH] kern/partition: Limit recursion in part_iterate() + +The part_iterate() is used by grub_partition_iterate() as a callback in +the partition iterate functions. However, part_iterate() may also call +the partition iterate functions which may lead to recursion. Fix potential +issue by limiting the recursion depth. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/kern/partition.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c +index edad9f9e4..704512a20 100644 +--- a/grub-core/kern/partition.c ++++ b/grub-core/kern/partition.c +@@ -28,6 +28,9 @@ + + grub_partition_map_t grub_partition_map_list; + ++#define MAX_RECURSION_DEPTH 32 ++static unsigned int recursion_depth = 0; ++ + /* + * Checks that disk->partition contains part. This function assumes that the + * start of part is relative to the start of disk->partition. Returns 1 if +@@ -208,7 +211,12 @@ part_iterate (grub_disk_t dsk, const grub_partition_t partition, void *data) + FOR_PARTITION_MAPS(partmap) + { + grub_err_t err; +- err = partmap->iterate (dsk, part_iterate, ctx); ++ recursion_depth++; ++ if (recursion_depth <= MAX_RECURSION_DEPTH) ++ err = partmap->iterate (dsk, part_iterate, ctx); ++ else ++ err = grub_error (GRUB_ERR_RECURSION_DEPTH, "maximum recursion depth exceeded"); ++ recursion_depth--; + if (err) + grub_errno = GRUB_ERR_NONE; + if (ctx->ret) diff --git a/0316-script-execute-Limit-the-recursion-depth.patch b/0316-script-execute-Limit-the-recursion-depth.patch new file mode 100644 index 00000000..6bf1d092 --- /dev/null +++ b/0316-script-execute-Limit-the-recursion-depth.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Thu, 18 Apr 2024 19:04:13 +0100 +Subject: [PATCH] script/execute: Limit the recursion depth + +If unbounded recursion is allowed it becomes possible to collide the +stack with the heap. As UEFI firmware often lacks guard pages this +becomes an exploitable issue as it is possible in some cases to do +a controlled overwrite of a section of this heap region with +arbitrary data. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/script/execute.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index c19b4bf70..7ed3a1a03 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -36,10 +36,18 @@ + is sizeof (int) * 3, and one extra for a possible -ve sign. */ + #define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1) + ++/* ++ * A limit on recursion, to avoid colliding with the heap. UEFI defines a baseline ++ * stack size of 128 KiB. So, assuming at most 1-2 KiB per iteration this should ++ * keep us safe. ++ */ ++#define MAX_RECURSION_DEPTH 64 ++ + static unsigned long is_continue; + static unsigned long active_loops; + static unsigned long active_breaks; + static unsigned long function_return; ++static unsigned long recursion_depth; + + #define GRUB_SCRIPT_SCOPE_MALLOCED 1 + #define GRUB_SCRIPT_SCOPE_ARGS_MALLOCED 2 +@@ -850,7 +858,13 @@ grub_script_execute_cmd (struct grub_script_cmd *cmd) + if (cmd == 0) + return 0; + ++ recursion_depth++; ++ ++ if (recursion_depth >= MAX_RECURSION_DEPTH) ++ return grub_error (GRUB_ERR_RECURSION_DEPTH, N_("maximum recursion depth exceeded")); ++ + ret = cmd->exec (cmd); ++ recursion_depth--; + + grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret); + grub_env_set ("?", errnobuf); diff --git a/0317-net-Unregister-net_default_ip-and-net_default_mac-va.patch b/0317-net-Unregister-net_default_ip-and-net_default_mac-va.patch new file mode 100644 index 00000000..c3f5636c --- /dev/null +++ b/0317-net-Unregister-net_default_ip-and-net_default_mac-va.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 15:27:10 -0600 +Subject: [PATCH] net: Unregister net_default_ip and net_default_mac variables + hooks on unload + +The net module is a dependency of normal. So, it shouldn't be possible +to unload the net. Though unregister variables hooks as a precaution. +It also gets in line with unregistering the other net module hooks. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/net/net.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index fdec64d55..9959a2ae8 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -2221,6 +2221,8 @@ GRUB_MOD_FINI(net) + + grub_register_variable_hook ("net_default_server", 0, 0); + grub_register_variable_hook ("pxe_default_server", 0, 0); ++ grub_register_variable_hook ("net_default_ip", 0, 0); ++ grub_register_variable_hook ("net_default_mac", 0, 0); + + grub_bootp_fini (); + grub_dns_fini (); diff --git a/0318-net-Remove-variables-hooks-when-interface-is-unregis.patch b/0318-net-Remove-variables-hooks-when-interface-is-unregis.patch new file mode 100644 index 00000000..c7b25c19 --- /dev/null +++ b/0318-net-Remove-variables-hooks-when-interface-is-unregis.patch @@ -0,0 +1,84 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 15:42:44 -0600 +Subject: [PATCH] net: Remove variables hooks when interface is unregisted + +The grub_net_network_level_interface_unregister(), previously +implemented in a header, did not remove the variables hooks that +were registered in grub_net_network_level_interface_register(). +Fix this by implementing the same logic used to register the +variables and move the function into the grub-core/net/net.c. + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/net/net.c | 33 +++++++++++++++++++++++++++++++++ + include/grub/net.h | 11 +---------- + 2 files changed, 34 insertions(+), 10 deletions(-) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 9959a2ae8..22d5cc3ba 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1066,6 +1066,39 @@ grub_net_add_ipv6_local (struct grub_net_network_level_interface *inter, + return 0; + } + ++void ++grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) ++{ ++ char *name; ++ ++ { ++ char buf[GRUB_NET_MAX_STR_HWADDR_LEN]; ++ ++ grub_net_hwaddr_to_str (&inter->hwaddress, buf); ++ name = grub_xasprintf ("net_%s_mac", inter->name); ++ if (name != NULL) ++ grub_register_variable_hook (name, NULL, NULL); ++ grub_free (name); ++ } ++ ++ { ++ char buf[GRUB_NET_MAX_STR_ADDR_LEN]; ++ ++ grub_net_addr_to_str (&inter->address, buf); ++ name = grub_xasprintf ("net_%s_ip", inter->name); ++ if (name != NULL) ++ grub_register_variable_hook (name, NULL, NULL); ++ grub_free (name); ++ } ++ ++ inter->card->num_ifaces--; ++ *inter->prev = inter->next; ++ if (inter->next) ++ inter->next->prev = inter->prev; ++ inter->next = 0; ++ inter->prev = 0; ++} ++ + grub_err_t + grub_net_add_ipv4_local (struct grub_net_network_level_interface *inter, + int mask) +diff --git a/include/grub/net.h b/include/grub/net.h +index 868c9a2ef..273afbddf 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -625,16 +625,7 @@ void grub_bootp_fini (void); + void grub_dns_init (void); + void grub_dns_fini (void); + +-static inline void +-grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) +-{ +- inter->card->num_ifaces--; +- *inter->prev = inter->next; +- if (inter->next) +- inter->next->prev = inter->prev; +- inter->next = 0; +- inter->prev = 0; +-} ++void grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter); + + void + grub_net_tcp_retransmit (void); diff --git a/0319-net-Fix-OOB-write-in-grub_net_search_config_file.patch b/0319-net-Fix-OOB-write-in-grub_net_search_config_file.patch new file mode 100644 index 00000000..d0830c83 --- /dev/null +++ b/0319-net-Fix-OOB-write-in-grub_net_search_config_file.patch @@ -0,0 +1,79 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 16:38:44 -0600 +Subject: [PATCH] net: Fix OOB write in grub_net_search_config_file() + +The function included a call to grub_strcpy() which copied data from an +environment variable to a buffer allocated in grub_cmd_normal(). The +grub_cmd_normal() didn't consider the length of the environment variable. +So, the copy operation could exceed the allocation and lead to an OOB +write. Fix the issue by replacing grub_strcpy() with grub_strlcpy() and +pass the underlying buffers size to the grub_net_search_config_file(). + +Fixes: CVE-2025-0624 + +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/net/net.c | 7 ++++--- + grub-core/normal/main.c | 2 +- + include/grub/net.h | 2 +- + 3 files changed, 6 insertions(+), 5 deletions(-) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 22d5cc3ba..6c8dfcba2 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -2023,14 +2023,15 @@ grub_config_search_through (char *config, char *suffix, + } + + grub_err_t +-grub_net_search_config_file (char *config) ++grub_net_search_config_file (char *config, grub_size_t config_buf_len) + { +- grub_size_t config_len; ++ grub_size_t config_len, suffix_len; + char *suffix; + + config_len = grub_strlen (config); + config[config_len] = '-'; + suffix = config + config_len + 1; ++ suffix_len = config_buf_len - (config_len + 1); + + struct grub_net_network_level_interface *inf; + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) +@@ -2056,7 +2057,7 @@ grub_net_search_config_file (char *config) + + if (client_uuid) + { +- grub_strcpy (suffix, client_uuid); ++ grub_strlcpy (suffix, client_uuid, suffix_len); + if (grub_config_search_through (config, suffix, 1, 0) == 0) + return GRUB_ERR_NONE; + } +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 86ffb388d..cad840e06 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -360,7 +360,7 @@ grub_try_normal_prefix (const char *prefix) + return err; + + grub_snprintf (config, config_len, "%s/grub.cfg", prefix); +- err = grub_net_search_config_file (config); ++ err = grub_net_search_config_file (config, config_len); + } + + if (err != GRUB_ERR_NONE) +diff --git a/include/grub/net.h b/include/grub/net.h +index 273afbddf..d280acd72 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -655,7 +655,7 @@ void + grub_net_remove_dns_server (const struct grub_net_network_level_address *s); + + grub_err_t +-grub_net_search_config_file (char *config); ++grub_net_search_config_file (char *config, grub_size_t config_buf_len); + + extern char *grub_net_default_server; + diff --git a/0320-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch b/0320-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch new file mode 100644 index 00000000..91b857d8 --- /dev/null +++ b/0320-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch @@ -0,0 +1,115 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Thu, 18 Apr 2024 17:32:34 +0100 +Subject: [PATCH] net/tftp: Fix stack buffer overflow in tftp_open() + +An overly long filename can be passed to tftp_open() which would cause +grub_normalize_filename() to write out of bounds. + +Fixed by adding an extra argument to grub_normalize_filename() for the +space available, making it act closer to a strlcpy(). As several fixed +strings are strcpy()'d after into the same buffer, their total length is +checked to see if they exceed the remaining space in the buffer. If so, +return an error. + +On the occasion simplify code a bit by removing unneeded rrqlen zeroing. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/net/tftp.c | 38 ++++++++++++++++++++++++-------------- + 1 file changed, 24 insertions(+), 14 deletions(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index f300a9d40..3d96e50f4 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -266,17 +266,19 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), + * forward slashes to a single forward slash. + */ + static void +-grub_normalize_filename (char *normalized, const char *filename) ++grub_normalize_filename (char *normalized, const char *filename, int c) + { + char *dest = normalized; + const char *src = filename; + +- while (*src != '\0') ++ while (*src != '\0' && c > 0) + { + if (src[0] == '/' && src[1] == '/') + src++; +- else ++ else { ++ c--; + *dest++ = *src++; ++ } + } + *dest = '\0'; + } +@@ -287,7 +289,7 @@ tftp_open (struct grub_file *file, const char *filename) + struct tftphdr *tftph; + char *rrq; + int i; +- int rrqlen; ++ int rrqlen, rrqsize; + int hdrlen; + grub_uint8_t open_data[1500]; + struct grub_net_buff nb; +@@ -315,37 +317,45 @@ tftp_open (struct grub_file *file, const char *filename) + + tftph = (struct tftphdr *) nb.data; + +- rrq = (char *) tftph->u.rrq; +- rrqlen = 0; +- + tftph->opcode = grub_cpu_to_be16_compile_time (TFTP_RRQ); + ++ rrq = (char *) tftph->u.rrq; ++ rrqsize = sizeof (tftph->u.rrq); ++ + /* + * Copy and normalize the filename to work-around issues on some TFTP + * servers when file names are being matched for remapping. + */ +- grub_normalize_filename (rrq, filename); +- rrqlen += grub_strlen (rrq) + 1; ++ grub_normalize_filename (rrq, filename, rrqsize); ++ ++ rrqlen = grub_strlen (rrq) + 1; + rrq += grub_strlen (rrq) + 1; + +- grub_strcpy (rrq, "octet"); ++ /* Verify there is enough space for the remaining components. */ + rrqlen += grub_strlen ("octet") + 1; ++ rrqlen += grub_strlen ("blksize") + 1; ++ rrqlen += grub_strlen ("1024") + 1; ++ rrqlen += grub_strlen ("tsize") + 1; ++ rrqlen += grub_strlen ("0") + 1; ++ ++ if (rrqlen >= rrqsize) { ++ grub_free (data); ++ return grub_error (GRUB_ERR_BAD_FILENAME, N_("filename too long")); ++ } ++ ++ grub_strcpy (rrq, "octet"); + rrq += grub_strlen ("octet") + 1; + + grub_strcpy (rrq, "blksize"); +- rrqlen += grub_strlen ("blksize") + 1; + rrq += grub_strlen ("blksize") + 1; + + grub_strcpy (rrq, "1024"); +- rrqlen += grub_strlen ("1024") + 1; + rrq += grub_strlen ("1024") + 1; + + grub_strcpy (rrq, "tsize"); +- rrqlen += grub_strlen ("tsize") + 1; + rrq += grub_strlen ("tsize") + 1; + + grub_strcpy (rrq, "0"); +- rrqlen += grub_strlen ("0") + 1; + rrq += grub_strlen ("0") + 1; + hdrlen = sizeof (tftph->opcode) + rrqlen; + diff --git a/0321-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch b/0321-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch new file mode 100644 index 00000000..848d527f --- /dev/null +++ b/0321-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 8 Mar 2024 22:47:20 +1100 +Subject: [PATCH] video/readers/jpeg: Do not permit duplicate SOF0 markers in + JPEG + +Otherwise a subsequent header could change the height and width +allowing future OOB writes. + +Fixes: CVE-2024-45774 + +Reported-by: Nils Langius +Signed-off-by: Daniel Axtens +Reviewed-by: Daniel Kiper +--- + grub-core/video/readers/jpeg.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c +index ae634fd41..631a89356 100644 +--- a/grub-core/video/readers/jpeg.c ++++ b/grub-core/video/readers/jpeg.c +@@ -339,6 +339,10 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data) + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + ++ if (data->image_height != 0 || data->image_width != 0) ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, ++ "jpeg: cannot have duplicate SOF0 markers"); ++ + if (grub_jpeg_get_byte (data) != 8) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, + "jpeg: only 8-bit precision is supported"); diff --git a/0322-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch b/0322-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch new file mode 100644 index 00000000..1fee4bf0 --- /dev/null +++ b/0322-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch @@ -0,0 +1,138 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 16:41:57 -0600 +Subject: [PATCH] kern/dl: Fix for an integer overflow in grub_dl_ref() + +It was possible to overflow the value of mod->ref_count, a signed +integer, by repeatedly invoking insmod on an already loaded module. +This led to a use-after-free. As once ref_count was overflowed it became +possible to unload the module while there was still references to it. + +This resolves the issue by using grub_add() to check if the ref_count +will overflow and then stops further increments. Further changes were +also made to grub_dl_unref() to check for the underflow condition and +the reference count was changed to an unsigned 64-bit integer. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/commands/minicmd.c | 2 +- + grub-core/kern/dl.c | 17 ++++++++++++----- + include/grub/dl.h | 8 ++++---- + util/misc.c | 4 ++-- + 4 files changed, 19 insertions(+), 12 deletions(-) + +diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c +index 2bd3ac76f..2001043cf 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -167,7 +167,7 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)), + { + grub_dl_dep_t dep; + +- grub_printf ("%s\t%d\t\t", mod->name, mod->ref_count); ++ grub_printf ("%s\t%" PRIuGRUB_UINT64_T "\t\t", mod->name, mod->ref_count); + for (dep = mod->dep; dep; dep = dep->next) + { + if (dep != mod->dep) +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 2eaef7150..fe7c3b940 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + #include + + /* Platforms where modules are in a readonly area of memory. */ +@@ -613,7 +614,7 @@ grub_dl_resolve_dependencies (grub_dl_t mod, Elf_Ehdr *e) + return GRUB_ERR_NONE; + } + +-int ++grub_uint64_t + grub_dl_ref (grub_dl_t mod) + { + grub_dl_dep_t dep; +@@ -624,10 +625,13 @@ grub_dl_ref (grub_dl_t mod) + for (dep = mod->dep; dep; dep = dep->next) + grub_dl_ref (dep->mod); + +- return ++mod->ref_count; ++ if (grub_add (mod->ref_count, 1, &mod->ref_count)) ++ grub_fatal ("Module reference count overflow"); ++ ++ return mod->ref_count; + } + +-int ++grub_uint64_t + grub_dl_unref (grub_dl_t mod) + { + grub_dl_dep_t dep; +@@ -638,10 +642,13 @@ grub_dl_unref (grub_dl_t mod) + for (dep = mod->dep; dep; dep = dep->next) + grub_dl_unref (dep->mod); + +- return --mod->ref_count; ++ if (grub_sub (mod->ref_count, 1, &mod->ref_count)) ++ grub_fatal ("Module reference count underflow"); ++ ++ return mod->ref_count; + } + +-int ++grub_uint64_t + grub_dl_ref_count (grub_dl_t mod) + { + if (mod == NULL) +diff --git a/include/grub/dl.h b/include/grub/dl.h +index 1e1262a28..055bb564e 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -177,7 +177,7 @@ typedef struct grub_dl_dep *grub_dl_dep_t; + struct grub_dl + { + char *name; +- int ref_count; ++ grub_uint64_t ref_count; + int persistent; + grub_dl_dep_t dep; + grub_dl_segment_t segment; +@@ -206,9 +206,9 @@ grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name); + grub_dl_t grub_dl_load_core (void *addr, grub_size_t size); + grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size); + int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod); +-extern int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod); +-extern int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod); +-extern int EXPORT_FUNC(grub_dl_ref_count) (grub_dl_t mod); ++extern grub_uint64_t EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod); ++extern grub_uint64_t EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod); ++extern grub_uint64_t EXPORT_FUNC(grub_dl_ref_count) (grub_dl_t mod); + + extern grub_dl_t EXPORT_VAR(grub_dl_head); + +diff --git a/util/misc.c b/util/misc.c +index d545212d9..0f928e5b4 100644 +--- a/util/misc.c ++++ b/util/misc.c +@@ -190,14 +190,14 @@ grub_xputs_real (const char *str) + + void (*grub_xputs) (const char *str) = grub_xputs_real; + +-int ++grub_uint64_t + grub_dl_ref (grub_dl_t mod) + { + (void) mod; + return 0; + } + +-int ++grub_uint64_t + grub_dl_unref (grub_dl_t mod) + { + (void) mod; diff --git a/0323-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch b/0323-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch new file mode 100644 index 00000000..213ef199 --- /dev/null +++ b/0323-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 17:01:26 -0600 +Subject: [PATCH] kern/dl: Check for the SHF_INFO_LINK flag in + grub_dl_relocate_symbols() + +The grub_dl_relocate_symbols() iterates through the sections in +an ELF looking for relocation sections. According to the spec [1] +the SHF_INFO_LINK flag should be set if the sh_info field is meant +to be a section index. + +[1] https://refspecs.linuxbase.org/elf/gabi4+/ch4.sheader.html + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/kern/dl.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index fe7c3b940..cb49bdc4b 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -681,6 +681,9 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) + grub_dl_segment_t seg; + grub_err_t err; + ++ if (!(s->sh_flags & SHF_INFO_LINK)) ++ continue; ++ + seg = grub_dl_find_segment(mod, s->sh_info); + if (!seg) + continue; diff --git a/0324-commands-extcmd-Missing-check-for-failed-allocation.patch b/0324-commands-extcmd-Missing-check-for-failed-allocation.patch new file mode 100644 index 00000000..44e8c915 --- /dev/null +++ b/0324-commands-extcmd-Missing-check-for-failed-allocation.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Fri, 22 Nov 2024 06:27:55 +0000 +Subject: [PATCH] commands/extcmd: Missing check for failed allocation + +The grub_extcmd_dispatcher() calls grub_arg_list_alloc() to allocate +a grub_arg_list struct but it does not verify the allocation was successful. +In case of failed allocation the NULL state pointer can be accessed in +parse_option() through grub_arg_parse() which may lead to a security issue. + +Fixes: CVE-2024-45775 + +Reported-by: Nils Langius +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Alec Brown +--- + grub-core/commands/extcmd.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/commands/extcmd.c b/grub-core/commands/extcmd.c +index 90a5ca24a..c236be13a 100644 +--- a/grub-core/commands/extcmd.c ++++ b/grub-core/commands/extcmd.c +@@ -49,6 +49,9 @@ grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args, + } + + state = grub_arg_list_alloc (ext, argc, args); ++ if (state == NULL) ++ return grub_errno; ++ + if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc)) + { + context.state = state; diff --git a/0325-commands-ls-Fix-NULL-dereference.patch b/0325-commands-ls-Fix-NULL-dereference.patch new file mode 100644 index 00000000..c58177b7 --- /dev/null +++ b/0325-commands-ls-Fix-NULL-dereference.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Sun, 12 May 2024 11:08:23 +0100 +Subject: [PATCH] commands/ls: Fix NULL dereference + +The grub_strrchr() may return NULL when the dirname do not contain "/". +This can happen on broken filesystems. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/commands/ls.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c +index 6a1c7f5d3..f660946a2 100644 +--- a/grub-core/commands/ls.c ++++ b/grub-core/commands/ls.c +@@ -241,7 +241,11 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) + + grub_file_close (file); + +- p = grub_strrchr (dirname, '/') + 1; ++ p = grub_strrchr (dirname, '/'); ++ if (p == NULL) ++ goto fail; ++ ++p; ++ + ctx.dirname = grub_strndup (dirname, p - dirname); + if (ctx.dirname == NULL) + goto fail; diff --git a/0326-commands-pgp-Unregister-the-check_signatures-hooks-o.patch b/0326-commands-pgp-Unregister-the-check_signatures-hooks-o.patch new file mode 100644 index 00000000..8305f909 --- /dev/null +++ b/0326-commands-pgp-Unregister-the-check_signatures-hooks-o.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Fri, 1 Nov 2024 19:24:29 +0000 +Subject: [PATCH] commands/pgp: Unregister the "check_signatures" hooks on + module unload + +If the hooks are not removed they can be called after the module has +been unloaded leading to an use-after-free. + +Fixes: CVE-2025-0622 + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/commands/pgp.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c +index 847a5046a..fa3ef5c75 100644 +--- a/grub-core/commands/pgp.c ++++ b/grub-core/commands/pgp.c +@@ -982,6 +982,8 @@ GRUB_MOD_INIT(pgp) + + GRUB_MOD_FINI(pgp) + { ++ grub_register_variable_hook ("check_signatures", NULL, NULL); ++ grub_env_unset ("check_signatures"); + grub_verifier_unregister (&grub_pubkey_verifier); + grub_unregister_extcmd (cmd); + grub_unregister_extcmd (cmd_trust); diff --git a/0327-normal-Remove-variables-hooks-on-module-unload.patch b/0327-normal-Remove-variables-hooks-on-module-unload.patch new file mode 100644 index 00000000..d730194a --- /dev/null +++ b/0327-normal-Remove-variables-hooks-on-module-unload.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Fri, 1 Nov 2024 23:46:55 +0000 +Subject: [PATCH] normal: Remove variables hooks on module unload + +The normal module does not entirely cleanup after itself in +its GRUB_MOD_FINI() leaving a few variables hooks in place. +It is not possible to unload normal module now but fix the +issues for completeness. + +On the occasion replace 0s with NULLs for "pager" variable +hooks unregister. + +Fixes: CVE-2025-0622 + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/normal/main.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index cad840e06..dd20e5129 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -690,7 +690,9 @@ GRUB_MOD_FINI(normal) + grub_xputs = grub_xputs_saved; + + grub_set_history (0); +- grub_register_variable_hook ("pager", 0, 0); ++ grub_register_variable_hook ("pager", NULL, NULL); ++ grub_register_variable_hook ("color_normal", NULL, NULL); ++ grub_register_variable_hook ("color_highlight", NULL, NULL); + grub_fs_autoload_hook = 0; + grub_unregister_command (cmd_clear); + } diff --git a/0328-gettext-Remove-variables-hooks-on-module-unload.patch b/0328-gettext-Remove-variables-hooks-on-module-unload.patch new file mode 100644 index 00000000..9cc952ee --- /dev/null +++ b/0328-gettext-Remove-variables-hooks-on-module-unload.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Fri, 1 Nov 2024 23:52:06 +0000 +Subject: [PATCH] gettext: Remove variables hooks on module unload + +The gettext module does not entirely cleanup after itself in +its GRUB_MOD_FINI() leaving a few variables hooks in place. +It is not possible to unload gettext module because normal +module depends on it. Though fix the issues for completeness. + +Fixes: CVE-2025-0622 + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/gettext/gettext.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index 631af7a94..465143cb6 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -542,6 +542,10 @@ GRUB_MOD_INIT (gettext) + + GRUB_MOD_FINI (gettext) + { ++ grub_register_variable_hook ("locale_dir", NULL, NULL); ++ grub_register_variable_hook ("secondary_locale_dir", NULL, NULL); ++ grub_register_variable_hook ("lang", NULL, NULL); ++ + grub_gettext_delete_list (&main_context); + grub_gettext_delete_list (&secondary_context); + diff --git a/0329-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch b/0329-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch new file mode 100644 index 00000000..d8db5c15 --- /dev/null +++ b/0329-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Fri, 22 Nov 2024 06:27:56 +0000 +Subject: [PATCH] gettext: Integer overflow leads to heap OOB write or read + +Calculation of ctx->grub_gettext_msg_list size in grub_mofile_open() may +overflow leading to subsequent OOB write or read. This patch fixes the +issue by replacing grub_zalloc() and explicit multiplication with +grub_calloc() which does the same thing in safe manner. + +Fixes: CVE-2024-45776 + +Reported-by: Nils Langius +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Alec Brown +--- + grub-core/gettext/gettext.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index 465143cb6..c17040269 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -323,8 +323,8 @@ grub_mofile_open (struct grub_gettext_context *ctx, + for (ctx->grub_gettext_max_log = 0; ctx->grub_gettext_max >> ctx->grub_gettext_max_log; + ctx->grub_gettext_max_log++); + +- ctx->grub_gettext_msg_list = grub_zalloc (ctx->grub_gettext_max +- * sizeof (ctx->grub_gettext_msg_list[0])); ++ ctx->grub_gettext_msg_list = grub_calloc (ctx->grub_gettext_max, ++ sizeof (ctx->grub_gettext_msg_list[0])); + if (!ctx->grub_gettext_msg_list) + { + grub_file_close (fd); diff --git a/0330-gettext-Integer-overflow-leads-to-heap-OOB-write.patch b/0330-gettext-Integer-overflow-leads-to-heap-OOB-write.patch new file mode 100644 index 00000000..5b22d585 --- /dev/null +++ b/0330-gettext-Integer-overflow-leads-to-heap-OOB-write.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Fri, 22 Nov 2024 06:27:57 +0000 +Subject: [PATCH] gettext: Integer overflow leads to heap OOB write + +The size calculation of the translation buffer in +grub_gettext_getstr_from_position() may overflow +to 0 leading to heap OOB write. This patch fixes +the issue by using grub_add() and checking for +an overflow. + +Fixes: CVE-2024-45777 + +Reported-by: Nils Langius +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Alec Brown +--- + grub-core/gettext/gettext.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index c17040269..fffe3a054 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -99,6 +100,7 @@ grub_gettext_getstr_from_position (struct grub_gettext_context *ctx, + char *translation; + struct string_descriptor desc; + grub_err_t err; ++ grub_size_t alloc_sz; + + internal_position = (off + position * sizeof (desc)); + +@@ -109,7 +111,10 @@ grub_gettext_getstr_from_position (struct grub_gettext_context *ctx, + length = grub_cpu_to_le32 (desc.length); + offset = grub_cpu_to_le32 (desc.offset); + +- translation = grub_malloc (length + 1); ++ if (grub_add (length, 1, &alloc_sz)) ++ return NULL; ++ ++ translation = grub_malloc (alloc_sz); + if (!translation) + return NULL; + diff --git a/0331-commands-read-Fix-an-integer-overflow-when-supplying.patch b/0331-commands-read-Fix-an-integer-overflow-when-supplying.patch new file mode 100644 index 00000000..33ea08dd --- /dev/null +++ b/0331-commands-read-Fix-an-integer-overflow-when-supplying.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jonathan Bar Or +Date: Thu, 23 Jan 2025 19:17:05 +0100 +Subject: [PATCH] commands/read: Fix an integer overflow when supplying more + than 2^31 characters + +The grub_getline() function currently has a signed integer variable "i" +that can be overflown when user supplies more than 2^31 characters. +It results in a memory corruption of the allocated line buffer as well +as supplying large negative values to grub_realloc(). + +Fixes: CVE-2025-0690 + +Reported-by: Jonathan Bar Or +Signed-off-by: Jonathan Bar Or +Reviewed-by: Daniel Kiper +--- + grub-core/commands/read.c | 19 +++++++++++++++---- + 1 file changed, 15 insertions(+), 4 deletions(-) + +diff --git a/grub-core/commands/read.c b/grub-core/commands/read.c +index 597c90706..8d72e45c9 100644 +--- a/grub-core/commands/read.c ++++ b/grub-core/commands/read.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -37,13 +38,14 @@ static const struct grub_arg_option options[] = + static char * + grub_getline (int silent) + { +- int i; ++ grub_size_t i; + char *line; + char *tmp; + int c; ++ grub_size_t alloc_size; + + i = 0; +- line = grub_malloc (1 + i + sizeof('\0')); ++ line = grub_malloc (1 + sizeof('\0')); + if (! line) + return NULL; + +@@ -59,8 +61,17 @@ grub_getline (int silent) + line[i] = (char) c; + if (!silent) + grub_printf ("%c", c); +- i++; +- tmp = grub_realloc (line, 1 + i + sizeof('\0')); ++ if (grub_add (i, 1, &i)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ if (grub_add (i, 1 + sizeof('\0'), &alloc_size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ tmp = grub_realloc (line, alloc_size); + if (! tmp) + { + grub_free (line); diff --git a/0332-commands-test-Stack-overflow-due-to-unlimited-recurs.patch b/0332-commands-test-Stack-overflow-due-to-unlimited-recurs.patch new file mode 100644 index 00000000..3dc101b1 --- /dev/null +++ b/0332-commands-test-Stack-overflow-due-to-unlimited-recurs.patch @@ -0,0 +1,83 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Mon, 16 Dec 2024 20:22:41 +0000 +Subject: [PATCH] commands/test: Stack overflow due to unlimited recursion + depth + +The test_parse() evaluates test expression recursively. Due to lack of +recursion depth check a specially crafted expression may cause a stack +overflow. The recursion is only triggered by the parentheses usage and +it can be unlimited. However, sensible expressions are unlikely to +contain more than a few parentheses. So, this patch limits the recursion +depth to 100, which should be sufficient. + +Reported-by: Nils Langius +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/commands/test.c | 21 ++++++++++++++++++--- + 1 file changed, 18 insertions(+), 3 deletions(-) + +diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c +index 62d3fb398..b585c3d70 100644 +--- a/grub-core/commands/test.c ++++ b/grub-core/commands/test.c +@@ -29,6 +29,9 @@ + + GRUB_MOD_LICENSE ("GPLv3+"); + ++/* Set a limit on recursion to avoid stack overflow. */ ++#define MAX_TEST_RECURSION_DEPTH 100 ++ + /* A simple implementation for signed numbers. */ + static int + grub_strtosl (char *arg, const char ** const end, int base) +@@ -150,7 +153,7 @@ get_fileinfo (char *path, struct test_parse_ctx *ctx) + + /* Parse a test expression starting from *argn. */ + static int +-test_parse (char **args, int *argn, int argc) ++test_parse (char **args, int *argn, int argc, int *depth) + { + struct test_parse_ctx ctx = { + .and = 1, +@@ -387,13 +390,24 @@ test_parse (char **args, int *argn, int argc) + if (grub_strcmp (args[*argn], ")") == 0) + { + (*argn)++; ++ if (*depth > 0) ++ (*depth)--; ++ + return ctx.or || ctx.and; + } + /* Recursively invoke if parenthesis. */ + if (grub_strcmp (args[*argn], "(") == 0) + { + (*argn)++; +- update_val (test_parse (args, argn, argc), &ctx); ++ ++ if (++(*depth) > MAX_TEST_RECURSION_DEPTH) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("max recursion depth exceeded")); ++ depth--; ++ return ctx.or || ctx.and; ++ } ++ ++ update_val (test_parse (args, argn, argc, depth), &ctx); + continue; + } + +@@ -428,11 +442,12 @@ grub_cmd_test (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) + { + int argn = 0; ++ int depth = 0; + + if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0) + argc--; + +- return test_parse (args, &argn, argc) ? GRUB_ERR_NONE ++ return test_parse (args, &argn, argc, &depth) ? GRUB_ERR_NONE + : grub_error (GRUB_ERR_TEST_FAILURE, N_("false")); + } + diff --git a/0333-commands-minicmd-Block-the-dump-command-in-lockdown-.patch b/0333-commands-minicmd-Block-the-dump-command-in-lockdown-.patch new file mode 100644 index 00000000..a9991461 --- /dev/null +++ b/0333-commands-minicmd-Block-the-dump-command-in-lockdown-.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Thu, 18 Apr 2024 20:29:39 +0100 +Subject: [PATCH] commands/minicmd: Block the dump command in lockdown mode + +The dump enables a user to read memory which should not be possible +in lockdown mode. + +Fixes: CVE-2025-1118 + +Reported-by: B Horn +Reported-by: Jonathan Bar Or +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/commands/minicmd.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c +index 2001043cf..9efb7718c 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -215,8 +215,8 @@ GRUB_MOD_INIT(minicmd) + grub_register_command ("help", grub_mini_cmd_help, + 0, N_("Show this message.")); + cmd_dump = +- grub_register_command ("dump", grub_mini_cmd_dump, +- N_("ADDR [SIZE]"), N_("Show memory contents.")); ++ grub_register_command_lockdown ("dump", grub_mini_cmd_dump, ++ N_("ADDR [SIZE]"), N_("Show memory contents.")); + cmd_rmmod = + grub_register_command ("rmmod", grub_mini_cmd_rmmod, + N_("MODULE"), N_("Remove a module.")); diff --git a/0334-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch b/0334-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch new file mode 100644 index 00000000..e787d6f7 --- /dev/null +++ b/0334-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Tue, 11 Feb 2025 17:12:29 -0600 +Subject: [PATCH] commands/memrw: Disable memory reading in lockdown mode + +With the rest of module being blocked in lockdown mode it does not make +a lot of sense to leave memory reading enabled. This also goes in par +with disabling the dump command. + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/commands/memrw.c | 21 ++++++++++++--------- + 1 file changed, 12 insertions(+), 9 deletions(-) + +diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c +index 39cf3a06d..9d8a54a4b 100644 +--- a/grub-core/commands/memrw.c ++++ b/grub-core/commands/memrw.c +@@ -126,17 +126,20 @@ GRUB_MOD_INIT(memrw) + return; + + cmd_read_byte = +- grub_register_extcmd ("read_byte", grub_cmd_read, 0, +- N_("ADDR"), N_("Read 8-bit value from ADDR."), +- options); ++ grub_register_extcmd_lockdown ("read_byte", grub_cmd_read, 0, ++ N_("ADDR"), ++ N_("Read 8-bit value from ADDR."), ++ options); + cmd_read_word = +- grub_register_extcmd ("read_word", grub_cmd_read, 0, +- N_("ADDR"), N_("Read 16-bit value from ADDR."), +- options); ++ grub_register_extcmd_lockdown ("read_word", grub_cmd_read, 0, ++ N_("ADDR"), ++ N_("Read 16-bit value from ADDR."), ++ options); + cmd_read_dword = +- grub_register_extcmd ("read_dword", grub_cmd_read, 0, +- N_("ADDR"), N_("Read 32-bit value from ADDR."), +- options); ++ grub_register_extcmd_lockdown ("read_dword", grub_cmd_read, 0, ++ N_("ADDR"), ++ N_("Read 32-bit value from ADDR."), ++ options); + cmd_write_byte = + grub_register_command_lockdown ("write_byte", grub_cmd_write, + N_("ADDR VALUE [MASK]"), diff --git a/0335-commands-hexdump-Disable-memory-reading-in-lockdown-.patch b/0335-commands-hexdump-Disable-memory-reading-in-lockdown-.patch new file mode 100644 index 00000000..ae523f80 --- /dev/null +++ b/0335-commands-hexdump-Disable-memory-reading-in-lockdown-.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: B Horn +Date: Fri, 19 Apr 2024 22:31:45 +0100 +Subject: [PATCH] commands/hexdump: Disable memory reading in lockdown mode + +Reported-by: B Horn +Signed-off-by: B Horn +Reviewed-by: Daniel Kiper +--- + grub-core/commands/hexdump.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/hexdump.c b/grub-core/commands/hexdump.c +index eaa12465b..d6f61d98a 100644 +--- a/grub-core/commands/hexdump.c ++++ b/grub-core/commands/hexdump.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -51,7 +52,11 @@ grub_cmd_hexdump (grub_extcmd_context_t ctxt, int argc, char **args) + length = (state[1].set) ? grub_strtoul (state[1].arg, 0, 0) : 256; + + if (!grub_strcmp (args[0], "(mem)")) +- hexdump (skip, (char *) (grub_addr_t) skip, length); ++ { ++ if (grub_is_lockdown() == GRUB_LOCKDOWN_ENABLED) ++ return grub_error (GRUB_ERR_ACCESS_DENIED, N_("memory reading is disabled in lockdown mode")); ++ hexdump (skip, (char *) (grub_addr_t) skip, length); ++ } + else if ((args[0][0] == '(') && (args[0][namelen - 1] == ')')) + { + grub_disk_t disk; diff --git a/0336-fs-bfs-Disable-under-lockdown.patch b/0336-fs-bfs-Disable-under-lockdown.patch new file mode 100644 index 00000000..c8364628 --- /dev/null +++ b/0336-fs-bfs-Disable-under-lockdown.patch @@ -0,0 +1,52 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Sat, 23 Mar 2024 15:59:43 +1100 +Subject: [PATCH] fs/bfs: Disable under lockdown + +The BFS is not fuzz-clean. Don't allow it to be loaded under lockdown. +This will also disable the AFS. + +Fixes: CVE-2024-45778 +Fixes: CVE-2024-45779 + +Reported-by: Nils Langius +Signed-off-by: Daniel Axtens +Reviewed-by: Daniel Kiper +--- + grub-core/fs/bfs.c | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/grub-core/fs/bfs.c b/grub-core/fs/bfs.c +index f37b16895..c92fd7916 100644 +--- a/grub-core/fs/bfs.c ++++ b/grub-core/fs/bfs.c +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1106,8 +1107,11 @@ GRUB_MOD_INIT (bfs) + { + COMPILE_TIME_ASSERT (1 << LOG_EXTENT_SIZE == + sizeof (struct grub_bfs_extent)); +- grub_bfs_fs.mod = mod; +- grub_fs_register (&grub_bfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_bfs_fs.mod = mod; ++ grub_fs_register (&grub_bfs_fs); ++ } + } + + #ifdef MODE_AFS +@@ -1116,5 +1120,6 @@ GRUB_MOD_FINI (afs) + GRUB_MOD_FINI (bfs) + #endif + { +- grub_fs_unregister (&grub_bfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_bfs_fs); + } diff --git a/0337-fs-Disable-many-filesystems-under-lockdown.patch b/0337-fs-Disable-many-filesystems-under-lockdown.patch new file mode 100644 index 00000000..edd6c407 --- /dev/null +++ b/0337-fs-Disable-many-filesystems-under-lockdown.patch @@ -0,0 +1,391 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Sat, 23 Mar 2024 16:20:45 +1100 +Subject: [PATCH] fs: Disable many filesystems under lockdown + +The idea is to permit the following: btrfs, cpio, exfat, ext, f2fs, fat, +hfsplus, iso9660, squash4, tar, xfs and zfs. + +The JFS, ReiserFS, romfs, UDF and UFS security vulnerabilities were +reported by Jonathan Bar Or . + +Fixes: CVE-2025-0677 +Fixes: CVE-2025-0684 +Fixes: CVE-2025-0685 +Fixes: CVE-2025-0686 +Fixes: CVE-2025-0689 + +Suggested-by: Daniel Axtens +Signed-off-by: Daniel Axtens +Reviewed-by: Daniel Kiper +--- + grub-core/fs/affs.c | 11 ++++++++--- + grub-core/fs/cbfs.c | 11 ++++++++--- + grub-core/fs/jfs.c | 11 ++++++++--- + grub-core/fs/minix.c | 11 ++++++++--- + grub-core/fs/nilfs2.c | 11 ++++++++--- + grub-core/fs/ntfs.c | 11 ++++++++--- + grub-core/fs/reiserfs.c | 11 ++++++++--- + grub-core/fs/romfs.c | 11 ++++++++--- + grub-core/fs/sfs.c | 11 ++++++++--- + grub-core/fs/udf.c | 11 ++++++++--- + grub-core/fs/ufs.c | 11 ++++++++--- + 11 files changed, 88 insertions(+), 33 deletions(-) + +diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c +index 9b0afb954..520a001c7 100644 +--- a/grub-core/fs/affs.c ++++ b/grub-core/fs/affs.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -703,12 +704,16 @@ static struct grub_fs grub_affs_fs = + + GRUB_MOD_INIT(affs) + { +- grub_affs_fs.mod = mod; +- grub_fs_register (&grub_affs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_affs_fs.mod = mod; ++ grub_fs_register (&grub_affs_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI(affs) + { +- grub_fs_unregister (&grub_affs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_affs_fs); + } +diff --git a/grub-core/fs/cbfs.c b/grub-core/fs/cbfs.c +index 2332745fe..b62c8777c 100644 +--- a/grub-core/fs/cbfs.c ++++ b/grub-core/fs/cbfs.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -390,13 +391,17 @@ GRUB_MOD_INIT (cbfs) + #if (defined (__i386__) || defined (__x86_64__)) && !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_MACHINE_XEN) + init_cbfsdisk (); + #endif +- grub_cbfs_fs.mod = mod; +- grub_fs_register (&grub_cbfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_cbfs_fs.mod = mod; ++ grub_fs_register (&grub_cbfs_fs); ++ } + } + + GRUB_MOD_FINI (cbfs) + { +- grub_fs_unregister (&grub_cbfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_cbfs_fs); + #if (defined (__i386__) || defined (__x86_64__)) && !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_MACHINE_XEN) + fini_cbfsdisk (); + #endif +diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c +index b0283ac00..ab175c7f1 100644 +--- a/grub-core/fs/jfs.c ++++ b/grub-core/fs/jfs.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1005,12 +1006,16 @@ static struct grub_fs grub_jfs_fs = + + GRUB_MOD_INIT(jfs) + { +- grub_jfs_fs.mod = mod; +- grub_fs_register (&grub_jfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_jfs_fs.mod = mod; ++ grub_fs_register (&grub_jfs_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI(jfs) + { +- grub_fs_unregister (&grub_jfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_jfs_fs); + } +diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c +index b7679c3e2..4440fcca8 100644 +--- a/grub-core/fs/minix.c ++++ b/grub-core/fs/minix.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -734,8 +735,11 @@ GRUB_MOD_INIT(minix) + #endif + #endif + { +- grub_minix_fs.mod = mod; +- grub_fs_register (&grub_minix_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_minix_fs.mod = mod; ++ grub_fs_register (&grub_minix_fs); ++ } + my_mod = mod; + } + +@@ -757,5 +761,6 @@ GRUB_MOD_FINI(minix) + #endif + #endif + { +- grub_fs_unregister (&grub_minix_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_minix_fs); + } +diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c +index 4e1e71738..26e6077ff 100644 +--- a/grub-core/fs/nilfs2.c ++++ b/grub-core/fs/nilfs2.c +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1231,12 +1232,16 @@ GRUB_MOD_INIT (nilfs2) + grub_nilfs2_dat_entry)); + COMPILE_TIME_ASSERT (1 << LOG_INODE_SIZE + == sizeof (struct grub_nilfs2_inode)); +- grub_nilfs2_fs.mod = mod; +- grub_fs_register (&grub_nilfs2_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_nilfs2_fs.mod = mod; ++ grub_fs_register (&grub_nilfs2_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI (nilfs2) + { +- grub_fs_unregister (&grub_nilfs2_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_nilfs2_fs); + } +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index 4e144cc3c..e00349b1d 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1541,12 +1542,16 @@ static struct grub_fs grub_ntfs_fs = + + GRUB_MOD_INIT (ntfs) + { +- grub_ntfs_fs.mod = mod; +- grub_fs_register (&grub_ntfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_ntfs_fs.mod = mod; ++ grub_fs_register (&grub_ntfs_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI (ntfs) + { +- grub_fs_unregister (&grub_ntfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_ntfs_fs); + } +diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c +index e8b0b6383..ca47e0a43 100644 +--- a/grub-core/fs/reiserfs.c ++++ b/grub-core/fs/reiserfs.c +@@ -39,6 +39,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1407,12 +1408,16 @@ static struct grub_fs grub_reiserfs_fs = + + GRUB_MOD_INIT(reiserfs) + { +- grub_reiserfs_fs.mod = mod; +- grub_fs_register (&grub_reiserfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_reiserfs_fs.mod = mod; ++ grub_fs_register (&grub_reiserfs_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI(reiserfs) + { +- grub_fs_unregister (&grub_reiserfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_reiserfs_fs); + } +diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c +index 56b0b2b2f..eafab03b2 100644 +--- a/grub-core/fs/romfs.c ++++ b/grub-core/fs/romfs.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -475,11 +476,15 @@ static struct grub_fs grub_romfs_fs = + + GRUB_MOD_INIT(romfs) + { +- grub_romfs_fs.mod = mod; +- grub_fs_register (&grub_romfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_romfs_fs.mod = mod; ++ grub_fs_register (&grub_romfs_fs); ++ } + } + + GRUB_MOD_FINI(romfs) + { +- grub_fs_unregister (&grub_romfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_romfs_fs); + } +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index f0d7cac43..88705b3a2 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + #include + + GRUB_MOD_LICENSE ("GPLv3+"); +@@ -779,12 +780,16 @@ static struct grub_fs grub_sfs_fs = + + GRUB_MOD_INIT(sfs) + { +- grub_sfs_fs.mod = mod; +- grub_fs_register (&grub_sfs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_sfs_fs.mod = mod; ++ grub_fs_register (&grub_sfs_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI(sfs) + { +- grub_fs_unregister (&grub_sfs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_sfs_fs); + } +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index 8765c633c..3d5ee5af5 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -1455,12 +1456,16 @@ static struct grub_fs grub_udf_fs = { + + GRUB_MOD_INIT (udf) + { +- grub_udf_fs.mod = mod; +- grub_fs_register (&grub_udf_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_udf_fs.mod = mod; ++ grub_fs_register (&grub_udf_fs); ++ } + my_mod = mod; + } + + GRUB_MOD_FINI (udf) + { +- grub_fs_unregister (&grub_udf_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_udf_fs); + } +diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c +index e82d9356d..8b5adbd48 100644 +--- a/grub-core/fs/ufs.c ++++ b/grub-core/fs/ufs.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -899,8 +900,11 @@ GRUB_MOD_INIT(ufs1) + #endif + #endif + { +- grub_ufs_fs.mod = mod; +- grub_fs_register (&grub_ufs_fs); ++ if (!grub_is_lockdown ()) ++ { ++ grub_ufs_fs.mod = mod; ++ grub_fs_register (&grub_ufs_fs); ++ } + my_mod = mod; + } + +@@ -914,6 +918,7 @@ GRUB_MOD_FINI(ufs1) + #endif + #endif + { +- grub_fs_unregister (&grub_ufs_fs); ++ if (!grub_is_lockdown ()) ++ grub_fs_unregister (&grub_ufs_fs); + } + diff --git a/0338-disk-Use-safe-math-macros-to-prevent-overflows.patch b/0338-disk-Use-safe-math-macros-to-prevent-overflows.patch new file mode 100644 index 00000000..db3d9371 --- /dev/null +++ b/0338-disk-Use-safe-math-macros-to-prevent-overflows.patch @@ -0,0 +1,543 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 11 Feb 2025 17:59:04 -0600 +Subject: [PATCH] disk: Use safe math macros to prevent overflows + +Replace direct arithmetic operations with macros from include/grub/safemath.h +to prevent potential overflow issues when calculating the memory sizes. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/disk/cryptodisk.c | 36 ++++++++++++++++++------ + grub-core/disk/diskfilter.c | 9 ++++-- + grub-core/disk/ieee1275/obdisk.c | 43 ++++++++++++++++++++++++---- + grub-core/disk/ieee1275/ofdisk.c | 60 ++++++++++++++++++++++++++++++++++------ + grub-core/disk/ldm.c | 36 ++++++++++++++++++++---- + grub-core/disk/luks2.c | 7 ++++- + grub-core/disk/memdisk.c | 7 ++++- + grub-core/disk/plainmount.c | 9 ++++-- + 8 files changed, 172 insertions(+), 35 deletions(-) + +diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c +index 06a42b2d7..872776010 100644 +--- a/grub-core/disk/cryptodisk.c ++++ b/grub-core/disk/cryptodisk.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #ifdef GRUB_UTIL + #include +@@ -1475,7 +1476,7 @@ static char * + luks_script_get (grub_size_t *sz) + { + grub_cryptodisk_t i; +- grub_size_t size = 0; ++ grub_size_t size = 0, mul; + char *ptr, *ret; + + *sz = 0; +@@ -1484,10 +1485,6 @@ luks_script_get (grub_size_t *sz) + if (grub_strcmp (i->modname, "luks") == 0 || + grub_strcmp (i->modname, "luks2") == 0) + { +- size += grub_strlen (i->modname); +- size += sizeof ("_mount"); +- size += grub_strlen (i->uuid); +- size += grub_strlen (i->cipher->cipher->name); + /* + * Add space in the line for (in order) spaces, cipher mode, cipher IV + * mode, sector offset, sector size and the trailing newline. This is +@@ -1495,14 +1492,35 @@ luks_script_get (grub_size_t *sz) + * in an earlier version of this code that are unaccounted for. It is + * left in the calculations in case it is needed. At worst, its short- + * lived wasted space. ++ * ++ * 60 = 5 + 5 + 8 + 20 + 6 + 1 + 15 + */ +- size += 5 + 5 + 8 + 20 + 6 + 1 + 15; ++ if (grub_add (size, grub_strlen (i->modname), &size) || ++ grub_add (size, sizeof ("_mount") + 60, &size) || ++ grub_add (size, grub_strlen (i->uuid), &size) || ++ grub_add (size, grub_strlen (i->cipher->cipher->name), &size) || ++ grub_mul (i->keysize, 2, &mul) || ++ grub_add (size, mul, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while obtaining size of luks script"); ++ return 0; ++ } + if (i->essiv_hash) +- size += grub_strlen (i->essiv_hash->name); +- size += i->keysize * 2; ++ { ++ if (grub_add (size, grub_strlen (i->essiv_hash->name), &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while obtaining size of luks script"); ++ return 0; ++ } ++ } + } ++ if (grub_add (size, 1, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while obtaining size of luks script"); ++ return 0; ++ } + +- ret = grub_malloc (size + 1); ++ ret = grub_malloc (size); + if (!ret) + return 0; + +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index c35ce8915..fef0b815a 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #ifdef GRUB_UTIL + #include + #include +@@ -1041,7 +1042,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, + { + struct grub_diskfilter_vg *array; + int i; +- grub_size_t j; ++ grub_size_t j, sz; + grub_uint64_t totsize; + struct grub_diskfilter_pv *pv; + grub_err_t err; +@@ -1142,7 +1143,11 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, + } + array->lvs->vg = array; + +- array->lvs->idname = grub_malloc (sizeof ("mduuid/") + 2 * uuidlen); ++ if (grub_mul (uuidlen, 2, &sz) || ++ grub_add (sz, sizeof ("mduuid/"), &sz)) ++ goto fail; ++ ++ array->lvs->idname = grub_malloc (sz); + if (!array->lvs->idname) + goto fail; + +diff --git a/grub-core/disk/ieee1275/obdisk.c b/grub-core/disk/ieee1275/obdisk.c +index cd923b90f..9d4c42665 100644 +--- a/grub-core/disk/ieee1275/obdisk.c ++++ b/grub-core/disk/ieee1275/obdisk.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -128,9 +129,17 @@ count_commas (const char *src) + static char * + decode_grub_devname (const char *name) + { +- char *devpath = grub_malloc (grub_strlen (name) + 1); ++ char *devpath; + char *p, c; ++ grub_size_t sz; + ++ if (grub_add (grub_strlen (name), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device name")); ++ return NULL; ++ } ++ ++ devpath = grub_malloc (sz); + if (devpath == NULL) + return NULL; + +@@ -156,12 +165,20 @@ static char * + encode_grub_devname (const char *path) + { + char *encoding, *optr; ++ grub_size_t sz; + + if (path == NULL) + return NULL; + +- encoding = grub_malloc (sizeof (IEEE1275_DEV) + count_commas (path) + +- grub_strlen (path) + 1); ++ if (grub_add (sizeof (IEEE1275_DEV) + 1, count_commas (path), &sz) || ++ grub_add (sz, grub_strlen (path), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining encoding size")); ++ grub_print_error (); ++ return NULL; ++ } ++ ++ encoding = grub_malloc (sz); + + if (encoding == NULL) + { +@@ -396,6 +413,14 @@ canonicalise_disk (const char *devname) + + real_unit_str_len = grub_strlen (op->name) + sizeof (IEEE1275_DISK_ALIAS) + + grub_strlen (real_unit_address); ++ if (grub_add (grub_strlen (op->name), sizeof (IEEE1275_DISK_ALIAS), &real_unit_str_len) || ++ grub_add (real_unit_str_len, grub_strlen (real_unit_address), &real_unit_str_len)) ++ { ++ grub_free (parent); ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of canonical name")); ++ grub_print_error (); ++ return NULL; ++ } + + real_canon = grub_malloc (real_unit_str_len); + +@@ -413,6 +438,7 @@ canonicalise_disk (const char *devname) + static struct disk_dev * + add_canon_disk (const char *cname) + { ++ grub_size_t sz; + struct disk_dev *dev; + + dev = grub_zalloc (sizeof (struct disk_dev)); +@@ -428,13 +454,18 @@ add_canon_disk (const char *cname) + * arguments and allows a client program to open + * the entire (raw) disk. Any disk label is ignored. + */ +- dev->raw_name = grub_malloc (grub_strlen (cname) + sizeof (":nolabel")); ++ if (grub_add (grub_strlen (cname), sizeof (":nolabel"), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while appending :nolabel to end of canonical name"); ++ goto failed; ++ } ++ ++ dev->raw_name = grub_malloc (sz); + + if (dev->raw_name == NULL) + goto failed; + +- grub_snprintf (dev->raw_name, grub_strlen (cname) + sizeof (":nolabel"), +- "%s:nolabel", cname); ++ grub_snprintf (dev->raw_name, sz, "%s:nolabel", cname); + } + + /* +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index 57624fde5..6c628635f 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + static char *last_devpath; + static grub_ieee1275_ihandle_t last_ihandle; +@@ -81,6 +82,7 @@ ofdisk_hash_add_real (char *devpath) + struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)]; + const char *iptr; + char *optr; ++ grub_size_t sz; + + p = grub_zalloc (sizeof (*p)); + if (!p) +@@ -88,8 +90,14 @@ ofdisk_hash_add_real (char *devpath) + + p->devpath = devpath; + +- p->grub_devpath = grub_malloc (sizeof ("ieee1275/") +- + 2 * grub_strlen (p->devpath)); ++ if (grub_mul (grub_strlen (p->devpath), 2, &sz) || ++ grub_add (sz, sizeof ("ieee1275/"), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device path")); ++ return NULL; ++ } ++ ++ p->grub_devpath = grub_malloc (sz); + + if (!p->grub_devpath) + { +@@ -99,7 +107,13 @@ ofdisk_hash_add_real (char *devpath) + + if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0)) + { +- p->open_path = grub_malloc (grub_strlen (p->devpath) + 3); ++ if (grub_add (grub_strlen (p->devpath), 3, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open path")); ++ return NULL; ++ } ++ ++ p->open_path = grub_malloc (sz); + if (!p->open_path) + { + grub_free (p->grub_devpath); +@@ -225,7 +239,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + args; + char *buf, *bufptr; + unsigned i; +- ++ grub_size_t sz; + + RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle) + if (! ihandle) +@@ -246,7 +260,14 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + return; + } + +- buf = grub_malloc (grub_strlen (alias->path) + 32); ++ if (grub_add (grub_strlen (alias->path), 32, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while creating buffer for vscsi"); ++ grub_ieee1275_close (ihandle); ++ return; ++ } ++ ++ buf = grub_malloc (sz); + if (!buf) + return; + bufptr = grub_stpcpy (buf, alias->path); +@@ -290,9 +311,15 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + grub_uint64_t *table; + grub_uint16_t table_size; + grub_ieee1275_ihandle_t ihandle; ++ grub_size_t sz; + +- buf = grub_malloc (grub_strlen (alias->path) + +- sizeof ("/disk@7766554433221100")); ++ if (grub_add (grub_strlen (alias->path), sizeof ("/disk@7766554433221100"), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while creating buffer for sas_ioa"); ++ return; ++ } ++ ++ buf = grub_malloc (sz); + if (!buf) + return; + bufptr = grub_stpcpy (buf, alias->path); +@@ -432,9 +459,17 @@ grub_ofdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, + static char * + compute_dev_path (const char *name) + { +- char *devpath = grub_malloc (grub_strlen (name) + 3); ++ char *devpath; + char *p, c; ++ grub_size_t sz; + ++ if (grub_add (grub_strlen (name), 3, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device path")); ++ return NULL; ++ } ++ ++ devpath = grub_malloc (sz); + if (!devpath) + return NULL; + +@@ -657,6 +692,7 @@ insert_bootpath (void) + char *bootpath; + grub_ssize_t bootpath_size; + char *type; ++ grub_size_t sz; + + if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath", + &bootpath_size) +@@ -667,7 +703,13 @@ insert_bootpath (void) + return; + } + +- bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64); ++ if (grub_add (bootpath_size, 64, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining bootpath size")); ++ return; ++ } ++ ++ bootpath = (char *) grub_malloc (sz); + if (! bootpath) + { + grub_print_error (); +diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c +index 34bfe6bd1..4101b15d8 100644 +--- a/grub-core/disk/ldm.c ++++ b/grub-core/disk/ldm.c +@@ -220,6 +220,7 @@ make_vg (grub_disk_t disk, + struct grub_ldm_vblk vblk[GRUB_DISK_SECTOR_SIZE + / sizeof (struct grub_ldm_vblk)]; + unsigned i; ++ grub_size_t sz; + err = grub_disk_read (disk, cursec, 0, + sizeof(vblk), &vblk); + if (err) +@@ -251,7 +252,13 @@ make_vg (grub_disk_t disk, + grub_free (pv); + goto fail2; + } +- pv->internal_id = grub_malloc (ptr[0] + 2); ++ if (grub_add (ptr[0], 2, &sz)) ++ { ++ grub_free (pv); ++ goto fail2; ++ } ++ ++ pv->internal_id = grub_malloc (sz); + if (!pv->internal_id) + { + grub_free (pv); +@@ -276,7 +283,15 @@ make_vg (grub_disk_t disk, + goto fail2; + } + pv->id.uuidlen = *ptr; +- pv->id.uuid = grub_malloc (pv->id.uuidlen + 1); ++ ++ if (grub_add (pv->id.uuidlen, 1, &sz)) ++ { ++ grub_free (pv->internal_id); ++ grub_free (pv); ++ goto fail2; ++ } ++ ++ pv->id.uuid = grub_malloc (sz); + grub_memcpy (pv->id.uuid, ptr + 1, pv->id.uuidlen); + pv->id.uuid[pv->id.uuidlen] = 0; + +@@ -343,7 +358,13 @@ make_vg (grub_disk_t disk, + grub_free (lv); + goto fail2; + } +- lv->internal_id = grub_malloc ((grub_size_t) ptr[0] + 2); ++ if (grub_add (ptr[0], 2, &sz)) ++ { ++ grub_free (lv->segments); ++ grub_free (lv); ++ goto fail2; ++ } ++ lv->internal_id = grub_malloc (sz); + if (!lv->internal_id) + { + grub_free (lv); +@@ -455,6 +476,7 @@ make_vg (grub_disk_t disk, + struct grub_ldm_vblk vblk[GRUB_DISK_SECTOR_SIZE + / sizeof (struct grub_ldm_vblk)]; + unsigned i; ++ grub_size_t sz; + err = grub_disk_read (disk, cursec, 0, + sizeof(vblk), &vblk); + if (err) +@@ -490,7 +512,12 @@ make_vg (grub_disk_t disk, + grub_free (comp); + goto fail2; + } +- comp->internal_id = grub_malloc ((grub_size_t) ptr[0] + 2); ++ if (grub_add (ptr[0], 2, &sz)) ++ { ++ grub_free (comp); ++ goto fail2; ++ } ++ comp->internal_id = grub_malloc (sz); + if (!comp->internal_id) + { + grub_free (comp); +@@ -640,7 +667,6 @@ make_vg (grub_disk_t disk, + if (lv->segments->node_alloc == lv->segments->node_count) + { + void *t; +- grub_size_t sz; + + if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) || + grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz)) +diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c +index d5106402f..8036d76ff 100644 +--- a/grub-core/disk/luks2.c ++++ b/grub-core/disk/luks2.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -569,6 +570,7 @@ luks2_recover_key (grub_disk_t source, + gcry_err_code_t gcry_ret; + grub_json_t *json = NULL, keyslots; + grub_err_t ret; ++ grub_size_t sz; + + if (cargs->key_data == NULL || cargs->key_len == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no key data"); +@@ -577,7 +579,10 @@ luks2_recover_key (grub_disk_t source, + if (ret) + return ret; + +- json_header = grub_zalloc (grub_be_to_cpu64 (header.hdr_size) - sizeof (header)); ++ if (grub_sub (grub_be_to_cpu64 (header.hdr_size), sizeof (header), &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, "underflow detected while calculating json header size"); ++ ++ json_header = grub_zalloc (sz); + if (!json_header) + return GRUB_ERR_OUT_OF_MEMORY; + +diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c +index 613779cf3..36de3bfab 100644 +--- a/grub-core/disk/memdisk.c ++++ b/grub-core/disk/memdisk.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -96,7 +97,11 @@ GRUB_MOD_INIT(memdisk) + + grub_dprintf ("memdisk", "Found memdisk image at %p\n", memdisk_orig_addr); + +- memdisk_size = header->size - sizeof (struct grub_module_header); ++ if (grub_sub (header->size, sizeof (struct grub_module_header), &memdisk_size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "underflow detected while obtaining memdisk size"); ++ return; ++ } + memdisk_addr = grub_malloc (memdisk_size); + + grub_dprintf ("memdisk", "Copying memdisk image to dynamic memory\n"); +diff --git a/grub-core/disk/plainmount.c b/grub-core/disk/plainmount.c +index 47e64805f..21ec4072c 100644 +--- a/grub-core/disk/plainmount.c ++++ b/grub-core/disk/plainmount.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -126,7 +127,7 @@ plainmount_configure_password (grub_cryptodisk_t dev, const char *hash, + grub_uint8_t *derived_hash, *dh; + char *p; + unsigned int round, i, len, size; +- grub_size_t alloc_size; ++ grub_size_t alloc_size, sz; + grub_err_t err = GRUB_ERR_NONE; + + /* Support none (plain) hash */ +@@ -145,7 +146,11 @@ plainmount_configure_password (grub_cryptodisk_t dev, const char *hash, + * Allocate buffer for the password and for an added prefix character + * for each hash round ('alloc_size' may not be a multiple of 'len'). + */ +- p = grub_zalloc (alloc_size + (alloc_size / len) + 1); ++ if (grub_add (alloc_size, (alloc_size / len), &sz) || ++ grub_add (sz, 1, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while allocating size of password buffer")); ++ ++ p = grub_zalloc (sz); + derived_hash = grub_zalloc (GRUB_CRYPTODISK_MAX_KEYLEN * 2); + if (p == NULL || derived_hash == NULL) + { diff --git a/0339-disk-Prevent-overflows-when-allocating-memory-for-ar.patch b/0339-disk-Prevent-overflows-when-allocating-memory-for-ar.patch new file mode 100644 index 00000000..15a916f2 --- /dev/null +++ b/0339-disk-Prevent-overflows-when-allocating-memory-for-ar.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 12 Feb 2025 10:26:44 -0600 +Subject: [PATCH] disk: Prevent overflows when allocating memory for arrays + +Use grub_calloc() when allocating memory for arrays to ensure proper +overflow checks are in place. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/disk/lvm.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index 794248540..a395b200d 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -671,8 +671,7 @@ grub_lvm_detect (grub_disk_t disk, + goto lvs_segment_fail; + } + +- seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) +- * seg->node_count); ++ seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); + + p = grub_strstr (p, "mirrors = ["); + if (p == NULL) +@@ -760,8 +759,7 @@ grub_lvm_detect (grub_disk_t disk, + } + } + +- seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) +- * seg->node_count); ++ seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); + + p = grub_strstr (p, "raids = ["); + if (p == NULL) diff --git a/0340-disk-Check-if-returned-pointer-for-allocated-memory-.patch b/0340-disk-Check-if-returned-pointer-for-allocated-memory-.patch new file mode 100644 index 00000000..efb631e9 --- /dev/null +++ b/0340-disk-Check-if-returned-pointer-for-allocated-memory-.patch @@ -0,0 +1,152 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 22 Jan 2025 02:55:11 +0000 +Subject: [PATCH] disk: Check if returned pointer for allocated memory is NULL + +When using grub_malloc(), grub_zalloc() or grub_calloc(), these functions can +fail if we are out of memory. After allocating memory we should check if these +functions returned NULL and handle this error if they did. + +On the occasion make a NULL check in ATA code more obvious. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/disk/ata.c | 4 ++-- + grub-core/disk/ieee1275/obdisk.c | 6 ++++++ + grub-core/disk/ldm.c | 6 ++++++ + grub-core/disk/lvm.c | 14 ++++++++++++++ + grub-core/disk/memdisk.c | 2 ++ + 5 files changed, 30 insertions(+), 2 deletions(-) + +diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c +index 7b6ac7bfc..a2433e29e 100644 +--- a/grub-core/disk/ata.c ++++ b/grub-core/disk/ata.c +@@ -112,10 +112,10 @@ grub_ata_identify (struct grub_ata *dev) + return grub_atapi_identify (dev); + + info64 = grub_malloc (GRUB_DISK_SECTOR_SIZE); ++ if (info64 == NULL) ++ return grub_errno; + info32 = (grub_uint32_t *) info64; + info16 = (grub_uint16_t *) info64; +- if (! info16) +- return grub_errno; + + grub_memset (&parms, 0, sizeof (parms)); + parms.buffer = info16; +diff --git a/grub-core/disk/ieee1275/obdisk.c b/grub-core/disk/ieee1275/obdisk.c +index 9d4c42665..fcc39e0a2 100644 +--- a/grub-core/disk/ieee1275/obdisk.c ++++ b/grub-core/disk/ieee1275/obdisk.c +@@ -423,6 +423,12 @@ canonicalise_disk (const char *devname) + } + + real_canon = grub_malloc (real_unit_str_len); ++ if (real_canon == NULL) ++ { ++ grub_free (parent); ++ grub_print_error (); ++ return NULL; ++ } + + grub_snprintf (real_canon, real_unit_str_len, "%s/disk@%s", + op->name, real_unit_address); +diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c +index 4101b15d8..048e29cd0 100644 +--- a/grub-core/disk/ldm.c ++++ b/grub-core/disk/ldm.c +@@ -292,6 +292,12 @@ make_vg (grub_disk_t disk, + } + + pv->id.uuid = grub_malloc (sz); ++ if (pv->id.uuid == NULL) ++ { ++ grub_free (pv->internal_id); ++ grub_free (pv); ++ goto fail2; ++ } + grub_memcpy (pv->id.uuid, ptr + 1, pv->id.uuidlen); + pv->id.uuid[pv->id.uuidlen] = 0; + +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index a395b200d..b2dff76d1 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -370,6 +370,8 @@ grub_lvm_detect (grub_disk_t disk, + break; + + pv = grub_zalloc (sizeof (*pv)); ++ if (pv == NULL) ++ goto fail4; + q = p; + while (*q != ' ' && q < mda_end) + q++; +@@ -379,6 +381,8 @@ grub_lvm_detect (grub_disk_t disk, + + s = q - p; + pv->name = grub_malloc (s + 1); ++ if (pv->name == NULL) ++ goto pvs_fail_noname; + grub_memcpy (pv->name, p, s); + pv->name[s] = '\0'; + +@@ -451,6 +455,8 @@ grub_lvm_detect (grub_disk_t disk, + break; + + lv = grub_zalloc (sizeof (*lv)); ++ if (lv == NULL) ++ goto fail4; + + q = p; + while (*q != ' ' && q < mda_end) +@@ -545,6 +551,8 @@ grub_lvm_detect (grub_disk_t disk, + goto lvs_fail; + } + lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); ++ if (lv->segments == NULL) ++ goto lvs_fail; + seg = lv->segments; + + for (i = 0; i < lv->segment_count; i++) +@@ -612,6 +620,8 @@ grub_lvm_detect (grub_disk_t disk, + + seg->nodes = grub_calloc (seg->node_count, + sizeof (*stripe)); ++ if (seg->nodes == NULL) ++ goto lvs_segment_fail; + stripe = seg->nodes; + + p = grub_strstr (p, "stripes = ["); +@@ -672,6 +682,8 @@ grub_lvm_detect (grub_disk_t disk, + } + + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); ++ if (seg->nodes == NULL) ++ goto lvs_segment_fail; + + p = grub_strstr (p, "mirrors = ["); + if (p == NULL) +@@ -760,6 +772,8 @@ grub_lvm_detect (grub_disk_t disk, + } + + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); ++ if (seg->nodes == NULL) ++ goto lvs_segment_fail; + + p = grub_strstr (p, "raids = ["); + if (p == NULL) +diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c +index 36de3bfab..2d7afaea3 100644 +--- a/grub-core/disk/memdisk.c ++++ b/grub-core/disk/memdisk.c +@@ -103,6 +103,8 @@ GRUB_MOD_INIT(memdisk) + return; + } + memdisk_addr = grub_malloc (memdisk_size); ++ if (memdisk_addr == NULL) ++ return; + + grub_dprintf ("memdisk", "Copying memdisk image to dynamic memory\n"); + grub_memmove (memdisk_addr, memdisk_orig_addr, memdisk_size); diff --git a/0341-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch b/0341-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch new file mode 100644 index 00000000..2836631a --- /dev/null +++ b/0341-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 22 Jan 2025 02:55:12 +0000 +Subject: [PATCH] disk/ieee1275/ofdisk: Call grub_ieee1275_close() when + grub_malloc() fails + +In the dev_iterate() function a handle is opened but isn't closed when +grub_malloc() returns NULL. We should fix this by closing it on error. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/disk/ieee1275/ofdisk.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index 6c628635f..71237b256 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -269,7 +269,10 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + + buf = grub_malloc (sz); + if (!buf) +- return; ++ { ++ grub_ieee1275_close (ihandle); ++ return; ++ } + bufptr = grub_stpcpy (buf, alias->path); + + for (i = 0; i < args.nentries; i++) diff --git a/0342-fs-Use-safe-math-macros-to-prevent-overflows.patch b/0342-fs-Use-safe-math-macros-to-prevent-overflows.patch new file mode 100644 index 00000000..43eb12c7 --- /dev/null +++ b/0342-fs-Use-safe-math-macros-to-prevent-overflows.patch @@ -0,0 +1,353 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 12 Feb 2025 10:33:31 -0600 +Subject: [PATCH] fs: Use safe math macros to prevent overflows + +Replace direct arithmetic operations with macros from include/grub/safemath.h +to prevent potential overflow issues when calculating the memory sizes. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/archelp.c | 9 ++++++++- + grub-core/fs/btrfs.c | 34 ++++++++++++++++++++++++++++------ + grub-core/fs/cpio_common.c | 16 ++++++++++++++-- + grub-core/fs/f2fs.c | 17 +++++++++++++++-- + grub-core/fs/ntfscomp.c | 9 ++++++++- + grub-core/fs/squash4.c | 12 +++++++++--- + grub-core/fs/xfs.c | 17 +++++++++++++++-- + 7 files changed, 97 insertions(+), 17 deletions(-) + +diff --git a/grub-core/fs/archelp.c b/grub-core/fs/archelp.c +index c1dcc6285..0816b28de 100644 +--- a/grub-core/fs/archelp.c ++++ b/grub-core/fs/archelp.c +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -68,6 +69,7 @@ handle_symlink (struct grub_archelp_data *data, + char *rest; + char *linktarget; + grub_size_t linktarget_len; ++ grub_size_t sz; + + *restart = 0; + +@@ -98,7 +100,12 @@ handle_symlink (struct grub_archelp_data *data, + if (linktarget[0] == '\0') + return GRUB_ERR_NONE; + linktarget_len = grub_strlen (linktarget); +- target = grub_malloc (linktarget_len + grub_strlen (*name) + 2); ++ ++ if (grub_add (linktarget_len, grub_strlen (*name), &sz) || ++ grub_add (sz, 2, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("link target length overflow")); ++ ++ target = grub_malloc (sz); + if (!target) + return grub_errno; + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 6593f5175..3e4924b65 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2031,6 +2031,7 @@ find_path (struct grub_btrfs_data *data, + char *origpath = NULL; + unsigned symlinks_max = 32; + const char *relpath = grub_env_get ("btrfs_relative_path"); ++ grub_size_t sz; + + follow_default = 0; + origpath = grub_strdup (path); +@@ -2157,9 +2158,15 @@ find_path (struct grub_btrfs_data *data, + struct grub_btrfs_dir_item *cdirel; + if (elemsize > allocated) + { +- allocated = 2 * elemsize; ++ if (grub_mul (2, elemsize, &allocated) || ++ grub_add (allocated, 1, &sz)) ++ { ++ grub_free (path_alloc); ++ grub_free (origpath); ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("directory item size overflow")); ++ } + grub_free (direl); +- direl = grub_malloc (allocated + 1); ++ direl = grub_malloc (sz); + if (!direl) + { + grub_free (path_alloc); +@@ -2223,8 +2230,16 @@ find_path (struct grub_btrfs_data *data, + grub_free (origpath); + return err; + } +- tmp = grub_malloc (grub_le_to_cpu64 (inode.size) +- + grub_strlen (path) + 1); ++ ++ if (grub_add (grub_le_to_cpu64 (inode.size), grub_strlen (path), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_free (direl); ++ grub_free (path_alloc); ++ grub_free (origpath); ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("buffer size overflow")); ++ } ++ tmp = grub_malloc (sz); + if (!tmp) + { + grub_free (direl); +@@ -2371,6 +2386,7 @@ grub_btrfs_dir (grub_device_t device, const char *path, + grub_uint8_t type; + grub_size_t est_size = 0; + char *new_path = NULL; ++ grub_size_t sz; + + if (!data) + return grub_errno; +@@ -2420,9 +2436,15 @@ grub_btrfs_dir (grub_device_t device, const char *path, + } + if (elemsize > allocated) + { +- allocated = 2 * elemsize; ++ if (grub_mul (2, elemsize, &allocated) || ++ grub_add (allocated, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("directory element size overflow")); ++ r = -grub_errno; ++ break; ++ } + grub_free (direl); +- direl = grub_malloc (allocated + 1); ++ direl = grub_malloc (sz); + if (!direl) + { + r = -grub_errno; +diff --git a/grub-core/fs/cpio_common.c b/grub-core/fs/cpio_common.c +index 5d41b6fdb..6ba58b354 100644 +--- a/grub-core/fs/cpio_common.c ++++ b/grub-core/fs/cpio_common.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -48,6 +49,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + struct head hd; + grub_size_t namesize; + grub_uint32_t modeval; ++ grub_size_t sz; + + data->hofs = data->next_hofs; + +@@ -76,7 +78,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + + *mode = modeval; + +- *name = grub_malloc (namesize + 1); ++ if (grub_add (namesize, 1, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("file name size overflow")); ++ ++ *name = grub_malloc (sz); + if (*name == NULL) + return grub_errno; + +@@ -110,10 +115,17 @@ grub_cpio_get_link_target (struct grub_archelp_data *data) + { + char *ret; + grub_err_t err; ++ grub_size_t sz; + + if (data->size == 0) + return grub_strdup (""); +- ret = grub_malloc (data->size + 1); ++ ++ if (grub_add (data->size, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("target data size overflow")); ++ return NULL; ++ } ++ ret = grub_malloc (sz); + if (!ret) + return NULL; + +diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c +index f6d6beaa5..72b4aa1e6 100644 +--- a/grub-core/fs/f2fs.c ++++ b/grub-core/fs/f2fs.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -958,6 +959,7 @@ grub_f2fs_read_symlink (grub_fshelp_node_t node) + char *symlink; + struct grub_fshelp_node *diro = node; + grub_uint64_t filesize; ++ grub_size_t sz; + + if (!diro->inode_read) + { +@@ -968,7 +970,12 @@ grub_f2fs_read_symlink (grub_fshelp_node_t node) + + filesize = grub_f2fs_file_size(&diro->inode.i); + +- symlink = grub_malloc (filesize + 1); ++ if (grub_add (filesize, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("symlink size overflow")); ++ return 0; ++ } ++ symlink = grub_malloc (sz); + if (!symlink) + return 0; + +@@ -997,6 +1004,7 @@ grub_f2fs_check_dentries (struct grub_f2fs_dir_iter_ctx *ctx) + enum FILE_TYPE ftype; + int name_len; + int ret; ++ int sz; + + if (grub_f2fs_test_bit_le (i, ctx->bitmap) == 0) + { +@@ -1010,7 +1018,12 @@ grub_f2fs_check_dentries (struct grub_f2fs_dir_iter_ctx *ctx) + if (name_len >= F2FS_NAME_LEN) + return 0; + +- filename = grub_malloc (name_len + 1); ++ if (grub_add (name_len, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("directory entry name length overflow")); ++ return 0; ++ } ++ filename = grub_malloc (sz); + if (!filename) + return 0; + +diff --git a/grub-core/fs/ntfscomp.c b/grub-core/fs/ntfscomp.c +index a009f2c2d..f168a318e 100644 +--- a/grub-core/fs/ntfscomp.c ++++ b/grub-core/fs/ntfscomp.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -310,6 +311,7 @@ ntfscomp (grub_uint8_t *dest, grub_disk_addr_t ofs, + { + grub_err_t ret; + grub_disk_addr_t vcn; ++ int log_sz; + + if (ctx->attr->sbuf) + { +@@ -349,7 +351,12 @@ ntfscomp (grub_uint8_t *dest, grub_disk_addr_t ofs, + } + + ctx->comp.comp_head = ctx->comp.comp_tail = 0; +- ctx->comp.cbuf = grub_malloc (1 << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR)); ++ if (grub_add (ctx->comp.log_spc, GRUB_NTFS_BLK_SHR, &log_sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("compression buffer size overflow")); ++ return 0; ++ } ++ ctx->comp.cbuf = grub_malloc (1 << log_sz); + if (!ctx->comp.cbuf) + return 0; + +diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c +index 6e9d63874..f91ff3bfa 100644 +--- a/grub-core/fs/squash4.c ++++ b/grub-core/fs/squash4.c +@@ -460,11 +460,11 @@ grub_squash_read_symlink (grub_fshelp_node_t node) + { + char *ret; + grub_err_t err; +- grub_size_t sz; ++ grub_uint32_t sz; + + if (grub_add (grub_le_to_cpu32 (node->ino.symlink.namelen), 1, &sz)) + { +- grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("symlink name length overflow")); + return NULL; + } + +@@ -580,6 +580,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + struct grub_squash_dirent di; + struct grub_squash_inode ino; + grub_size_t sz; ++ grub_uint16_t nlen; + + err = read_chunk (dir->data, &di, sizeof (di), + grub_le_to_cpu64 (dir->data->sb.diroffset) +@@ -595,7 +596,12 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + if (err) + return 0; + +- buf = grub_malloc (grub_le_to_cpu16 (di.namelen) + 2); ++ if (grub_add (grub_le_to_cpu16 (di.namelen), 2, &nlen)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("name length overflow")); ++ return 0; ++ } ++ buf = grub_malloc (nlen); + if (!buf) + return 0; + err = read_chunk (dir->data, buf, +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 6c952aef1..c60db7361 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -718,6 +718,7 @@ static char * + grub_xfs_read_symlink (grub_fshelp_node_t node) + { + grub_ssize_t size = grub_be_to_cpu64 (node->inode.size); ++ grub_size_t sz; + + if (size < 0) + { +@@ -739,7 +740,12 @@ grub_xfs_read_symlink (grub_fshelp_node_t node) + if (node->data->hascrc) + off = 56; + +- symlink = grub_malloc (size + 1); ++ if (grub_add (size, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("symlink size overflow")); ++ return 0; ++ } ++ symlink = grub_malloc (sz); + if (!symlink) + return 0; + +@@ -789,8 +795,15 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, + { + struct grub_fshelp_node *fdiro; + grub_err_t err; ++ grub_size_t sz; + +- fdiro = grub_malloc (grub_xfs_fshelp_size(ctx->diro->data) + 1); ++ if (grub_add (grub_xfs_fshelp_size(ctx->diro->data), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("directory data size overflow")); ++ grub_print_error (); ++ return 0; ++ } ++ fdiro = grub_malloc (sz); + if (!fdiro) + { + grub_print_error (); diff --git a/0343-fs-Prevent-overflows-when-allocating-memory-for-arra.patch b/0343-fs-Prevent-overflows-when-allocating-memory-for-arra.patch new file mode 100644 index 00000000..936c2f87 --- /dev/null +++ b/0343-fs-Prevent-overflows-when-allocating-memory-for-arra.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Tue, 21 Jan 2025 19:02:37 +0000 +Subject: [PATCH] fs: Prevent overflows when allocating memory for arrays + +Use grub_calloc() when allocating memory for arrays to ensure proper +overflow checks are in place. + +The HFS+ and squash4 security vulnerabilities were reported by +Jonathan Bar Or . + +Fixes: CVE-2025-0678 +Fixes: CVE-2025-1125 + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/btrfs.c | 4 ++-- + grub-core/fs/hfspluscomp.c | 9 +++++++-- + grub-core/fs/squash4.c | 8 ++++---- + 3 files changed, 13 insertions(+), 8 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 3e4924b65..3228e1788 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -1409,8 +1409,8 @@ grub_btrfs_mount (grub_device_t dev) + } + + data->n_devices_allocated = 16; +- data->devices_attached = grub_malloc (sizeof (data->devices_attached[0]) +- * data->n_devices_allocated); ++ data->devices_attached = grub_calloc (data->n_devices_allocated, ++ sizeof (data->devices_attached[0])); + if (!data->devices_attached) + { + grub_free (data); +diff --git a/grub-core/fs/hfspluscomp.c b/grub-core/fs/hfspluscomp.c +index 48ae438d8..a80954ee6 100644 +--- a/grub-core/fs/hfspluscomp.c ++++ b/grub-core/fs/hfspluscomp.c +@@ -244,14 +244,19 @@ hfsplus_open_compressed_real (struct grub_hfsplus_file *node) + return 0; + } + node->compress_index_size = grub_le_to_cpu32 (index_size); +- node->compress_index = grub_malloc (node->compress_index_size +- * sizeof (node->compress_index[0])); ++ node->compress_index = grub_calloc (node->compress_index_size, ++ sizeof (node->compress_index[0])); + if (!node->compress_index) + { + node->compressed = 0; + grub_free (attr_node); + return grub_errno; + } ++ ++ /* ++ * The node->compress_index_size * sizeof (node->compress_index[0]) is safe here ++ * due to relevant checks done in grub_calloc() above. ++ */ + if (grub_hfsplus_read_file (node, 0, 0, + 0x104 + sizeof (index_size), + node->compress_index_size +diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c +index f91ff3bfa..cf2bca822 100644 +--- a/grub-core/fs/squash4.c ++++ b/grub-core/fs/squash4.c +@@ -822,10 +822,10 @@ direct_read (struct grub_squash_data *data, + break; + } + total_blocks = ((total_size + data->blksz - 1) >> data->log2_blksz); +- ino->block_sizes = grub_malloc (total_blocks +- * sizeof (ino->block_sizes[0])); +- ino->cumulated_block_sizes = grub_malloc (total_blocks +- * sizeof (ino->cumulated_block_sizes[0])); ++ ino->block_sizes = grub_calloc (total_blocks, ++ sizeof (ino->block_sizes[0])); ++ ino->cumulated_block_sizes = grub_calloc (total_blocks, ++ sizeof (ino->cumulated_block_sizes[0])); + if (!ino->block_sizes || !ino->cumulated_block_sizes) + { + grub_free (ino->block_sizes); diff --git a/0344-fs-Prevent-overflows-when-assigning-returned-values-.patch b/0344-fs-Prevent-overflows-when-assigning-returned-values-.patch new file mode 100644 index 00000000..97f8098f --- /dev/null +++ b/0344-fs-Prevent-overflows-when-assigning-returned-values-.patch @@ -0,0 +1,105 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Tue, 21 Jan 2025 19:02:38 +0000 +Subject: [PATCH] fs: Prevent overflows when assigning returned values from + read_number() + +The direct assignment of the unsigned long long value returned by +read_number() can potentially lead to an overflow on a 32-bit systems. +The fix replaces the direct assignments with calls to grub_cast() +which detects the overflows and safely assigns the values if no +overflow is detected. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/cpio_common.c | 18 ++++++++++++++---- + grub-core/fs/tar.c | 23 ++++++++++++++++------- + 2 files changed, 30 insertions(+), 11 deletions(-) + +diff --git a/grub-core/fs/cpio_common.c b/grub-core/fs/cpio_common.c +index 6ba58b354..45ac119a8 100644 +--- a/grub-core/fs/cpio_common.c ++++ b/grub-core/fs/cpio_common.c +@@ -62,11 +62,21 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + #endif + ) + return grub_error (GRUB_ERR_BAD_FS, "invalid cpio archive"); +- data->size = read_number (hd.filesize, ARRAY_SIZE (hd.filesize)); ++ ++ if (grub_cast (read_number (hd.filesize, ARRAY_SIZE (hd.filesize)), &data->size)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("data size overflow")); ++ + if (mtime) +- *mtime = read_number (hd.mtime, ARRAY_SIZE (hd.mtime)); +- modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode)); +- namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize)); ++ { ++ if (grub_cast (read_number (hd.mtime, ARRAY_SIZE (hd.mtime)), mtime)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("mtime overflow")); ++ } ++ ++ if (grub_cast (read_number (hd.mode, ARRAY_SIZE (hd.mode)), &modeval)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("mode overflow")); ++ ++ if (grub_cast (read_number (hd.namesize, ARRAY_SIZE (hd.namesize)), &namesize)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("namesize overflow")); + + /* Don't allow negative numbers. */ + if (namesize >= 0x80000000) +diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c +index fd2ec1f74..1eaa5349f 100644 +--- a/grub-core/fs/tar.c ++++ b/grub-core/fs/tar.c +@@ -99,9 +99,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + if (hd.typeflag == 'L') + { + grub_err_t err; +- grub_size_t namesize = read_number (hd.size, sizeof (hd.size)); ++ grub_size_t namesize; + +- if (grub_add (namesize, 1, &sz)) ++ if (grub_cast (read_number (hd.size, sizeof (hd.size)), &namesize) || ++ grub_add (namesize, 1, &sz)) + return grub_error (GRUB_ERR_BAD_FS, N_("name size overflow")); + + *name = grub_malloc (sz); +@@ -123,9 +124,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + if (hd.typeflag == 'K') + { + grub_err_t err; +- grub_size_t linksize = read_number (hd.size, sizeof (hd.size)); ++ grub_size_t linksize; + +- if (grub_add (linksize, 1, &sz)) ++ if (grub_cast (read_number (hd.size, sizeof (hd.size)), &linksize) || ++ grub_add (linksize, 1, &sz)) + return grub_error (GRUB_ERR_BAD_FS, N_("link size overflow")); + + if (data->linkname_alloc < sz) +@@ -174,15 +176,22 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + (*name)[extra_size + sizeof (hd.name)] = 0; + } + +- data->size = read_number (hd.size, sizeof (hd.size)); ++ if (grub_cast (read_number (hd.size, sizeof (hd.size)), &data->size)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("data size overflow")); ++ + data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE; + data->next_hofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) & + ~(GRUB_DISK_SECTOR_SIZE - 1)); + if (mtime) +- *mtime = read_number (hd.mtime, sizeof (hd.mtime)); ++ { ++ if (grub_cast (read_number (hd.mtime, sizeof (hd.mtime)), mtime)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("mtime overflow")); ++ } + if (mode) + { +- *mode = read_number (hd.mode, sizeof (hd.mode)); ++ if (grub_cast (read_number (hd.mode, sizeof (hd.mode)), mode)) ++ return grub_error (GRUB_ERR_BAD_FS, N_("mode overflow")); ++ + switch (hd.typeflag) + { + /* Hardlink. */ diff --git a/0345-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch b/0345-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch new file mode 100644 index 00000000..427877de --- /dev/null +++ b/0345-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch @@ -0,0 +1,138 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 22 Jan 2025 07:17:02 +0000 +Subject: [PATCH] fs/zfs: Use safe math macros to prevent overflows + +Replace direct arithmetic operations with macros from include/grub/safemath.h +to prevent potential overflow issues when calculating the memory sizes. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/zfs/zfs.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ + 1 file changed, 44 insertions(+), 6 deletions(-) + +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index a497b1869..2f303d655 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -2387,6 +2387,7 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, + zap_dnode->endian) << DNODE_SHIFT); + grub_err_t err; + grub_zfs_endian_t endian; ++ grub_size_t sz; + + if (zap_verify (zap, zap_dnode->endian)) + return 0; +@@ -2448,8 +2449,14 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, + if (le->le_type != ZAP_CHUNK_ENTRY) + continue; + +- buf = grub_malloc (grub_zfs_to_cpu16 (le->le_name_length, endian) +- * name_elem_length + 1); ++ if (grub_mul (grub_zfs_to_cpu16 (le->le_name_length, endian), name_elem_length, &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("buffer size overflow")); ++ grub_free (l); ++ return grub_errno; ++ } ++ buf = grub_malloc (sz); + if (zap_leaf_array_get (l, endian, blksft, + grub_zfs_to_cpu16 (le->le_name_chunk, + endian), +@@ -2872,6 +2879,7 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, + && ((grub_zfs_to_cpu64(((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_mode, dnode_path->dn.endian) >> 12) & 0xf) == 0xa) + { + char *sym_value; ++ grub_size_t sz; + grub_size_t sym_sz; + int free_symval = 0; + char *oldpath = path, *oldpathbuf = path_buf; +@@ -2923,7 +2931,18 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, + break; + free_symval = 1; + } +- path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1); ++ ++ if (grub_add (sym_sz, grub_strlen (oldpath), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("path buffer size overflow")); ++ grub_free (oldpathbuf); ++ if (free_symval) ++ grub_free (sym_value); ++ err = grub_errno; ++ break; ++ } ++ path = path_buf = grub_malloc (sz); + if (!path_buf) + { + grub_free (oldpathbuf); +@@ -2960,6 +2979,7 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, + { + void *sahdrp; + int hdrsize; ++ grub_size_t sz; + + if (dnode_path->dn.dn.dn_bonuslen != 0) + { +@@ -2993,7 +3013,15 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, + + SA_SIZE_OFFSET), + dnode_path->dn.endian); + char *oldpath = path, *oldpathbuf = path_buf; +- path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1); ++ if (grub_add (sym_sz, grub_strlen (oldpath), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("path buffer size overflow")); ++ grub_free (oldpathbuf); ++ err = grub_errno; ++ break; ++ } ++ path = path_buf = grub_malloc (sz); + if (!path_buf) + { + grub_free (oldpathbuf); +@@ -3568,6 +3596,7 @@ grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist, const char *name, + unsigned i; + grub_size_t nelm; + int elemsize = 0; ++ int sz; + + found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST_ARRAY, &nvpair, + &size, &nelm); +@@ -3602,7 +3631,12 @@ grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist, const char *name, + return 0; + } + +- ret = grub_zalloc (elemsize + sizeof (grub_uint32_t)); ++ if (grub_add (elemsize, sizeof (grub_uint32_t), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("elemsize overflow")); ++ return 0; ++ } ++ ret = grub_zalloc (sz); + if (!ret) + return 0; + grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); +@@ -4193,6 +4227,7 @@ iterate_zap_snap (const char *name, grub_uint64_t val, + struct grub_dirhook_info info; + char *name2; + int ret; ++ grub_size_t sz; + + dnode_end_t mdn; + +@@ -4213,7 +4248,10 @@ iterate_zap_snap (const char *name, grub_uint64_t val, + return 0; + } + +- name2 = grub_malloc (grub_strlen (name) + 2); ++ if (grub_add (grub_strlen (name), 2, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("name length overflow")); ++ ++ name2 = grub_malloc (sz); + name2[0] = '@'; + grub_memcpy (name2 + 1, name, grub_strlen (name) + 1); + ret = ctx->hook (name2, &info, ctx->hook_data); diff --git a/0346-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch b/0346-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch new file mode 100644 index 00000000..64c0e286 --- /dev/null +++ b/0346-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 22 Jan 2025 07:17:03 +0000 +Subject: [PATCH] fs/zfs: Prevent overflows when allocating memory for arrays + +Use grub_calloc() when allocating memory for arrays to ensure proper +overflow checks are in place. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/zfs/zfs.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 2f303d655..9ab7bf319 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -723,8 +723,8 @@ fill_vdev_info_real (struct grub_zfs_data *data, + { + fill->n_children = nelm; + +- fill->children = grub_zalloc (fill->n_children +- * sizeof (fill->children[0])); ++ fill->children = grub_calloc (fill->n_children, ++ sizeof (fill->children[0])); + } + + for (i = 0; i < nelm; i++) +@@ -3712,8 +3712,8 @@ zfs_mount (grub_device_t dev) + #endif + + data->n_devices_allocated = 16; +- data->devices_attached = grub_malloc (sizeof (data->devices_attached[0]) +- * data->n_devices_allocated); ++ data->devices_attached = grub_calloc (data->n_devices_allocated, ++ sizeof (data->devices_attached[0])); + data->n_devices_attached = 0; + err = scan_disk (dev, data, 1, &inserted); + if (err) diff --git a/0347-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch b/0347-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch new file mode 100644 index 00000000..7870587f --- /dev/null +++ b/0347-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch @@ -0,0 +1,88 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 22 Jan 2025 07:17:01 +0000 +Subject: [PATCH] fs/zfs: Check if returned pointer for allocated memory is + NULL + +When using grub_malloc() or grub_zalloc(), these functions can fail if +we are out of memory. After allocating memory we should check if these +functions returned NULL and handle this error if they did. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/zfs/zfs.c | 26 ++++++++++++++++++++++++++ + 1 file changed, 26 insertions(+) + +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 9ab7bf319..6e6d1c921 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -614,6 +614,8 @@ zfs_fetch_nvlist (struct grub_zfs_device_desc *diskdesc, char **nvlist) + return grub_error (GRUB_ERR_BUG, "member drive unknown"); + + *nvlist = grub_malloc (VDEV_PHYS_SIZE); ++ if (!*nvlist) ++ return grub_errno; + + /* Read in the vdev name-value pair list (112K). */ + err = grub_disk_read (diskdesc->dev->disk, diskdesc->vdev_phys_sector, 0, +@@ -725,6 +727,11 @@ fill_vdev_info_real (struct grub_zfs_data *data, + + fill->children = grub_calloc (fill->n_children, + sizeof (fill->children[0])); ++ if (!fill->children) ++ { ++ grub_free (type); ++ return grub_errno; ++ } + } + + for (i = 0; i < nelm; i++) +@@ -2457,6 +2464,11 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, + return grub_errno; + } + buf = grub_malloc (sz); ++ if (!buf) ++ { ++ grub_free (l); ++ return grub_errno; ++ } + if (zap_leaf_array_get (l, endian, blksft, + grub_zfs_to_cpu16 (le->le_name_chunk, + endian), +@@ -2472,6 +2484,12 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, + val_length = ((int) le->le_value_length + * (int) le->le_int_size); + val = grub_malloc (grub_zfs_to_cpu16 (val_length, endian)); ++ if (!val) ++ { ++ grub_free (l); ++ grub_free (buf); ++ return grub_errno; ++ } + if (zap_leaf_array_get (l, endian, blksft, + grub_zfs_to_cpu16 (le->le_value_chunk, + endian), +@@ -3714,6 +3732,11 @@ zfs_mount (grub_device_t dev) + data->n_devices_allocated = 16; + data->devices_attached = grub_calloc (data->n_devices_allocated, + sizeof (data->devices_attached[0])); ++ if (!data->devices_attached) ++ { ++ grub_free (data); ++ return NULL; ++ } + data->n_devices_attached = 0; + err = scan_disk (dev, data, 1, &inserted); + if (err) +@@ -4252,6 +4275,9 @@ iterate_zap_snap (const char *name, grub_uint64_t val, + return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("name length overflow")); + + name2 = grub_malloc (sz); ++ if (!name2) ++ return grub_errno; ++ + name2[0] = '@'; + grub_memcpy (name2 + 1, name, grub_strlen (name) + 1); + ret = ctx->hook (name2, &info, ctx->hook_data); diff --git a/0348-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch b/0348-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch new file mode 100644 index 00000000..988bcbe7 --- /dev/null +++ b/0348-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 22 Jan 2025 07:17:04 +0000 +Subject: [PATCH] fs/zfs: Add missing NULL check after grub_strdup() call + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/zfs/zfs.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 6e6d1c921..5ff647ffb 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -3309,6 +3309,8 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, + filename = 0; + snapname = 0; + fsname = grub_strdup (fullpath); ++ if (!fsname) ++ return grub_errno; + } + else + { diff --git a/0349-net-Use-safe-math-macros-to-prevent-overflows.patch b/0349-net-Use-safe-math-macros-to-prevent-overflows.patch new file mode 100644 index 00000000..60ebaf63 --- /dev/null +++ b/0349-net-Use-safe-math-macros-to-prevent-overflows.patch @@ -0,0 +1,240 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 12 Feb 2025 10:38:17 -0600 +Subject: [PATCH] net: Use safe math macros to prevent overflows + +Replace direct arithmetic operations with macros from include/grub/safemath.h +to prevent potential overflow issues when calculating the memory sizes. + +Signed-off-by: Lidong Chen +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/net/bootp.c | 16 +++++++++++-- + grub-core/net/dns.c | 9 ++++++- + grub-core/net/drivers/ieee1275/ofnet.c | 20 ++++++++++++++-- + grub-core/net/net.c | 43 +++++++++++++++++++++++++++------- + 4 files changed, 75 insertions(+), 13 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 9cbdc2264..bed70c0b2 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + static int + dissect_url (const char *url, char **proto, char **host, char **path) +@@ -1479,6 +1480,7 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + unsigned num; + const grub_uint8_t *ptr; + grub_uint8_t taglength; ++ grub_uint8_t len; + + if (argc < 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, +@@ -1520,7 +1522,12 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + if (grub_strcmp (args[3], "string") == 0) + { + grub_err_t err = GRUB_ERR_NONE; +- char *val = grub_malloc (taglength + 1); ++ char *val; ++ ++ if (grub_add (taglength, 1, &len)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("tag length overflow")); ++ ++ val = grub_malloc (len); + if (!val) + return grub_errno; + grub_memcpy (val, ptr, taglength); +@@ -1553,7 +1560,12 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + if (grub_strcmp (args[3], "hex") == 0) + { + grub_err_t err = GRUB_ERR_NONE; +- char *val = grub_malloc (2 * taglength + 1); ++ char *val; ++ ++ if (grub_mul (taglength, 2, &len) || grub_add (len, 1, &len)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("tag length overflow")); ++ ++ val = grub_malloc (len); + int i; + if (!val) + return grub_errno; +diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c +index fcc09aa65..39b0c46cf 100644 +--- a/grub-core/net/dns.c ++++ b/grub-core/net/dns.c +@@ -224,10 +224,17 @@ get_name (const grub_uint8_t *name_at, const grub_uint8_t *head, + { + int length; + char *ret; ++ int len; + + if (!check_name_real (name_at, head, tail, NULL, &length, NULL)) + return NULL; +- ret = grub_malloc (length + 1); ++ ++ if (grub_add (length, 1, &len)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("name length overflow")); ++ return NULL; ++ } ++ ret = grub_malloc (len); + if (!ret) + return NULL; + if (!check_name_real (name_at, head, tail, NULL, NULL, ret)) +diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c +index c56461ff1..b5336dfbb 100644 +--- a/grub-core/net/drivers/ieee1275/ofnet.c ++++ b/grub-core/net/drivers/ieee1275/ofnet.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -392,6 +393,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias) + grub_uint8_t *pprop; + char *shortname; + char need_suffix = 1; ++ grub_size_t sz; + + if (grub_strcmp (alias->type, "network") != 0) + return 0; +@@ -449,9 +451,23 @@ search_net_devices (struct grub_ieee1275_devalias *alias) + } + + if (need_suffix) +- ofdata->path = grub_malloc (grub_strlen (alias->path) + sizeof (SUFFIX)); ++ { ++ if (grub_add (grub_strlen (alias->path), sizeof (SUFFIX), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obatining size of ofdata path")); ++ grub_print_error (); ++ return 0; ++ } ++ } + else +- ofdata->path = grub_malloc (grub_strlen (alias->path) + 1); ++ { ++ if (grub_add (grub_strlen (alias->path), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obatining size of ofdata path")); ++ grub_print_error (); ++ return 0; ++ } ++ } + if (!ofdata->path) + { + grub_print_error (); +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 6c8dfcba2..22224453f 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + #ifdef GRUB_MACHINE_EFI + #include + #endif +@@ -211,6 +212,7 @@ grub_net_ipv6_get_slaac (struct grub_net_card *card, + { + struct grub_net_slaac_mac_list *slaac; + char *ptr; ++ grub_size_t sz; + + for (slaac = card->slaac_list; slaac; slaac = slaac->next) + if (grub_net_hwaddr_cmp (&slaac->address, hwaddr) == 0) +@@ -220,9 +222,16 @@ grub_net_ipv6_get_slaac (struct grub_net_card *card, + if (!slaac) + return NULL; + +- slaac->name = grub_malloc (grub_strlen (card->name) +- + GRUB_NET_MAX_STR_HWADDR_LEN +- + sizeof (":slaac")); ++ if (grub_add (grub_strlen (card->name), ++ (GRUB_NET_MAX_STR_HWADDR_LEN + sizeof (":slaac")), &sz)) ++ { ++ grub_free (slaac); ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "overflow detected while obtaining size of slaac name"); ++ return NULL; ++ } ++ ++ slaac->name = grub_malloc (sz); + ptr = grub_stpcpy (slaac->name, card->name); + if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0) + { +@@ -293,6 +302,7 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card, + char *name; + char *ptr; + grub_net_network_level_address_t addr; ++ grub_size_t sz; + + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; + addr.ipv6[0] = grub_cpu_to_be64_compile_time (0xfe80ULL << 48); +@@ -307,9 +317,14 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card, + return inf; + } + +- name = grub_malloc (grub_strlen (card->name) +- + GRUB_NET_MAX_STR_HWADDR_LEN +- + sizeof (":link")); ++ if (grub_add (grub_strlen (card->name), ++ (GRUB_NET_MAX_STR_HWADDR_LEN + sizeof (":link")), &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "overflow detected while obtaining size of link name"); ++ return NULL; ++ } ++ name = grub_malloc (sz); + if (!name) + return NULL; + +@@ -1516,9 +1531,15 @@ grub_net_open_real (const char *name) + if (grub_strchr (port_start + 1, ':')) + { + int iplen = grub_strlen (server); ++ grub_size_t sz; + + /* Bracket bare IPv6 addr. */ +- host = grub_malloc (iplen + 3); ++ if (grub_add (iplen, 3, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining length of host")); ++ return NULL; ++ } ++ host = grub_malloc (sz); + if (!host) + return NULL; + +@@ -1773,6 +1794,7 @@ grub_env_set_net_property (const char *intername, const char *suffix, + { + char *varname, *varvalue; + char *ptr; ++ grub_size_t sz; + + varname = grub_xasprintf ("net_%s_%s", intername, suffix); + if (!varname) +@@ -1780,7 +1802,12 @@ grub_env_set_net_property (const char *intername, const char *suffix, + for (ptr = varname; *ptr; ptr++) + if (*ptr == ':') + *ptr = '_'; +- varvalue = grub_malloc (len + 1); ++ if (grub_add (len, 1, &sz)) ++ { ++ grub_free (varname); ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while obtaining the size of an env variable"); ++ } ++ varvalue = grub_malloc (sz); + if (!varvalue) + { + grub_free (varname); diff --git a/0350-net-Prevent-overflows-when-allocating-memory-for-arr.patch b/0350-net-Prevent-overflows-when-allocating-memory-for-arr.patch new file mode 100644 index 00000000..c6619d2f --- /dev/null +++ b/0350-net-Prevent-overflows-when-allocating-memory-for-arr.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 22 Jan 2025 18:04:43 +0000 +Subject: [PATCH] net: Prevent overflows when allocating memory for arrays + +Use grub_calloc() when allocating memory for arrays to ensure proper +overflow checks are in place. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/net/dns.c | 4 ++-- + grub-core/net/net.c | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c +index 39b0c46cf..f20cd6f83 100644 +--- a/grub-core/net/dns.c ++++ b/grub-core/net/dns.c +@@ -470,8 +470,8 @@ grub_net_dns_lookup (const char *name, + && grub_get_time_ms () < dns_cache[h].limit_time) + { + grub_dprintf ("dns", "retrieved from cache\n"); +- *addresses = grub_malloc (dns_cache[h].naddresses +- * sizeof ((*addresses)[0])); ++ *addresses = grub_calloc (dns_cache[h].naddresses, ++ sizeof ((*addresses)[0])); + if (!*addresses) + return grub_errno; + *naddresses = dns_cache[h].naddresses; +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 22224453f..d426ad2c4 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -91,8 +91,8 @@ grub_net_link_layer_add_address (struct grub_net_card *card, + /* Add sender to cache table. */ + if (card->link_layer_table == NULL) + { +- card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE +- * sizeof (card->link_layer_table[0])); ++ card->link_layer_table = grub_calloc (LINK_LAYER_CACHE_SIZE, ++ sizeof (card->link_layer_table[0])); + if (card->link_layer_table == NULL) + return; + } diff --git a/0351-net-Check-if-returned-pointer-for-allocated-memory-i.patch b/0351-net-Check-if-returned-pointer-for-allocated-memory-i.patch new file mode 100644 index 00000000..7b5b647b --- /dev/null +++ b/0351-net-Check-if-returned-pointer-for-allocated-memory-i.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 22 Jan 2025 18:04:44 +0000 +Subject: [PATCH] net: Check if returned pointer for allocated memory is NULL + +When using grub_malloc(), the function can fail if we are out of memory. +After allocating memory we should check if this function returned NULL +and handle this error if it did. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/net/net.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index d426ad2c4..bec297cb6 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -232,6 +232,11 @@ grub_net_ipv6_get_slaac (struct grub_net_card *card, + } + + slaac->name = grub_malloc (sz); ++ if (slaac->name == NULL) ++ { ++ grub_free (slaac); ++ return NULL; ++ } + ptr = grub_stpcpy (slaac->name, card->name); + if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0) + { diff --git a/0352-fs-sfs-Check-if-allocated-memory-is-NULL.patch b/0352-fs-sfs-Check-if-allocated-memory-is-NULL.patch new file mode 100644 index 00000000..57d2960b --- /dev/null +++ b/0352-fs-sfs-Check-if-allocated-memory-is-NULL.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 28 Jan 2025 05:15:50 +0000 +Subject: [PATCH] fs/sfs: Check if allocated memory is NULL + +When using grub_zalloc(), if we are out of memory, this function can fail. +After allocating memory, we should check if grub_zalloc() returns NULL. +If so, we should handle this error. + +Fixes: CID 473856 + +Signed-off-by: Alec Brown +Reviewed-by: Ross Philipson +Reviewed-by: Daniel Kiper +--- + grub-core/fs/sfs.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index 88705b3a2..bad4ae8d1 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -429,6 +429,9 @@ grub_sfs_mount (grub_disk_t disk) + - 24 /* offsetof (struct grub_sfs_objc, objects) */ + - 25); /* offsetof (struct grub_sfs_obj, filename) */ + data->label = grub_zalloc (max_len + 1); ++ if (data->label == NULL) ++ goto fail; ++ + grub_strncpy (data->label, (char *) rootobjc->objects[0].filename, max_len); + + grub_free (rootobjc_data); diff --git a/0353-script-execute-Fix-potential-underflow-and-NULL-dere.patch b/0353-script-execute-Fix-potential-underflow-and-NULL-dere.patch new file mode 100644 index 00000000..575c81a9 --- /dev/null +++ b/0353-script-execute-Fix-potential-underflow-and-NULL-dere.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 29 Jan 2025 06:48:37 +0000 +Subject: [PATCH] script/execute: Fix potential underflow and NULL dereference + +The result is initialized to 0 in grub_script_arglist_to_argv(). +If the for loop condition is not met both result.args and result.argc +remain 0 causing result.argc - 1 to underflow and/or result.args NULL +dereference. Fix the issues by adding relevant checks. + +Fixes: CID 473880 + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/script/execute.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index 7ed3a1a03..014132703 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -794,6 +794,9 @@ cleanup: + } + } + ++ if (result.args == NULL || result.argc == 0) ++ goto fail; ++ + if (! result.args[result.argc - 1]) + result.argc--; + diff --git a/0354-osdep-unix-getroot-Fix-potential-underflow.patch b/0354-osdep-unix-getroot-Fix-potential-underflow.patch new file mode 100644 index 00000000..09c223ea --- /dev/null +++ b/0354-osdep-unix-getroot-Fix-potential-underflow.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Wed, 29 Jan 2025 06:48:38 +0000 +Subject: [PATCH] osdep/unix/getroot: Fix potential underflow + +The entry_len is initialized in grub_find_root_devices_from_mountinfo() +to 0 before the while loop iterates through /proc/self/mountinfo. If the +file is empty or contains only invalid entries entry_len remains +0 causing entry_len - 1 in the subsequent for loop initialization +to underflow. To prevent this add a check to ensure entry_len > 0 before +entering the for loop. + +Fixes: CID 473877 + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +Reviewed-by: Ross Philipson +--- + grub-core/osdep/linux/getroot.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index b32582eb3..b83259321 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -596,6 +596,9 @@ again: + } + } + ++ if (!entry_len) ++ goto out; ++ + /* Now scan visible mounts for the ones we're interested in. */ + for (i = entry_len - 1; i >= 0; i--) + { diff --git a/0355-misc-Ensure-consistent-overflow-error-messages.patch b/0355-misc-Ensure-consistent-overflow-error-messages.patch new file mode 100644 index 00000000..411a4fbc --- /dev/null +++ b/0355-misc-Ensure-consistent-overflow-error-messages.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Tue, 21 Jan 2025 19:02:39 +0000 +Subject: [PATCH] misc: Ensure consistent overflow error messages + +Update the overflow error messages to make them consistent +across the GRUB code. + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ntfs.c | 2 +- + grub-core/fs/ntfscomp.c | 2 +- + grub-core/video/readers/png.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index e00349b1d..960833a34 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -574,7 +574,7 @@ retry: + goto retry; + } + } +- return grub_error (GRUB_ERR_BAD_FS, "run list overflown"); ++ return grub_error (GRUB_ERR_BAD_FS, "run list overflow"); + } + ctx->curr_vcn = ctx->next_vcn; + ctx->next_vcn += read_run_data (run, c1, 0); /* length of current VCN */ +diff --git a/grub-core/fs/ntfscomp.c b/grub-core/fs/ntfscomp.c +index f168a318e..b68bf5e40 100644 +--- a/grub-core/fs/ntfscomp.c ++++ b/grub-core/fs/ntfscomp.c +@@ -30,7 +30,7 @@ static grub_err_t + decomp_nextvcn (struct grub_ntfs_comp *cc) + { + if (cc->comp_head >= cc->comp_tail) +- return grub_error (GRUB_ERR_BAD_FS, "compression block overflown"); ++ return grub_error (GRUB_ERR_BAD_FS, "compression block overflow"); + if (grub_disk_read + (cc->disk, + (cc->comp_table[cc->comp_head].next_lcn - +diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c +index 3163e97bf..aa7524b7d 100644 +--- a/grub-core/video/readers/png.c ++++ b/grub-core/video/readers/png.c +@@ -626,7 +626,7 @@ static grub_err_t + grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n) + { + if (--data->raw_bytes < 0) +- return grub_error (GRUB_ERR_BAD_FILE_TYPE, "image size overflown"); ++ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "image size overflow"); + + if (data->cur_column == 0) + { diff --git a/0356-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch b/0356-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch new file mode 100644 index 00000000..70342514 --- /dev/null +++ b/0356-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 4 Feb 2025 15:11:10 +0000 +Subject: [PATCH] bus/usb/ehci: Define GRUB_EHCI_TOGGLE as grub_uint32_t + +The Coverity indicates that GRUB_EHCI_TOGGLE is an int that contains +a negative value and we are using it for the variable token which is +grub_uint32_t. To remedy this we can cast the definition to grub_uint32_t. + +Fixes: CID 473851 + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/bus/usb/ehci.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c +index 9abebc6bd..2db07c7c0 100644 +--- a/grub-core/bus/usb/ehci.c ++++ b/grub-core/bus/usb/ehci.c +@@ -218,7 +218,7 @@ enum + + #define GRUB_EHCI_TERMINATE (1<<0) + +-#define GRUB_EHCI_TOGGLE (1<<31) ++#define GRUB_EHCI_TOGGLE ((grub_uint32_t) 1<<31) + + enum + { diff --git a/0357-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch b/0357-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch new file mode 100644 index 00000000..2ae5ec6f --- /dev/null +++ b/0357-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 4 Feb 2025 15:11:11 +0000 +Subject: [PATCH] normal/menu: Use safe math to avoid an integer overflow + +The Coverity indicates that the variable current_entry might overflow. +To prevent this use safe math when adding GRUB_MENU_PAGE_SIZE to current_entry. + +On the occasion fix limiting condition which was broken. + +Fixes: CID 473853 + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/normal/menu.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index cda10fa8b..97687013c 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + /* Time to delay after displaying an error message about a default/fallback + entry failing to boot. */ +@@ -784,9 +785,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot) + + case GRUB_TERM_CTRL | 'c': + case GRUB_TERM_KEY_NPAGE: +- if (current_entry + GRUB_MENU_PAGE_SIZE < menu->size) +- current_entry += GRUB_MENU_PAGE_SIZE; +- else ++ if (grub_add (current_entry, GRUB_MENU_PAGE_SIZE, ¤t_entry) || current_entry >= menu->size) + current_entry = menu->size - 1; + menu_set_chosen_entry (current_entry); + break; diff --git a/0358-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch b/0358-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch new file mode 100644 index 00000000..a170fa95 --- /dev/null +++ b/0358-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Thu, 6 Feb 2025 18:16:56 +0000 +Subject: [PATCH] kern/partition: Add sanity check after grub_strtoul() call + +The current code incorrectly assumes that both the input and the values +returned by grub_strtoul() are always valid which can lead to potential +errors. This fix ensures proper validation to prevent any unintended issues. + +Fixes: CID 473843 + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/kern/partition.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c +index 704512a20..c6a578cf4 100644 +--- a/grub-core/kern/partition.c ++++ b/grub-core/kern/partition.c +@@ -125,14 +125,22 @@ grub_partition_probe (struct grub_disk *disk, const char *str) + for (ptr = str; *ptr;) + { + grub_partition_map_t partmap; +- int num; ++ unsigned long num; + const char *partname, *partname_end; + + partname = ptr; + while (*ptr && grub_isalpha (*ptr)) + ptr++; + partname_end = ptr; +- num = grub_strtoul (ptr, &ptr, 0) - 1; ++ ++ num = grub_strtoul (ptr, &ptr, 0); ++ if (*ptr != '\0' || num == 0 || num > GRUB_INT_MAX) ++ { ++ grub_error (GRUB_ERR_BAD_NUMBER, N_("invalid partition number")); ++ return 0; ++ } ++ ++ num -= 1; + + curpart = 0; + /* Use the first partition map type found. */ diff --git a/0359-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch b/0359-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch new file mode 100644 index 00000000..7af2fd0b --- /dev/null +++ b/0359-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lidong Chen +Date: Thu, 6 Feb 2025 18:16:57 +0000 +Subject: [PATCH] kern/misc: Add sanity check after grub_strtoul() call + +When the format string, fmt0, includes a positional argument +grub_strtoul() or grub_strtoull() is called to extract the argument +position. However, the returned argument position isn't fully validated. +If the format is something like "%0$x" then these functions return +0 which leads to an underflow in the calculation of the args index, curn. +The fix is to add a check to ensure the extracted argument position is +greater than 0 before computing curn. Additionally, replace one +grub_strtoull() with grub_strtoul() and change curn type to make code +more correct. + +Fixes: CID 473841 + +Signed-off-by: Lidong Chen +Reviewed-by: Daniel Kiper +--- + grub-core/kern/misc.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 98700423d..69bd655f3 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -912,7 +912,7 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, + while ((c = *fmt++) != 0) + { + int longfmt = 0; +- grub_size_t curn; ++ unsigned long curn; + const char *p; + + if (c != '%') +@@ -930,7 +930,10 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, + + if (*fmt == '$') + { +- curn = grub_strtoull (p, 0, 10) - 1; ++ curn = grub_strtoul (p, 0, 10); ++ if (curn == 0) ++ continue; ++ curn--; + fmt++; + } + +@@ -1116,6 +1119,8 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, + + if (*fmt == '$') + { ++ if (format1 == 0) ++ continue; + curn = format1 - 1; + fmt++; + format1 = 0; diff --git a/0360-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch b/0360-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch new file mode 100644 index 00000000..9c8819bb --- /dev/null +++ b/0360-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 12 Feb 2025 10:56:13 -0600 +Subject: [PATCH] loader/i386/linux: Cast left shift to grub_uint32_t + +The Coverity complains that we might overflow into a negative value when +setting linux_params.kernel_alignment to (1 << align). We can remedy +this by casting it to grub_uint32_t. + +Fixes: CID 473876 + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/loader/i386/linux.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 90121e9bc..33a852197 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -823,7 +823,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + GRUB_MEM_ATTR_R|GRUB_MEM_ATTR_W, GRUB_MEM_ATTR_X); + + linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; +- linux_params.kernel_alignment = (1 << align); ++ linux_params.kernel_alignment = ((grub_uint32_t)1 << align); + linux_params.ps_mouse = linux_params.padding11 = 0; + linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; + diff --git a/0361-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch b/0361-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch new file mode 100644 index 00000000..272293b2 --- /dev/null +++ b/0361-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Wed, 5 Feb 2025 22:04:08 +0000 +Subject: [PATCH] loader/i386/bsd: Use safe math to avoid underflow + +The operation kern_end - kern_start may underflow when we input it into +grub_relocator_alloc_chunk_addr() call. To avoid this we can use safe +math for this subtraction. + +Fixes: CID 73845 + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/loader/i386/bsd.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c +index 8075ac9b0..50f96ea7a 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -1341,6 +1341,7 @@ static grub_err_t + grub_bsd_load_elf (grub_elf_t elf, const char *filename) + { + grub_err_t err; ++ grub_size_t sz; + + kern_end = 0; + kern_start = ~0; +@@ -1371,8 +1372,11 @@ grub_bsd_load_elf (grub_elf_t elf, const char *filename) + + if (grub_errno) + return grub_errno; +- err = grub_relocator_alloc_chunk_addr (relocator, &ch, +- kern_start, kern_end - kern_start); ++ ++ if (grub_sub (kern_end, kern_start, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, "underflow detected while determining size of kernel for relocator"); ++ ++ err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, sz); + if (err) + return err; + +@@ -1432,8 +1436,10 @@ grub_bsd_load_elf (grub_elf_t elf, const char *filename) + { + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, +- kern_end - kern_start); ++ if (grub_sub (kern_end, kern_start, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, "underflow detected while determining size of kernel for relocator"); ++ ++ err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, sz); + if (err) + return err; + kern_chunk_src = get_virtual_current_address (ch); diff --git a/0362-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch b/0362-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch new file mode 100644 index 00000000..c237f462 --- /dev/null +++ b/0362-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 21 Feb 2025 09:06:12 +0800 +Subject: [PATCH] fs/ext2: Rework out-of-bounds read for inline and external + extents + +Previously, the number of extent entries was not properly capped based +on the actual available space. This could lead to insufficient reads for +external extents, since the computation was based solely on the inline +extent layout. + +In this patch, when processing the extent header, we determine whether +the header is stored inline (i.e., at inode->blocks.dir_blocks) or in an +external extent block. We then clamp the number of entries accordingly +(using max_inline_ext for inline extents and max_external_ext for +external extent blocks). + +This change ensures that only the valid number of extent entries is +processed, preventing out-of-bound reads and potential filesystem +corruption. + +Fixes: 7e2f750f0a (fs/ext2: Fix out-of-bounds read for inline extents) + +Signed-off-by: Michael Chang +Tested-by: Christian Hesse +Reviewed-by: Daniel Kiper +--- + grub-core/fs/ext2.c | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index c3058f7..a5650c3 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -496,7 +496,10 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + int i; + grub_disk_addr_t ret; + grub_uint16_t nent; ++ /* maximum number of extent entries in the inode's inline extent area */ + const grub_uint16_t max_inline_ext = sizeof (inode->blocks) / sizeof (*ext) - 1; /* Minus 1 extent header. */ ++ /* maximum number of extent entries in the external extent block */ ++ const grub_uint16_t max_external_ext = EXT2_BLOCK_SIZE(data) / sizeof (*ext) - 1; /* Minus 1 extent header. */ + + if (grub_ext4_find_leaf (data, (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, + fileblock, &leaf) != GRUB_ERR_NONE) +@@ -513,8 +516,18 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + + nent = grub_le_to_cpu16 (leaf->entries); + +- if (leaf->depth == 0) ++ /* ++ * Determine the effective number of extent entries (nent) to process: ++ * If the extent header (leaf) is stored inline in the inode’s block ++ * area (i.e. at inode->blocks.dir_blocks), then only max_inline_ext ++ * entries can fit. ++ * Otherwise, if the header was read from an external extent block, use ++ * the larger limit, max_external_ext, based on the full block size. ++ */ ++ if (leaf == (struct grub_ext4_extent_header *) inode->blocks.dir_blocks) + nent = grub_min (nent, max_inline_ext); ++ else ++ nent = grub_min (nent, max_external_ext); + + for (i = 0; i < nent; i++) + { diff --git a/0363-powerpc-increase-MIN-RMA-size-for-CAS-negotiation.patch b/0363-powerpc-increase-MIN-RMA-size-for-CAS-negotiation.patch new file mode 100644 index 00000000..1e7dc90d --- /dev/null +++ b/0363-powerpc-increase-MIN-RMA-size-for-CAS-negotiation.patch @@ -0,0 +1,117 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Avnish Chouhan +Date: Thu, 13 Mar 2025 19:45:50 +0530 +Subject: [PATCH] powerpc: increase MIN RMA size for CAS negotiation + +Change RMA size from 512 MB to 768 MB which will result +in more memory at boot time for PowerPC. When vTPM, Secure Boot or +FADump are enabled on PowerPC, the 512 MB RMA memory is not sufficient for +booting. With this 512 MB RMA, GRUB2 runs out of memory and fails to +boot the machine. Sometimes even usage of CDROM requires more memory +for installation and along with the options mentioned above exhausts +the boot memory which results in boot failures. Increasing the RMA size +will resolves multiple out of memory issues observed in PowerPC. + +Failure details (GRUB2 debugs): + + kern/ieee1275/init.c:550: mm requested region of size 8513000, flags 1 + kern/ieee1275/init.c:563: Cannot satisfy allocation and retain minimum runtime space + kern/ieee1275/init.c:550: mm requested region of size 8513000, flags 0 + kern/ieee1275/init.c:563: Cannot satisfy allocation and retain minimum runtime space + kern/file.c:215: Closing `/ppc/ppc64/initrd.img' ... + kern/disk.c:297: Closing `ieee1275//vdevice/v-scsi@30000067/disk@8300000000000000'... + kern/disk.c:311: Closing `ieee1275//vdevice/v-scsi@30000067/disk@8300000000000000' succeeded. + kern/file.c:225: Closing `/ppc/ppc64/initrd.img' failed with 3. + kern/file.c:148: Opening `/ppc/ppc64/initrd.img' succeeded. + error: ../../grub-core/kern/mm.c:552:out of memory. + +Signed-off-by: Avnish Chouhan +--- + grub-core/kern/ieee1275/init.c | 51 +++++++++++++++++++++++++++++++++++++----- + 1 file changed, 46 insertions(+), 5 deletions(-) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 4ec6598cfbb8..bb791f80f41c 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -737,7 +737,7 @@ struct cas_vector + + /* + * Call ibm,client-architecture-support to try to get more RMA. +- * We ask for 512MB which should be enough to verify a distro kernel. ++ * We ask for 768MB which should be enough to verify a distro kernel. + * We ignore most errors: if we don't succeed we'll proceed with whatever + * memory we have. + */ +@@ -809,7 +809,7 @@ grub_ieee1275_ibm_cas (void) + .vec1 = 0x80, /* ignore */ + .vec2_size = 1 + sizeof (struct option_vector2) - 2, + .vec2 = { +- 0, 0, -1, -1, -1, -1, -1, 512, -1, 0, 48 ++ 0, 0, -1, -1, -1, -1, -1, 768, -1, 0, 48 + }, + .vec3_size = 2 - 1, + .vec3 = 0x00e0, /* ask for FP + VMX + DFP but don't halt if unsatisfied */ +@@ -846,6 +846,10 @@ grub_claim_heap (void) + { + grub_err_t err; + grub_uint32_t total = HEAP_MAX_SIZE; ++#if defined(__powerpc__) ++ grub_uint32_t ibm_ca_support_reboot = 0; ++ grub_ssize_t actual; ++#endif + + err = grub_ieee1275_total_mem (&rmo_top); + +@@ -858,11 +862,48 @@ grub_claim_heap (void) + grub_mm_add_region_fn = grub_ieee1275_mm_add_region; + + #if defined(__powerpc__) ++ /* Check if it's a CAS reboot with below property. If so, we will skip CAS call */ ++ if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, ++ "ibm,client-architecture-support-reboot", ++ &ibm_ca_support_reboot, ++ sizeof (ibm_ca_support_reboot), ++ &actual) >= 0) ++ grub_dprintf ("ieee1275", "ibm,client-architecture-support-reboot: %" PRIuGRUB_UINT32_T "\n", ++ ibm_ca_support_reboot); ++ + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY)) + { +- /* if we have an error, don't call CAS, just hope for the best */ +- if (err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * 1024)) +- grub_ieee1275_ibm_cas (); ++ /* ++ * If we have an error, don't call CAS. Just hope for the best. ++ * Along with the above, if the rmo_top is 512 MB or above. We ++ * will skip the CAS call. However, if we call CAS, the rmo_top ++ * will be set to 768 MB via CAS Vector2. But we need to call ++ * CAS with "rmo_top < 512 MB" to avoid the issue on the older ++ * Linux kernel, which still uses rmo_top as 512 MB. If we call ++ * CAS with a condition "rmo_top < 768 MB", it will result in an ++ * issue due to the IBM CAS reboot feature and we won't be able ++ * to boot the newer kernel. Whenever a reboot is detected as ++ * the CAS reboot by GRUB. It will boot the machine with the ++ * last booted kernel by reading the variable "boot-last-label" ++ * which has the info related to the last boot and it's specific ++ * to IBM PowerPC. Due to this, the machine will boot with the ++ * last booted kernel which has rmo_top as 512 MB. Also, if the ++ * reboot is detected as a CAS reboot, the GRUB will skip the CAS ++ * call. As the CAS has already been called earlier, so it is ++ * not required to call CAS even if the other conditions are met. ++ * This condition will also prevent a scenario where the machine ++ * get stuck in the CAS reboot loop while booting. A machine with ++ * an older kernel, having option_vector2 MIN_RMA as 512 MB in ++ * Linux prom_init.c and GRUB uses "rmo_top < 768 MB" condition ++ * for calling CAS. Due to their respective conditions, linux ++ * CAS and GRUB CAS will keep doing the CAS calls and change ++ * the MIN_RMA from 768(changed by GRUB) to 512(changed by Linux) ++ * to 768(changed by GRUB) to 512(changed by Linux) and so on, ++ * and the machine will stuck in this CAS reboot loop forever. ++ * IBM PAPR : https://openpower.foundation/specifications/linuxonpower/ ++ */ ++ if (!ibm_ca_support_reboot && err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * 1024)) ++ grub_ieee1275_ibm_cas (); + } + #endif + diff --git a/0364-script-execute-Don-t-let-trailing-blank-lines-determ.patch b/0364-script-execute-Don-t-let-trailing-blank-lines-determ.patch new file mode 100644 index 00000000..fd2eb2bf --- /dev/null +++ b/0364-script-execute-Don-t-let-trailing-blank-lines-determ.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: James Le Cuirot +Date: Thu, 24 Oct 2024 14:42:46 +0100 +Subject: [PATCH] script/execute: Don't let trailing blank lines determine the + return code + +grub_script_execute_sourcecode() parses and executes code one line at a +time, updating the return code each time because only the last line +determines the final status. However, trailing new lines were also +executed, masking any failure on the previous line. Fix this by only +trying to execute the command when there is actually one present. + +This has presumably never been noticed because this code is not used by +regular functions, only in special cases like eval and menu entries. The +latter generally don't return at all, having booted an OS. When failing +to boot, upstream GRUB triggers the fallback mechanism regardless of the +return code. + +We noticed the problem while using Red Hat's patches, which change this +behaviour to take account of the return code. In that case, a failure +takes you back to the menu rather than triggering a fallback. + +Signed-off-by: James Le Cuirot +--- + grub-core/script/execute.c | 5 ++++- + tests/grub_script_eval.in | 10 +++++++++- + 2 files changed, 13 insertions(+), 2 deletions(-) + +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index 014132703..3d26a3fe4 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -952,7 +952,10 @@ grub_script_execute_sourcecode (const char *source) + break; + } + +- ret = grub_script_execute (parsed_script); ++ /* Don't let trailing blank lines determine the return code. */ ++ if (parsed_script->cmd) ++ ret = grub_script_execute (parsed_script); ++ + grub_script_free (parsed_script); + grub_free (line); + } +diff --git a/tests/grub_script_eval.in b/tests/grub_script_eval.in +index c97b78d77..9c6211042 100644 +--- a/tests/grub_script_eval.in ++++ b/tests/grub_script_eval.in +@@ -3,4 +3,12 @@ + eval echo "Hello world" + valname=tst + eval $valname=hi +-echo $tst +\ No newline at end of file ++echo $tst ++ ++if eval " ++false ++"; then ++ echo should have failed ++else ++ echo failed as expected ++fi +-- +2.48.1 + diff --git a/0365-normal-menu-Check-return-code-of-the-script-when-exe.patch b/0365-normal-menu-Check-return-code-of-the-script-when-exe.patch new file mode 100644 index 00000000..3ce0eec3 --- /dev/null +++ b/0365-normal-menu-Check-return-code-of-the-script-when-exe.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: James Le Cuirot +Date: Thu, 24 Oct 2024 15:00:26 +0100 +Subject: [PATCH] normal/menu: Check return code of the script when executing a + menu entry + +Don't rely on grub_errno here because grub_script_execute_new_scope() +calls grub_print_error(), which always resets grub_errno back to +GRUB_ERR_NONE. It may also get reset by grub_wait_after_message(). + +This problem was observed when a "bad signature" error resulted in the +menu being redisplayed rather than the fallback mechanism being +triggered, although another change was also needed to fix it. This only +happens with Red Hat's patches because upstream GRUB triggers the +fallback mechanism regardless of the return code. + +Signed-off-by: James Le Cuirot +--- + grub-core/normal/menu.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 97687013c..a2703dabb 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -377,14 +377,14 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + if (ptr && ptr[0] && ptr[1]) + grub_env_set ("default", ptr + 1); + +- grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args); ++ err = grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args); + + if (errs_before != grub_err_printed_errors) + grub_wait_after_message (); + + errs_before = grub_err_printed_errors; + +- if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ()) ++ if (err == GRUB_ERR_NONE && grub_loader_is_loaded ()) + /* Implicit execution of boot, only if something is loaded. */ + err = grub_command_execute ("boot", 0, 0); + +-- +2.48.1 + diff --git a/0366-ieee1275-ofnet-Fix-grub_malloc-removed-after-added-s.patch b/0366-ieee1275-ofnet-Fix-grub_malloc-removed-after-added-s.patch new file mode 100644 index 00000000..92da0261 --- /dev/null +++ b/0366-ieee1275-ofnet-Fix-grub_malloc-removed-after-added-s.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nicolas Frayer +Date: Wed, 19 Mar 2025 17:39:41 +0100 +Subject: [PATCH] ieee1275/ofnet: Fix grub_malloc() removed after added safe + math functions + +grub_malloc() has been inadvertently removed from the ieee1275/ofnet +code after it has been modified to use safe match function. + +Fixes: 4beeff8a (net: Use safe math macros to prevent overflows) + +Tested-by: Marta Lewandowska +Reviewed-by: Daniel Kiper +Signed-off-by: Nicolas Frayer +--- + grub-core/net/drivers/ieee1275/ofnet.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c +index 3e1b9094e2ab..37bc82467f60 100644 +--- a/grub-core/net/drivers/ieee1275/ofnet.c ++++ b/grub-core/net/drivers/ieee1275/ofnet.c +@@ -463,6 +463,9 @@ search_net_devices (struct grub_ieee1275_devalias *alias) + return 0; + } + } ++ ++ ofdata->path = grub_malloc(sz); ++ + if (!ofdata->path) + { + grub_print_error (); diff --git a/0367-grub-mkimage-Create-new-ELF-note-for-SBAT.patch b/0367-grub-mkimage-Create-new-ELF-note-for-SBAT.patch new file mode 100644 index 00000000..25023c80 --- /dev/null +++ b/0367-grub-mkimage-Create-new-ELF-note-for-SBAT.patch @@ -0,0 +1,167 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Sudhakar Kuppusamy +Date: Wed, 23 Oct 2024 17:54:32 +0530 +Subject: [PATCH] grub-mkimage: Create new ELF note for SBAT + +In order to store the SBAT data we create a new ELF note. The string +".sbat", zero-padded to 4 byte alignment, shall be entered in the name +field. The string "SBAT"'s ASCII values, 0x53424154, should be entered +in the type field. + +Signed-off-by: Daniel Axtens +Signed-off-by: Sudhakar Kuppusamy +Reviewed-by: Daniel Kiper +--- + include/grub/util/mkimage.h | 4 ++-- + util/grub-mkimagexx.c | 48 +++++++++++++++++++++++++++++++++++++++++++-- + util/mkimage.c | 5 +++-- + 3 files changed, 51 insertions(+), 6 deletions(-) + +diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h +index 6f1da89b9b65..881e3031f41f 100644 +--- a/include/grub/util/mkimage.h ++++ b/include/grub/util/mkimage.h +@@ -51,12 +51,12 @@ grub_mkimage_load_image64 (const char *kernel_path, + const struct grub_install_image_target_desc *image_target); + void + grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target, +- int note, size_t appsig_size, char **core_img, size_t *core_size, ++ int note, size_t appsig_size, char *sbat, char **core_img, size_t *core_size, + Elf32_Addr target_addr, + struct grub_mkimage_layout *layout); + void + grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target, +- int note, size_t appsig_size, char **core_img, size_t *core_size, ++ int note, size_t appsig_size, char *sbat, char **core_img, size_t *core_size, + Elf64_Addr target_addr, + struct grub_mkimage_layout *layout); + +diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c +index 9488f052510a..b9930544889d 100644 +--- a/util/grub-mkimagexx.c ++++ b/util/grub-mkimagexx.c +@@ -116,6 +116,14 @@ struct section_metadata + const char *strtab; + }; + ++#define GRUB_SBAT_NOTE_NAME ".sbat" ++#define GRUB_SBAT_NOTE_TYPE 0x53424154 /* "SBAT" */ ++ ++struct grub_sbat_note { ++ Elf32_Nhdr header; ++ char name[ALIGN_UP(sizeof(GRUB_SBAT_NOTE_NAME), 4)]; ++}; ++ + static int + is_relocatable (const struct grub_install_image_target_desc *image_target) + { +@@ -217,7 +225,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr) + + void + SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target, +- int note, size_t appsig_size, char **core_img, size_t *core_size, ++ int note, size_t appsig_size, char *sbat, char **core_img, size_t *core_size, + Elf_Addr target_addr, + struct grub_mkimage_layout *layout) + { +@@ -226,10 +234,17 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + Elf_Ehdr *ehdr; + Elf_Phdr *phdr; + Elf_Shdr *shdr; +- int header_size, footer_size = 0; ++ int header_size, footer_size = 0, footer_offset = 0; + int phnum = 1; + int shnum = 4; + int string_size = sizeof (".text") + sizeof ("mods") + 1; ++ char *footer; ++ ++ if (sbat) ++ { ++ phnum++; ++ footer_size += ALIGN_UP (sizeof (struct grub_sbat_note) + layout->sbat_size, 4); ++ } + + if (appsig_size) + { +@@ -263,6 +278,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + ehdr = (void *) elf_img; + phdr = (void *) (elf_img + sizeof (*ehdr)); + shdr = (void *) (elf_img + sizeof (*ehdr) + phnum * sizeof (*phdr)); ++ footer = elf_img + program_size + header_size; + memcpy (ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELFCLASSXX; + if (!image_target->bigendian) +@@ -435,6 +451,8 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + phdr->p_filesz = grub_host_to_target32 (XEN_NOTE_SIZE); + phdr->p_memsz = 0; + phdr->p_offset = grub_host_to_target32 (header_size + program_size); ++ footer = ptr; ++ footer_offset = XEN_NOTE_SIZE; + } + + if (image_target->id == IMAGE_XEN_PVH) +@@ -468,6 +486,8 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + phdr->p_filesz = grub_host_to_target32 (XEN_PVH_NOTE_SIZE); + phdr->p_memsz = 0; + phdr->p_offset = grub_host_to_target32 (header_size + program_size); ++ footer = ptr; ++ footer_offset = XEN_PVH_NOTE_SIZE; + } + + if (note) +@@ -498,6 +518,30 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc + phdr->p_filesz = grub_host_to_target32 (note_size); + phdr->p_memsz = 0; + phdr->p_offset = grub_host_to_target32 (header_size + program_size); ++ footer = (elf_img + program_size + header_size + note_size); ++ footer_offset += note_size; ++ } ++ ++ if (sbat) ++ { ++ int note_size = ALIGN_UP (sizeof (struct grub_sbat_note) + layout->sbat_size, 4); ++ struct grub_sbat_note *note_ptr = (struct grub_sbat_note *) footer; ++ ++ note_ptr->header.n_namesz = grub_host_to_target32 (sizeof (GRUB_SBAT_NOTE_NAME)); ++ note_ptr->header.n_descsz = grub_host_to_target32 (ALIGN_UP(layout->sbat_size, 4)); ++ note_ptr->header.n_type = grub_host_to_target32 (GRUB_SBAT_NOTE_TYPE); ++ memcpy (note_ptr->name, GRUB_SBAT_NOTE_NAME, sizeof (GRUB_SBAT_NOTE_NAME)); ++ memcpy ((char *)(note_ptr + 1), sbat, layout->sbat_size); ++ ++ phdr++; ++ phdr->p_type = grub_host_to_target32 (PT_NOTE); ++ phdr->p_flags = grub_host_to_target32 (PF_R); ++ phdr->p_align = grub_host_to_target32 (image_target->voidp_sizeof); ++ phdr->p_vaddr = 0; ++ phdr->p_paddr = 0; ++ phdr->p_filesz = grub_host_to_target32 (note_size); ++ phdr->p_memsz = 0; ++ phdr->p_offset = grub_host_to_target32 (header_size + program_size + footer_offset); + } + + if (appsig_size) { +diff --git a/util/mkimage.c b/util/mkimage.c +index f31fdefa814a..7fa6a7b21954 100644 +--- a/util/mkimage.c ++++ b/util/mkimage.c +@@ -1848,6 +1848,7 @@ grub_install_generate_image (const char *dir, const char *prefix, + case IMAGE_I386_IEEE1275: + { + grub_uint64_t target_addr; ++ char *sbat = NULL; + if (image_target->id == IMAGE_LOONGSON_ELF) + { + if (comp == GRUB_COMPRESSION_NONE) +@@ -1859,10 +1860,10 @@ grub_install_generate_image (const char *dir, const char *prefix, + else + target_addr = image_target->link_addr; + if (image_target->voidp_sizeof == 4) +- grub_mkimage_generate_elf32 (image_target, note, appsig_size, &core_img, ++ grub_mkimage_generate_elf32 (image_target, note, appsig_size, sbat, &core_img, + &core_size, target_addr, &layout); + else +- grub_mkimage_generate_elf64 (image_target, note, appsig_size, &core_img, ++ grub_mkimage_generate_elf64 (image_target, note, appsig_size, sbat, &core_img, + &core_size, target_addr, &layout); + } + break; diff --git a/0368-grub-mkimage-Add-SBAT-metadata-into-ELF-note-for-Pow.patch b/0368-grub-mkimage-Add-SBAT-metadata-into-ELF-note-for-Pow.patch new file mode 100644 index 00000000..1ce74aed --- /dev/null +++ b/0368-grub-mkimage-Add-SBAT-metadata-into-ELF-note-for-Pow.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Sudhakar Kuppusamy +Date: Wed, 23 Oct 2024 17:54:33 +0530 +Subject: [PATCH] grub-mkimage: Add SBAT metadata into ELF note for PowerPC + targets + +The SBAT metadata is read from CSV file and transformed into an ELF note +with the -s option. + +Signed-off-by: Daniel Axtens +Signed-off-by: Sudhakar Kuppusamy +Reviewed-by: Daniel Kiper +--- + util/mkimage.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/util/mkimage.c b/util/mkimage.c +index 7fa6a7b21954..f92949d1df25 100644 +--- a/util/mkimage.c ++++ b/util/mkimage.c +@@ -957,8 +957,8 @@ grub_install_generate_image (const char *dir, const char *prefix, + total_module_size += dtb_size + sizeof (struct grub_module_header); + } + +- if (sbat_path != NULL && image_target->id != IMAGE_EFI) +- grub_util_error (_(".sbat section can be embedded into EFI images only")); ++ if (sbat_path != NULL && (image_target->id != IMAGE_EFI && image_target->id != IMAGE_PPC)) ++ grub_util_error (_("SBAT data can be added only to EFI or powerpc-ieee1275 images")); + + if (disable_shim_lock) + total_module_size += sizeof (struct grub_module_header); +@@ -1849,6 +1849,13 @@ grub_install_generate_image (const char *dir, const char *prefix, + { + grub_uint64_t target_addr; + char *sbat = NULL; ++ if (sbat_path != NULL) ++ { ++ sbat_size = grub_util_get_image_size (sbat_path); ++ sbat = xmalloc (sbat_size); ++ grub_util_load_image (sbat_path, sbat); ++ layout.sbat_size = sbat_size; ++ } + if (image_target->id == IMAGE_LOONGSON_ELF) + { + if (comp == GRUB_COMPRESSION_NONE) diff --git a/0369-10_linux.in-escape-kernel-option-characters-properly.patch b/0369-10_linux.in-escape-kernel-option-characters-properly.patch new file mode 100644 index 00000000..fe245e8e --- /dev/null +++ b/0369-10_linux.in-escape-kernel-option-characters-properly.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 7 May 2025 13:23:37 -0600 +Subject: [PATCH] 10_linux.in: escape kernel option characters properly + +This handles cases where kernel options, specifically the values, +contain special characters, in this case ';', '&' and '$'. + +For example, the user defines the following GRUB_CMDLINE_LINUX on the +default grub file /etc/default/grub, note the dolar sign on the 'memmap' +option + + GRUB_CMDLINE_LINUX="console=ttyS0 memmap=32g\\\$0x2000000000" + +then regenerating the grub cfg and BLS options line with the +grub2-mkconfig command, resulting into + + options root=UUID=6baedf23-2510-499a-815d-48b58cf6e619 ro + rootflags=subvol=root console=ttyS0 memmap=32g\$0x2000000000 + +without this patch, we would end up with + + options root=UUID=6baedf23-2510-499a-815d-48b58cf6e619 ro + rootflags=subvol=root console=ttyS0 memmap=32g$0x2000000000 + +Note the missing '\' which is required to escape the '$', otherwise +it would be consider a variable by blscfg parser which is not the case. + +Signed-off-by: Leo Sandoval +--- + util/grub.d/10_linux.in | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 11c19304f8..cdfb72a1e3 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -178,6 +178,9 @@ update_bls_cmdline() + options="${options} ${GRUB_CMDLINE_LINUX_DEBUG}" + fi + options="$(echo "${options}" | sed -e 's/\//\\\//g')" ++ options="$(echo "${options}" | sed -e 's/\;/\\\;/g')" ++ options="$(echo "${options}" | sed -e 's/\\&/\\\\&/g')" ++ options="$(echo "${options}" | sed -e 's/\$/\\\$/g')" + sed -i -e "s/^options.*/options ${options}/" "${blsdir}/${bls}.conf" + done + } diff --git a/0370-blscfg-check-if-variable-is-escaped-before-consideri.patch b/0370-blscfg-check-if-variable-is-escaped-before-consideri.patch new file mode 100644 index 00000000..fba69064 --- /dev/null +++ b/0370-blscfg-check-if-variable-is-escaped-before-consideri.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Wed, 7 May 2025 13:49:47 -0600 +Subject: [PATCH] blscfg: check if variable is escaped before considering one + +Otherwise escaped variables are considered real variables. + +Signed-off-by: Leo Sandoval +--- + grub-core/commands/blscfg.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 6e398fc175..5d931b0c9b 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -695,7 +695,8 @@ static char *expand_val(const char *value) + return NULL; + + while (*value) { +- if (*value == '$') { ++ /* It's a variable only when *value is '$' and it is not escaped with '\'*/ ++ if (*value == '$' && *end != '\\') { + if (start != end) { + buffer = field_append(is_var, buffer, start, end); + if (!buffer) diff --git a/0371-kern-rescue_reader-Block-the-rescue-mode-until-the-C.patch b/0371-kern-rescue_reader-Block-the-rescue-mode-until-the-C.patch new file mode 100644 index 00000000..5d588b1c --- /dev/null +++ b/0371-kern-rescue_reader-Block-the-rescue-mode-until-the-C.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Fri, 28 Feb 2025 17:00:53 +0300 +Subject: [PATCH] kern/rescue_reader: Block the rescue mode until the CLI + authentication + +This further mitigates potential misuse of the CLI after the +root device has been successfully unlocked via TPM. + +Fixes: CVE-2025-4382 + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + grub-core/kern/rescue_reader.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/rescue_reader.c b/grub-core/kern/rescue_reader.c +index 4259857ba9..a71ada8fb7 100644 +--- a/grub-core/kern/rescue_reader.c ++++ b/grub-core/kern/rescue_reader.c +@@ -79,7 +79,7 @@ void __attribute__ ((noreturn)) + grub_rescue_run (void) + { + /* Stall if the CLI has been disabled */ +- if (grub_is_cli_disabled ()) ++ if (grub_is_cli_disabled () || grub_is_cli_need_auth ()) + { + grub_printf ("Rescue mode has been disabled...\n"); + diff --git a/0372-commands-search-Introduce-the-cryptodisk-only-argume.patch b/0372-commands-search-Introduce-the-cryptodisk-only-argume.patch new file mode 100644 index 00000000..53e7eaae --- /dev/null +++ b/0372-commands-search-Introduce-the-cryptodisk-only-argume.patch @@ -0,0 +1,133 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Sat, 1 Mar 2025 14:16:48 +0300 +Subject: [PATCH] commands/search: Introduce the --cryptodisk-only argument + +This allows users to restrict the "search" command's scope to +encrypted disks only. + +Typically, this command is used to "rebase" $root and $prefix +before loading additional configuration files via "source" or +"configfile". Unfortunately, this leads to security problems, +like CVE-2023-4001, when an unexpected, attacker-controlled +device is chosen by the "search" command. + +The --cryptodisk-only argument allows users to ensure that the +file system picked is encrypted. + +This feature supports the CLI authentication, blocking bypass +attempts. + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + grub-core/commands/search.c | 20 ++++++++++++++++++++ + grub-core/commands/search_wrap.c | 7 ++++++- + grub-core/normal/main.c | 3 ++- + include/grub/search.h | 9 +++++---- + 4 files changed, 33 insertions(+), 6 deletions(-) + +diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c +index d538b36219..84362b54b3 100644 +--- a/grub-core/commands/search.c ++++ b/grub-core/commands/search.c +@@ -182,6 +182,26 @@ iterate_device (const char *name, void *data) + grub_device_close (dev); + } + ++ /* Limit to encrypted disks when requested. */ ++ if (ctx->flags & SEARCH_FLAGS_CRYPTODISK_ONLY) ++ { ++ grub_device_t dev; ++ ++ dev = grub_device_open (name); ++ if (dev == NULL) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ if (dev->disk == NULL || dev->disk->dev->id != GRUB_DISK_DEVICE_CRYPTODISK_ID) ++ { ++ grub_device_close (dev); ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ grub_device_close (dev); ++ } ++ + /* Skip it if it's not the root device when requested. */ + if (ctx->flags & SEARCH_FLAGS_ROOTDEV_ONLY) + { +diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c +index 4fe6440c65..ec2fb638f1 100644 +--- a/grub-core/commands/search_wrap.c ++++ b/grub-core/commands/search_wrap.c +@@ -41,6 +41,7 @@ static const struct grub_arg_option options[] = + ARG_TYPE_STRING}, + {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0}, + {"efidisk-only", 0, 0, N_("Only probe EFI disks."), 0, 0}, ++ {"cryptodisk-only", 0, 0, N_("Only probe encrypted disks."), 0, 0}, + {"root-dev-only", 'r', 0, N_("Only probe root device."), 0, 0}, + {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT. If HINT ends in comma, " +@@ -76,6 +77,7 @@ enum options + SEARCH_SET, + SEARCH_NO_FLOPPY, + SEARCH_EFIDISK_ONLY, ++ SEARCH_CRYPTODISK_ONLY, + SEARCH_ROOTDEV_ONLY, + SEARCH_HINT, + SEARCH_HINT_IEEE1275, +@@ -191,6 +193,9 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) + if (state[SEARCH_EFIDISK_ONLY].set) + flags |= SEARCH_FLAGS_EFIDISK_ONLY; + ++ if (state[SEARCH_CRYPTODISK_ONLY].set) ++ flags |= SEARCH_FLAGS_CRYPTODISK_ONLY; ++ + if (state[SEARCH_ROOTDEV_ONLY].set) + flags |= SEARCH_FLAGS_ROOTDEV_ONLY; + +@@ -215,7 +220,7 @@ GRUB_MOD_INIT(search) + cmd = + grub_register_extcmd ("search", grub_cmd_search, + GRUB_COMMAND_FLAG_EXTRACTOR | GRUB_COMMAND_ACCEPT_DASH, +- N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]" ++ N_("[-f|-l|-u|-s|-n] [--cryptodisk-only] [--hint HINT [--hint HINT] ...]" + " NAME"), + N_("Search devices by file, filesystem label" + " or filesystem UUID." +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index dd20e51290..6f7290a897 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -615,7 +615,8 @@ static const char *features[] = { + "feature_chainloader_bpb", "feature_ntldr", "feature_platform_search_hint", + "feature_default_font_path", "feature_all_video_module", + "feature_menuentry_id", "feature_menuentry_options", "feature_200_final", +- "feature_nativedisk_cmd", "feature_timeout_style" ++ "feature_nativedisk_cmd", "feature_timeout_style", ++ "feature_search_cryptodisk_only" + }; + + GRUB_MOD_INIT(normal) +diff --git a/include/grub/search.h b/include/grub/search.h +index 9343c66b13..b6b5c8be1f 100644 +--- a/include/grub/search.h ++++ b/include/grub/search.h +@@ -21,10 +21,11 @@ + + enum search_flags + { +- SEARCH_FLAGS_NONE = 0, +- SEARCH_FLAGS_NO_FLOPPY = 1, +- SEARCH_FLAGS_EFIDISK_ONLY = 2, +- SEARCH_FLAGS_ROOTDEV_ONLY = 4 ++ SEARCH_FLAGS_NONE = 0, ++ SEARCH_FLAGS_NO_FLOPPY = 1, ++ SEARCH_FLAGS_EFIDISK_ONLY = 2, ++ SEARCH_FLAGS_ROOTDEV_ONLY = 4, ++ SEARCH_FLAGS_CRYPTODISK_ONLY = 8 + }; + + void grub_search_fs_file (const char *key, const char *var, diff --git a/0373-disk-diskfilter-Introduce-the-cryptocheck-command.patch b/0373-disk-diskfilter-Introduce-the-cryptocheck-command.patch new file mode 100644 index 00000000..a56fc858 --- /dev/null +++ b/0373-disk-diskfilter-Introduce-the-cryptocheck-command.patch @@ -0,0 +1,133 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Sun, 2 Mar 2025 18:08:22 +0300 +Subject: [PATCH] disk/diskfilter: Introduce the "cryptocheck" command + +This command examines a given diskfilter device, e.g., an LVM disk, +and checks if underlying disks, physical volumes, are cryptodisks, +e.g., LUKS disks, this layout is called "LVM-on-LUKS". + +The return value is 0 when all underlying disks (of a given device) +are cryptodisks (1 if at least one disk is unencrypted or in an +unknown state). + +Users are encouraged to include the relevant check before loading +anything from an LVM disk that is supposed to be encrypted. + +This further supports the CLI authentication, blocking bypass +attempts when booting from an encrypted LVM disk. + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + grub-core/disk/diskfilter.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 75 insertions(+) + +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index fef0b815ab..216be6a782 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -1365,6 +1366,73 @@ grub_diskfilter_get_pv_from_disk (grub_disk_t disk, + } + #endif + ++static int ++grub_diskfilter_check_pvs_encrypted (grub_disk_t disk, int *pvs_cnt) ++{ ++ struct grub_diskfilter_lv *lv = disk->data; ++ struct grub_diskfilter_pv *pv; ++ ++ *pvs_cnt = 0; ++ ++ if (lv->vg->pvs) ++ for (pv = lv->vg->pvs; pv; pv = pv->next) ++ { ++ (*pvs_cnt)++; ++ ++ if (pv->disk == NULL) ++ { ++ /* Can be a partially activated VG, bail out. */ ++ return GRUB_ERR_TEST_FAILURE; ++ } ++ ++ if (pv->disk->dev->id != GRUB_DISK_DEVICE_CRYPTODISK_ID) ++ { ++ /* All backing devices must be cryptodisks, stop. */ ++ return GRUB_ERR_TEST_FAILURE; ++ } ++ } ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_cryptocheck (grub_command_t cmd __attribute__ ((unused)), ++ int argc, char **args) ++{ ++ grub_disk_t disk; ++ int check_pvs_res; ++ int namelen; ++ int pvs_cnt; ++ ++ if (argc != 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("disk name expected")); ++ ++ namelen = grub_strlen (args[0]); ++ if (namelen > 2 && (args[0][0] == '(') && (args[0][namelen - 1] == ')')) ++ args[0][namelen - 1] = 0; ++ else ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("invalid disk: %s"), ++ args[0]); ++ ++ if (!is_valid_diskfilter_name (&args[0][1])) ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("unrecognized disk: %s"), ++ &args[0][1]); ++ ++ disk = grub_disk_open (&args[0][1]); ++ if (disk == NULL) ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("no such disk: %s"), ++ &args[0][1]); ++ ++ check_pvs_res = grub_diskfilter_check_pvs_encrypted (disk, &pvs_cnt); ++ grub_disk_close (disk); ++ ++ grub_printf("%s is %sencrypted (%d pv%s examined)\n", &args[0][1], ++ (check_pvs_res == GRUB_ERR_NONE) ? "" : "un", ++ pvs_cnt, ++ (pvs_cnt > 1) ? "s" : ""); ++ ++ return check_pvs_res; ++} ++ + static struct grub_disk_dev grub_diskfilter_dev = + { + .name = "diskfilter", +@@ -1381,14 +1449,21 @@ static struct grub_disk_dev grub_diskfilter_dev = + .next = 0 + }; + ++static grub_command_t cmd; ++ + + GRUB_MOD_INIT(diskfilter) + { + grub_disk_dev_register (&grub_diskfilter_dev); ++ cmd = grub_register_command ("cryptocheck", grub_cmd_cryptocheck, ++ N_("DEVICE"), ++ N_("Check if a logical volume resides on encrypted disks.")); + } + + GRUB_MOD_FINI(diskfilter) + { + grub_disk_dev_unregister (&grub_diskfilter_dev); ++ if (cmd != NULL) ++ grub_unregister_command (cmd); + free_array (); + } diff --git a/0374-commands-search-Add-the-diskfilter-support.patch b/0374-commands-search-Add-the-diskfilter-support.patch new file mode 100644 index 00000000..5edb3ea8 --- /dev/null +++ b/0374-commands-search-Add-the-diskfilter-support.patch @@ -0,0 +1,67 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Sun, 2 Mar 2025 23:32:43 +0300 +Subject: [PATCH] commands/search: Add the diskfilter support + +When the --cryptodisk-only argument is given, also check the target +device using the "cryptocheck" command, if available. + +This extends the checks to common layouts like LVM-on-LUKS, so the +--cryptodisk-only argument transparently handles such setups. + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + grub-core/commands/search.c | 32 +++++++++++++++++++++++++++++++- + 1 file changed, 31 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c +index 84362b54b3..1cf714ad7d 100644 +--- a/grub-core/commands/search.c ++++ b/grub-core/commands/search.c +@@ -150,6 +150,36 @@ check_for_duplicate (const char *name, void *data) + return ret; + } + ++static bool ++is_unencrypted_disk (grub_disk_t disk) ++{ ++ grub_command_t cmd; ++ char *disk_str; ++ int disk_str_len; ++ int res; ++ ++ if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) ++ return false; /* This is (crypto) disk. */ ++ ++ if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID) ++ { ++ cmd = grub_command_find ("cryptocheck"); ++ if (cmd == NULL) /* No diskfilter module loaded for some reason. */ ++ return true; ++ ++ disk_str_len = grub_strlen (disk->name) + 2 + 1; ++ disk_str = grub_malloc (disk_str_len); ++ if (disk_str == NULL) /* Something is wrong, better report as unencrypted. */ ++ return true; ++ ++ grub_snprintf (disk_str, disk_str_len, "(%s)", disk->name); ++ res = cmd->func (cmd, 1, &disk_str); ++ grub_free (disk_str); ++ return (res != GRUB_ERR_NONE) ? true : false; /* GRUB_ERR_NONE for encrypted. */ ++ } ++ return true; ++} ++ + /* Helper for FUNC_NAME. */ + static int + iterate_device (const char *name, void *data) +@@ -193,7 +223,7 @@ iterate_device (const char *name, void *data) + grub_errno = GRUB_ERR_NONE; + return 0; + } +- if (dev->disk == NULL || dev->disk->dev->id != GRUB_DISK_DEVICE_CRYPTODISK_ID) ++ if (dev->disk == NULL || is_unencrypted_disk (dev->disk) == true) + { + grub_device_close (dev); + grub_errno = GRUB_ERR_NONE; diff --git a/0375-docs-Document-available-crypto-disks-checks.patch b/0375-docs-Document-available-crypto-disks-checks.patch new file mode 100644 index 00000000..ac22920f --- /dev/null +++ b/0375-docs-Document-available-crypto-disks-checks.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Mon, 10 Mar 2025 15:33:46 +0300 +Subject: [PATCH] docs: Document available crypto disks checks + +Document the --cryptodisk-only argument. Also, document the +"cryptocheck" command invoked when that argument is processed. + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 22 +++++++++++++++++++++- + 1 file changed, 21 insertions(+), 1 deletion(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 2d6d73a78d..93e23be99d 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -4365,6 +4365,7 @@ you forget a command, you can run the command @command{help} + * configfile:: Load a configuration file + * cpuid:: Check for CPU features + * crc:: Compute or check CRC32 checksums ++* cryptocheck:: Check if a device is encrypted + * cryptomount:: Mount a crypto device + * cutmem:: Remove memory regions + * date:: Display or set current date and time +@@ -4674,6 +4675,16 @@ Alias for @code{hashsum --hash crc32 arg @dots{}}. See command @command{hashsum} + (@pxref{hashsum}) for full description. + @end deffn + ++@node cryptocheck ++@subsection cryptocheck ++ ++@deffn Command cryptocheck device ++Check if a given diskfilter device is backed by encrypted devices ++(@pxref{cryptomount} for additional information). ++ ++The command examines all backing devices, physical volumes, of a specified ++logical volume, like LVM2, and fails when at least one of them is unencrypted. ++@end deffn + + @node cryptomount + @subsection cryptomount +@@ -5522,7 +5533,8 @@ unbootable. @xref{Using GPG-style digital signatures}, for more information. + + @deffn Command search @ + [@option{--file}|@option{--label}|@option{--fs-uuid}] @ +- [@option{--set} [var]] [@option{--no-floppy}|@option{--efidisk-only}] name ++ [@option{--set} [var]] [@option{--no-floppy}|@option{--efidisk-only}|@option{--cryptodisk-only}] @ ++ name + Search devices by file (@option{-f}, @option{--file}), filesystem label + (@option{-l}, @option{--label}), or filesystem UUID (@option{-u}, + @option{--fs-uuid}). +@@ -5537,6 +5549,14 @@ devices, which can be slow. + The (@option{--efidisk-only}) option prevents searching any other devices then + EFI disks. This is typically used when chainloading to local EFI partition. + ++The (@option{--cryptodisk-only}) option prevents searching any devices other ++than encrypted disks. This is typically used when booting from an encrypted ++file system to ensure that no code gets executed from an unencrypted device ++having the same filesystem UUID or label. ++ ++This option implicitly invokes the command @command{cryptocheck}, if it is ++available (@pxref{cryptocheck} for additional information). ++ + The @samp{search.file}, @samp{search.fs_label}, and @samp{search.fs_uuid} + commands are aliases for @samp{search --file}, @samp{search --label}, and + @samp{search --fs-uuid} respectively. diff --git a/0376-disk-cryptodisk-Add-the-erase-secrets-function.patch b/0376-disk-cryptodisk-Add-the-erase-secrets-function.patch new file mode 100644 index 00000000..5a995cf3 --- /dev/null +++ b/0376-disk-cryptodisk-Add-the-erase-secrets-function.patch @@ -0,0 +1,147 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Tue, 6 May 2025 12:25:20 -0600 +Subject: [PATCH] disk/cryptodisk: Add the "erase secrets" function + +This commit adds the grub_cryptodisk_erasesecrets() function to wipe +master keys from all cryptodisks. This function is EFI-only. + +Since there is no easy way to "force unmount" a given encrypted disk, +this function renders all mounted cryptodisks unusable. An attempt to +read them will return garbage. + +This is why this function must be used in "no way back" conditions. + +Currently, it is used when unloading the cryptodisk module and when +performing the "exit" command (it is often used to switch to the next +EFI application). This function is not called when performing the +"chainloader" command, because the callee may return to GRUB. For this +reason, users are encouraged to use "exit" instead of "chainloader" to +execute third-party boot applications. + +This function does not guarantee that all secrets are wiped from RAM. +Console output, chunks from disk read requests and other may remain. + +This function does not clear the IV prefix and rekey key for geli disks. + +Also, this commit adds the relevant documentation improvements. + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 6 ++++++ + grub-core/commands/minicmd.c | 11 +++++++++++ + grub-core/disk/cryptodisk.c | 28 ++++++++++++++++++++++++++++ + include/grub/cryptodisk.h | 1 + + 4 files changed, 46 insertions(+) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 93e23be99d..0af47b5ade 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -4721,6 +4721,11 @@ namespace in addition to the cryptodisk namespace. + + Support for plain encryption mode (plain dm-crypt) is provided via separate + @command{@pxref{plainmount}} command. ++ ++On the EFI platform, GRUB tries to erase master keys from memory when the cryptodisk ++module is unloaded or the command @command{exit} is executed. All secrets remain in ++memory when the command @command{chainloader} is issued, because execution can ++return to GRUB on the EFI platform. + @end deffn + + @node cutmem +@@ -6982,6 +6987,7 @@ USB support provides benefits similar to ATA (for USB disks) or AT (for USB + keyboards). In addition it allows USBserial. + + Chainloading refers to the ability to load another bootloader through the same protocol ++and on some platforms, like EFI, allow that bootloader to return to the GRUB. + + Hints allow faster disk discovery by already knowing in advance which is the disk in + question. On some platforms hints are correct unless you move the disk between boots. +diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c +index 9efb7718c3..eb786766a8 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -29,6 +29,10 @@ + #include + #include + ++#ifdef GRUB_MACHINE_EFI ++#include ++#endif ++ + GRUB_MOD_LICENSE ("GPLv3+"); + + /* cat FILE */ +@@ -199,6 +203,13 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)), + retval = n; + } + ++#ifdef GRUB_MACHINE_EFI ++ /* ++ * The "exit" command is often used to launch the next boot application. ++ * So, erase the secrets. ++ */ ++ grub_cryptodisk_erasesecrets (); ++#endif + grub_exit (retval); + /* Not reached. */ + } +diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c +index 8727760100..9597d2d3bd 100644 +--- a/grub-core/disk/cryptodisk.c ++++ b/grub-core/disk/cryptodisk.c +@@ -1677,6 +1677,31 @@ grub_cryptodisk_challenge_password (void) + + return GRUB_ERR_NONE; + } ++ ++void ++grub_cryptodisk_erasesecrets (void) ++{ ++ grub_cryptodisk_t i; ++ grub_uint8_t *buf; ++ ++ buf = grub_zalloc (GRUB_CRYPTODISK_MAX_KEYLEN); ++ if (buf == NULL) ++ grub_fatal ("grub_cryptodisk_erasesecrets: cannot allocate memory"); ++ ++ for (i = cryptodisk_list; i != NULL; i = i->next) ++ if (grub_cryptodisk_setkey (i, buf, i->keysize)) ++ grub_fatal ("grub_cryptodisk_erasesecrets: cannot erase secrets for %s", i->source); ++ else ++ grub_printf ("Erased crypto secrets for %s\n", i->source); ++ /* ++ * Unfortunately, there is no way to "force unmount" a given disk, it may ++ * have mounted "child" disks as well, e.g., an LVM volume. So, this ++ * function MUST be called when there is no way back, e.g., when exiting. ++ * Otherwise, subsequent read calls for a cryptodisk will return garbage. ++ */ ++ ++ grub_free (buf); ++} + #endif /* GRUB_MACHINE_EFI */ + + struct grub_procfs_entry luks_script = +@@ -1700,6 +1725,9 @@ GRUB_MOD_INIT (cryptodisk) + + GRUB_MOD_FINI (cryptodisk) + { ++#ifdef GRUB_MACHINE_EFI ++ grub_cryptodisk_erasesecrets (); ++#endif + grub_disk_dev_unregister (&grub_cryptodisk_dev); + cryptodisk_cleanup (); + grub_unregister_extcmd (cmd); +diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h +index d2572f8b05..ef307dfd5d 100644 +--- a/include/grub/cryptodisk.h ++++ b/include/grub/cryptodisk.h +@@ -189,5 +189,6 @@ grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk); + + #ifdef GRUB_MACHINE_EFI + grub_err_t grub_cryptodisk_challenge_password (void); ++void grub_cryptodisk_erasesecrets (void); + #endif + #endif diff --git a/0377-disk-cryptodisk-Wipe-the-passphrase-from-memory.patch b/0377-disk-cryptodisk-Wipe-the-passphrase-from-memory.patch new file mode 100644 index 00000000..17405318 --- /dev/null +++ b/0377-disk-cryptodisk-Wipe-the-passphrase-from-memory.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Maxim Suhanov +Date: Tue, 4 Mar 2025 15:27:59 +0300 +Subject: [PATCH] disk/cryptodisk: Wipe the passphrase from memory + +Switching to another EFI boot application while there are secrets in +RAM is dangerous, because not all firmware is wiping memory on free. + +To reduce the attack surface, wipe the passphrase acquired when +unlocking an encrypted volume. + +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + grub-core/disk/cryptodisk.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c +index 9597d2d3bd..26457095d3 100644 +--- a/grub-core/disk/cryptodisk.c ++++ b/grub-core/disk/cryptodisk.c +@@ -1164,6 +1164,7 @@ grub_cryptodisk_scan_device_real (const char *name, + + if (askpass) + { ++ grub_memset (cargs->key_data, 0, cargs->key_len); + cargs->key_len = 0; + grub_free (cargs->key_data); + } diff --git a/0378-cryptocheck-Add-quiet-option.patch b/0378-cryptocheck-Add-quiet-option.patch new file mode 100644 index 00000000..b62c6403 --- /dev/null +++ b/0378-cryptocheck-Add-quiet-option.patch @@ -0,0 +1,114 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Fri, 14 Mar 2025 19:03:39 +0800 +Subject: [PATCH] cryptocheck: Add --quiet option + +The option can be used to suppress output if we only want to test the +return value of the command. + +Also, mention this option in the documentation. + +Signed-off-by: Michael Chang +Signed-off-by: Maxim Suhanov +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 4 +++- + grub-core/commands/search.c | 7 ++++++- + grub-core/disk/diskfilter.c | 25 +++++++++++++++++++------ + 3 files changed, 28 insertions(+), 8 deletions(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 0af47b5ade..ae01e8c994 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -4678,12 +4678,14 @@ Alias for @code{hashsum --hash crc32 arg @dots{}}. See command @command{hashsum} + @node cryptocheck + @subsection cryptocheck + +-@deffn Command cryptocheck device ++@deffn Command cryptocheck [ @option{--quiet} ] device + Check if a given diskfilter device is backed by encrypted devices + (@pxref{cryptomount} for additional information). + + The command examines all backing devices, physical volumes, of a specified + logical volume, like LVM2, and fails when at least one of them is unencrypted. ++ ++The option @option{--quiet} can be given to suppress the output. + @end deffn + + @node cryptomount +diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c +index 1cf714ad7d..c432c0ac6f 100644 +--- a/grub-core/commands/search.c ++++ b/grub-core/commands/search.c +@@ -163,6 +163,9 @@ is_unencrypted_disk (grub_disk_t disk) + + if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID) + { ++ char opt[] = "--quiet"; ++ char *args[2]; ++ + cmd = grub_command_find ("cryptocheck"); + if (cmd == NULL) /* No diskfilter module loaded for some reason. */ + return true; +@@ -173,7 +176,9 @@ is_unencrypted_disk (grub_disk_t disk) + return true; + + grub_snprintf (disk_str, disk_str_len, "(%s)", disk->name); +- res = cmd->func (cmd, 1, &disk_str); ++ args[0] = opt; ++ args[1] = disk_str; ++ res = cmd->func (cmd, 2, args); + grub_free (disk_str); + return (res != GRUB_ERR_NONE) ? true : false; /* GRUB_ERR_NONE for encrypted. */ + } +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index 216be6a782..04b64aebc6 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -1402,6 +1402,19 @@ grub_cmd_cryptocheck (grub_command_t cmd __attribute__ ((unused)), + int check_pvs_res; + int namelen; + int pvs_cnt; ++ int opt_quiet = 0; ++ ++ if (argc == 2) ++ { ++ if (grub_strcmp (args[0], "--quiet") == 0) ++ { ++ opt_quiet = 1; ++ argc--; ++ args++; ++ } ++ else ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unrecognized option: %s"), args[0]); ++ } + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("disk name expected")); +@@ -1424,11 +1437,11 @@ grub_cmd_cryptocheck (grub_command_t cmd __attribute__ ((unused)), + + check_pvs_res = grub_diskfilter_check_pvs_encrypted (disk, &pvs_cnt); + grub_disk_close (disk); +- +- grub_printf("%s is %sencrypted (%d pv%s examined)\n", &args[0][1], +- (check_pvs_res == GRUB_ERR_NONE) ? "" : "un", +- pvs_cnt, +- (pvs_cnt > 1) ? "s" : ""); ++ if (!opt_quiet) ++ grub_printf ("%s is %sencrypted (%d pv%s examined)\n", &args[0][1], ++ (check_pvs_res == GRUB_ERR_NONE) ? "" : "un", ++ pvs_cnt, ++ (pvs_cnt > 1) ? "s" : ""); + + return check_pvs_res; + } +@@ -1456,7 +1469,7 @@ GRUB_MOD_INIT(diskfilter) + { + grub_disk_dev_register (&grub_diskfilter_dev); + cmd = grub_register_command ("cryptocheck", grub_cmd_cryptocheck, +- N_("DEVICE"), ++ N_("[--quiet] DEVICE"), + N_("Check if a logical volume resides on encrypted disks.")); + } + diff --git a/0379-loader-efi-chainloader-Fix-double-free.patch b/0379-loader-efi-chainloader-Fix-double-free.patch new file mode 100644 index 00000000..ae51483b --- /dev/null +++ b/0379-loader-efi-chainloader-Fix-double-free.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Thomas Frauendorfer | Miray Software +Date: Wed, 21 May 2025 10:56:19 +0200 +Subject: [PATCH] loader/efi/chainloader: Fix double free + +Signed-off-by: Thomas Frauendorfer | Miray Software +Reviewed-by: Nicolas Frayer +--- + grub-core/loader/efi/chainloader.c | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 7652f5a..0a78d0d 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -1193,9 +1193,6 @@ fail: + if (address) + grub_efi_free_pages (address, pages); + +- if (cmdline) +- grub_free (cmdline); +- + if (image_handle != NULL) + grub_efi_unload_image (image_handle); + diff --git a/0380-loader-efi-chainloader-Fix-null-pointer-dereference.patch b/0380-loader-efi-chainloader-Fix-null-pointer-dereference.patch new file mode 100644 index 00000000..1a5048ab --- /dev/null +++ b/0380-loader-efi-chainloader-Fix-null-pointer-dereference.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Thomas Frauendorfer | Miray Software +Date: Tue, 20 May 2025 09:20:46 +0200 +Subject: [PATCH] loader/efi/chainloader: Fix null pointer dereference + +This fixes a null pointer access during netboot +introduced in +* Allow chainloading EFI apps from loop mounts. + +The commit accesses dev->disk without testing it. +But when booting through network dev->disk will be NULL + +Signed-off-by: Thomas Frauendorfer | Miray Software +Reviewed-by: Nicolas Frayer +--- + grub-core/loader/efi/chainloader.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 0a78d0d..a004020 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -1006,7 +1006,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_free (devname); + + /* if device is loopback, use underlying dev */ +- if (dev && dev->disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID) ++ if (dev && dev->disk && dev->disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID) + { + struct grub_loopback *d; + orig_dev = dev; diff --git a/0381-osdep-linux-getroot-Detect-DDF-container-similar-to-.patch b/0381-osdep-linux-getroot-Detect-DDF-container-similar-to-.patch new file mode 100644 index 00000000..95628b3b --- /dev/null +++ b/0381-osdep-linux-getroot-Detect-DDF-container-similar-to-.patch @@ -0,0 +1,86 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Thu, 24 Apr 2025 11:43:28 +0200 +Subject: [PATCH] osdep/linux/getroot: Detect DDF container similar to IMSM +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Similarly to Intel IMSM, there are BIOS and UEFI implementations that +support DDF containers natively. + +DDF and IMSM are very similar in handling, especially these should not +be considered as RAID abstraction. This fixes the requirement of having +a device map when probing DDF containers. + +Fixes: https://issues.redhat.com/browse/RHEL-44336 + +Signed-off-by: Renaud Métrich +Reviewed-by: Daniel Kiper +--- + grub-core/osdep/linux/getroot.c | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index b832593213e6..4bf386b590b5 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -127,7 +127,7 @@ struct btrfs_ioctl_search_args { + struct btrfs_ioctl_fs_info_args) + + static int +-grub_util_is_imsm (const char *os_dev); ++grub_util_is_imsm_or_ddf (const char *os_dev); + + + #define ESCAPED_PATH_MAX (4 * PATH_MAX) +@@ -759,10 +759,10 @@ out: + } + + static int +-grub_util_is_imsm (const char *os_dev) ++grub_util_is_imsm_or_ddf (const char *os_dev) + { + int retry; +- int is_imsm = 0; ++ int is_imsm_or_ddf = 0; + int container_seen = 0; + const char *dev = os_dev; + +@@ -823,10 +823,17 @@ grub_util_is_imsm (const char *os_dev) + if (strncmp (buf, "MD_METADATA=imsm", + sizeof ("MD_METADATA=imsm") - 1) == 0) + { +- is_imsm = 1; ++ is_imsm_or_ddf = 1; + grub_util_info ("%s is imsm", dev); + break; + } ++ if (strncmp (buf, "MD_METADATA=ddf", ++ sizeof ("MD_METADATA=ddf") - 1) == 0) ++ { ++ is_imsm_or_ddf = 1; ++ grub_util_info ("%s is ddf", dev); ++ break; ++ } + } + + free (buf); +@@ -837,7 +844,7 @@ grub_util_is_imsm (const char *os_dev) + + if (dev != os_dev) + free ((void *) dev); +- return is_imsm; ++ return is_imsm_or_ddf; + } + + char * +@@ -1202,7 +1209,7 @@ grub_util_get_dev_abstraction_os (const char *os_dev) + + /* Check for RAID. */ + if (!strncmp (os_dev, "/dev/md", 7) && ! grub_util_device_is_mapped (os_dev) +- && !grub_util_is_imsm (os_dev)) ++ && !grub_util_is_imsm_or_ddf (os_dev)) + return GRUB_DEV_ABSTRACTION_RAID; + return GRUB_DEV_ABSTRACTION_NONE; + } diff --git a/0382-Set-correctly-the-memory-attributes-for-the-kernel-P.patch b/0382-Set-correctly-the-memory-attributes-for-the-kernel-P.patch new file mode 100644 index 00000000..6fe22da7 --- /dev/null +++ b/0382-Set-correctly-the-memory-attributes-for-the-kernel-P.patch @@ -0,0 +1,291 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Tue, 29 Jul 2025 09:43:37 -0600 +Subject: [PATCH] Set correctly the memory attributes for the kernel PE + sections + +Currently the whole kernel memory region is set to RO, so at some +point when execution is passed to the kernel, the latter faults on a +memory write access, e.g. zeroing .bss section. The proposed change +sets the memory attribute appropriately for each kernel PE section. + +Signed-off-by: Leo Sandoval +--- + grub-core/loader/efi/linux.c | 170 +++++++++++++++++++++++++++----------- + grub-core/loader/i386/efi/linux.c | 5 +- + include/grub/efi/linux.h | 6 ++ + 3 files changed, 134 insertions(+), 47 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index ef55556f2d..111edf0e1d 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + #include + + GRUB_MOD_LICENSE ("GPLv3+"); +@@ -202,22 +203,133 @@ grub_efi_check_nx_required (int *nx_required) + typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); + + grub_err_t +-grub_efi_linux_boot (grub_addr_t k_address, grub_size_t k_size, ++grub_efi_mem_set_att(grub_addr_t k_address, grub_size_t k_size, ++ grub_size_t k_start, int nx_supported) ++{ ++ grub_addr_t k_start_address = k_address + k_start; ++ ++ grub_uint64_t default_set_attrs = GRUB_MEM_ATTR_R | GRUB_MEM_ATTR_W | GRUB_MEM_ATTR_X; ++ grub_uint64_t default_clear_attrs = 0; ++ grub_uint64_t stack_set_attrs = default_set_attrs; ++ grub_uint64_t stack_clear_attrs = default_clear_attrs; ++ grub_uint64_t kernel_set_attrs = default_set_attrs; ++ grub_uint64_t kernel_clear_attrs = default_clear_attrs; ++ grub_uint64_t attrs; ++ ++ struct grub_msdos_image_header *header; ++ struct grub_pe_image_header *pe_image_header; ++ struct grub_pe32_coff_header *coff_header; ++ struct grub_pe32_section_table *section, *sections; ++ grub_uint16_t i; ++ grub_size_t sz; ++ ++ header = (struct grub_msdos_image_header *)k_address; ++ ++ if (grub_add ((grub_addr_t) header, header->pe_image_header_offset, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("Error on PE image header address calculation")); ++ ++ pe_image_header = (struct grub_pe_image_header *) (sz); ++ ++ if (pe_image_header > (k_address + k_size)) ++ return grub_error (GRUB_ERR_BAD_OS, N_("PE image header address is invalid")); ++ ++ if (grub_memcmp (pe_image_header->signature, GRUB_PE32_SIGNATURE, ++ GRUB_PE32_SIGNATURE_SIZE) != 0) ++ return grub_error (GRUB_ERR_BAD_OS, N_("kernel PE magic is invalid")); ++ ++ coff_header = &(pe_image_header->coff_header); ++ grub_dprintf ("nx", "coff_header 0x%"PRIxGRUB_ADDR" machine %08x\n", (grub_addr_t)coff_header, coff_header->machine); ++ ++ if (grub_add ((grub_addr_t) coff_header, sizeof (*coff_header), &sz) || ++ grub_add (sz, coff_header->optional_header_size, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("Error on PE sections calculation")); ++ ++ sections = (struct grub_pe32_section_table *) (sz); ++ ++ if (sections > (k_address + k_size)) ++ return grub_error (GRUB_ERR_BAD_OS, N_("Section address is invalid")); ++ ++ /* Parse the PE, remove W for code section, remove X for data sections, RO for the rest */ ++ for (i = 0, section = sections; i < coff_header->num_sections; i++, section++) ++ { ++ kernel_set_attrs = default_set_attrs; ++ kernel_clear_attrs = default_clear_attrs; ++ ++ if (nx_supported) ++ { ++ if (section->characteristics & GRUB_PE32_SCN_MEM_EXECUTE) ++ { ++ /* RX section */ ++ kernel_set_attrs &= ~GRUB_MEM_ATTR_W; ++ kernel_clear_attrs |= GRUB_MEM_ATTR_W; ++ } ++ else if (section->characteristics & GRUB_PE32_SCN_MEM_WRITE) ++ { ++ /* RW section */ ++ kernel_set_attrs &= ~GRUB_MEM_ATTR_X; ++ kernel_clear_attrs |= GRUB_MEM_ATTR_X; ++ } ++ else ++ { ++ /* RO section */ ++ kernel_set_attrs &= ~GRUB_MEM_ATTR_W & ~GRUB_MEM_ATTR_X; ++ kernel_clear_attrs |= GRUB_MEM_ATTR_X | GRUB_MEM_ATTR_W ; ++ } ++ } ++ ++ /* Make sure we are inside range */ ++ if (grub_add ((grub_addr_t) k_address, section->raw_data_offset, &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("Error on PE Executable section calculation")); ++ ++ grub_update_mem_attrs (sz, section->raw_data_size, kernel_set_attrs, kernel_clear_attrs); ++ ++ grub_get_mem_attrs (sz, 4096, &attrs); ++ grub_dprintf ("nx", "permissions for section %s 0x%"PRIxGRUB_ADDR" are %s%s%s\n", ++ section->name, ++ (grub_addr_t)sz, ++ (attrs & GRUB_MEM_ATTR_R) ? "r" : "-", ++ (attrs & GRUB_MEM_ATTR_W) ? "w" : "-", ++ (attrs & GRUB_MEM_ATTR_X) ? "x" : "-"); ++ } ++ ++ if (grub_stack_addr != (grub_addr_t)-1ll) ++ { ++ if (nx_supported) ++ { ++ stack_set_attrs &= ~GRUB_MEM_ATTR_X; ++ stack_clear_attrs |= GRUB_MEM_ATTR_X; ++ } ++ ++ grub_dprintf ("nx", "Setting attributes for stack at 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" to rw%c\n", ++ grub_stack_addr, grub_stack_addr + grub_stack_size - 1, ++ (stack_set_attrs & GRUB_MEM_ATTR_X) ? 'x' : '-'); ++ ++ grub_update_mem_attrs (grub_stack_addr, grub_stack_size, ++ stack_set_attrs, stack_clear_attrs); ++ ++ grub_get_mem_attrs (grub_stack_addr, 4096, &attrs); ++ grub_dprintf ("nx", "permissions for 0x%"PRIxGRUB_ADDR" are %s%s%s\n", ++ grub_stack_addr, ++ (attrs & GRUB_MEM_ATTR_R) ? "r" : "-", ++ (attrs & GRUB_MEM_ATTR_W) ? "w" : "-", ++ (attrs & GRUB_MEM_ATTR_X) ? "x" : "-"); ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++ ++grub_err_t ++grub_efi_linux_boot (grub_addr_t k_address, grub_size_t k_size, grub_size_t k_start, + grub_off_t h_offset, void *k_params, + int nx_supported) + { ++ grub_addr_t k_start_address = k_address + k_start; + grub_efi_loaded_image_t *loaded_image = NULL; + handover_func hf; + int offset = 0; +- grub_uint64_t stack_set_attrs = GRUB_MEM_ATTR_R | +- GRUB_MEM_ATTR_W | +- GRUB_MEM_ATTR_X; +- grub_uint64_t stack_clear_attrs = 0; +- grub_uint64_t kernel_set_attrs = stack_set_attrs; +- grub_uint64_t kernel_clear_attrs = stack_clear_attrs; +- grub_uint64_t attrs; + int nx_required = 0; +- ++ + #ifdef __x86_64__ + offset = 512; + #endif +@@ -241,47 +353,13 @@ grub_efi_linux_boot (grub_addr_t k_address, grub_size_t k_size, + if (nx_required && !nx_supported) + return grub_error (GRUB_ERR_BAD_OS, N_("kernel does not support NX loading required by policy")); + +- if (nx_supported) +- { +- kernel_set_attrs &= ~GRUB_MEM_ATTR_W; +- kernel_clear_attrs |= GRUB_MEM_ATTR_W; +- stack_set_attrs &= ~GRUB_MEM_ATTR_X; +- stack_clear_attrs |= GRUB_MEM_ATTR_X; +- } +- +- grub_dprintf ("nx", "Setting attributes for 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" to r%cx\n", +- k_address, k_address + k_size - 1, +- (kernel_set_attrs & GRUB_MEM_ATTR_W) ? 'w' : '-'); +- grub_update_mem_attrs (k_address, k_size, +- kernel_set_attrs, kernel_clear_attrs); +- +- grub_get_mem_attrs (k_address, 4096, &attrs); +- grub_dprintf ("nx", "permissions for 0x%"PRIxGRUB_ADDR" are %s%s%s\n", +- (grub_addr_t)k_address, +- (attrs & GRUB_MEM_ATTR_R) ? "r" : "-", +- (attrs & GRUB_MEM_ATTR_W) ? "w" : "-", +- (attrs & GRUB_MEM_ATTR_X) ? "x" : "-"); +- if (grub_stack_addr != (grub_addr_t)-1ll) +- { +- grub_dprintf ("nx", "Setting attributes for stack at 0x%"PRIxGRUB_ADDR"-0x%"PRIxGRUB_ADDR" to rw%c\n", +- grub_stack_addr, grub_stack_addr + grub_stack_size - 1, +- (stack_set_attrs & GRUB_MEM_ATTR_X) ? 'x' : '-'); +- grub_update_mem_attrs (grub_stack_addr, grub_stack_size, +- stack_set_attrs, stack_clear_attrs); +- +- grub_get_mem_attrs (grub_stack_addr, 4096, &attrs); +- grub_dprintf ("nx", "permissions for 0x%"PRIxGRUB_ADDR" are %s%s%s\n", +- grub_stack_addr, +- (attrs & GRUB_MEM_ATTR_R) ? "r" : "-", +- (attrs & GRUB_MEM_ATTR_W) ? "w" : "-", +- (attrs & GRUB_MEM_ATTR_X) ? "x" : "-"); +- } ++ grub_efi_mem_set_att (k_address, k_size, k_start, nx_supported); + + #if defined(__i386__) || defined(__x86_64__) + asm volatile ("cli"); + #endif + +- hf = (handover_func)((char *)k_address + h_offset + offset); ++ hf = (handover_func)((char *)k_start_address + h_offset + offset); + hf (grub_efi_image_handle, grub_efi_system_table, k_params); + + return GRUB_ERR_BUG; +@@ -451,7 +529,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args, + + grub_dprintf ("linux", "linux command line: '%s'\n", args); + +- retval = grub_efi_linux_boot (addr, size, handover_offset, ++ retval = grub_efi_linux_boot (addr, size, 0, handover_offset, + (void *)addr, nx_supported); + + /* Never reached... */ +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index abbf6b24f5..6c310d9879 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -41,6 +41,7 @@ static grub_command_t cmd_linuxefi, cmd_initrdefi; + struct grub_linuxefi_context { + void *kernel_mem; + grub_uint64_t kernel_size; ++ grub_uint64_t kernel_start; + grub_uint32_t handover_offset; + struct linux_kernel_params *params; + char *cmdline; +@@ -169,6 +170,7 @@ grub_linuxefi_boot (void *data) + + return grub_efi_linux_boot ((grub_addr_t)context->kernel_mem, + context->kernel_size, ++ context->kernel_start, + context->handover_offset, + context->params, + context->nx_supported); +@@ -527,7 +529,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + LOW_U32(kernel_mem)); + lh->code32_start = LOW_U32(kernel_mem); + +- grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); ++ grub_memcpy (kernel_mem, (char *)kernel, filelen); + + lh->type_of_loader = 0x6; + grub_dprintf ("linux", "setting lh->type_of_loader = 0x%02x\n", +@@ -544,6 +546,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + context->kernel_mem = kernel_mem; + context->kernel_size = kernel_size; ++ context->kernel_start = start; + context->handover_offset = handover_offset; + context->params = params; + context->cmdline = cmdline; +diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h +index 5b4e626c37..cd17be506a 100644 +--- a/include/grub/efi/linux.h ++++ b/include/grub/efi/linux.h +@@ -27,6 +27,7 @@ + grub_err_t + EXPORT_FUNC(grub_efi_linux_boot) (grub_addr_t kernel_address, + grub_size_t kernel_size, ++ grub_size_t kernel_start, + grub_off_t handover_offset, + void *kernel_param, int nx_enabled); + +@@ -38,4 +39,9 @@ EXPORT_FUNC(grub_efi_check_nx_image_support) (grub_addr_t kernel_addr, + grub_err_t + EXPORT_FUNC(grub_efi_check_nx_required) (int *nx_required); + ++grub_err_t ++EXPORT_FUNC(grub_efi_mem_set_att) (grub_addr_t k_address, ++ grub_size_t k_size, ++ grub_size_t k_start, int nx_supported); ++ + #endif /* ! GRUB_EFI_LINUX_HEADER */ diff --git a/0383-Include-function-name-on-debug-print-function.patch b/0383-Include-function-name-on-debug-print-function.patch new file mode 100644 index 00000000..e38ad7f3 --- /dev/null +++ b/0383-Include-function-name-on-debug-print-function.patch @@ -0,0 +1,102 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Fri, 11 Apr 2025 15:31:53 -0600 +Subject: [PATCH] Include function name on debug and error print functions + +Together with the line number, the debug log gives more context when +debugging. + +Signed-off-by: Leo Sandoval +--- + grub-core/kern/err.c | 4 ++-- + grub-core/kern/misc.c | 4 ++-- + include/grub/err.h | 6 +++--- + include/grub/misc.h | 5 +++-- + 4 files changed, 10 insertions(+), 9 deletions(-) + +diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c +index aebfe0cf83..ba04b57fb7 100644 +--- a/grub-core/kern/err.c ++++ b/grub-core/kern/err.c +@@ -38,14 +38,14 @@ static int grub_error_stack_assert; + #endif + + grub_err_t +-grub_error (grub_err_t n, const char *file, const int line, const char *fmt, ...) ++grub_error (grub_err_t n, const char *file, const char *function, const int line, const char *fmt, ...) + { + va_list ap; + int m; + + grub_errno = n; + +- m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%d:", file, line); ++ m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%s:%d:", file, function, line); + if (m < 0) + m = 0; + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 69bd655f3d..541c7bb80c 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -248,7 +248,7 @@ grub_debug_enabled (const char * condition) + } + + void +-grub_real_dprintf (const char *file, const int line, const char *condition, ++grub_real_dprintf (const char *file, const char *function, const int line, const char *condition, + const char *fmt, ...) + { + va_list args; +@@ -272,7 +272,7 @@ grub_real_dprintf (const char *file, const int line, const char *condition, + else + last_had_cr = 0; + #endif +- grub_printf ("%s:%d:%s: ", file, line, condition); ++ grub_printf ("%s:%s:%d:%s: ", file, function, line, condition); + va_start (args, fmt); + grub_vprintf (fmt, args); + va_end (args); +diff --git a/include/grub/err.h b/include/grub/err.h +index 7530f58b29..6379a6baf8 100644 +--- a/include/grub/err.h ++++ b/include/grub/err.h +@@ -88,10 +88,10 @@ struct grub_error_saved + extern grub_err_t EXPORT_VAR(grub_errno); + extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG]; + +-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...) +- __attribute__ ((format (GNU_PRINTF, 4, 5))); ++grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const char *function, const int line, const char *fmt, ...) ++ __attribute__ ((format (GNU_PRINTF, 5, 6))); + +-#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__) ++#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__) + + + void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn)); +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 0429339ef3..2b9096a0b3 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -43,7 +43,7 @@ + #define CONCAT(a, b) CONCAT_(a, b) + #endif + +-#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__) ++#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __FUNCTION__, __LINE__, condition, __VA_ARGS__) + + void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n); + char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src); +@@ -420,9 +420,10 @@ int EXPORT_FUNC(grub_puts_) (const char *s); + int EXPORT_FUNC(grub_debug_is_enabled) (void); + int EXPORT_FUNC(grub_debug_enabled) (const char *condition); + void EXPORT_FUNC(grub_real_dprintf) (const char *file, ++ const char *function, + const int line, + const char *condition, +- const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5))); ++ const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 5, 6))); + int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); + int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); + void EXPORT_FUNC(grub_qdprintf) (const char *condition, diff --git a/0384-kern-misc-Implement-grub_strtok.patch b/0384-kern-misc-Implement-grub_strtok.patch new file mode 100644 index 00000000..e9e0e1ec --- /dev/null +++ b/0384-kern-misc-Implement-grub_strtok.patch @@ -0,0 +1,109 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 12 Aug 2025 03:45:32 +0000 +Subject: [PATCH] kern/misc: Implement grub_strtok() + +Add the functions grub_strtok() and grub_strtok_r() to help parse strings into +tokens separated by characters in the "delim" parameter. These functions are +present in gnulib but calling them directly from the gnulib code is quite +challenging since the call "#include " would include the header file +grub-core/lib/posix_wrap/string.h instead of grub-core/lib/gnulib/string.h, +where strtok() and strtok_r() are declared. Since this overlap is quite +problematic, the simpler solution was to implement the code in the GRUB based +on gnulib's implementation. For more information on these functions, visit the +Linux Programmer's Manual, man strtok. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/kern/misc.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ + include/grub/misc.h | 3 +++ + 2 files changed, 65 insertions(+) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 69bd655f3d..c69fe7fb19 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -453,6 +453,68 @@ grub_strword (const char *haystack, const char *needle) + return 0; + } + ++char * ++grub_strtok_r (char *s, const char *delim, char **save_ptr) ++{ ++ char *token; ++ const char *c; ++ bool is_delim; ++ ++ if (s == NULL) ++ s = *save_ptr; ++ ++ /* Scan leading delimiters. */ ++ while (*s != '\0') ++ { ++ is_delim = false; ++ for (c = delim; *c != '\0'; c++) ++ { ++ if (*s == *c) ++ { ++ is_delim = true; ++ break; ++ } ++ } ++ if (is_delim == true) ++ s++; ++ else ++ break; ++ } ++ ++ if (*s == '\0') ++ { ++ *save_ptr = s; ++ return NULL; ++ } ++ ++ /* Find the end of the token. */ ++ token = s; ++ while (*s != '\0') ++ { ++ for (c = delim; *c != '\0'; c++) ++ { ++ if (*s == *c) ++ { ++ *s = '\0'; ++ *save_ptr = s + 1; ++ return token; ++ } ++ } ++ s++; ++ } ++ ++ *save_ptr = s; ++ return token; ++} ++ ++char * ++grub_strtok (char *s, const char *delim) ++{ ++ static char *last; ++ ++ return grub_strtok_r (s, delim, &last); ++} ++ + int + grub_isspace (int c) + { +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 0429339ef3..626f0c3535 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -134,6 +134,9 @@ char *EXPORT_FUNC(grub_strchr) (const char *s, int c); + char *EXPORT_FUNC(grub_strrchr) (const char *s, int c); + int EXPORT_FUNC(grub_strword) (const char *s, const char *w); + ++char *EXPORT_FUNC(grub_strtok_r) (char *s, const char *delim, char **save_ptr); ++char *EXPORT_FUNC(grub_strtok) (char *s, const char *delim); ++ + /* Copied from gnulib. + Written by Bruno Haible , 2005. */ + static inline char * diff --git a/0385-blsuki-Add-blscfg-command-to-parse-Boot-Loader-Speci.patch b/0385-blsuki-Add-blscfg-command-to-parse-Boot-Loader-Speci.patch new file mode 100644 index 00000000..e2bf790a --- /dev/null +++ b/0385-blsuki-Add-blscfg-command-to-parse-Boot-Loader-Speci.patch @@ -0,0 +1,1354 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 12 Aug 2025 03:45:33 +0000 +Subject: [PATCH] blsuki: Add blscfg command to parse Boot Loader Specification + snippets + +The BootLoaderSpec (BLS) defines a scheme where different bootloaders can +share a format for boot items and a configuration directory that accepts +these common configurations as drop-in files. + +The BLS Specification: https://uapi-group.org/specifications/specs/boot_loader_specification/ + +Signed-off-by: Peter Jones +Signed-off-by: Javier Martinez Canillas +Signed-off-by: Will Thompson +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + bootstrap.conf | 1 + + docs/grub.texi | 74 ++- + grub-core/Makefile.core.def | 12 + + grub-core/commands/blscfg.c | 2 +- + grub-core/commands/blsuki.c | 1028 ++++++++++++++++++++++++++++++++++++++++ + grub-core/commands/legacycfg.c | 4 +- + grub-core/commands/menuentry.c | 7 +- + grub-core/normal/main.c | 4 + + include/grub/menu.h | 14 + + include/grub/normal.h | 2 +- + 10 files changed, 1140 insertions(+), 8 deletions(-) + create mode 100644 grub-core/commands/blsuki.c + +diff --git a/bootstrap.conf b/bootstrap.conf +index 60de0597c5..799cdb1a35 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -24,6 +24,7 @@ gnulib_modules=" + argp + base64 + error ++ filevercmp + fnmatch + getdelim + getline +diff --git a/docs/grub.texi b/docs/grub.texi +index ae01e8c994..336f8e87ed 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -3275,6 +3275,7 @@ These variables have special meaning to GRUB. + + @menu + * biosnum:: ++* blsuki_save_default:: + * check_appended_signatures:: + * check_signatures:: + * chosen:: +@@ -3339,6 +3340,11 @@ this. + For an alternative approach which also changes BIOS drive mappings for the + chain-loaded system, @pxref{drivemap}. + ++@node blsuki_save_default ++@subsection blsuki_save_default ++ ++If this variable is set, menu entries generated from BLS config files ++(@pxref{blscfg}) will be set as the default boot entry when selected. + + @node check_appended_signatures + @subsection check_appended_signatures +@@ -3346,7 +3352,6 @@ chain-loaded system, @pxref{drivemap}. + This variable controls whether GRUB enforces appended signature validation on + certain loaded files. @xref{Using appended signatures}. + +- + @node check_signatures + @subsection check_signatures + +@@ -4355,6 +4360,7 @@ you forget a command, you can run the command @command{help} + * background_image:: Load background image for active terminal + * badram:: Filter out bad regions of RAM + * blocklist:: Print a block list ++* blscfg:: Load Boot Loader Specification menu entries + * boot:: Start up your operating system + * cat:: Show the contents of a file + * clear:: Clear the screen +@@ -4542,6 +4548,72 @@ Print a block list (@pxref{Block list syntax}) for @var{file}. + @end deffn + + ++@node blscfg ++@subsection blscfg ++ ++@deffn Command blscfg [@option{-p|--path} dir] [@option{-f|--enable-fallback}] [@option{-d|--show-default}] [@option{-n|--show-non-default}] [@option{-e|--entry} file] ++Load Boot Loader Specification (BLS) entries into the GRUB menu. Boot entries ++generated from @command{blscfg} won't interfere with entries from @file{grub.cfg} appearing in ++the GRUB menu. Also, entries generated from @command{blscfg} exists only in memory and ++don't update @file{grub.cfg}. ++ ++By default, the BLS entries are stored in the @file{/loader/entries} directory in the ++boot partition. If BLS entries are stored elsewhere, the @option{--path} option can be ++used to check a different directory instead of the default location. If no BLS ++entries are found while using the @option{--path} option, the @option{--enable-fallback} option ++can be used to check for entries in the default location. ++ ++The @option{--show-default} option allows the default boot entry to be added to the ++GRUB menu from the BLS entries. ++ ++The @option{--show-non-default} option allows non-default boot entries to be added to ++the GRUB menu from the BLS entries. ++ ++The @option{--entry} option allows specific boot entries to be added to the GRUB menu ++from the BLS entries. ++ ++The @option{--entry}, @option{--show-default}, and @option{--show-non-default} options ++are used to filter which BLS entries are added to the GRUB menu. If none are ++used, all entries in the default location or the location specified by @option{--path} ++will be added to the GRUB menu. ++ ++A BLS config file example: ++@example ++# /boot/loader/entries/6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf ++title Fedora 19 (Rawhide) ++sort-key fedora ++machine-id 6a9857a393724b7a981ebb5b8495b9ea ++version 3.8.0-2.fc19.x86_64 ++options root=UUID=6d3376e4-fc93-4509-95ec-a21d68011da2 quiet ++architecture x64 ++linux /6a9857a393724b7a981ebb5b8495b9ea/3.8.0-2.fc19.x86_64/linux ++initrd /6a9857a393724b7a981ebb5b8495b9ea/3.8.0-2.fc19.x86_64/initrd ++@end example ++ ++For more information on BLS entry keys as well as other information on BLS, ++see: @uref{https://uapi-group.org/specifications/specs/boot_loader_specification/, The Boot Loader Specification}. For the GRUB, there are a few additional ++BLS entry keys based on the @command{menuentry} command (@pxref{menuentry}). ++ ++The @code{grub_class} key may be used any number of times to group menu entries into ++classes. Menu themes may display different classes using different styles. ++ ++The @code{grub_users} key grants specific users access to specific menu ++entries. @xref{Security}. ++ ++The @code{grub_hotkey} key associates a hotkey with a menu entry. ++@var{key} may be a single letter, or one of the aliases @samp{backspace}, ++@samp{tab}, or @samp{delete}. ++ ++The @code{grub_args} key can be used for any other argument to be passed as positonal ++parameters when the list of commands generated from the BLS config file are ++executed. ++ ++Variable expansion using the @samp{$} character (@xref{Shell-like scripting}) may be ++used with BLS config files for the GRUB but might not be compatible with other ++bootloaders. ++@end deffn ++ ++ + @node boot + @subsection boot + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 95fd18d2dd..5e0e757344 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -884,6 +884,18 @@ module = { + enable = i386_xen_pvh; + }; + ++module = { ++ name = blsuki; ++ common = commands/blsuki.c; ++ common = lib/gnulib/filevercmp.c; ++ enable = powerpc_ieee1275; ++ enable = efi; ++ enable = i386_pc; ++ enable = emu; ++ cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; ++ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; ++}; ++ + module = { + name = boot; + common = commands/boot.c; +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 5d931b0c9b..38913d6964 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -955,7 +955,7 @@ static void create_entry (struct bls_entry *entry) + clinux, options ? " " : "", options ? options : "", + initrd ? initrd : "", dt ? dt : ""); + +- grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index, entry); ++ grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index, entry, NULL); + grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id); + + finish: +diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c +new file mode 100644 +index 0000000000..9440adb100 +--- /dev/null ++++ b/grub-core/commands/blsuki.c +@@ -0,0 +1,1028 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2025 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++#define GRUB_BLS_CONFIG_PATH "/loader/entries/" ++ ++#define BLS_EXT_LEN (sizeof (".conf") - 1) ++ ++/* ++ * It is highly unlikely to ever receive a large amount of keyval pairs. A ++ * limit of 10000 is more than enough. ++ */ ++#define BLSUKI_KEYVALS_MAX 10000 ++ ++static const struct grub_arg_option bls_opt[] = ++ { ++ {"path", 'p', 0, "Specify path to find BLS entries.", N_("DIR"), ARG_TYPE_PATHNAME}, ++ {"enable-fallback", 'f', 0, "Fallback to the default BLS path if --path fails to find BLS entries.", 0, ARG_TYPE_NONE}, ++ {"show-default", 'd', 0, "Allow the default BLS entry to be added to the GRUB menu.", 0, ARG_TYPE_NONE}, ++ {"show-non-default", 'n', 0, "Allow the non-default BLS entries to be added to the GRUB menu.", 0, ARG_TYPE_NONE}, ++ {"entry", 'e', 0, "Allow specific BLS entries to be added to the GRUB menu.", N_("FILE"), ARG_TYPE_FILE}, ++ {0, 0, 0, 0, 0, 0} ++ }; ++ ++struct keyval ++{ ++ const char *key; ++ char *val; ++}; ++ ++struct read_entry_info ++{ ++ const char *devid; ++ const char *dirname; ++ grub_file_t file; ++}; ++ ++struct find_entry_info ++{ ++ const char *dirname; ++ const char *devid; ++ grub_device_t dev; ++ grub_fs_t fs; ++}; ++ ++static grub_blsuki_entry_t *entries; ++ ++#define FOR_BLSUKI_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries) ++ ++/* ++ * This function will add a new keyval pair to a list of keyvals stored in the ++ * entry parameter. ++ */ ++static grub_err_t ++blsuki_add_keyval (grub_blsuki_entry_t *entry, char *key, char *val) ++{ ++ char *k, *v; ++ struct keyval **kvs, *kv; ++ grub_size_t size; ++ int new_n = entry->nkeyvals + 1; ++ ++ if (new_n > BLSUKI_KEYVALS_MAX) ++ return grub_error (GRUB_ERR_BAD_NUMBER, "too many keyval pairs"); ++ ++ if (entry->keyvals_size == 0) ++ { ++ size = sizeof (struct keyval *); ++ kvs = grub_malloc (size); ++ if (kvs == NULL) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate space for BLS key values"); ++ ++ entry->keyvals = kvs; ++ entry->keyvals_size = size; ++ } ++ else if (entry->keyvals_size < new_n * sizeof (struct keyval *)) ++ { ++ size = entry->keyvals_size * 2; ++ kvs = grub_realloc (entry->keyvals, size); ++ if (kvs == NULL) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't reallocate space for BLS key values"); ++ ++ entry->keyvals = kvs; ++ entry->keyvals_size = size; ++ } ++ ++ kv = grub_malloc (sizeof (struct keyval)); ++ if (kv == NULL) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't find space for new BLS key value"); ++ ++ k = grub_strdup (key); ++ if (k == NULL) ++ { ++ grub_free (kv); ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't find space for new BLS key value"); ++ } ++ ++ v = grub_strdup (val); ++ if (v == NULL) ++ { ++ grub_free (k); ++ grub_free (kv); ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't find space for new BLS key value"); ++ } ++ ++ kv->key = k; ++ kv->val = v; ++ entry->keyvals[entry->nkeyvals] = kv; ++ entry->nkeyvals = new_n; ++ ++ return GRUB_ERR_NONE; ++} ++ ++/* ++ * Find the value of the key named by keyname. If there are allowed to be ++ * more than one, pass a pointer set to -1 to the last parameter the first ++ * time, and pass the same pointer through each time after, and it'll return ++ * them in sorted order as defined in the BLS fragment file. ++ */ ++static char * ++blsuki_get_val (grub_blsuki_entry_t *entry, const char *keyname, int *last) ++{ ++ int idx, start = (last != NULL) ? (*last + 1) : 0; ++ struct keyval *kv = NULL; ++ char *ret = NULL; ++ ++ for (idx = start; idx < entry->nkeyvals; idx++) ++ { ++ kv = entry->keyvals[idx]; ++ ++ if (grub_strcmp (keyname, kv->key) == 0) ++ { ++ ret = kv->val; ++ break; ++ } ++ } ++ ++ if (last != NULL) ++ { ++ if (idx == entry->nkeyvals) ++ *last = -1; ++ else ++ *last = idx; ++ } ++ ++ return ret; ++} ++ ++/* ++ * Add a new grub_blsuki_entry_t struct to the entries list and sort it's ++ * position on the list. ++ */ ++static grub_err_t ++blsuki_add_entry (grub_blsuki_entry_t *entry) ++{ ++ grub_blsuki_entry_t *e, *last = NULL; ++ int rc; ++ ++ if (entries == NULL) ++ { ++ grub_dprintf ("blsuki", "Add entry with id \"%s\"\n", entry->filename); ++ entries = entry; ++ return GRUB_ERR_NONE; ++ } ++ ++ FOR_BLSUKI_ENTRIES (e) ++ { ++ rc = filevercmp (entry->filename, e->filename); ++ if (rc == 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("duplicate file: `%s'"), entry->filename); ++ ++ if (rc > 0) ++ { ++ grub_dprintf ("blsuki", "Add entry with id \"%s\"\n", entry->filename); ++ grub_list_push (GRUB_AS_LIST_P (&e), GRUB_AS_LIST (entry)); ++ if (entry->next == entries) ++ { ++ entries = entry; ++ entry->prev = NULL; ++ } ++ else if (last != NULL) ++ last->next = entry; ++ ++ return GRUB_ERR_NONE; ++ } ++ last = e; ++ } ++ ++ if (last != NULL) ++ { ++ grub_dprintf ("blsuki", "Add entry with id \"%s\"\n", entry->filename); ++ last->next = entry; ++ entry->prev = &last; ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++/* ++ * This function parses each line of a BLS config file to obtain the key value ++ * pairs that will be used to setup the GRUB menu entries. The key value pair ++ * will be stored in a list in the entry parameter. ++ */ ++static grub_err_t ++bls_parse_keyvals (grub_file_t f, grub_blsuki_entry_t *entry) ++{ ++ grub_err_t err = GRUB_ERR_NONE; ++ ++ for (;;) ++ { ++ char *line, *key, *val; ++ ++ line = grub_file_getline (f); ++ if (line == NULL) ++ break; ++ ++ key = grub_strtok_r (line, " \t", &val); ++ if (key == NULL) ++ { ++ grub_free (line); ++ break; ++ } ++ if (*key == '#') ++ { ++ grub_free (line); ++ continue; ++ } ++ ++ while (*val == ' ' || *val == '\t') ++ val++; ++ ++ if (*val == '\0') ++ { ++ grub_free (line); ++ break; ++ } ++ ++ err = blsuki_add_keyval (entry, key, val); ++ grub_free (line); ++ if (err != GRUB_ERR_NONE) ++ break; ++ } ++ ++ return err; ++} ++ ++/* ++ * If a file hasn't already been opened, this function opens a BLS config file ++ * and initializes entry data before parsing keyvals and adding the entry to ++ * the list of BLS entries. ++ */ ++static int ++blsuki_read_entry (const char *filename, ++ const struct grub_dirhook_info *dirhook_info __attribute__ ((__unused__)), ++ void *data) ++{ ++ grub_size_t path_len = 0, filename_len; ++ grub_err_t err; ++ char *p = NULL; ++ grub_file_t f = NULL; ++ grub_blsuki_entry_t *entry; ++ struct read_entry_info *info = (struct read_entry_info *) data; ++ ++ grub_dprintf ("blsuki", "filename: \"%s\"\n", filename); ++ ++ filename_len = grub_strlen (filename); ++ ++ if (info->file != NULL) ++ f = info->file; ++ else ++ { ++ if (filename_len < BLS_EXT_LEN || ++ grub_strcmp (filename + filename_len - BLS_EXT_LEN, ".conf") != 0) ++ return 0; ++ ++ p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname, filename); ++ ++ f = grub_file_open (p, GRUB_FILE_TYPE_CONFIG); ++ grub_free (p); ++ if (f == NULL) ++ goto finish; ++ } ++ ++ entry = grub_zalloc (sizeof (*entry)); ++ if (entry == NULL) ++ goto finish; ++ ++ /* ++ * If a file is opened before this function, the filename may have a path. ++ * Since the filename is used for the ID of the GRUB menu entry, we can ++ * remove the path. ++ */ ++ if (info->file != NULL) ++ { ++ char *slash; ++ ++ slash = grub_strrchr (filename, '/'); ++ if (slash != NULL) ++ path_len = slash - filename + 1; ++ } ++ filename_len -= path_len; ++ ++ entry->filename = grub_strndup (filename + path_len, filename_len); ++ if (entry->filename == NULL) ++ { ++ grub_free (entry); ++ goto finish; ++ } ++ ++ err = bls_parse_keyvals (f, entry); ++ ++ if (err == GRUB_ERR_NONE) ++ blsuki_add_entry (entry); ++ else ++ grub_free (entry); ++ ++ finish: ++ if (f != NULL) ++ grub_file_close (f); ++ ++ return 0; ++} ++ ++/* ++ * This function returns a list of values that had the same key in the BLS ++ * config file. The number of entries in this list is returned by the len ++ * parameter. ++ */ ++static char ** ++blsuki_make_list (grub_blsuki_entry_t *entry, const char *key, int *len) ++{ ++ int last = -1; ++ char *val; ++ int nlist = 0; ++ char **list; ++ ++ list = grub_zalloc (sizeof (char *)); ++ if (list == NULL) ++ return NULL; ++ ++ while (1) ++ { ++ char **new; ++ ++ /* ++ * Since the same key might appear more than once, the 'last' variable ++ * starts at -1 and increments to indicate the last index in the list ++ * we obtained from blsuki_get_val(). ++ */ ++ val = blsuki_get_val (entry, key, &last); ++ if (val == NULL) ++ break; ++ ++ new = grub_realloc (list, (nlist + 2) * sizeof (char *)); ++ if (new == NULL) ++ break; ++ ++ list = new; ++ list[nlist++] = val; ++ list[nlist] = NULL; ++ } ++ ++ if (nlist == 0) ++ { ++ grub_free (list); ++ return NULL; ++ } ++ ++ if (len != NULL) ++ *len = nlist; ++ ++ return list; ++} ++ ++/* ++ * This function appends a field to the end of a buffer. If the field given is ++ * an enviornmental variable, it gets the value stored for that variable and ++ * appends that to the buffer instead. ++ */ ++static char * ++blsuki_field_append (bool is_env_var, char *buffer, const char *start, const char *end) ++{ ++ char *tmp; ++ const char *field; ++ grub_size_t size = 0; ++ ++ tmp = grub_strndup (start, end - start + 1); ++ if (tmp == NULL) ++ return NULL; ++ ++ field = tmp; ++ ++ if (is_env_var == true) ++ { ++ field = grub_env_get (tmp); ++ if (field == NULL) ++ return buffer; ++ } ++ ++ if (grub_add (grub_strlen (field), 1, &size)) ++ return NULL; ++ ++ if (buffer == NULL) ++ buffer = grub_zalloc (size); ++ else ++ { ++ if (grub_add (size, grub_strlen (buffer), &size)) ++ return NULL; ++ ++ buffer = grub_realloc (buffer, size); ++ } ++ ++ if (buffer == NULL) ++ return NULL; ++ ++ tmp = buffer + grub_strlen (buffer); ++ tmp = grub_stpcpy (tmp, field); ++ ++ if (is_env_var == true) ++ tmp = grub_stpcpy (tmp, " "); ++ ++ return buffer; ++} ++ ++/* ++ * This function takes a value string, checks for environmental variables, and ++ * returns the value string with all environmental variables replaced with the ++ * value stored in the variable. ++ */ ++static char * ++blsuki_expand_val (const char *value) ++{ ++ char *buffer = NULL; ++ const char *start = value; ++ const char *end = value; ++ bool is_env_var = false; ++ ++ if (value == NULL) ++ return NULL; ++ ++ while (*value != '\0') ++ { ++ if (*value == '$') ++ { ++ if (start != end) ++ { ++ buffer = blsuki_field_append (is_env_var, buffer, start, end); ++ if (buffer == NULL) ++ return NULL; ++ } ++ ++ is_env_var = true; ++ start = value + 1; ++ } ++ else if (is_env_var == true) ++ { ++ if (grub_isalnum (*value) == 0 && *value != '_') ++ { ++ buffer = blsuki_field_append (is_env_var, buffer, start, end); ++ is_env_var = false; ++ start = value; ++ if (*start == ' ') ++ start++; ++ } ++ } ++ ++ end = value; ++ value++; ++ } ++ ++ if (start != end) ++ { ++ buffer = blsuki_field_append (is_env_var, buffer, start, end); ++ if (buffer == NULL) ++ return NULL; ++ } ++ ++ return buffer; ++} ++ ++/* ++ * This function returns a string with the command to load a linux kernel with ++ * kernel command-line options based on what was specified in the BLS config ++ * file. ++ */ ++static char * ++bls_get_linux (grub_blsuki_entry_t *entry) ++{ ++ char *linux_path; ++ char *linux_cmd = NULL; ++ char *options = NULL; ++ char *tmp; ++ grub_size_t size; ++ ++ linux_path = blsuki_get_val (entry, "linux", NULL); ++ options = blsuki_expand_val (blsuki_get_val (entry, "options", NULL)); ++ ++ if (grub_add (sizeof ("linux "), grub_strlen (linux_path), &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while calculating linux buffer size"); ++ goto finish; ++ } ++ ++ if (options != NULL) ++ { ++ if (grub_add (size, grub_strlen (options), &size) || ++ grub_add (size, 1, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while calculating linux buffer size"); ++ goto finish; ++ } ++ } ++ ++ linux_cmd = grub_malloc (size); ++ if (linux_cmd == NULL) ++ goto finish; ++ ++ tmp = linux_cmd; ++ tmp = grub_stpcpy (tmp, "linux "); ++ tmp = grub_stpcpy (tmp, linux_path); ++ if (options != NULL) ++ { ++ tmp = grub_stpcpy (tmp, " "); ++ tmp = grub_stpcpy (tmp, options); ++ } ++ ++ tmp = grub_stpcpy (tmp, "\n"); ++ ++ finish: ++ grub_free (options); ++ return linux_cmd; ++} ++ ++/* ++ * This function returns a string with the command to load all initrds for a ++ * linux kernel image based on the list provided by the BLS config file. ++ */ ++static char * ++bls_get_initrd (grub_blsuki_entry_t *entry) ++{ ++ char **initrd_list; ++ char *initrd_cmd = NULL; ++ char *tmp; ++ grub_size_t size; ++ int i; ++ ++ initrd_list = blsuki_make_list (entry, "initrd", NULL); ++ if (initrd_list != NULL) ++ { ++ size = sizeof ("initrd"); ++ ++ for (i = 0; initrd_list != NULL && initrd_list[i] != NULL; i++) ++ { ++ if (grub_add (size, 1, &size) || ++ grub_add (size, grub_strlen (initrd_list[i]), &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected calculating initrd buffer size"); ++ goto finish; ++ } ++ } ++ ++ if (grub_add (size, 1, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected calculating initrd buffer size"); ++ goto finish; ++ } ++ ++ initrd_cmd = grub_malloc (size); ++ if (initrd_cmd == NULL) ++ goto finish; ++ ++ tmp = grub_stpcpy (initrd_cmd, "initrd"); ++ for (i = 0; initrd_list != NULL && initrd_list[i] != NULL; i++) ++ { ++ grub_dprintf ("blsuki", "adding initrd %s\n", initrd_list[i]); ++ tmp = grub_stpcpy (tmp, " "); ++ tmp = grub_stpcpy (tmp, initrd_list[i]); ++ } ++ tmp = grub_stpcpy (tmp, "\n"); ++ } ++ ++ finish: ++ grub_free (initrd_list); ++ return initrd_cmd; ++} ++ ++/* ++ * This function returns a string with the command to load a device tree blob ++ * from the BLS config file. ++ */ ++static char * ++bls_get_devicetree (grub_blsuki_entry_t *entry) ++{ ++ char *dt_path; ++ char *dt_cmd = NULL; ++ char *tmp; ++ grub_size_t size; ++ ++ dt_path = blsuki_expand_val (blsuki_get_val (entry, "devicetree", NULL)); ++ if (dt_path != NULL) ++ { ++ if (grub_add (sizeof ("devicetree "), grub_strlen (dt_path), &size) || ++ grub_add (size, 1, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected calculating device tree buffer size"); ++ return NULL; ++ } ++ ++ dt_cmd = grub_malloc (size); ++ if (dt_cmd == NULL) ++ return NULL; ++ ++ tmp = dt_cmd; ++ tmp = grub_stpcpy (dt_cmd, "devicetree "); ++ tmp = grub_stpcpy (tmp, dt_path); ++ tmp = grub_stpcpy (tmp, "\n"); ++ } ++ ++ return dt_cmd; ++} ++ ++/* ++ * This function puts together all of the commands generated from the contents ++ * of the BLS config file and creates a new entry in the GRUB boot menu. ++ */ ++static void ++bls_create_entry (grub_blsuki_entry_t *entry) ++{ ++ int argc = 0; ++ const char **argv = NULL; ++ char *title = NULL; ++ char *linux_path = NULL; ++ char *linux_cmd = NULL; ++ char *initrd_cmd = NULL; ++ char *dt_cmd = NULL; ++ char *id = entry->filename; ++ grub_size_t id_len; ++ char *hotkey = NULL; ++ char *users = NULL; ++ char **classes = NULL; ++ char **args = NULL; ++ char *src = NULL; ++ int i; ++ grub_size_t size; ++ bool blsuki_save_default; ++ ++ linux_path = blsuki_get_val (entry, "linux", NULL); ++ if (linux_path == NULL) ++ { ++ grub_dprintf ("blsuki", "Skipping file %s with no 'linux' key.\n", entry->filename); ++ goto finish; ++ } ++ ++ id_len = grub_strlen (id); ++ if (id_len >= BLS_EXT_LEN && grub_strcmp (id + id_len - BLS_EXT_LEN, ".conf") == 0) ++ id[id_len - BLS_EXT_LEN] = '\0'; ++ ++ title = blsuki_get_val (entry, "title", NULL); ++ hotkey = blsuki_get_val (entry, "grub_hotkey", NULL); ++ users = blsuki_expand_val (blsuki_get_val (entry, "grub_users", NULL)); ++ classes = blsuki_make_list (entry, "grub_class", NULL); ++ args = blsuki_make_list (entry, "grub_arg", &argc); ++ ++ argc++; ++ if (grub_mul (argc + 1, sizeof (char *), &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected creating argv list")); ++ goto finish; ++ } ++ ++ argv = grub_malloc (size); ++ if (argv == NULL) ++ goto finish; ++ ++ argv[0] = (title != NULL) ? title : linux_path; ++ for (i = 1; i < argc; i++) ++ argv[i] = args[i - 1]; ++ argv[argc] = NULL; ++ ++ linux_cmd = bls_get_linux (entry); ++ if (linux_cmd == NULL) ++ goto finish; ++ ++ initrd_cmd = bls_get_initrd (entry); ++ if (grub_errno != GRUB_ERR_NONE) ++ goto finish; ++ ++ dt_cmd = bls_get_devicetree (entry); ++ if (grub_errno != GRUB_ERR_NONE) ++ goto finish; ++ ++ blsuki_save_default = grub_env_get_bool ("blsuki_save_default", false); ++ src = grub_xasprintf ("%s%s%s%s", ++ blsuki_save_default ? "savedefault\n" : "", ++ linux_cmd, initrd_cmd ? initrd_cmd : "", ++ dt_cmd ? dt_cmd : ""); ++ ++ grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, entry); ++ ++ finish: ++ grub_free (linux_cmd); ++ grub_free (dt_cmd); ++ grub_free (initrd_cmd); ++ grub_free (classes); ++ grub_free (args); ++ grub_free (argv); ++ grub_free (src); ++} ++ ++/* ++ * This function fills a find_entry_info struct passed in by the info parameter. ++ * If the dirname or devid parameters are set to NULL, the dirname and devid ++ * fields in the info parameter will be set to default values. If info already ++ * has a value in the dev fields, we can compare it to the value passed in by ++ * the devid parameter or the default devid to see if we need to open a new ++ * device. ++ */ ++static grub_err_t ++blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, const char *devid) ++{ ++ grub_device_t dev; ++ grub_fs_t fs; ++ ++ if (info == NULL) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "info parameter is not set"); ++ ++ if (devid == NULL) ++ { ++ devid = grub_env_get ("root"); ++ if (devid == NULL) ++ return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable '%s' isn't set"), "root"); ++ } ++ ++ /* Check that we aren't closing and opening the same device. */ ++ if (info->dev != NULL && grub_strcmp (info->devid, devid) != 0) ++ { ++ grub_device_close (info->dev); ++ info->dev = NULL; ++ } ++ /* If we are using the same device, then we can skip this step and only set the directory. */ ++ if (info->dev == NULL) ++ { ++ grub_dprintf ("blsuki", "opening %s\n", devid); ++ dev = grub_device_open (devid); ++ if (dev == NULL) ++ return grub_errno; ++ ++ grub_dprintf ("blsuki", "probing fs\n"); ++ fs = grub_fs_probe (dev); ++ if (fs == NULL) ++ { ++ grub_device_close (dev); ++ return grub_errno; ++ } ++ ++ info->devid = devid; ++ info->dev = dev; ++ info->fs = fs; ++ } ++ ++ info->dirname = dirname; ++ ++ return GRUB_ERR_NONE; ++} ++ ++/* ++ * This function searches for BLS config files based on the data in the info ++ * parameter. If the fallback option is enabled, the default location will be ++ * checked for BLS config files if the first attempt fails. ++ */ ++static void ++blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) ++{ ++ struct read_entry_info read_entry_info; ++ grub_fs_t dir_fs = NULL; ++ grub_device_t dir_dev = NULL; ++ bool fallback = false; ++ int r; ++ ++ do ++ { ++ read_entry_info.file = NULL; ++ read_entry_info.dirname = info->dirname; ++ ++ grub_dprintf ("blsuki", "scanning dir: %s\n", info->dirname); ++ dir_dev = info->dev; ++ dir_fs = info->fs; ++ read_entry_info.devid = info->devid; ++ ++ r = dir_fs->fs_dir (dir_dev, read_entry_info.dirname, blsuki_read_entry, ++ &read_entry_info); ++ if (r != 0) ++ { ++ grub_dprintf ("blsuki", "blsuki_read_entry returned error\n"); ++ grub_errno = GRUB_ERR_NONE; ++ } ++ ++ /* ++ * If we aren't able to find BLS entries in the directory given by info->dirname, ++ * we can fallback to the default location "/boot/loader/entries/" and see if we ++ * can find the files there. ++ */ ++ if (entries == NULL && fallback == false && enable_fallback == true) ++ { ++ blsuki_set_find_entry_info (info, GRUB_BLS_CONFIG_PATH, NULL); ++ grub_dprintf ("blsuki", "Entries weren't found in %s, fallback to %s\n", ++ read_entry_info.dirname, info->dirname); ++ fallback = true; ++ } ++ else ++ fallback = false; ++ } ++ while (fallback == true); ++} ++ ++static grub_err_t ++blsuki_load_entries (char *path, bool enable_fallback) ++{ ++ grub_size_t len; ++ static grub_err_t r; ++ const char *devid = NULL; ++ char *dir = NULL; ++ struct find_entry_info info = { ++ .dev = NULL, ++ .fs = NULL, ++ .dirname = NULL, ++ }; ++ struct read_entry_info rei = { ++ .devid = NULL, ++ .dirname = NULL, ++ }; ++ ++ if (path != NULL) ++ { ++ len = grub_strlen (path); ++ if (len >= BLS_EXT_LEN && grub_strcmp (path + len - BLS_EXT_LEN, ".conf") == 0) ++ { ++ rei.file = grub_file_open (path, GRUB_FILE_TYPE_CONFIG); ++ if (rei.file == NULL) ++ return grub_errno; ++ ++ /* blsuki_read_entry() closes the file. */ ++ return blsuki_read_entry (path, NULL, &rei); ++ } ++ else if (path[0] == '(') ++ { ++ devid = path + 1; ++ ++ dir = grub_strchr (path, ')'); ++ if (dir == NULL) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid file name `%s'"), path); ++ ++ *dir = '\0'; ++ ++ /* Check if there is more than the devid in the path. */ ++ if (dir + 1 < path + len) ++ dir = dir + 1; ++ } ++ else if (path[0] == '/') ++ dir = path; ++ } ++ ++ if (dir == NULL) ++ dir = (char *) GRUB_BLS_CONFIG_PATH; ++ ++ r = blsuki_set_find_entry_info (&info, dir, devid); ++ if (r == GRUB_ERR_NONE) ++ blsuki_find_entry (&info, enable_fallback); ++ ++ if (info.dev != NULL) ++ grub_device_close (info.dev); ++ ++ return r; ++} ++ ++static bool ++blsuki_is_default_entry (const char *def_entry, grub_blsuki_entry_t *entry, int idx) ++{ ++ const char *title; ++ const char *def_entry_end; ++ long def_idx; ++ ++ if (def_entry == NULL || *def_entry == '\0') ++ return false; ++ ++ if (grub_strcmp (def_entry, entry->filename) == 0) ++ return true; ++ ++ title = blsuki_get_val (entry, "title", NULL); ++ ++ if (title != NULL && grub_strcmp (def_entry, title) == 0) ++ return true; ++ ++ def_idx = grub_strtol (def_entry, &def_entry_end, 0); ++ if (*def_entry_end != '\0' || def_idx < 0 || def_idx > GRUB_INT_MAX) ++ return false; ++ ++ if ((int) def_idx == idx) ++ return true; ++ ++ return false; ++} ++ ++/* ++ * This function creates a GRUB boot menu entry for each BLS entry in the ++ * entries list. ++ */ ++static grub_err_t ++blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id) ++{ ++ const char *def_entry = NULL; ++ grub_blsuki_entry_t *entry = NULL; ++ int idx = 0; ++ ++ def_entry = grub_env_get ("default"); ++ ++ FOR_BLSUKI_ENTRIES(entry) ++ { ++ if (entry->visible == true) ++ { ++ idx++; ++ continue; ++ } ++ if ((show_default == true && blsuki_is_default_entry (def_entry, entry, idx) == true) || ++ (show_non_default == true && blsuki_is_default_entry (def_entry, entry, idx) == false) || ++ (entry_id != NULL && grub_strcmp (entry_id, entry->filename) == 0)) ++ { ++ bls_create_entry (entry); ++ entry->visible = true; ++ } ++ ++ idx++; ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_blscfg (grub_extcmd_context_t ctxt, int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ grub_err_t err; ++ struct grub_arg_list *state = ctxt->state; ++ char *path = NULL; ++ char *entry_id = NULL; ++ bool enable_fallback = false; ++ bool show_default = false; ++ bool show_non_default = false; ++ bool all = true; ++ entries = NULL; ++ ++ if (state[0].set) ++ path = state[0].arg; ++ if (state[1].set) ++ enable_fallback = true; ++ if (state[2].set) ++ { ++ show_default = true; ++ all = false; ++ } ++ if (state[3].set) ++ { ++ show_non_default = true; ++ all = false; ++ } ++ if (state[4].set) ++ { ++ entry_id = state[4].arg; ++ all = false; ++ } ++ if (all == true) ++ { ++ show_default = true; ++ show_non_default = true; ++ } ++ ++ err = blsuki_load_entries (path, enable_fallback); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ ++ return blsuki_create_entries (show_default, show_non_default, entry_id); ++} ++ ++static grub_extcmd_t bls_cmd; ++ ++GRUB_MOD_INIT(blsuki) ++{ ++ bls_cmd = grub_register_extcmd ("blscfg", grub_cmd_blscfg, 0, ++ N_("[-p|--path] [-f|--enable-fallback] DIR [-d|--show-default] [-n|--show-non-default] [-e|--entry] FILE"), ++ N_("Import Boot Loader Specification snippets."), ++ bls_opt); ++} ++ ++GRUB_MOD_FINI(blsuki) ++{ ++ grub_unregister_extcmd (bls_cmd); ++} +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index 86bcda6954..a5d296769e 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -143,7 +143,7 @@ legacy_file (const char *filename) + args[0] = oldname; + grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy", + NULL, NULL, +- entrysrc, 0, NULL, NULL); ++ entrysrc, 0, NULL, NULL, NULL); + grub_free (args); + entrysrc[0] = 0; + grub_free (oldname); +@@ -205,7 +205,7 @@ legacy_file (const char *filename) + args[0] = entryname; + grub_normal_add_menu_entry (1, args, NULL, NULL, NULL, + NULL, NULL, entrysrc, 0, NULL, +- NULL); ++ NULL, NULL); + grub_free (args); + } + +diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c +index b175a1b43b..d6cf329203 100644 +--- a/grub-core/commands/menuentry.c ++++ b/grub-core/commands/menuentry.c +@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args, + char **classes, const char *id, + const char *users, const char *hotkey, + const char *prefix, const char *sourcecode, +- int submenu, int *index, struct bls_entry *bls) ++ int submenu, int *index, struct bls_entry *bls, grub_blsuki_entry_t *blsuki) + { + int menu_hotkey = 0; + char **menu_args = NULL; +@@ -196,6 +196,7 @@ grub_normal_add_menu_entry (int argc, const char **args, + (*last)->sourcecode = menu_sourcecode; + (*last)->submenu = submenu; + (*last)->bls = bls; ++ (*last)->blsuki = blsuki; + + menu->size++; + if (index) +@@ -297,7 +298,7 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + ctxt->state[2].arg, 0, + ctxt->state[3].arg, + ctxt->extcmd->cmd->name[0] == 's', +- NULL, NULL); ++ NULL, NULL, NULL); + + src = args[argc - 1]; + args[argc - 1] = NULL; +@@ -315,7 +316,7 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + users, + ctxt->state[2].arg, prefix, src + 1, + ctxt->extcmd->cmd->name[0] == 's', NULL, +- NULL); ++ NULL, NULL); + + src[len - 1] = ch; + args[argc - 1] = src; +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 6f7290a897..e038ed14b8 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -75,6 +75,10 @@ grub_normal_free_menu (grub_menu_t menu) + { + entry->bls->visible = 0; + } ++ if (entry->blsuki) ++ { ++ entry->blsuki->visible = 0; ++ } + + grub_free ((void *) entry->id); + grub_free ((void *) entry->users); +diff --git a/include/grub/menu.h b/include/grub/menu.h +index 0acdc2aa6b..43a3c5809b 100644 +--- a/include/grub/menu.h ++++ b/include/grub/menu.h +@@ -20,6 +20,7 @@ + #ifndef GRUB_MENU_HEADER + #define GRUB_MENU_HEADER 1 + ++ + struct bls_entry + { + struct bls_entry *next; +@@ -30,6 +31,18 @@ struct bls_entry + int visible; + }; + ++struct grub_blsuki_entry ++{ ++ struct grub_blsuki_entry *next; ++ struct grub_blsuki_entry **prev; ++ struct keyval **keyvals; ++ grub_size_t keyvals_size; ++ int nkeyvals; ++ char *filename; ++ bool visible; ++}; ++typedef struct grub_blsuki_entry grub_blsuki_entry_t; ++ + struct grub_menu_entry_class + { + char *name; +@@ -73,6 +86,7 @@ struct grub_menu_entry + + /* BLS used to populate the entry */ + struct bls_entry *bls; ++ grub_blsuki_entry_t *blsuki; + }; + typedef struct grub_menu_entry *grub_menu_entry_t; + +diff --git a/include/grub/normal.h b/include/grub/normal.h +index 8839ad85a1..6d2b59db88 100644 +--- a/include/grub/normal.h ++++ b/include/grub/normal.h +@@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes, + const char *id, + const char *users, const char *hotkey, + const char *prefix, const char *sourcecode, +- int submenu, int *index, struct bls_entry *bls); ++ int submenu, int *index, struct bls_entry *bls, grub_blsuki_entry_t *blsuki); + + grub_err_t + grub_normal_set_password (const char *user, const char *password); diff --git a/0386-util-misc.c-Change-offset-type-for-grub_util_write_i.patch b/0386-util-misc.c-Change-offset-type-for-grub_util_write_i.patch new file mode 100644 index 00000000..f80fb5c9 --- /dev/null +++ b/0386-util-misc.c-Change-offset-type-for-grub_util_write_i.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 12 Aug 2025 03:45:34 +0000 +Subject: [PATCH] util/misc.c: Change offset type for + grub_util_write_image_at() + +Adding filevercmp support to grub-core/commands/blsuki.c from gnulib will cause +issues with the type of the offset parameter for grub_util_write_image_at() for +emu builds. To fix this issue, we can change the type from off_t to grub_off_t. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + include/grub/util/misc.h | 2 +- + util/misc.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h +index e9e0a6724a..bfce065583 100644 +--- a/include/grub/util/misc.h ++++ b/include/grub/util/misc.h +@@ -36,7 +36,7 @@ char *grub_util_read_image (const char *path); + void grub_util_load_image (const char *path, char *buf); + void grub_util_write_image (const char *img, size_t size, FILE *out, + const char *name); +-void grub_util_write_image_at (const void *img, size_t size, off_t offset, ++void grub_util_write_image_at (const void *img, size_t size, grub_off_t offset, + FILE *out, const char *name); + + char *make_system_path_relative_to_its_root (const char *path); +diff --git a/util/misc.c b/util/misc.c +index 0f928e5b49..6e16a68d9a 100644 +--- a/util/misc.c ++++ b/util/misc.c +@@ -101,7 +101,7 @@ grub_util_read_image (const char *path) + } + + void +-grub_util_write_image_at (const void *img, size_t size, off_t offset, FILE *out, ++grub_util_write_image_at (const void *img, size_t size, grub_off_t offset, FILE *out, + const char *name) + { + grub_util_info ("writing 0x%" GRUB_HOST_PRIxLONG_LONG " bytes at offset 0x%" diff --git a/0387-blsuki-Check-for-mounted-boot-in-emu.patch b/0387-blsuki-Check-for-mounted-boot-in-emu.patch new file mode 100644 index 00000000..3f207333 --- /dev/null +++ b/0387-blsuki-Check-for-mounted-boot-in-emu.patch @@ -0,0 +1,342 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robbie Harwood +Date: Tue, 12 Aug 2025 03:45:35 +0000 +Subject: [PATCH] blsuki: Check for mounted /boot in emu + +Irritatingly, BLS defines paths relative to the mountpoint of the +filesystem which contains its snippets, not / or any other fixed +location. So grub-emu needs to know whether /boot is a separate +filesystem from / and conditionally prepend a path. + +Signed-off-by: Robbie Harwood +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/Makefile.core.def | 3 ++ + grub-core/commands/blsuki.c | 83 +++++++++++++++++++++++++++++++++++++---- + grub-core/osdep/linux/getroot.c | 8 ++++ + grub-core/osdep/unix/getroot.c | 4 +- + include/grub/emu/misc.h | 2 +- + 5 files changed, 91 insertions(+), 9 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 5e0e757344..885dd436de 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -376,6 +376,9 @@ kernel = { + emu = kern/emu/cache_s.S; + emu = kern/emu/hostdisk.c; + emu = osdep/unix/hostdisk.c; ++ emu = osdep/relpath.c; ++ emu = osdep/getroot.c; ++ emu = osdep/unix/getroot.c; + emu = osdep/exec.c; + extra_dist = osdep/unix/exec.c; + emu = osdep/devmapper/hostdisk.c; +diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c +index 9440adb100..ed93a150b1 100644 +--- a/grub-core/commands/blsuki.c ++++ b/grub-core/commands/blsuki.c +@@ -32,6 +32,13 @@ + #include + #include + ++#ifdef GRUB_MACHINE_EMU ++#include ++#define GRUB_BOOT_DEVICE "/boot" ++#else ++#define GRUB_BOOT_DEVICE "" ++#endif ++ + GRUB_MOD_LICENSE ("GPLv3+"); + + #define GRUB_BLS_CONFIG_PATH "/loader/entries/" +@@ -79,6 +86,34 @@ static grub_blsuki_entry_t *entries; + + #define FOR_BLSUKI_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries) + ++/* ++ * BLS appears to make paths relative to the filesystem that snippets are ++ * on, not /. Attempt to cope. ++ */ ++static char *blsuki_update_boot_device (char *tmp) ++{ ++#ifdef GRUB_MACHINE_EMU ++ static int separate_boot = -1; ++ char *ret; ++ ++ if (separate_boot != -1) ++ goto probed; ++ ++ separate_boot = 0; ++ ++ ret = grub_make_system_path_relative_to_its_root (GRUB_BOOT_DEVICE); ++ ++ if (ret != NULL && ret[0] == '\0') ++ separate_boot = 1; ++ ++ probed: ++ if (separate_boot == 0) ++ return tmp; ++#endif ++ ++ return grub_stpcpy (tmp, GRUB_BOOT_DEVICE); ++} ++ + /* + * This function will add a new keyval pair to a list of keyvals stored in the + * entry parameter. +@@ -526,7 +561,7 @@ bls_get_linux (grub_blsuki_entry_t *entry) + linux_path = blsuki_get_val (entry, "linux", NULL); + options = blsuki_expand_val (blsuki_get_val (entry, "options", NULL)); + +- if (grub_add (sizeof ("linux "), grub_strlen (linux_path), &size)) ++ if (grub_add (sizeof ("linux " GRUB_BOOT_DEVICE), grub_strlen (linux_path), &size)) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected while calculating linux buffer size"); + goto finish; +@@ -548,6 +583,7 @@ bls_get_linux (grub_blsuki_entry_t *entry) + + tmp = linux_cmd; + tmp = grub_stpcpy (tmp, "linux "); ++ tmp = blsuki_update_boot_device (tmp); + tmp = grub_stpcpy (tmp, linux_path); + if (options != NULL) + { +@@ -582,7 +618,7 @@ bls_get_initrd (grub_blsuki_entry_t *entry) + + for (i = 0; initrd_list != NULL && initrd_list[i] != NULL; i++) + { +- if (grub_add (size, 1, &size) || ++ if (grub_add (size, sizeof (" " GRUB_BOOT_DEVICE) - 1, &size) || + grub_add (size, grub_strlen (initrd_list[i]), &size)) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected calculating initrd buffer size"); +@@ -605,6 +641,7 @@ bls_get_initrd (grub_blsuki_entry_t *entry) + { + grub_dprintf ("blsuki", "adding initrd %s\n", initrd_list[i]); + tmp = grub_stpcpy (tmp, " "); ++ tmp = blsuki_update_boot_device (tmp); + tmp = grub_stpcpy (tmp, initrd_list[i]); + } + tmp = grub_stpcpy (tmp, "\n"); +@@ -630,7 +667,7 @@ bls_get_devicetree (grub_blsuki_entry_t *entry) + dt_path = blsuki_expand_val (blsuki_get_val (entry, "devicetree", NULL)); + if (dt_path != NULL) + { +- if (grub_add (sizeof ("devicetree "), grub_strlen (dt_path), &size) || ++ if (grub_add (sizeof ("devicetree " GRUB_BOOT_DEVICE), grub_strlen (dt_path), &size) || + grub_add (size, 1, &size)) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow detected calculating device tree buffer size"); +@@ -643,6 +680,7 @@ bls_get_devicetree (grub_blsuki_entry_t *entry) + + tmp = dt_cmd; + tmp = grub_stpcpy (dt_cmd, "devicetree "); ++ tmp = blsuki_update_boot_device (tmp); + tmp = grub_stpcpy (tmp, dt_path); + tmp = grub_stpcpy (tmp, "\n"); + } +@@ -757,7 +795,11 @@ blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, c + + if (devid == NULL) + { ++#ifdef GRUB_MACHINE_EMU ++ devid = "host"; ++#else + devid = grub_env_get ("root"); ++#endif + if (devid == NULL) + return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable '%s' isn't set"), "root"); + } +@@ -799,10 +841,13 @@ blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, c + * parameter. If the fallback option is enabled, the default location will be + * checked for BLS config files if the first attempt fails. + */ +-static void ++static grub_err_t + blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) + { + struct read_entry_info read_entry_info; ++ char *default_dir = NULL; ++ char *tmp; ++ grub_size_t default_size; + grub_fs_t dir_fs = NULL; + grub_device_t dir_dev = NULL; + bool fallback = false; +@@ -833,7 +878,15 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) + */ + if (entries == NULL && fallback == false && enable_fallback == true) + { +- blsuki_set_find_entry_info (info, GRUB_BLS_CONFIG_PATH, NULL); ++ default_size = sizeof (GRUB_BOOT_DEVICE) + sizeof (GRUB_BLS_CONFIG_PATH) - 1; ++ default_dir = grub_malloc (default_size); ++ if (default_dir == NULL) ++ return grub_errno; ++ ++ tmp = blsuki_update_boot_device (default_dir); ++ tmp = grub_stpcpy (tmp, GRUB_BLS_CONFIG_PATH); ++ ++ blsuki_set_find_entry_info (info, default_dir, NULL); + grub_dprintf ("blsuki", "Entries weren't found in %s, fallback to %s\n", + read_entry_info.dirname, info->dirname); + fallback = true; +@@ -842,6 +895,9 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) + fallback = false; + } + while (fallback == true); ++ ++ grub_free (default_dir); ++ return GRUB_ERR_NONE; + } + + static grub_err_t +@@ -851,6 +907,9 @@ blsuki_load_entries (char *path, bool enable_fallback) + static grub_err_t r; + const char *devid = NULL; + char *dir = NULL; ++ char *default_dir = NULL; ++ char *tmp; ++ grub_size_t dir_size; + struct find_entry_info info = { + .dev = NULL, + .fs = NULL, +@@ -892,15 +951,25 @@ blsuki_load_entries (char *path, bool enable_fallback) + } + + if (dir == NULL) +- dir = (char *) GRUB_BLS_CONFIG_PATH; ++ { ++ dir_size = sizeof (GRUB_BOOT_DEVICE) + sizeof (GRUB_BLS_CONFIG_PATH) - 2; ++ default_dir = grub_malloc (dir_size); ++ if (default_dir == NULL) ++ return grub_errno; ++ ++ tmp = blsuki_update_boot_device (default_dir); ++ tmp = grub_stpcpy (tmp, GRUB_BLS_CONFIG_PATH); ++ dir = default_dir; ++ } + + r = blsuki_set_find_entry_info (&info, dir, devid); + if (r == GRUB_ERR_NONE) +- blsuki_find_entry (&info, enable_fallback); ++ r = blsuki_find_entry (&info, enable_fallback); + + if (info.dev != NULL) + grub_device_close (info.dev); + ++ grub_free (default_dir); + return r; + } + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 4bf386b590..8bf281c1d8 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -139,6 +139,7 @@ struct mountinfo_entry + char fstype[ESCAPED_PATH_MAX + 1], device[ESCAPED_PATH_MAX + 1]; + }; + ++#ifdef GRUB_UTIL + static char ** + grub_util_raid_getmembers (const char *name, int bootable) + { +@@ -199,6 +200,7 @@ grub_util_raid_getmembers (const char *name, int bootable) + + return devicelist; + } ++#endif + + /* Statting something on a btrfs filesystem always returns a virtual device + major/minor pair rather than the real underlying device, because btrfs +@@ -700,6 +702,7 @@ out: + return ret; + } + ++#ifdef GRUB_UTIL + static char * + get_mdadm_uuid (const char *os_dev) + { +@@ -757,6 +760,7 @@ out: + + return name; + } ++#endif + + static int + grub_util_is_imsm_or_ddf (const char *os_dev) +@@ -1096,6 +1100,7 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st, + return path; + } + ++#ifdef GRUB_UTIL + static char * + grub_util_get_raid_grub_dev (const char *os_dev) + { +@@ -1198,6 +1203,7 @@ grub_util_get_raid_grub_dev (const char *os_dev) + } + return grub_dev; + } ++#endif + + enum grub_dev_abstraction_types + grub_util_get_dev_abstraction_os (const char *os_dev) +@@ -1214,6 +1220,7 @@ grub_util_get_dev_abstraction_os (const char *os_dev) + return GRUB_DEV_ABSTRACTION_NONE; + } + ++#ifdef GRUB_UTIL + int + grub_util_pull_device_os (const char *os_dev, + enum grub_dev_abstraction_types ab) +@@ -1270,6 +1277,7 @@ grub_util_get_grub_dev_os (const char *os_dev) + + return grub_dev; + } ++#endif + + static void *mp = NULL; + static void +diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c +index ee11b02fb6..62581ba601 100644 +--- a/grub-core/osdep/unix/getroot.c ++++ b/grub-core/osdep/unix/getroot.c +@@ -16,8 +16,8 @@ + * along with GRUB. If not, see . + */ + +-#include + #include ++#include + + #include + #include +@@ -567,6 +567,7 @@ grub_guess_root_devices (const char *dir_in) + + #endif + ++#ifdef GRUB_UTIL + void + grub_util_pull_lvm_by_command (const char *os_dev) + { +@@ -663,6 +664,7 @@ out: + free (buf); + free (vgid); + } ++#endif + + /* ZFS has similar problems to those of btrfs (see above). */ + void +diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h +index f3a712a8b2..59b8038c60 100644 +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -39,7 +39,7 @@ void grub_fini_all (void); + void grub_find_zpool_from_dir (const char *dir, + char **poolname, char **poolfs); + +-char *grub_make_system_path_relative_to_its_root (const char *path) ++char *EXPORT_FUNC (grub_make_system_path_relative_to_its_root) (const char *path) + WARN_UNUSED_RESULT; + int + grub_util_device_is_mapped (const char *dev); diff --git a/0388-blsuki-Add-uki-command-to-load-Unified-Kernel-Image-.patch b/0388-blsuki-Add-uki-command-to-load-Unified-Kernel-Image-.patch new file mode 100644 index 00000000..fe91d9e4 --- /dev/null +++ b/0388-blsuki-Add-uki-command-to-load-Unified-Kernel-Image-.patch @@ -0,0 +1,822 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Tue, 12 Aug 2025 03:45:36 +0000 +Subject: [PATCH] blsuki: Add uki command to load Unified Kernel Image entries + +A Unified Kernel Image (UKI) is a single UEFI PE file that combines +a UEFI boot stub, a Linux kernel image, an initrd, and further resources. +The uki command will locate where the UKI file is and create a GRUB menu +entry to load it. + +The Unified Kernel Image Specification: https://uapi-group.org/specifications/specs/unified_kernel_image/ + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 36 +++- + grub-core/commands/blsuki.c | 476 ++++++++++++++++++++++++++++++++++++++++---- + include/grub/menu.h | 2 + + 3 files changed, 474 insertions(+), 40 deletions(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 336f8e87ed..531e847f32 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -3344,7 +3344,8 @@ chain-loaded system, @pxref{drivemap}. + @subsection blsuki_save_default + + If this variable is set, menu entries generated from BLS config files +-(@pxref{blscfg}) will be set as the default boot entry when selected. ++(@pxref{blscfg}) or UKI files (@pxref{uki}) will be set as the default boot ++entry when selected. + + @node check_appended_signatures + @subsection check_appended_signatures +@@ -4434,6 +4435,7 @@ you forget a command, you can run the command @command{help} + * true:: Do nothing, successfully + * trust:: Add public key to list of trusted keys + * trust_certificate:: Add an x509 certificate to the list of trusted certificates ++* uki:: Load Unified Kernel Image menu entries + * unset:: Unset an environment variable + @comment * vbeinfo:: List available video modes + * verify_appended:: Verify appended digital signature +@@ -6062,6 +6064,38 @@ Unset the environment variable @var{envvar}. + @end deffn + + ++@node uki ++@subsection uki ++ ++@deffn Command uki [@option{-p|--path} dir] [@option{-f|--enable-fallback}] [@option{-d|--show-default}] [@option{-n|--show-non-default}] [@option{-e|--entry} file] ++Load Unified Kernel Image (UKI) files into the GRUB menu. Boot entries ++generated from @command{uki} won't interfere with entries from @file{grub.cfg} appearing in the ++GRUB menu. Also, entries generated from @command{uki} exists only in memory and don't ++update @file{grub.cfg}. ++ ++By default, the UKI files are stored in the @file{/EFI/Linux} directory in the EFI ++system partition. If UKI files are stored elsewhere, the @option{--path} option can be ++used to check a different directory instead of the default location. If no UKI ++files are found while using the @option{--path} option, the @option{--enable-fallback} option can ++be used to check for files in the default location. ++ ++The @option{--show-default} option allows the default boot entry to be added to the ++GRUB menu from the UKI files. ++ ++The @option{--show-non-default} option allows non-default boot entries to be added to ++the GRUB menu from the UKI files. ++ ++The @option{--entry} option allows specific boot entries to be added to the GRUB menu ++from the UKI files. ++ ++The @option{--entry}, @option{--show-default}, and @option{--show-non-default} options ++are used to filter which UKI files are added to the GRUB menu. If none are ++used, all files in the default location or the location specified by @option{--path} ++will be added to the GRUB menu. ++ ++For more information on UKI, see: @uref{https://uapi-group.org/specifications/specs/unified_kernel_image/, The Unified Kernel Image Specification} ++@end deffn ++ + @ignore + @node vbeinfo + @subsection vbeinfo +diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c +index ed93a150b1..cb00f936a7 100644 +--- a/grub-core/commands/blsuki.c ++++ b/grub-core/commands/blsuki.c +@@ -32,6 +32,12 @@ + #include + #include + ++#ifdef GRUB_MACHINE_EFI ++#include ++#include ++#include ++#endif ++ + #ifdef GRUB_MACHINE_EMU + #include + #define GRUB_BOOT_DEVICE "/boot" +@@ -42,14 +48,28 @@ + GRUB_MOD_LICENSE ("GPLv3+"); + + #define GRUB_BLS_CONFIG_PATH "/loader/entries/" ++#define GRUB_UKI_CONFIG_PATH "/EFI/Linux" + + #define BLS_EXT_LEN (sizeof (".conf") - 1) ++#define UKI_EXT_LEN (sizeof (".efi") - 1) + + /* + * It is highly unlikely to ever receive a large amount of keyval pairs. A + * limit of 10000 is more than enough. + */ + #define BLSUKI_KEYVALS_MAX 10000 ++/* ++ * The only sections we read are ".cmdline" and ".osrel". The ".cmdline" ++ * section has a size limit of 4096 and it would be very unlikely for the size ++ * of the ".osrel" section to be 5 times larger than 4096. ++ */ ++#define UKI_SECTION_SIZE_MAX (5 * 4096) ++ ++enum blsuki_cmd_type ++ { ++ BLSUKI_BLS_CMD, ++ BLSUKI_UKI_CMD, ++ }; + + static const struct grub_arg_option bls_opt[] = + { +@@ -61,6 +81,18 @@ static const struct grub_arg_option bls_opt[] = + {0, 0, 0, 0, 0, 0} + }; + ++#ifdef GRUB_MACHINE_EFI ++static const struct grub_arg_option uki_opt[] = ++ { ++ {"path", 'p', 0, N_("Specify path to find UKI entries."), N_("DIR"), ARG_TYPE_PATHNAME}, ++ {"enable-fallback", 'f', 0, "Fallback to the default BLS path if --path fails to find UKI entries.", 0, ARG_TYPE_NONE}, ++ {"show-default", 'd', 0, N_("Allow the default UKI entry to be added to the GRUB menu."), 0, ARG_TYPE_NONE}, ++ {"show-non-default", 'n', 0, N_("Allow the non-default UKI entries to be added to the GRUB menu."), 0, ARG_TYPE_NONE}, ++ {"entry", 'e', 0, N_("Allow specificUKII entries to be added to the GRUB menu."), N_("FILE"), ARG_TYPE_FILE}, ++ {0, 0, 0, 0, 0, 0} ++ }; ++#endif ++ + struct keyval + { + const char *key; +@@ -71,6 +103,7 @@ struct read_entry_info + { + const char *devid; + const char *dirname; ++ enum blsuki_cmd_type cmd_type; + grub_file_t file; + }; + +@@ -82,7 +115,7 @@ struct find_entry_info + grub_fs_t fs; + }; + +-static grub_blsuki_entry_t *entries; ++static grub_blsuki_entry_t *entries = NULL; + + #define FOR_BLSUKI_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries) + +@@ -181,7 +214,7 @@ blsuki_add_keyval (grub_blsuki_entry_t *entry, char *key, char *val) + * Find the value of the key named by keyname. If there are allowed to be + * more than one, pass a pointer set to -1 to the last parameter the first + * time, and pass the same pointer through each time after, and it'll return +- * them in sorted order as defined in the BLS fragment file. ++ * them in sorted order. + */ + static char * + blsuki_get_val (grub_blsuki_entry_t *entry, const char *keyname, int *last) +@@ -310,20 +343,212 @@ bls_parse_keyvals (grub_file_t f, grub_blsuki_entry_t *entry) + return err; + } + ++#ifdef GRUB_MACHINE_EFI ++/* ++ * This function searches for the .cmdline, .osrel, and .linux sections of a ++ * UKI. We only need to store the data for the .cmdline and .osrel sections, ++ * but we also need to verify that the .linux section exists. ++ */ ++static grub_err_t ++uki_parse_keyvals (grub_file_t f, grub_blsuki_entry_t *entry) ++{ ++ struct grub_msdos_image_header *dos = NULL; ++ struct grub_pe_image_header *pe = NULL; ++ grub_off_t section_offset = 0; ++ struct grub_pe32_section_table *section = NULL; ++ struct grub_pe32_coff_header *coff_header = NULL; ++ char *val = NULL; ++ char *key = NULL; ++ const char *target[] = {".cmdline", ".osrel", ".linux", NULL}; ++ bool has_linux = false; ++ grub_err_t err = GRUB_ERR_NONE; ++ ++ dos = grub_zalloc (sizeof (*dos)); ++ if (dos == NULL) ++ return grub_errno; ++ if (grub_file_read (f, dos, sizeof (*dos)) < (grub_ssize_t) sizeof (*dos)) ++ { ++ err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read UKI image header"); ++ goto finish; ++ } ++ if (dos->msdos_magic != GRUB_DOS_MAGIC) ++ { ++ err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "plain image kernel is not supported"); ++ goto finish; ++ } ++ ++ grub_dprintf ("blsuki", "PE/COFF header @ %08x\n", dos->pe_image_header_offset); ++ pe = grub_zalloc (sizeof (*pe)); ++ if (pe == NULL) ++ { ++ err = grub_errno; ++ goto finish; ++ } ++ if (grub_file_seek (f, dos->pe_image_header_offset) == (grub_off_t) -1 || ++ grub_file_read (f, pe, sizeof (*pe)) != sizeof (*pe)) ++ { ++ err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read COFF image header"); ++ goto finish; ++ } ++ if (pe->optional_header.magic != GRUB_PE32_NATIVE_MAGIC) ++ { ++ err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "non-native image not supported"); ++ goto finish; ++ } ++ ++ coff_header = &(pe->coff_header); ++ section_offset = dos->pe_image_header_offset + sizeof (*pe); ++ ++ for (int i = 0; i < coff_header->num_sections; i++) ++ { ++ section = grub_zalloc (sizeof (*section)); ++ if (section == NULL) ++ { ++ err = grub_errno; ++ goto finish; ++ } ++ ++ if (grub_file_seek (f, section_offset) == (grub_off_t) -1 || ++ grub_file_read (f, section, sizeof (*section)) != sizeof (*section)) ++ { ++ err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read section header"); ++ goto finish; ++ } ++ ++ key = grub_strndup (section->name, 8); ++ if (key == NULL) ++ { ++ err = grub_errno; ++ goto finish; ++ } ++ ++ for (int j = 0; target[j] != NULL; j++) ++ { ++ if (grub_strcmp (key, target[j]) == 0) ++ { ++ /* ++ * We don't need to read the contents of the .linux PE section, but we ++ * should verify that the section exists. ++ */ ++ if (grub_strcmp (key, ".linux") == 0) ++ { ++ has_linux = true; ++ break; ++ } ++ ++ if (section->raw_data_size > UKI_SECTION_SIZE_MAX) ++ { ++ err = grub_error (GRUB_ERR_BAD_NUMBER, "UKI section size is larger than expected"); ++ goto finish; ++ } ++ ++ val = grub_zalloc (section->raw_data_size); ++ if (val == NULL) ++ { ++ err = grub_errno; ++ goto finish; ++ } ++ ++ if (grub_file_seek (f, section->raw_data_offset) == (grub_off_t) -1 || ++ grub_file_read (f, val, section->raw_data_size) != (grub_ssize_t) section->raw_data_size) ++ { ++ err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read section"); ++ goto finish; ++ } ++ ++ err = blsuki_add_keyval (entry, key, val); ++ if (err != GRUB_ERR_NONE) ++ goto finish; ++ ++ break; ++ } ++ } ++ ++ section_offset += sizeof (*section); ++ grub_free (section); ++ grub_free (val); ++ grub_free (key); ++ section = NULL; ++ val = NULL; ++ key = NULL; ++ } ++ ++ if (has_linux == false) ++ err = grub_error (GRUB_ERR_NO_KERNEL, "UKI is missing the '.linux' section"); ++ ++ finish: ++ grub_free (dos); ++ grub_free (pe); ++ grub_free (section); ++ grub_free (val); ++ grub_free (key); ++ return err; ++} ++ ++/* ++ * This function obtains the keyval pairs when the .osrel data is input into ++ * the osrel_ptr parameter and returns the keyval pair. Since we are using ++ * grub_strtok_r(), the osrel_ptr will be updated to the following line of ++ * osrel. This function returns NULL when it reaches the end of osrel. ++ */ ++static char * ++uki_read_osrel (char **osrel_ptr, char **val_ret) ++{ ++ char *key, *val; ++ grub_size_t val_size; ++ ++ for (;;) ++ { ++ key = grub_strtok_r (NULL, "\n\r", osrel_ptr); ++ if (key == NULL) ++ return NULL; ++ ++ /* Remove leading white space */ ++ while (*key == ' ' || *key == '\t') ++ key++; ++ ++ /* Skip commented lines */ ++ if (*key == '#') ++ continue; ++ ++ /* Split key/value */ ++ key = grub_strtok_r (key, "=", &val); ++ if (key == NULL || *val == '\0') ++ continue; ++ ++ /* Remove quotes from value */ ++ val_size = grub_strlen (val); ++ if ((*val == '\"' && val[val_size - 1] == '\"') || ++ (*val == '\'' && val[val_size - 1] == '\'')) ++ { ++ val[val_size - 1] = '\0'; ++ val++; ++ } ++ ++ *val_ret = val; ++ break; ++ } ++ ++ return key; ++} ++#endif ++ + /* + * If a file hasn't already been opened, this function opens a BLS config file +- * and initializes entry data before parsing keyvals and adding the entry to +- * the list of BLS entries. ++ * or UKI and initializes entry data before parsing keyvals and adding the entry ++ * to the list of BLS or UKI entries. + */ + static int + blsuki_read_entry (const char *filename, + const struct grub_dirhook_info *dirhook_info __attribute__ ((__unused__)), + void *data) + { +- grub_size_t path_len = 0, filename_len; +- grub_err_t err; ++ grub_size_t path_len = 0, ext_len = 0, filename_len; ++ grub_err_t err = GRUB_ERR_NONE; + char *p = NULL; ++ const char *ext = NULL; + grub_file_t f = NULL; ++ enum grub_file_type file_type = 0; + grub_blsuki_entry_t *entry; + struct read_entry_info *info = (struct read_entry_info *) data; + +@@ -331,17 +556,31 @@ blsuki_read_entry (const char *filename, + + filename_len = grub_strlen (filename); + ++ if (info->cmd_type == BLSUKI_BLS_CMD) ++ { ++ ext = ".conf"; ++ ext_len = BLS_EXT_LEN; ++ file_type = GRUB_FILE_TYPE_CONFIG; ++ } ++#ifdef GRUB_MACHINE_EFI ++ else if (info->cmd_type == BLSUKI_UKI_CMD) ++ { ++ ext = ".efi"; ++ ext_len = UKI_EXT_LEN; ++ file_type = GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE; ++ } ++#endif ++ + if (info->file != NULL) + f = info->file; + else + { +- if (filename_len < BLS_EXT_LEN || +- grub_strcmp (filename + filename_len - BLS_EXT_LEN, ".conf") != 0) ++ if (filename_len < ext_len || ++ grub_strcmp (filename + filename_len - ext_len, ext) != 0) + return 0; + + p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname, filename); +- +- f = grub_file_open (p, GRUB_FILE_TYPE_CONFIG); ++ f = grub_file_open (p, file_type); + grub_free (p); + if (f == NULL) + goto finish; +@@ -373,7 +612,26 @@ blsuki_read_entry (const char *filename, + goto finish; + } + +- err = bls_parse_keyvals (f, entry); ++ entry->dirname = grub_strdup (info->dirname); ++ if (entry->dirname == NULL) ++ { ++ grub_free (entry); ++ goto finish; ++ } ++ ++ entry->devid = grub_strdup (info->devid); ++ if (entry->devid == NULL) ++ { ++ grub_free (entry); ++ goto finish; ++ } ++ ++ if (info->cmd_type == BLSUKI_BLS_CMD) ++ err = bls_parse_keyvals (f, entry); ++#ifdef GRUB_MACHINE_EFI ++ else if (info->cmd_type == BLSUKI_UKI_CMD) ++ err = uki_parse_keyvals (f, entry); ++#endif + + if (err == GRUB_ERR_NONE) + blsuki_add_entry (entry); +@@ -389,7 +647,7 @@ blsuki_read_entry (const char *filename, + + /* + * This function returns a list of values that had the same key in the BLS +- * config file. The number of entries in this list is returned by the len ++ * config file or UKI. The number of entries in this list is returned by the len + * parameter. + */ + static char ** +@@ -764,7 +1022,7 @@ bls_create_entry (grub_blsuki_entry_t *entry) + linux_cmd, initrd_cmd ? initrd_cmd : "", + dt_cmd ? dt_cmd : ""); + +- grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, entry); ++ grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, NULL, NULL, entry); + + finish: + grub_free (linux_cmd); +@@ -776,6 +1034,70 @@ bls_create_entry (grub_blsuki_entry_t *entry) + grub_free (src); + } + ++#ifdef GRUB_MACHINE_EFI ++/* ++ * This function puts together the section data received from the UKI and ++ * generates a new entry in the GRUB boot menu. ++ */ ++static void ++uki_create_entry (grub_blsuki_entry_t *entry) ++{ ++ const char **argv = NULL; ++ char *id = entry->filename; ++ char *title = NULL; ++ char *options = NULL; ++ char *osrel, *osrel_line; ++ char *key = NULL; ++ char *value = NULL; ++ char *src = NULL; ++ bool blsuki_save_default; ++ ++ /* ++ * Although .osrel is listed as optional in the UKI specification, the .osrel ++ * section is needed to generate the GRUB menu entry title. ++ */ ++ osrel = blsuki_get_val (entry, ".osrel", NULL); ++ if (osrel == NULL) ++ { ++ grub_dprintf ("blsuki", "Skipping file %s with no '.osrel' key.\n", entry->filename); ++ goto finish; ++ } ++ ++ osrel_line = osrel; ++ while ((key = uki_read_osrel (&osrel_line, &value)) != NULL) ++ { ++ if (grub_strcmp ("PRETTY_NAME", key) == 0) ++ { ++ title = value; ++ break; ++ } ++ } ++ ++ options = blsuki_get_val (entry, ".cmdline", NULL); ++ ++ argv = grub_zalloc (2 * sizeof (char *)); ++ if (argv == NULL) ++ goto finish; ++ argv[0] = title; ++ ++ blsuki_save_default = grub_env_get_bool ("blsuki_save_default", false); ++ src = grub_xasprintf ("%schainloader (%s)%s/%s%s%s\n", ++ blsuki_save_default ? "savedefault\n" : "", ++ entry->devid, entry->dirname, ++ entry->filename, ++ (options != NULL) ? " " : "", ++ (options != NULL) ? options : ""); ++ ++ grub_normal_add_menu_entry (1, argv, NULL, id, NULL, NULL, NULL, src, 0, NULL, NULL, entry); ++ ++ finish: ++ grub_free (argv); ++ grub_free (src); ++ grub_free (options); ++ grub_free (osrel); ++} ++#endif ++ + /* + * This function fills a find_entry_info struct passed in by the info parameter. + * If the dirname or devid parameters are set to NULL, the dirname and devid +@@ -785,7 +1107,7 @@ bls_create_entry (grub_blsuki_entry_t *entry) + * device. + */ + static grub_err_t +-blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, const char *devid) ++blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, const char *devid, enum blsuki_cmd_type cmd_type) + { + grub_device_t dev; + grub_fs_t fs; +@@ -795,10 +1117,23 @@ blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, c + + if (devid == NULL) + { ++ if (cmd_type == BLSUKI_BLS_CMD) ++ { + #ifdef GRUB_MACHINE_EMU +- devid = "host"; ++ devid = "host"; + #else +- devid = grub_env_get ("root"); ++ devid = grub_env_get ("root"); ++#endif ++ } ++#ifdef GRUB_MACHINE_EFI ++ else if (cmd_type == BLSUKI_UKI_CMD) ++ { ++ grub_efi_loaded_image_t *image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ ++ if (image == NULL) ++ return grub_error (GRUB_ERR_BAD_DEVICE, N_("unable to find boot device")); ++ devid = grub_efidisk_get_device_name (image->device_handle); ++ } + #endif + if (devid == NULL) + return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable '%s' isn't set"), "root"); +@@ -837,15 +1172,16 @@ blsuki_set_find_entry_info (struct find_entry_info *info, const char *dirname, c + } + + /* +- * This function searches for BLS config files based on the data in the info +- * parameter. If the fallback option is enabled, the default location will be +- * checked for BLS config files if the first attempt fails. ++ * This function searches for BLS config files and UKIs based on the data in the ++ * info parameter. If the fallback option is enabled, the default location will ++ * be checked for BLS config files or UKIs if the first attempt fails. + */ + static grub_err_t +-blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) ++blsuki_find_entry (struct find_entry_info *info, bool enable_fallback, enum blsuki_cmd_type cmd_type) + { + struct read_entry_info read_entry_info; + char *default_dir = NULL; ++ const char *cmd_dir = NULL; + char *tmp; + grub_size_t default_size; + grub_fs_t dir_fs = NULL; +@@ -862,6 +1198,7 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) + dir_dev = info->dev; + dir_fs = info->fs; + read_entry_info.devid = info->devid; ++ read_entry_info.cmd_type = cmd_type; + + r = dir_fs->fs_dir (dir_dev, read_entry_info.dirname, blsuki_read_entry, + &read_entry_info); +@@ -874,19 +1211,27 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) + /* + * If we aren't able to find BLS entries in the directory given by info->dirname, + * we can fallback to the default location "/boot/loader/entries/" and see if we +- * can find the files there. ++ * can find the files there. If we can't find UKI entries, fallback to ++ * "/EFI/Linux" on the EFI system partition. + */ + if (entries == NULL && fallback == false && enable_fallback == true) + { +- default_size = sizeof (GRUB_BOOT_DEVICE) + sizeof (GRUB_BLS_CONFIG_PATH) - 1; ++ if (cmd_type == BLSUKI_BLS_CMD) ++ cmd_dir = GRUB_BLS_CONFIG_PATH; ++#ifdef GRUB_MACHINE_EFI ++ else if (cmd_type == BLSUKI_UKI_CMD) ++ cmd_dir = GRUB_UKI_CONFIG_PATH; ++#endif ++ ++ default_size = sizeof (GRUB_BOOT_DEVICE) + grub_strlen (cmd_dir); + default_dir = grub_malloc (default_size); + if (default_dir == NULL) + return grub_errno; + + tmp = blsuki_update_boot_device (default_dir); +- tmp = grub_stpcpy (tmp, GRUB_BLS_CONFIG_PATH); ++ tmp = grub_stpcpy (tmp, cmd_dir); + +- blsuki_set_find_entry_info (info, default_dir, NULL); ++ blsuki_set_find_entry_info (info, default_dir, NULL, cmd_type); + grub_dprintf ("blsuki", "Entries weren't found in %s, fallback to %s\n", + read_entry_info.dirname, info->dirname); + fallback = true; +@@ -901,15 +1246,17 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback) + } + + static grub_err_t +-blsuki_load_entries (char *path, bool enable_fallback) ++blsuki_load_entries (char *path, bool enable_fallback, enum blsuki_cmd_type cmd_type) + { +- grub_size_t len; ++ grub_size_t len, ext_len = 0; + static grub_err_t r; + const char *devid = NULL; + char *dir = NULL; + char *default_dir = NULL; + char *tmp; ++ const char *cmd_dir = NULL; + grub_size_t dir_size; ++ const char *ext = NULL; + struct find_entry_info info = { + .dev = NULL, + .fs = NULL, +@@ -918,12 +1265,26 @@ blsuki_load_entries (char *path, bool enable_fallback) + struct read_entry_info rei = { + .devid = NULL, + .dirname = NULL, ++ .cmd_type = cmd_type, + }; + + if (path != NULL) + { ++ if (cmd_type == BLSUKI_BLS_CMD) ++ { ++ ext = ".conf"; ++ ext_len = BLS_EXT_LEN; ++ } ++#ifdef GRUB_MACHINE_EFI ++ else if (cmd_type == BLSUKI_UKI_CMD) ++ { ++ ext = ".efi"; ++ ext_len = UKI_EXT_LEN; ++ } ++#endif ++ + len = grub_strlen (path); +- if (len >= BLS_EXT_LEN && grub_strcmp (path + len - BLS_EXT_LEN, ".conf") == 0) ++ if (len >= ext_len && grub_strcmp (path + len - ext_len, ext) == 0) + { + rei.file = grub_file_open (path, GRUB_FILE_TYPE_CONFIG); + if (rei.file == NULL) +@@ -952,19 +1313,26 @@ blsuki_load_entries (char *path, bool enable_fallback) + + if (dir == NULL) + { +- dir_size = sizeof (GRUB_BOOT_DEVICE) + sizeof (GRUB_BLS_CONFIG_PATH) - 2; ++ if (cmd_type == BLSUKI_BLS_CMD) ++ cmd_dir = GRUB_BLS_CONFIG_PATH; ++#ifdef GRUB_MACHINE_EFI ++ else if (cmd_type == BLSUKI_UKI_CMD) ++ cmd_dir = GRUB_UKI_CONFIG_PATH; ++#endif ++ ++ dir_size = sizeof (GRUB_BOOT_DEVICE) + grub_strlen (cmd_dir); + default_dir = grub_malloc (dir_size); + if (default_dir == NULL) + return grub_errno; + + tmp = blsuki_update_boot_device (default_dir); +- tmp = grub_stpcpy (tmp, GRUB_BLS_CONFIG_PATH); ++ tmp = grub_stpcpy (tmp, cmd_dir); + dir = default_dir; + } + +- r = blsuki_set_find_entry_info (&info, dir, devid); ++ r = blsuki_set_find_entry_info (&info, dir, devid, cmd_type); + if (r == GRUB_ERR_NONE) +- r = blsuki_find_entry (&info, enable_fallback); ++ r = blsuki_find_entry (&info, enable_fallback, cmd_type); + + if (info.dev != NULL) + grub_device_close (info.dev); +@@ -1002,11 +1370,11 @@ blsuki_is_default_entry (const char *def_entry, grub_blsuki_entry_t *entry, int + } + + /* +- * This function creates a GRUB boot menu entry for each BLS entry in the +- * entries list. ++ * This function creates a GRUB boot menu entry for each BLS or UKI entry in ++ * the entries list. + */ + static grub_err_t +-blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id) ++blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id, enum blsuki_cmd_type cmd_type) + { + const char *def_entry = NULL; + grub_blsuki_entry_t *entry = NULL; +@@ -1025,7 +1393,12 @@ blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id) + (show_non_default == true && blsuki_is_default_entry (def_entry, entry, idx) == false) || + (entry_id != NULL && grub_strcmp (entry_id, entry->filename) == 0)) + { +- bls_create_entry (entry); ++ if (cmd_type == BLSUKI_BLS_CMD) ++ bls_create_entry (entry); ++#ifdef GRUB_MACHINE_EFI ++ else if (cmd_type == BLSUKI_UKI_CMD) ++ uki_create_entry (entry); ++#endif + entry->visible = true; + } + +@@ -1036,8 +1409,7 @@ blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id) + } + + static grub_err_t +-grub_cmd_blscfg (grub_extcmd_context_t ctxt, int argc __attribute__ ((unused)), +- char **args __attribute__ ((unused))) ++blsuki_cmd (grub_extcmd_context_t ctxt, enum blsuki_cmd_type cmd_type) + { + grub_err_t err; + struct grub_arg_list *state = ctxt->state; +@@ -1074,24 +1446,50 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt, int argc __attribute__ ((unused)), + show_non_default = true; + } + +- err = blsuki_load_entries (path, enable_fallback); ++ err = blsuki_load_entries (path, enable_fallback, cmd_type); + if (err != GRUB_ERR_NONE) + return err; + +- return blsuki_create_entries (show_default, show_non_default, entry_id); ++ return blsuki_create_entries (show_default, show_non_default, entry_id, cmd_type); ++} ++ ++static grub_err_t ++grub_cmd_blscfg (grub_extcmd_context_t ctxt, int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ return blsuki_cmd (ctxt, BLSUKI_BLS_CMD); + } + + static grub_extcmd_t bls_cmd; + ++#ifdef GRUB_MACHINE_EFI ++static grub_err_t ++grub_cmd_uki (grub_extcmd_context_t ctxt, int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ return blsuki_cmd (ctxt, BLSUKI_UKI_CMD); ++} ++ ++static grub_extcmd_t uki_cmd; ++#endif ++ + GRUB_MOD_INIT(blsuki) + { + bls_cmd = grub_register_extcmd ("blscfg", grub_cmd_blscfg, 0, + N_("[-p|--path] [-f|--enable-fallback] DIR [-d|--show-default] [-n|--show-non-default] [-e|--entry] FILE"), + N_("Import Boot Loader Specification snippets."), + bls_opt); ++#ifdef GRUB_MACHINE_EFI ++ uki_cmd = grub_register_extcmd ("uki", grub_cmd_uki, 0, ++ N_("[-p|--path] DIR [-f|--enable-fallback] [-d|--show-default] [-n|--show-non-default] [-e|--entry] FILE"), ++ N_("Import Unified Kernel Images"), uki_opt); ++#endif + } + + GRUB_MOD_FINI(blsuki) + { + grub_unregister_extcmd (bls_cmd); ++#ifdef GRUB_MACHINE_EFI ++ grub_unregister_extcmd (uki_cmd); ++#endif + } +diff --git a/include/grub/menu.h b/include/grub/menu.h +index 43a3c5809b..0e4978dc3b 100644 +--- a/include/grub/menu.h ++++ b/include/grub/menu.h +@@ -39,6 +39,8 @@ struct grub_blsuki_entry + grub_size_t keyvals_size; + int nkeyvals; + char *filename; ++ char *dirname; ++ char *devid; + bool visible; + }; + typedef struct grub_blsuki_entry grub_blsuki_entry_t; diff --git a/0389-posix_wrap-Tweaks-in-preparation-for-libtasn1.patch b/0389-posix_wrap-Tweaks-in-preparation-for-libtasn1.patch new file mode 100644 index 00000000..d5932723 --- /dev/null +++ b/0389-posix_wrap-Tweaks-in-preparation-for-libtasn1.patch @@ -0,0 +1,168 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens +Date: Fri, 15 Nov 2024 15:34:29 +0800 +Subject: [PATCH] posix_wrap: Tweaks in preparation for libtasn1 + +Cc: Vladimir Serbinenko +Signed-off-by: Daniel Axtens +Signed-off-by: Gary Lin +Reviewed-by: Daniel Kiper +Tested-by: Stefan Berger +--- + grub-core/lib/posix_wrap/c-ctype.h | 114 +++++++++++++++++++++++++++++++++++++ + grub-core/lib/posix_wrap/string.h | 21 +++++++ + 2 files changed, 135 insertions(+) + create mode 100644 grub-core/lib/posix_wrap/c-ctype.h + +diff --git a/grub-core/lib/posix_wrap/c-ctype.h b/grub-core/lib/posix_wrap/c-ctype.h +new file mode 100644 +index 0000000000..5f8fc8ce3f +--- /dev/null ++++ b/grub-core/lib/posix_wrap/c-ctype.h +@@ -0,0 +1,114 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2024 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_POSIX_C_CTYPE_H ++#define GRUB_POSIX_C_CTYPE_H 1 ++ ++#include ++ ++static inline bool ++c_isspace (int c) ++{ ++ return !!grub_isspace (c); ++} ++ ++static inline bool ++c_isdigit (int c) ++{ ++ return !!grub_isdigit (c); ++} ++ ++static inline bool ++c_islower (int c) ++{ ++ return !!grub_islower (c); ++} ++ ++static inline bool ++c_isascii (int c) ++{ ++ return !(c & ~0x7f); ++} ++ ++static inline bool ++c_isupper (int c) ++{ ++ return !!grub_isupper (c); ++} ++ ++static inline bool ++c_isxdigit (int c) ++{ ++ return !!grub_isxdigit (c); ++} ++ ++static inline bool ++c_isprint (int c) ++{ ++ return !!grub_isprint (c); ++} ++ ++static inline bool ++c_iscntrl (int c) ++{ ++ return !grub_isprint (c); ++} ++ ++static inline bool ++c_isgraph (int c) ++{ ++ return grub_isprint (c) && !grub_isspace (c); ++} ++ ++static inline bool ++c_isalnum (int c) ++{ ++ return grub_isalpha (c) || grub_isdigit (c); ++} ++ ++static inline bool ++c_ispunct (int c) ++{ ++ return grub_isprint (c) && !grub_isspace (c) && !c_isalnum (c); ++} ++ ++static inline bool ++c_isalpha (int c) ++{ ++ return !!grub_isalpha (c); ++} ++ ++static inline bool ++c_isblank (int c) ++{ ++ return c == ' ' || c == '\t'; ++} ++ ++static inline int ++c_tolower (int c) ++{ ++ return grub_tolower (c); ++} ++ ++static inline int ++c_toupper (int c) ++{ ++ return grub_toupper (c); ++} ++ ++#endif +diff --git a/grub-core/lib/posix_wrap/string.h b/grub-core/lib/posix_wrap/string.h +index 1adb450b5a..d3e400d500 100644 +--- a/grub-core/lib/posix_wrap/string.h ++++ b/grub-core/lib/posix_wrap/string.h +@@ -84,6 +84,27 @@ memchr (const void *s, int c, grub_size_t n) + return grub_memchr (s, c, n); + } + ++static inline char * ++strncat (char *dest, const char *src, grub_size_t n) ++{ ++ const char *end; ++ char *str = dest; ++ grub_size_t src_len; ++ ++ dest += grub_strlen (dest); ++ ++ end = grub_memchr (src, '\0', n); ++ if (end != NULL) ++ src_len = (grub_size_t) (end - src); ++ else ++ src_len = n; ++ ++ dest[src_len] = '\0'; ++ grub_memcpy (dest, src, src_len); ++ ++ return str; ++} ++ + #define memcmp grub_memcmp + #define memcpy grub_memcpy + #define memmove grub_memmove diff --git a/0390-blsuki-do-not-register-blscfg-command.patch b/0390-blsuki-do-not-register-blscfg-command.patch new file mode 100644 index 00000000..3fd4fa59 --- /dev/null +++ b/0390-blsuki-do-not-register-blscfg-command.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Thu, 13 Nov 2025 11:57:52 -0600 +Subject: [PATCH] blsuki: do not register blscfg command + +The blscfg command is already defined on commands/blscfg.c so do not +register it on blsuki.c. Also, the 'uki' command is only intended for +EFI system so remove the other platforms from the module. + +Signed-off-by: Leo Sandoval +--- + grub-core/Makefile.core.def | 2 -- + grub-core/commands/blsuki.c | 4 ---- + 2 files changed, 6 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 885dd436de..a545ee430b 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -893,8 +893,6 @@ module = { + common = lib/gnulib/filevercmp.c; + enable = powerpc_ieee1275; + enable = efi; +- enable = i386_pc; +- enable = emu; + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; + }; +diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c +index cb00f936a7..bcd0114d85 100644 +--- a/grub-core/commands/blsuki.c ++++ b/grub-core/commands/blsuki.c +@@ -1475,10 +1475,6 @@ static grub_extcmd_t uki_cmd; + + GRUB_MOD_INIT(blsuki) + { +- bls_cmd = grub_register_extcmd ("blscfg", grub_cmd_blscfg, 0, +- N_("[-p|--path] [-f|--enable-fallback] DIR [-d|--show-default] [-n|--show-non-default] [-e|--entry] FILE"), +- N_("Import Boot Loader Specification snippets."), +- bls_opt); + #ifdef GRUB_MACHINE_EFI + uki_cmd = grub_register_extcmd ("uki", grub_cmd_uki, 0, + N_("[-p|--path] DIR [-f|--enable-fallback] [-d|--show-default] [-n|--show-non-default] [-e|--entry] FILE"), diff --git a/0391-misc-add-z-length-modifier-support.patch b/0391-misc-add-z-length-modifier-support.patch new file mode 100644 index 00000000..2fdcd77c --- /dev/null +++ b/0391-misc-add-z-length-modifier-support.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:32 +0800 +Subject: [PATCH] misc: add z length modifier support + +Add support for the 'z' length modifier in the printf code. This allows +printing of size_t and ssize_t values using %zu, %zd and related +formats. The parser maps 'z' to the correct integer width based on +sizeof (size_t). + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Daniel Kiper +--- + grub-core/kern/misc.c | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index c1c77c300c..2568a5489b 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -30,6 +30,7 @@ + #if DEBUG_WITH_TIMESTAMPS + #include + #endif ++#include + + union printf_arg + { +@@ -883,6 +884,9 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, + COMPILE_TIME_ASSERT (sizeof (long) <= sizeof (long long)); + COMPILE_TIME_ASSERT (sizeof (long long) == sizeof (void *) + || sizeof (int) == sizeof (void *)); ++ COMPILE_TIME_ASSERT (sizeof (size_t) == sizeof (unsigned) ++ || sizeof (size_t) == sizeof (unsigned long) ++ || sizeof (size_t) == sizeof (unsigned long long)); + + fmt = fmt0; + while ((c = *fmt++) != 0) +@@ -917,11 +921,17 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, + fmt++; + + c = *fmt++; ++ if (c == 'z') ++ { ++ c = *fmt++; ++ goto do_count; ++ } + if (c == 'l') + c = *fmt++; + if (c == 'l') + c = *fmt++; + ++ do_count: + switch (c) + { + case 'p': +@@ -1018,6 +1028,14 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, + continue; + } + ++ if (c == 'z') ++ { ++ c = *fmt++; ++ if (sizeof (size_t) == sizeof (unsigned long)) ++ longfmt = 1; ++ else if (sizeof (size_t) == sizeof (unsigned long long)) ++ longfmt = 2; ++ } + if (c == 'l') + { + c = *fmt++; +@@ -1194,6 +1212,8 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, + } + + c = *fmt++; ++ if (c == 'z') ++ c = *fmt++; + if (c == 'l') + c = *fmt++; + if (c == 'l') diff --git a/0392-tests-add-z-modifier-printf-tests.patch b/0392-tests-add-z-modifier-printf-tests.patch new file mode 100644 index 00000000..ce86dc4a --- /dev/null +++ b/0392-tests-add-z-modifier-printf-tests.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:33 +0800 +Subject: [PATCH] tests: add z modifier printf tests + +Add unit tests for %zd, %zu and %zx to verify size_t and ssize_t +formatting matches system snprintf. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Daniel Kiper +--- + tests/printf_unit_test.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/tests/printf_unit_test.c b/tests/printf_unit_test.c +index 098c29fd9c..f2de187b03 100644 +--- a/tests/printf_unit_test.c ++++ b/tests/printf_unit_test.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + + #define MSG "printf test failed: %s, %s", real, expected + +@@ -73,6 +74,15 @@ printf_test (void) + grub_snprintf (real, sizeof (real), "%%0%dd ", 1); + snprintf (expected, sizeof (expected), "%%0%dd ", 1); + grub_test_assert (strcmp (real, expected) == 0, MSG); ++ grub_snprintf (real, sizeof (real), "%zd %zd %zd", (ssize_t) -1, (ssize_t) (SIZE_MAX >> 1), (ssize_t) 42); ++ snprintf (expected, sizeof (expected), "%zd %zd %zd", (ssize_t) -1, (ssize_t) (SIZE_MAX >> 1), (ssize_t) 42); ++ grub_test_assert (strcmp (real, expected) == 0, MSG); ++ grub_snprintf (real, sizeof (real), "%zu %zu %zu", (size_t) 0, (size_t) SIZE_MAX, (size_t) 42); ++ snprintf (expected, sizeof (expected), "%zu %zu %zu", (size_t) 0, (size_t) SIZE_MAX, (size_t) 42); ++ grub_test_assert (strcmp (real, expected) == 0, MSG); ++ grub_snprintf (real, sizeof (real), "%zx %zx %zx", (ssize_t) (SIZE_MAX >> 1), (size_t) SIZE_MAX, (size_t) 0xdeadbeefU); ++ snprintf (expected, sizeof (expected), "%zx %zx %zx", (ssize_t) (SIZE_MAX >> 1), (size_t) SIZE_MAX, (size_t) 0xdeadbeefU); ++ grub_test_assert (strcmp (real, expected) == 0, MSG); + } + + GRUB_UNIT_TEST ("printf_unit_test", printf_test); diff --git a/0393-util-grub-editenv-add-fs_envblk-open-helper.patch b/0393-util-grub-editenv-add-fs_envblk-open-helper.patch new file mode 100644 index 00000000..893c4c71 --- /dev/null +++ b/0393-util-grub-editenv-add-fs_envblk-open-helper.patch @@ -0,0 +1,219 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:34 +0800 +Subject: [PATCH] util/grub-editenv: add fs_envblk open helper + +This patch adds the logic to locate and open an environment block that +is stored in a reserved area on the device. It introduces the function +fs_envblk_open() together with helper routines to read the block pointed +to by the env_block variable, and to create the block on disk when it +does not exist yet. When a block is created, the code records its +location inside the file based envblk by setting env_block in block list +syntax of offset plus size in sectors. + +The env_block variable acts as a link from the file envblk to the raw +disk region so that later runs of grub-editenv can follow it and access +the external block. The helper is exposed through a small ops table +attached to fs_envblk so that later patches can call +fs_envblk->ops->open() without touching core code again. At this stage +variables are still stored in the file envblk and no redirection has +been applied. + +In relation to this, the fs_envblk_spec table defines the file-system +specific layout of the reserved raw blocks used for environment storage. +It is prepared to facilitate integration in grub-editenv, with Btrfs to +be added in the future once its reserved area is defined. + +An fs_envblk_init() helper is added to prepare it for using the ops with +its associated data context if the feature is available. It is not used +yet, but will be used later when a filesystem and its device are probed +to initialize the fs_envblk handle and enable access to the feature. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Avnish Chouhan +--- + util/grub-editenv.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 170 insertions(+) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index 948eec8a11..a544452e78 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -123,6 +123,176 @@ block, use `rm %s'."), + NULL, help_filter, NULL + }; + ++struct fs_envblk_spec { ++ const char *fs_name; ++ off_t offset; ++ size_t size; ++}; ++typedef struct fs_envblk_spec fs_envblk_spec_t; ++ ++static grub_envblk_t fs_envblk_open (grub_envblk_t envblk); ++ ++struct fs_envblk_ops { ++ grub_envblk_t (*open) (grub_envblk_t); ++}; ++typedef struct fs_envblk_ops fs_envblk_ops_t; ++ ++struct fs_envblk { ++ fs_envblk_spec_t *spec; ++ fs_envblk_ops_t *ops; ++ const char *dev; ++}; ++typedef struct fs_envblk *fs_envblk_t; ++ ++static fs_envblk_ops_t fs_envblk_ops = { ++ .open = fs_envblk_open ++}; ++ ++/* ++ * fs_envblk_spec describes the file-system specific layout of reserved raw ++ * blocks used as environment blocks. ++ */ ++static fs_envblk_spec_t fs_envblk_spec[] = { ++ { NULL, 0, 0 } ++}; ++ ++static fs_envblk_t fs_envblk = NULL; ++ ++static void __attribute__ ((unused)) ++fs_envblk_init (const char *fs_name, const char *dev) ++{ ++ fs_envblk_spec_t *p; ++ ++ if (fs_name == NULL || dev == NULL) ++ return; ++ ++ for (p = fs_envblk_spec; p->fs_name != NULL; p++) ++ { ++ if (strcmp (fs_name, p->fs_name) == 0) ++ { ++ if (fs_envblk == NULL) ++ fs_envblk = xmalloc (sizeof (*fs_envblk)); ++ fs_envblk->spec = p; ++ fs_envblk->dev = xstrdup (dev); ++ fs_envblk->ops = &fs_envblk_ops; ++ break; ++ } ++ } ++} ++ ++static int ++read_env_block_var (const char *varname, const char *value, void *hook_data) ++{ ++ grub_envblk_t *p_envblk = (grub_envblk_t *) hook_data; ++ off_t off; ++ size_t sz; ++ char *p, *buf; ++ FILE *fp; ++ ++ if (p_envblk == NULL || fs_envblk == NULL) ++ return 1; ++ ++ if (strcmp (varname, "env_block") != 0) ++ return 0; ++ ++ off = strtol (value, &p, 10); ++ if (*p == '+') ++ sz = strtol (p + 1, &p, 10); ++ else ++ return 0; ++ ++ if (*p != '\0' || sz == 0) ++ return 0; ++ ++ off <<= GRUB_DISK_SECTOR_BITS; ++ sz <<= GRUB_DISK_SECTOR_BITS; ++ ++ fp = grub_util_fopen (fs_envblk->dev, "rb"); ++ if (fp == NULL) ++ grub_util_error (_("cannot open `%s': %s"), fs_envblk->dev, strerror (errno)); ++ ++ if (fseek (fp, off, SEEK_SET) < 0) ++ grub_util_error (_("cannot seek `%s': %s"), fs_envblk->dev, strerror (errno)); ++ ++ buf = xmalloc (sz); ++ if ((fread (buf, 1, sz, fp)) != sz) ++ grub_util_error (_("cannot read `%s': %s"), fs_envblk->dev, strerror (errno)); ++ ++ fclose (fp); ++ ++ *p_envblk = grub_envblk_open (buf, sz); ++ ++ return 1; ++} ++ ++static void ++create_env_on_block (void) ++{ ++ FILE *fp; ++ char *buf; ++ const char *device; ++ off_t offset; ++ size_t size; ++ ++ if (fs_envblk == NULL) ++ return; ++ ++ device = fs_envblk->dev; ++ offset = fs_envblk->spec->offset; ++ size = fs_envblk->spec->size; ++ ++ fp = grub_util_fopen (device, "r+b"); ++ if (fp == NULL) ++ grub_util_error (_("cannot open `%s': %s"), device, strerror (errno)); ++ ++ buf = xmalloc (size); ++ memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1); ++ memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#', size - sizeof (GRUB_ENVBLK_SIGNATURE) + 1); ++ ++ if (fseek (fp, offset, SEEK_SET) < 0) ++ grub_util_error (_("cannot seek `%s': %s"), device, strerror (errno)); ++ ++ if (fwrite (buf, 1, size, fp) != size) ++ grub_util_error (_("cannot write to `%s': %s"), device, strerror (errno)); ++ ++ grub_util_file_sync (fp); ++ free (buf); ++ fclose (fp); ++} ++ ++static grub_envblk_t ++fs_envblk_open (grub_envblk_t envblk) ++{ ++ grub_envblk_t envblk_on_block = NULL; ++ char *val; ++ off_t offset; ++ size_t size; ++ ++ if (envblk == NULL) ++ return NULL; ++ ++ offset = fs_envblk->spec->offset; ++ size = fs_envblk->spec->size; ++ ++ grub_envblk_iterate (envblk, &envblk_on_block, read_env_block_var); ++ ++ if (envblk_on_block != NULL && grub_envblk_size (envblk_on_block) == size) ++ return envblk_on_block; ++ ++ create_env_on_block (); ++ ++ offset = offset >> GRUB_DISK_SECTOR_BITS; ++ size = (size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS; ++ ++ val = xasprintf ("%lld+%zu", (long long) offset, size); ++ if (grub_envblk_set (envblk, "env_block", val) == 0) ++ grub_util_error ("%s", _("environment block too small")); ++ grub_envblk_iterate (envblk, &envblk_on_block, read_env_block_var); ++ free (val); ++ ++ return envblk_on_block; ++} ++ + static grub_envblk_t + open_envblk_file (const char *name) + { diff --git a/0394-util-grub-editenv-add-fs_envblk-write-helper.patch b/0394-util-grub-editenv-add-fs_envblk-write-helper.patch new file mode 100644 index 00000000..f94f747e --- /dev/null +++ b/0394-util-grub-editenv-add-fs_envblk-write-helper.patch @@ -0,0 +1,91 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:35 +0800 +Subject: [PATCH] util/grub-editenv: add fs_envblk write helper + +This patch adds the function fs_envblk_write to update the reserved +environment block on disk. The helper takes an in memory envblk buffer +and writes it back to the device at the location defined by the +fs_envblk specification. It performs size checks and uses file sync to +ensure that the updated data is flushed. + +The helper is also added into the fs_envblk ops table, together with the +open helper from the previous patch. With this change the basic input +and output path for an external environment block is complete. The +choice of which variables should be written externally will be handled +by later patches. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Avnish Chouhan +Reviewed-by: Daniel Kiper +--- + util/grub-editenv.c | 38 +++++++++++++++++++++++++++++++++++++- + 1 file changed, 37 insertions(+), 1 deletion(-) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index a544452e78..f4b69bb19f 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -131,9 +131,11 @@ struct fs_envblk_spec { + typedef struct fs_envblk_spec fs_envblk_spec_t; + + static grub_envblk_t fs_envblk_open (grub_envblk_t envblk); ++static void fs_envblk_write (grub_envblk_t envblk); + + struct fs_envblk_ops { + grub_envblk_t (*open) (grub_envblk_t); ++ void (*write) (grub_envblk_t); + }; + typedef struct fs_envblk_ops fs_envblk_ops_t; + +@@ -145,7 +147,8 @@ struct fs_envblk { + typedef struct fs_envblk *fs_envblk_t; + + static fs_envblk_ops_t fs_envblk_ops = { +- .open = fs_envblk_open ++ .open = fs_envblk_open, ++ .write = fs_envblk_write + }; + + /* +@@ -381,6 +384,39 @@ write_envblk (const char *name, grub_envblk_t envblk) + fclose (fp); + } + ++static void ++fs_envblk_write (grub_envblk_t envblk) ++{ ++ FILE *fp; ++ const char *device; ++ off_t offset; ++ size_t size; ++ ++ if (envblk == NULL) ++ return; ++ ++ device = fs_envblk->dev; ++ offset = fs_envblk->spec->offset; ++ size = fs_envblk->spec->size; ++ ++ if (grub_envblk_size (envblk) > size) ++ grub_util_error ("%s", _("environment block too small")); ++ ++ fp = grub_util_fopen (device, "r+b"); ++ ++ if (fp == NULL) ++ grub_util_error (_("cannot open `%s': %s"), device, strerror (errno)); ++ ++ if (fseek (fp, offset, SEEK_SET) < 0) ++ grub_util_error (_("cannot seek `%s': %s"), device, strerror (errno)); ++ ++ if (fwrite (grub_envblk_buffer (envblk), 1, grub_envblk_size (envblk), fp) != grub_envblk_size (envblk)) ++ grub_util_error (_("cannot write to `%s': %s"), device, strerror (errno)); ++ ++ grub_util_file_sync (fp); ++ fclose (fp); ++} ++ + static void + set_variables (const char *name, int argc, char *argv[]) + { diff --git a/0395-util-grub-editenv-wire-set_variables-to-optional-fs_.patch b/0395-util-grub-editenv-wire-set_variables-to-optional-fs_.patch new file mode 100644 index 00000000..bf9820a3 --- /dev/null +++ b/0395-util-grub-editenv-wire-set_variables-to-optional-fs_.patch @@ -0,0 +1,118 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:36 +0800 +Subject: [PATCH] util/grub-editenv: wire set_variables to optional fs_envblk + +This patch changes set_variables() so that it can use an external +environment block when one is present. The variable next_entry is +written into the external block, env_block is treated as read only, and +all other variables are written into the normal file based envblk. + +A cleanup step is added to handle cases where GRUB at runtime writes +variables into the external block because file based updates are not +safe on a copy on write filesystem such as Btrfs. For example, the +savedefault command can update saved_entry, and on Btrfs GRUB will place +that update in the external block instead of the file envblk. If an +older copy remains in the external block, it would override the newer +value from the file envblk when GRUB first loads the file and then +applies the external block on top of it. To avoid this, whenever a +variable is updated in the file envblk, any same named key in the +external block is deleted. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Avnish Chouhan +Reviewed-by: Daniel Kiper +--- + util/grub-editenv.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 56 insertions(+), 2 deletions(-) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index f4b69bb19f..be844bf902 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -417,12 +417,35 @@ fs_envblk_write (grub_envblk_t envblk) + fclose (fp); + } + ++struct var_lookup_ctx { ++ const char *varname; ++ bool found; ++}; ++typedef struct var_lookup_ctx var_lookup_ctx_t; ++ ++static int ++var_lookup_iter (const char *varname, const char *value __attribute__ ((unused)), void *hook_data) ++{ ++ var_lookup_ctx_t *ctx = (var_lookup_ctx_t *) hook_data; ++ ++ if (grub_strcmp (ctx->varname, varname) == 0) ++ { ++ ctx->found = true; ++ return 1; ++ } ++ return 0; ++} ++ + static void + set_variables (const char *name, int argc, char *argv[]) + { + grub_envblk_t envblk; ++ grub_envblk_t envblk_on_block = NULL; + + envblk = open_envblk_file (name); ++ if (fs_envblk != NULL) ++ envblk_on_block = fs_envblk->ops->open (envblk); ++ + while (argc) + { + char *p; +@@ -433,15 +456,46 @@ set_variables (const char *name, int argc, char *argv[]) + + *(p++) = 0; + +- if (! grub_envblk_set (envblk, argv[0], p)) +- grub_util_error ("%s", _("environment block too small")); ++ if ((strcmp (argv[0], "next_entry") == 0) && envblk_on_block != NULL) ++ { ++ if (grub_envblk_set (envblk_on_block, argv[0], p) == 0) ++ grub_util_error ("%s", _("environment block too small")); ++ goto next; ++ } + ++ if (strcmp (argv[0], "env_block") == 0) ++ { ++ grub_util_warn (_("can't set env_block as it's read-only")); ++ goto next; ++ } ++ ++ if (grub_envblk_set (envblk, argv[0], p) == 0) ++ grub_util_error ("%s", _("environment block too small")); ++ ++ if (envblk_on_block != NULL) ++ { ++ var_lookup_ctx_t ctx = { ++ .varname = argv[0], ++ .found = false ++ }; ++ ++ grub_envblk_iterate (envblk_on_block, &ctx, var_lookup_iter); ++ if (ctx.found == true) ++ grub_envblk_delete (envblk_on_block, argv[0]); ++ } ++ next: + argc--; + argv++; + } + + write_envblk (name, envblk); + grub_envblk_close (envblk); ++ ++ if (envblk_on_block != NULL) ++ { ++ fs_envblk->ops->write (envblk_on_block); ++ grub_envblk_close (envblk_on_block); ++ } + } + + static void diff --git a/0396-util-grub-editenv-wire-unset_variables-to-optional-f.patch b/0396-util-grub-editenv-wire-unset_variables-to-optional-f.patch new file mode 100644 index 00000000..4b517b39 --- /dev/null +++ b/0396-util-grub-editenv-wire-unset_variables-to-optional-f.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:37 +0800 +Subject: [PATCH] util/grub-editenv: wire unset_variables to optional fs_envblk + +This patch updates unset_variables() so that removals are also applied +to the external environment block when it is present. The code opens the +external block, deletes the same named keys there, and then writes the +external block back using fs_envblk_write(). The file based envblk is +still updated and written as before. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Avnish Chouhan +Reviewed-by: Daniel Kiper +--- + util/grub-editenv.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index be844bf902..7ff1da9b40 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -502,18 +502,32 @@ static void + unset_variables (const char *name, int argc, char *argv[]) + { + grub_envblk_t envblk; ++ grub_envblk_t envblk_on_block = NULL; + + envblk = open_envblk_file (name); ++ ++ if (fs_envblk != NULL) ++ envblk_on_block = fs_envblk->ops->open (envblk); ++ + while (argc) + { + grub_envblk_delete (envblk, argv[0]); + ++ if (envblk_on_block != NULL) ++ grub_envblk_delete (envblk_on_block, argv[0]); ++ + argc--; + argv++; + } + + write_envblk (name, envblk); + grub_envblk_close (envblk); ++ ++ if (envblk_on_block != NULL) ++ { ++ fs_envblk->ops->write (envblk_on_block); ++ grub_envblk_close (envblk_on_block); ++ } + } + + struct get_int_value_params { diff --git a/0397-util-grub-editenv-wire-list_variables-to-optional-fs.patch b/0397-util-grub-editenv-wire-list_variables-to-optional-fs.patch new file mode 100644 index 00000000..5687886d --- /dev/null +++ b/0397-util-grub-editenv-wire-list_variables-to-optional-fs.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:38 +0800 +Subject: [PATCH] util/grub-editenv: wire list_variables to optional fs_envblk + +This patch updates list_variables() so that it also prints entries from +the external environment block when one is present. The function first +lists all variables from the file based envblk, then iterates over the +external envblk and prints those as well. + +The output format remains the same as before. The change makes it +possible to inspect variables regardless of whether they are stored in +the file envblk or in the reserved block. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Avnish Chouhan +Reviewed-by: Sudhakar Kuppusamy +Reviewed-by: Daniel Kiper +--- + util/grub-editenv.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index 7ff1da9b40..170d8f139a 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -358,10 +358,17 @@ static void + list_variables (const char *name) + { + grub_envblk_t envblk; ++ grub_envblk_t envblk_on_block = NULL; + + envblk = open_envblk_file (name); ++ grub_envblk_iterate (envblk, &envblk_on_block, read_env_block_var); + grub_envblk_iterate (envblk, NULL, print_var); + grub_envblk_close (envblk); ++ if (envblk_on_block != NULL) ++ { ++ grub_envblk_iterate (envblk_on_block, NULL, print_var); ++ grub_envblk_close (envblk_on_block); ++ } + } + + static void diff --git a/0398-util-grub-editenv-add-probe-call-for-external-envblk.patch b/0398-util-grub-editenv-add-probe-call-for-external-envblk.patch new file mode 100644 index 00000000..9d583168 --- /dev/null +++ b/0398-util-grub-editenv-add-probe-call-for-external-envblk.patch @@ -0,0 +1,176 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:39 +0800 +Subject: [PATCH] util/grub-editenv: add probe call for external envblk + +This patch adds the probe_fs_envblk() function to identify the root +filesystem and invoke fs_envblk_init() with the probed filesystem type +and device. This checks if the feature is available and initializes the +handle, fs_envblk, to access the external environment block. It avoids +configurations with diskfilter or cryptodisk where filesystem blocks may +be remapped or encrypted. + +The probe is only invoked when grub-editenv is working on the default +environment file path. This restriction ensures that probing and +possible raw device access are not triggered for arbitrary user supplied +paths, but only for the standard grubenv file. In that case the code +checks if the filename equals DEFAULT_ENVBLK_PATH and then calls +probe_fs_envblk with fs_envblk_spec. The result is stored in the global +fs_envblk handle. At this stage the external environment block is only +detected and recorded, and the behavior of grub-editenv is unchanged. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Avnish Chouhan +--- + util/grub-editenv.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 113 insertions(+), 2 deletions(-) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index 170d8f139a..201dc7ccd4 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -23,8 +23,11 @@ + #include + #include + #include +-#include ++#include + #include ++#include ++#include ++#include + + #include + #include +@@ -161,7 +164,7 @@ static fs_envblk_spec_t fs_envblk_spec[] = { + + static fs_envblk_t fs_envblk = NULL; + +-static void __attribute__ ((unused)) ++static void + fs_envblk_init (const char *fs_name, const char *dev) + { + fs_envblk_spec_t *p; +@@ -582,6 +585,111 @@ incr_variables (const char *name, int argc, char *argv[]) + grub_envblk_close (envblk); + } + ++static bool ++is_abstraction (grub_device_t dev) ++{ ++ if (dev == NULL || dev->disk == NULL) ++ return false; ++ ++ if (dev->disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID || ++ dev->disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) ++ return true; ++ ++ return false; ++} ++ ++static void ++probe_fs_envblk (fs_envblk_spec_t *spec) ++{ ++ char **grub_devices = NULL; ++ char **curdev, **curdrive; ++ size_t ndev = 0; ++ char **grub_drives = NULL; ++ grub_device_t grub_dev = NULL; ++ grub_fs_t grub_fs = NULL; ++ bool have_abstraction = false; ++ ++ grub_util_biosdisk_init (DEFAULT_DEVICE_MAP); ++ grub_init_all (); ++ grub_gcry_init_all (); ++ ++ grub_lvm_fini (); ++ grub_mdraid09_fini (); ++ grub_mdraid1x_fini (); ++ grub_diskfilter_fini (); ++ grub_diskfilter_init (); ++ grub_mdraid09_init (); ++ grub_mdraid1x_init (); ++ grub_lvm_init (); ++ ++ grub_devices = grub_guess_root_devices (DEFAULT_DIRECTORY); ++ ++ if (grub_devices == NULL || grub_devices[0] == NULL) ++ { ++ grub_util_warn (_("cannot find a device for %s (is /dev mounted?)"), DEFAULT_DIRECTORY); ++ goto cleanup; ++ } ++ ++ for (curdev = grub_devices; *curdev != NULL; curdev++, ndev++) ++ grub_util_pull_device (*curdev); ++ ++ grub_drives = xcalloc ((ndev + 1), sizeof (grub_drives[0])); ++ ++ for (curdev = grub_devices, curdrive = grub_drives; *curdev != NULL; curdev++, ++ curdrive++) ++ { ++ *curdrive = grub_util_get_grub_dev (*curdev); ++ if (*curdrive == NULL) ++ { ++ grub_util_warn (_("cannot find a GRUB drive for %s. Check your device.map"), ++ *curdev); ++ goto cleanup; ++ } ++ } ++ *curdrive = NULL; ++ ++ grub_dev = grub_device_open (grub_drives[0]); ++ if (grub_dev == NULL) ++ { ++ grub_util_warn (_("cannot open device %s: %s"), grub_drives[0], grub_errmsg); ++ grub_errno = GRUB_ERR_NONE; ++ goto cleanup; ++ } ++ ++ grub_fs = grub_fs_probe (grub_dev); ++ if (grub_fs == NULL) ++ { ++ grub_util_warn (_("cannot probe fs for %s: %s"), grub_drives[0], grub_errmsg); ++ grub_errno = GRUB_ERR_NONE; ++ goto cleanup; ++ } ++ ++ have_abstraction = is_abstraction (grub_dev); ++ for (curdrive = grub_drives + 1; *curdrive != NULL && have_abstraction == false; curdrive++) ++ { ++ grub_device_t dev = grub_device_open (*curdrive); ++ ++ if (dev == NULL) ++ continue; ++ have_abstraction = is_abstraction (dev); ++ grub_device_close (dev); ++ } ++ ++ if (have_abstraction == false) ++ fs_envblk_init (grub_fs->name, grub_devices[0]); ++ ++ cleanup: ++ if (grub_devices != NULL) ++ for (curdev = grub_devices; *curdev != NULL; curdev++) ++ free (*curdev); ++ free (grub_devices); ++ free (grub_drives); ++ grub_device_close (grub_dev); ++ grub_gcry_fini_all (); ++ grub_fini_all (); ++ grub_util_biosdisk_fini (); ++} ++ + int + main (int argc, char *argv[]) + { +@@ -613,6 +721,9 @@ main (int argc, char *argv[]) + command = argv[curindex++]; + } + ++ if (strcmp (filename, DEFAULT_ENVBLK_PATH) == 0) ++ probe_fs_envblk (fs_envblk_spec); ++ + if (strcmp (command, "create") == 0) + grub_util_create_envblk_file (filename); + else if (strcmp (command, "list") == 0) diff --git a/0399-btrfs-add-environment-block-to-reserved-header-area.patch b/0399-btrfs-add-environment-block-to-reserved-header-area.patch new file mode 100644 index 00000000..dd877089 --- /dev/null +++ b/0399-btrfs-add-environment-block-to-reserved-header-area.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:40 +0800 +Subject: [PATCH] btrfs: add environment block to reserved header area + +This patch reserves space for the GRUB environment block inside the +Btrfs header. The block is placed at an offset of GRUB_ENV_BTRFS_OFFSET +, 256 KiB from the start of the device, and occupies one sector. To +protect the space, overflow guard sectors are placed before and after +the reserved block. + +The Btrfs header already defines regions for bootloader use. By adding +this entry, GRUB gains a fixed and safe location to store the +environment block without conflicting with other structures in the +header. + +Add Btrfs and its reserved area information to the fs_envblk_spec table. +With the groundworks done in previous patches, the function is now +complete and working in grub-editenv. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +--- + grub-core/fs/btrfs.c | 10 +++++++++- + include/grub/fs.h | 2 ++ + util/grub-editenv.c | 9 ++++++++- + 3 files changed, 19 insertions(+), 2 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 3228e17886..261c413e9f 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2650,11 +2650,16 @@ struct embed_region { + * https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#BOOTLOADER_SUPPORT + * The first 1 MiB on each device is unused with the exception of primary + * superblock that is on the offset 64 KiB and spans 4 KiB. ++ * ++ * Note: If this table is modified, also update ++ * util/grub-editenv.c::fs_envblk_spec, which describes the file-system ++ * specific layout of reserved raw blocks used as environment blocks so that ++ * both stay consistent. + */ + + static const struct { + struct embed_region available; +- struct embed_region used[6]; ++ struct embed_region used[9]; + } btrfs_head = { + .available = {0, GRUB_DISK_KiB_TO_SECTORS (1024)}, /* The first 1 MiB. */ + .used = { +@@ -2662,6 +2667,9 @@ static const struct { + {GRUB_DISK_KiB_TO_SECTORS (64) - 1, 1}, /* Overflow guard. */ + {GRUB_DISK_KiB_TO_SECTORS (64), GRUB_DISK_KiB_TO_SECTORS (4)}, /* 4 KiB superblock. */ + {GRUB_DISK_KiB_TO_SECTORS (68), 1}, /* Overflow guard. */ ++ {(GRUB_ENV_BTRFS_OFFSET >> GRUB_DISK_SECTOR_BITS) - 1, 1}, /* Overflow guard. */ ++ {(GRUB_ENV_BTRFS_OFFSET >> GRUB_DISK_SECTOR_BITS), 1}, /* Environment Block. */ ++ {(GRUB_ENV_BTRFS_OFFSET >> GRUB_DISK_SECTOR_BITS) + 1, 1}, /* Overflow guard. */ + {GRUB_DISK_KiB_TO_SECTORS (1024) - 1, 1}, /* Overflow guard. */ + {0, 0} /* Array terminator. */ + } +diff --git a/include/grub/fs.h b/include/grub/fs.h +index df4c93b16f..89e4d2b9bc 100644 +--- a/include/grub/fs.h ++++ b/include/grub/fs.h +@@ -132,4 +132,6 @@ grub_fs_unregister (grub_fs_t fs) + + grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device); + ++#define GRUB_ENV_BTRFS_OFFSET (256 * 1024) ++ + #endif /* ! GRUB_FS_HEADER */ +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index 201dc7ccd4..3c3f9d09f3 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -156,9 +156,16 @@ static fs_envblk_ops_t fs_envblk_ops = { + + /* + * fs_envblk_spec describes the file-system specific layout of reserved raw +- * blocks used as environment blocks. ++ * blocks used as environment blocks. At present only Btrfs is supported. Other ++ * file-systems may be added if they provide a similar facility and avoid the ++ * limitation of writing to COW. ++ * ++ * Note: If this table is modified, also update ++ * grub-core/fs/btrfs.c::btrfs_head, which defines the layout in the Btrfs ++ * header and exports GRUB_ENV_BTRFS_OFFSET, so that both stay consistent. + */ + static fs_envblk_spec_t fs_envblk_spec[] = { ++ { "btrfs", GRUB_ENV_BTRFS_OFFSET, GRUB_DISK_SECTOR_SIZE }, + { NULL, 0, 0 } + }; + diff --git a/0400-00_header.in-wire-grub.cfg-to-use-env_block-when-pre.patch b/0400-00_header.in-wire-grub.cfg-to-use-env_block-when-pre.patch new file mode 100644 index 00000000..a807bb91 --- /dev/null +++ b/0400-00_header.in-wire-grub.cfg-to-use-env_block-when-pre.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang via Grub-devel +Date: Fri, 17 Oct 2025 17:01:41 +0800 +Subject: [PATCH] 00_header.in: wire grub.cfg to use env_block when present + +This patch extends the generated grub.cfg so that it can use the +external environment block when the variable env_block is defined. +During boot, if env_block is set, grub.cfg builds a device path for it, +exports the variable, and then loads its contents in addition to the +normal grubenv file. + +When GRUB writes variables such as next_entry or saved_entry, the save +commands are changed to write into env_block if it is set, and to fall +back to the grubenv file otherwise. In this way the external environment +block is used automatically, and existing commands like savedefault or +save_env do not need to change. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Daniel Kiper +--- + util/grub.d/00_header.in | 26 +++++++++++++++++++++++--- + 1 file changed, 23 insertions(+), 3 deletions(-) + +diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in +index 3e1b77265d..a5d43929b8 100644 +--- a/util/grub.d/00_header.in ++++ b/util/grub.d/00_header.in +@@ -58,6 +58,13 @@ if [ -f \${config_directory}/grubenv ]; then + elif [ -s \$prefix/grubenv ]; then + load_env + fi ++ ++if [ "\${env_block}" ] ; then ++ set env_block="(\${root})\${env_block}" ++ export env_block ++ load_env -f "\${env_block}" ++fi ++ + EOF + if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then + cat < +Date: Fri, 17 Oct 2025 17:01:43 +0800 +Subject: [PATCH] btrfs: update doc link for bootloader support + +The old wiki link is obsolete and no longer updated, change it to the +current documentation. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Daniel Kiper +--- + grub-core/fs/btrfs.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 261c413e9f..2222c57abd 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2647,7 +2647,8 @@ struct embed_region { + }; + + /* +- * https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#BOOTLOADER_SUPPORT ++ * https://btrfs.readthedocs.io/en/latest/btrfs-man5.html#man-btrfs5-bootloader-support ++ * or invoke "man 5 btrfs" and visit the "bootloader support" subsection. + * The first 1 MiB on each device is unused with the exception of primary + * superblock that is on the offset 64 KiB and spans 4 KiB. + * diff --git a/0402-docs-add-Btrfs-env-block-and-special-env-vars.patch b/0402-docs-add-Btrfs-env-block-and-special-env-vars.patch new file mode 100644 index 00000000..11cf789d --- /dev/null +++ b/0402-docs-add-Btrfs-env-block-and-special-env-vars.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Mon, 27 Oct 2025 11:18:45 -0600 +Subject: [PATCH] docs: add Btrfs env block and special env vars + +Update grub.texi to describe the external environment block in the +reserved area of Btrfs header used for grub-reboot and savedefault, +and add a section documenting the saved_entry, next_entry, and +env_block variables. + +Signed-off-by: Michael Chang +Reviewed-by: Neal Gompa +Reviewed-by: Daniel Kiper +--- + docs/grub.texi | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 55 insertions(+) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 531e847f32..d669972337 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -3265,6 +3265,7 @@ GRUB. Others may be used freely in GRUB configuration files. + @menu + * Special environment variables:: + * Environment block:: ++* Special environment block variables:: + @end menu + + +@@ -3881,9 +3882,63 @@ For safety reasons, this storage is only available when installed on a plain + disk (no LVM or RAID), using a non-checksumming filesystem (no ZFS), and + using BIOS or EFI functions (no ATA, USB or IEEE1275). + ++On Btrfs filesystems, a reserved area in the filesystem header may be used to ++store the environment block. This static block avoids the problems of updating ++a normal file on a copy-on-write filesystem, where writing raw block is not ++stable and requires metadata update. The reserved area provides a fixed ++location that GRUB can update directly, allowing commands such as ++@command{grub-reboot} and @samp{GRUB_SAVEDEFAULT} to function correctly on ++Btrfs volumes. ++ + @command{grub2-mkconfig} uses this facility to implement + @samp{GRUB_SAVEDEFAULT} (@pxref{Simple configuration}). + ++@node Special environment block variables ++@section Special environment block variables ++ ++These special variables are usually written to the environment block ++(@pxref{Environment block}) to customize the behavior of @file{grub.cfg} ++generated by @command{grub-mkconfig}. ++ ++@menu ++* saved_entry:: ++* next_entry:: ++* env_block:: ++@end menu ++ ++@node saved_entry ++@subsection saved_entry ++ ++The @var{saved_entry} variable sets the default boot entry in @file{grub.cfg} ++created by @command{grub-mkconfig}. It can be set with ++@command{grub-set-default} to choose a default entry, or at runtime with the ++@code{savedefault} function in grub.cfg to save the current entry as the new ++default. This may require write access by GRUB. ++ ++@node next_entry ++@subsection next_entry ++ ++The @var{next_entry} variable sets the boot entry for the next boot only. After ++it is used, GRUB clears the value so it is not reused. This requires write ++access to the environment block (@pxref{Environment block}) at runtime. The ++@command{grub-reboot} command is usually used instead of changing this variable ++directly. ++ ++@node env_block ++@subsection env_block ++ ++If the filesystem is Btrfs and the disk is not an abstracted device such as ++LVM, RAID, or encryption, the reserved space in the Btrfs header can be used as ++the environment block (@pxref{Environment block}). This provides a fixed raw ++block that GRUB can reliably write to. The @var{env_block} records this ++location in GRUB blocklist syntax (@pxref{Block list syntax}) so that ++@command{grub-editenv} and @file{grub.cfg} know how to access and use the ++external raw block. ++ ++This variable is initialized when @file{grubenv} is first created by ++@command{grub-editenv} and is treated as read-only to avoid being overwritten ++with an unpredictable value. ++ + @node Modules + @chapter Modules + diff --git a/0403-kern-fs-Honour-file-read_hook-in-grub_fs_blocklist_r.patch b/0403-kern-fs-Honour-file-read_hook-in-grub_fs_blocklist_r.patch new file mode 100644 index 00000000..6aa5d83e --- /dev/null +++ b/0403-kern-fs-Honour-file-read_hook-in-grub_fs_blocklist_r.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Rasmus Villemoes +Date: Thu, 29 Aug 2024 13:01:02 +0200 +Subject: [PATCH] kern/fs: Honour file->read_hook() in grub_fs_blocklist_read() + +Unlike files accessed via a normal file system, the file->read_hook() is +not honoured when using blocklist notation. + +This means that when trying to use a dedicated, 1 KiB, raw partition +for the environment block and hence does something like + + save_env --file=(hd0,gpt9)0+2 X Y Z + +this fails with "sparse file not allowed", which is rather unexpected, +as I've explicitly said exactly which blocks should be used. Adding +a little debugging reveals that grub_file_size(file) is 1024 as expected, +but total_length is 0, simply because the callback was never invoked, so +blocklists is an empty list. + +Fix that by honouring the ->read_hook() set by the caller, also when +a "file" is specified with blocklist notation. + +Signed-off-by: Rasmus Villemoes +Reviewed-by: Vladimir Serbinenko +Reviewed-by: Daniel Kiper +--- + grub-core/kern/fs.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c +index f25bace620..9f6f4ef9da 100644 +--- a/grub-core/kern/fs.c ++++ b/grub-core/kern/fs.c +@@ -216,12 +216,15 @@ grub_fs_blocklist_read (grub_file_t file, char *buf, grub_size_t len) + grub_disk_addr_t sector; + grub_off_t offset; + grub_ssize_t ret = 0; ++ grub_disk_t disk = file->device->disk; + + if (len > file->size - file->offset) + len = file->size - file->offset; + + sector = (file->offset >> GRUB_DISK_SECTOR_BITS); + offset = (file->offset & (GRUB_DISK_SECTOR_SIZE - 1)); ++ disk->read_hook = file->read_hook; ++ disk->read_hook_data = file->read_hook_data; + for (p = file->data; p->length && len > 0; p++) + { + if (sector < p->length) +@@ -233,9 +236,12 @@ grub_fs_blocklist_read (grub_file_t file, char *buf, grub_size_t len) + >> GRUB_DISK_SECTOR_BITS) > p->length - sector) + size = ((p->length - sector) << GRUB_DISK_SECTOR_BITS) - offset; + +- if (grub_disk_read (file->device->disk, p->offset + sector, offset, ++ if (grub_disk_read (disk, p->offset + sector, offset, + size, buf) != GRUB_ERR_NONE) +- return -1; ++ { ++ ret = -1; ++ break; ++ } + + ret += size; + len -= size; +@@ -245,6 +251,8 @@ grub_fs_blocklist_read (grub_file_t file, char *buf, grub_size_t len) + else + sector -= p->length; + } ++ disk->read_hook = NULL; ++ disk->read_hook_data = NULL; + + return ret; + } diff --git a/0404-util-grub.d-00_header.in-Prefer-dev-instead-of-root-.patch b/0404-util-grub.d-00_header.in-Prefer-dev-instead-of-root-.patch new file mode 100644 index 00000000..efe9389e --- /dev/null +++ b/0404-util-grub.d-00_header.in-Prefer-dev-instead-of-root-.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Neal Gompa +Date: Wed, 26 Nov 2025 08:20:26 -0500 +Subject: [PATCH] util/grub.d/00_header.in: Prefer $dev instead of $root for + $env_block + +In UEFI environments where GRUB loads a stub grub.cfg on the EFI +System Partition (ESP) that points to the real one on the operating +system volume, the $root value is set to the ESP instead of the +operating system volume. + +This is particularly problematic for setups where the operating +system boot data is on a Btrfs volume and the external environment +block in the Btrfs bootloader space is used for grubenv data. + +Using $dev in its place resolves this problem, since the stub +grub.cfg populates this variable. Use it if it exists, and +fall back to $root accordingly. + +This is unlikely to be upstreamable, as it depends on the method +Fedora Linux and derivatives use to load the GRUB configuration. + +Signed-off-by: Neal Gompa +--- + util/grub.d/00_header.in | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in +index a5d43929b8..01f1f4144e 100644 +--- a/util/grub.d/00_header.in ++++ b/util/grub.d/00_header.in +@@ -60,7 +60,11 @@ elif [ -s \$prefix/grubenv ]; then + fi + + if [ "\${env_block}" ] ; then +- set env_block="(\${root})\${env_block}" ++ if [ "\${dev}" ]; then ++ set env_block="(\${dev})\${env_block}" ++ else ++ set env_block="(\${root})\${env_block}" ++ fi + export env_block + load_env -f "\${env_block}" + fi diff --git a/0405-grub.d-Support-the-external-environment-block-for-au.patch b/0405-grub.d-Support-the-external-environment-block-for-au.patch new file mode 100644 index 00000000..c75926a0 --- /dev/null +++ b/0405-grub.d-Support-the-external-environment-block-for-au.patch @@ -0,0 +1,89 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Neal Gompa +Date: Wed, 26 Nov 2025 08:37:57 -0500 +Subject: [PATCH] grub.d: Support the external environment block for automatic + hidden menu + +This allows the automatic hidden menu (and boot counting) mechanism +to use an external environment block if it exists and is configured +to be used. + +This is particularly important for supporting this mechanism on +systems with the operating system boot data on a Btrfs volume. + +This is unlikely to be upstreamable, as it depends on Fedora's GRUB +hidden menu and boot counting patch sets. + +Signed-off-by: Neal Gompa +--- + util/grub.d/08_fallback_counting.in | 6 +++++- + util/grub.d/10_reset_boot_success.in | 6 +++++- + util/grub.d/12_menu_auto_hide.in | 6 +++++- + util/grub.d/14_menu_show_once.in | 6 +++++- + 4 files changed, 20 insertions(+), 4 deletions(-) + +diff --git a/util/grub.d/08_fallback_counting.in b/util/grub.d/08_fallback_counting.in +index 2e2c3ff7d3..272cdb6533 100644 +--- a/util/grub.d/08_fallback_counting.in ++++ b/util/grub.d/08_fallback_counting.in +@@ -19,6 +19,10 @@ if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then + else + decrement boot_counter + fi +- save_env boot_counter ++ if [ "\${env_block}" ]; then ++ save_env -f "\${env_block}" boot_counter ++ else ++ save_env boot_counter ++ fi + fi + EOF +diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in +index e73f4137b3..ca04f9b699 100644 +--- a/util/grub.d/10_reset_boot_success.in ++++ b/util/grub.d/10_reset_boot_success.in +@@ -21,5 +21,9 @@ elif [ "\${boot_indeterminate}" = "1" ]; then + fi + # Reset boot_success for current boot + set boot_success=0 +-save_env boot_success boot_indeterminate ++if [ "\${env_block}" ]; then ++ save_env -f "\${env_block}" boot_success boot_indeterminate ++else ++ save_env boot_success boot_indeterminate ++fi + EOF +diff --git a/util/grub.d/12_menu_auto_hide.in b/util/grub.d/12_menu_auto_hide.in +index 6a7c0fa0d4..c2c207232e 100644 +--- a/util/grub.d/12_menu_auto_hide.in ++++ b/util/grub.d/12_menu_auto_hide.in +@@ -16,7 +16,11 @@ cat << EOF + if [ x\$feature_timeout_style = xy ] ; then + if [ "\${menu_show_once}" ]; then + unset menu_show_once +- save_env menu_show_once ++ if [ "\${env_block}" ]; then ++ save_env -f "\${env_block}" menu_show_once ++ else ++ save_env menu_show_once ++ fi + set timeout_style=menu + set timeout=60 + elif [ "\${menu_auto_hide}" -a "\${menu_hide_ok}" = "1" ]; then +diff --git a/util/grub.d/14_menu_show_once.in b/util/grub.d/14_menu_show_once.in +index 1cd7f36142..41b37b5ec7 100755 +--- a/util/grub.d/14_menu_show_once.in ++++ b/util/grub.d/14_menu_show_once.in +@@ -7,7 +7,11 @@ if [ x\$feature_timeout_style = xy ]; then + set timeout_style=menu + set timeout="\${menu_show_once_timeout}" + unset menu_show_once_timeout +- save_env menu_show_once_timeout ++ if [ "\${env_block}" ]; then ++ save_env -f "\${env_block}" menu_show_once_timeout ++ else ++ save_env menu_show_once_timeout ++ fi + fi + fi + EOF diff --git a/0406-grub-editenv-Make-automatic-hidden-menu-and-boot-cou.patch b/0406-grub-editenv-Make-automatic-hidden-menu-and-boot-cou.patch new file mode 100644 index 00000000..92b053bf --- /dev/null +++ b/0406-grub-editenv-Make-automatic-hidden-menu-and-boot-cou.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Neal Gompa +Date: Wed, 26 Nov 2025 08:48:10 -0500 +Subject: [PATCH] grub-editenv: Make automatic hidden menu and boot counting + use envblk when available + +This ensures the automatic hidden menu and boot counting settings +are set in the right place when an external environment block is used. + +This is unlikely to be upstreamable, as it depends on Fedora's GRUB +hidden menu and boot counting patch sets. + +Signed-off-by: Neal Gompa +--- + util/grub-editenv.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index 3c3f9d09f3..48611e4e17 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -473,7 +473,13 @@ set_variables (const char *name, int argc, char *argv[]) + + *(p++) = 0; + +- if ((strcmp (argv[0], "next_entry") == 0) && envblk_on_block != NULL) ++ if (((strcmp (argv[0], "next_entry") == 0) || ++ (strcmp (argv[0], "boot_counter") == 0) || ++ (strcmp (argv[0], "boot_indeterminate") == 0) || ++ (strcmp (argv[0], "boot_success") == 0) || ++ (strcmp (argv[0], "menu_show_once") == 0) || ++ (strcmp (argv[0], "menu_show_once_timeout") == 0)) ++ && envblk_on_block != NULL) + { + if (grub_envblk_set (envblk_on_block, argv[0], p) == 0) + grub_util_error ("%s", _("environment block too small")); diff --git a/0407-Increase-EFI-max-allocation-to-max-usable-address.patch b/0407-Increase-EFI-max-allocation-to-max-usable-address.patch new file mode 100644 index 00000000..a1297e44 --- /dev/null +++ b/0407-Increase-EFI-max-allocation-to-max-usable-address.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leo Sandoval +Date: Fri, 28 Nov 2025 11:30:19 -0600 +Subject: [PATCH] Increase EFI max allocation to max usable address + +Signed-off-by: Leo Sandoval +--- + include/grub/x86_64/efi/memory.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h +index e81cfb3221..547e3f82f8 100644 +--- a/include/grub/x86_64/efi/memory.h ++++ b/include/grub/x86_64/efi/memory.h +@@ -3,7 +3,7 @@ + + #if defined (__code_model_large__) + #define GRUB_EFI_MAX_USABLE_ADDRESS __UINTPTR_MAX__ +-#define GRUB_EFI_MAX_ALLOCATION_ADDRESS 0x7fffffff ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + #else + #define GRUB_EFI_MAX_USABLE_ADDRESS 0x7fffffff + #define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS diff --git a/20-grub.install b/20-grub.install index 2a0ac323..e402a4ce 100755 --- a/20-grub.install +++ b/20-grub.install @@ -19,6 +19,9 @@ MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID # If ${BOOT_DIR_ABS} exists, some other boot loader is active. [[ -d "${BOOT_DIR_ABS}" ]] && exit 0 +# UKIs are BLS type 2 entries, 90-uki-copy.install takes care of them +[ "x$KERNEL_INSTALL_LAYOUT" != "xuki" ] || exit 0 + BLS_DIR="/boot/loader/entries" mkbls() { @@ -29,6 +32,7 @@ mkbls() { local debugname="" local debugid="" local flavor="" + local devicetree_entry="" if [[ "$kernelver" == *\+* ]] ; then local flavor=-"${kernelver##*+}" @@ -38,6 +42,12 @@ mkbls() { fi fi + # Define devicetree_entry if the user defined GRUB_DEVICETREE + # in /etc/default/grub, otherwise leave it empty + if [ -n "$GRUB_DEVICETREE" ] ; then + local devicetree_entry="devicetree /dtb-${kernelver}/$GRUB_DEVICETREE" + fi + cat </dev/null && \ + restorecon -R "/boot/vmlinuz-${KERNEL_VERSION}" + for i in \ - "$KERNEL_IMAGE" \ "$KERNEL_DIR"/System.map \ "$KERNEL_DIR"/config \ "$KERNEL_DIR"/zImage.stub \ "$KERNEL_DIR"/dtb do [[ -e "$i" ]] || continue - rm -f "/boot/${i##*/}-${KERNEL_VERSION}" - cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}" + cp --remove-destination --preserve=timestamps -rT "$i" "/boot/${i##*/}-${KERNEL_VERSION}" command -v restorecon &>/dev/null && \ restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}" done # hmac is .vmlinuz-.hmac so needs a special treatment i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac" if [[ -e "$i" ]]; then - rm -f "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" - cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" + cp --remove-destination --preserve=timestamps "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" command -v restorecon &>/dev/null && \ restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" fi + # OLD method using gzip'd file (will be deprecated and removed in the future) # symvers is symvers-.gz symlink, needs a special treatment i="$KERNEL_DIR/symvers.gz" if [[ -e "$i" ]]; then - rm -f "/boot/symvers-${KERNEL_VERSION}.gz" - ln -s "$i" "/boot/symvers-${KERNEL_VERSION}.gz" + ln -fs "$i" "/boot/symvers-${KERNEL_VERSION}.gz" command -v restorecon &>/dev/null && \ restorecon "/boot/symvers-${KERNEL_VERSION}.gz" fi + # symvers is symvers-.xz symlink, needs a special treatment + i="$KERNEL_DIR/symvers.xz" + if [[ -e "$i" ]]; then + ln -fs "$i" "/boot/symvers-${KERNEL_VERSION}.xz" + command -v restorecon &>/dev/null && \ + restorecon "/boot/symvers-${KERNEL_VERSION}.xz" + fi fi if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then if [[ -f /etc/kernel/cmdline ]]; then + if [[ /etc/kernel/cmdline -ot /etc/default/grub ]]; then + # user modified /etc/default/grub manually; sync + grub2-mkconfig -o /etc/grub2.cfg + fi read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline elif [[ -f /usr/lib/kernel/cmdline ]]; then read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline @@ -126,7 +150,11 @@ case "$COMMAND" in sed -i -e "s,^initrd.*,initrd ${BOOTPREFIX}${INITRD},g" "${BLS_TARGET}" fi - if [[ "$KERNEL_VERSION" == *\+* ]] && [ "x$GRUB_DEFAULT_TO_DEBUG" != "xtrue" ]; then + if ( [[ "$KERNEL_VERSION" != *${GRUB_DEFAULT_KERNEL_TYPE}* ]] && \ + [ "x$GRUB_NON_STANDARD_KERNEL" == "xtrue" ] ) || \ + ( echo "$KERNEL_VERSION" | grep -E -q "64k|auto|rt|uki" && \ + [ "x$GRUB_NON_STANDARD_KERNEL" != "xtrue" ] ) || \ + ( [[ "$KERNEL_VERSION" == *debug* ]] && [ "x$GRUB_DEFAULT_TO_DEBUG" != "xtrue" ] ); then GRUB_UPDATE_DEFAULT_KERNEL=false fi @@ -136,7 +164,7 @@ case "$COMMAND" in if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")" - cp -aT "${BLS_TARGET}" "${BLS_DEBUG}" + cp --preserve=timestamps -T "${BLS_TARGET}" "${BLS_DEBUG}" TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')" OPTIONS="$(echo "${BOOT_OPTIONS[*]} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')" sed -i -e "s/^title.*/title ${TITLE}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}" @@ -146,7 +174,7 @@ case "$COMMAND" in fi fi if [ -n "$NEWDEFAULT" ]; then - grub2-editenv - set "saved_entry=${NEWDEFAULT}" + grub2-editenv - set "tmp_saved_entry=${NEWDEFAULT}" fi # this probably isn't the best place to do this, but it will do for now. @@ -165,7 +193,11 @@ case "$COMMAND" in exit 77 ;; remove) - + # If the boot entry type is type2, we are not removing the BLS entry + if [[ "x${KERNEL_INSTALL_BOOT_ENTRY_TYPE}" = "xtype2" ]]; then + [ "${KERNEL_INSTALL_VERBOSE}" -gt 0 ] && echo "The boot entry type is type2. Skip removing BLS entry." + exit 0 + fi if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then BLS_TARGET="${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf" BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")" diff --git a/95-set-boot-entry.install b/95-set-boot-entry.install new file mode 100755 index 00000000..9f92f9f4 --- /dev/null +++ b/95-set-boot-entry.install @@ -0,0 +1,44 @@ +#!/bin/bash + +[[ -f /etc/default/grub ]] && . /etc/default/grub +[[ -f /etc/os-release ]] && . /etc/os-release + +COMMAND="$1" +KERNEL_VERSION="$2" +BOOT_DIR_ABS="$3" +KERNEL_IMAGE="$4" + +case "$COMMAND" in + add) + if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then + entry=$(grub2-editenv list | grep tmp_saved_entry) + if [ -n "$entry" ]; then + BLS_ID=${entry##tmp_saved_entry=} + BLS_DIR="/boot/loader/entries" + BLS_TARGET="${BLS_DIR}/${BLS_ID}.conf" + + LINUX="$(grep '^linux[ \t]' "${BLS_TARGET}" | sed -e 's,^linux[ \t]*,,' | awk '{print $1}')" + INITRD="$(grep '^initrd[ \t]' "${BLS_TARGET}" | sed -e 's,^initrd[ \t]*,,' | awk '{print $1}')" + + ROOTPREFIX="" + [ -z "$(grub2-mkrelpath /boot)" ] && ROOTPREFIX="/boot" + + if [ -e "${ROOTPREFIX}${LINUX}" -a -n "${INITRD}" ]; then + if [ ! -e "${ROOTPREFIX}${INITRD}" ]; then + echo "Error: ${ROOTPREFIX}${INITRD} not found." + exit 1 + fi + if ! lsinitrd ${ROOTPREFIX}${INITRD} > /dev/null; then + echo "Error: ${ROOTPREFIX}${INITRD} appears to be corrupt." + exit 1 + fi + fi + + grub2-editenv - unset "tmp_saved_entry" + grub2-editenv - set "saved_entry=$BLS_ID" + fi + fi + ;; + *) + ;; +esac diff --git a/99-grub-mkconfig.install b/99-grub-mkconfig.install index d9686b51..1a5fed8c 100755 --- a/99-grub-mkconfig.install +++ b/99-grub-mkconfig.install @@ -4,38 +4,31 @@ if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then exit 0 fi -# PV and PVH Xen DomU guests boot with pygrub that doesn't have BLS support, -# also Xen Dom0 use the menuentries from 20_linux_xen and not the ones from -# 10_linux. So BLS support needs to be disabled for both Xen Dom0 and DomU. -if [[ -e /sys/hypervisor/type ]] && grep -q "^xen$" /sys/hypervisor/type; then +# Run grub2-mkconfig if ENABLE_BLSCFG is false +if grep -sq '^GRUB_ENABLE_BLSCFG="*false"*\s*$' /etc/default/grub; then RUN_MKCONFIG=true DISABLE_BLS=true fi -ARCH=$(uname -m) -# Older ppc64le OPAL firmware (petitboot version < 1.8.0) don't have BLS support -# so grub2-mkconfig has to be run to generate a config with menuentry commands. -if [[ $ARCH = "ppc64le" ]] && [ -d /sys/firmware/opal ]; then - - petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" - - if test -e ${petitboot_path}; then - read -r -d '' petitboot_version < ${petitboot_path} - petitboot_version="$(echo ${petitboot_version//v})" - major_version="$(echo ${petitboot_version} | cut -d . -f1)" - minor_version="$(echo ${petitboot_version} | cut -d . -f2)" - - if test -z ${petitboot_version} || test ${major_version} -lt 1 || \ - test ${major_version} -eq 1 -a ${minor_version} -lt 8; then - RUN_MKCONFIG=true - fi - else +# PV and PVH Xen DomU guests boot with pygrub that doesn't have BLS support, +# also Xen Dom0 use the menuentries from 20_linux_xen and not the ones from +# 10_linux. So BLS support needs to be disabled for both Xen Dom0 and DomU. +if [[ -e /sys/hypervisor/type ]] && grep -q "^xen$" /sys/hypervisor/type; then + if [ ! -e /sys/hypervisor/guest_type ] || ! grep -q "^HVM$" /sys/hypervisor/guest_type; then RUN_MKCONFIG=true + DISABLE_BLS=true fi fi +ARCH=$(uname -m) +# Older ppc64le OPAL firmware don't have BLS support so grub2-mkconfig has to be +# run to generate a config with menuentry commands. +if [[ $ARCH = "ppc64le" ]] && [ -d /sys/firmware/opal ]; then + RUN_MKCONFIG=true +fi + if [[ $DISABLE_BLS = "true" ]]; then - if grep -q '^GRUB_ENABLE_BLSCFG="*true"*\s*$' /etc/default/grub; then + if grep -sq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' /etc/default/grub; then sed -i 's/^GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/' /etc/default/grub fi fi diff --git a/README.do-rebase b/README.do-rebase new file mode 100644 index 00000000..42b7716b --- /dev/null +++ b/README.do-rebase @@ -0,0 +1,21 @@ +do-rebase script +================ + +The `do-rebase` is a useful script that helps the developers to take patches from +a remote repository & branch, apply those and create a commit. Although this sounds like +easy steps, each may take time and it is prone to errors (as any manual work). + +To see in action, supposed you have a one or more patches for `f42` release that fixes (or +enhances) a bug at the repository `git@github.com:someuser/grub2.git` with branch +name `hotfix`; the way to call the script is by + + $ ./do-rebase --dist=f42 --repo=git@github.com:someuser/grub2.git --branch=hotfix + +the script will then fetch the repository in a separate directory (`.rhboot.git`), compare +those `hotfix` commits that has not been merged in `master` (`git format-patch master..hotfix` +on the `.rhboot.git` repo), replace these with the ones in current working dir, finally create +a commit that you can of course amend. + +The script supports other useful options: `--amend --commit --nocommit --bumpspec --nobumpspec --pkgtool=`. +Worth mentioning that you do not have to specify a --pkgtool option: it is infered from the --dist parameter but in +case you want to override it, the options is there. diff --git a/bootstrap b/bootstrap index 5b08e7e2..c6d434da 100755 --- a/bootstrap +++ b/bootstrap @@ -1,10 +1,10 @@ #! /bin/sh # Print a version string. -scriptversion=2019-01-04.17; # UTC +scriptversion=2024-07-10.18; # UTC # Bootstrap this package from checked-out sources. -# Copyright (C) 2003-2019 Free Software Foundation, Inc. +# Copyright (C) 2003-2022 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,7 @@ PERL="${PERL-perl}" me=$0 -default_gnulib_url=git://git.sv.gnu.org/gnulib +default_gnulib_url=https://git.savannah.gnu.org/git/gnulib.git usage() { cat </dev/null) +if test -z "$package"; then + package=$(sed -n "$extract_package_name" configure.ac) \ + || die 'cannot find package name in configure.ac' +fi gnulib_name=lib$package build_aux=build-aux @@ -290,62 +313,6 @@ find_tool () eval "export $find_tool_envvar" } -# Override the default configuration, if necessary. -# Make sure that bootstrap.conf is sourced from the current directory -# if we were invoked as "sh bootstrap". -case "$0" in - */*) test -r "$0.conf" && . "$0.conf" ;; - *) test -r "$0.conf" && . ./"$0.conf" ;; -esac - -if test "$vc_ignore" = auto; then - vc_ignore= - test -d .git && vc_ignore=.gitignore - test -d CVS && vc_ignore="$vc_ignore .cvsignore" -fi - -if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then - use_gnulib=false -else - use_gnulib=true -fi - -# Translate configuration into internal form. - -# Parse options. - -for option -do - case $option in - --help) - usage - exit;; - --gnulib-srcdir=*) - GNULIB_SRCDIR=${option#--gnulib-srcdir=};; - --skip-po) - SKIP_PO=t;; - --force) - checkout_only_file=;; - --copy) - copy=true;; - --bootstrap-sync) - bootstrap_sync=true;; - --no-bootstrap-sync) - bootstrap_sync=false;; - --no-git) - use_git=false;; - *) - die "$option: unknown option";; - esac -done - -$use_git || test -d "$GNULIB_SRCDIR" \ - || die "Error: --no-git requires --gnulib-srcdir" - -if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then - die "Bootstrapping from a non-checked-out distribution is risky." -fi - # Strip blank and comment lines to leave significant entries. gitignore_entries() { sed '/^#/d; /^$/d' "$@" @@ -387,6 +354,137 @@ insert_vc_ignore() { insert_if_absent "$vc_ignore_file" "$pattern" } +symlink_to_dir() +{ + src=$1/$2 + dst=${3-$2} + + test -f "$src" && { + + # If the destination directory doesn't exist, create it. + # This is required at least for "lib/uniwidth/cjk.h". + dst_dir=$(dirname "$dst") + if ! test -d "$dst_dir"; then + mkdir -p "$dst_dir" + + # If we've just created a directory like lib/uniwidth, + # tell version control system(s) it's ignorable. + # FIXME: for now, this does only one level + parent=$(dirname "$dst_dir") + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + ig=$parent/$dot_ig + insert_vc_ignore $ig "${dst_dir##*/}" + done + fi + + if $copy; then + { + test ! -h "$dst" || { + echo "$me: rm -f $dst" && + rm -f "$dst" + } + } && + test -f "$dst" && + cmp -s "$src" "$dst" || { + echo "$me: cp -fp $src $dst" && + cp -fp "$src" "$dst" + } + else + # Leave any existing symlink alone, if it already points to the source, + # so that broken build tools that care about symlink times + # aren't confused into doing unnecessary builds. Conversely, if the + # existing symlink's timestamp is older than the source, make it afresh, + # so that broken tools aren't confused into skipping needed builds. See + # . + test -h "$dst" && + src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 && + dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 && + test "$src_i" = "$dst_i" && + both_ls=$(ls -dt "$src" "$dst") && + test "X$both_ls" = "X$dst$nl$src" || { + dot_dots= + case $src in + /*) ;; + *) + case /$dst/ in + *//* | */../* | */./* | /*/*/*/*/*/) + die "invalid symlink calculation: $src -> $dst";; + /*/*/*/*/) dot_dots=../../../;; + /*/*/*/) dot_dots=../../;; + /*/*/) dot_dots=../;; + esac;; + esac + + echo "$me: ln -fs $dot_dots$src $dst" && + ln -fs "$dot_dots$src" "$dst" + } + fi + } +} + +# Override the default configuration, if necessary. +# Make sure that bootstrap.conf is sourced from the current directory +# if we were invoked as "sh bootstrap". +case "$0" in + */*) test -r "$0.conf" && . "$0.conf" ;; + *) test -r "$0.conf" && . ./"$0.conf" ;; +esac + +if test "$vc_ignore" = auto; then + vc_ignore= + test -d .git && vc_ignore=.gitignore + test -d CVS && vc_ignore="$vc_ignore .cvsignore" +fi + +if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then + use_gnulib=false +else + use_gnulib=true +fi + +# Translate configuration into internal form. + +# Parse options. + +for option +do + case $option in + --help) + usage + exit;; + --version) + set -e + echo "bootstrap $scriptversion" + echo "$copyright" + exit 0 + ;; + --gnulib-srcdir=*) + GNULIB_SRCDIR=${option#--gnulib-srcdir=};; + --skip-po) + SKIP_PO=t;; + --force) + checkout_only_file=;; + --copy) + copy=true;; + --bootstrap-sync) + bootstrap_sync=true;; + --no-bootstrap-sync) + bootstrap_sync=false;; + --no-git) + use_git=false;; + *) + bootstrap_option_hook $option || die "$option: unknown option";; + esac +done + +$use_git || test -d "$GNULIB_SRCDIR" \ + || die "Error: --no-git requires --gnulib-srcdir" + +if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then + die "Bootstrapping from a non-checked-out distribution is risky." +fi + # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac. found_aux_dir=no grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \ @@ -665,9 +763,25 @@ if $use_gnulib; then shallow= if test -z "$GNULIB_REVISION"; then git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2' + git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ + || cleanup_gnulib + else + git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2' + mkdir -p "$gnulib_path" + # Only want a shallow checkout of $GNULIB_REVISION, but git does not + # support cloning by commit hash. So attempt a shallow fetch by commit + # hash to minimize the amount of data downloaded and changes needed to + # be processed, which can drastically reduce download and processing + # time for checkout. If the fetch by commit fails, a shallow fetch can + # not be performed because we do not know what the depth of the commit + # is without fetching all commits. So fallback to fetching all commits. + git -C "$gnulib_path" init + git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url} + git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \ + || git -C "$gnulib_path" fetch origin \ + || cleanup_gnulib + git -C "$gnulib_path" reset --hard FETCH_HEAD fi - git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ - || cleanup_gnulib trap - 1 2 13 15 fi @@ -784,75 +898,6 @@ case $SKIP_PO in fi;; esac -symlink_to_dir() -{ - src=$1/$2 - dst=${3-$2} - - test -f "$src" && { - - # If the destination directory doesn't exist, create it. - # This is required at least for "lib/uniwidth/cjk.h". - dst_dir=$(dirname "$dst") - if ! test -d "$dst_dir"; then - mkdir -p "$dst_dir" - - # If we've just created a directory like lib/uniwidth, - # tell version control system(s) it's ignorable. - # FIXME: for now, this does only one level - parent=$(dirname "$dst_dir") - for dot_ig in x $vc_ignore; do - test $dot_ig = x && continue - ig=$parent/$dot_ig - insert_vc_ignore $ig "${dst_dir##*/}" - done - fi - - if $copy; then - { - test ! -h "$dst" || { - echo "$me: rm -f $dst" && - rm -f "$dst" - } - } && - test -f "$dst" && - cmp -s "$src" "$dst" || { - echo "$me: cp -fp $src $dst" && - cp -fp "$src" "$dst" - } - else - # Leave any existing symlink alone, if it already points to the source, - # so that broken build tools that care about symlink times - # aren't confused into doing unnecessary builds. Conversely, if the - # existing symlink's timestamp is older than the source, make it afresh, - # so that broken tools aren't confused into skipping needed builds. See - # . - test -h "$dst" && - src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 && - dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 && - test "$src_i" = "$dst_i" && - both_ls=$(ls -dt "$src" "$dst") && - test "X$both_ls" = "X$dst$nl$src" || { - dot_dots= - case $src in - /*) ;; - *) - case /$dst/ in - *//* | */../* | */./* | /*/*/*/*/*/) - die "invalid symlink calculation: $src -> $dst";; - /*/*/*/*/) dot_dots=../../../;; - /*/*/*/) dot_dots=../../;; - /*/*/) dot_dots=../;; - esac;; - esac - - echo "$me: ln -fs $dot_dots$src $dst" && - ln -fs "$dot_dots$src" "$dst" - } - fi - } -} - version_controlled_file() { parent=$1 file=$2 @@ -970,7 +1015,7 @@ bootstrap_post_import_hook \ # Uninitialized submodules are listed with an initial dash. if $use_git && git submodule | grep '^-' >/dev/null; then die "some git submodules are not initialized. " \ - "Run 'git submodule init' and bootstrap again." + "Run 'git submodule update --init' and bootstrap again." fi # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some @@ -1064,7 +1109,7 @@ bootstrap_epilogue echo "$0: done. Now you can run './configure'." -# Local variables: +# Local Variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" diff --git a/bootstrap.conf b/bootstrap.conf index 6b043fc3..7a7813d2 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -1,6 +1,6 @@ # Bootstrap configuration. -# Copyright (C) 2006-2019 Free Software Foundation, Inc. +# Copyright (C) 2006-2022 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,11 +16,10 @@ # along with this program. If not, see . -GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 +GNULIB_REVISION=9f48fb992a3d7e96610c4ce8be969cff2d61a01b # gnulib modules used by this package. -# mbswidth is used by gnulib-fix-width.diff's changes to argp rather than -# directly. +# mbswidth is used by fix-width.diff's changes to argp rather than directly. gnulib_modules=" argp base64 @@ -35,6 +34,7 @@ gnulib_modules=" realloc-gnu regex save-cwd + stdbool " gnulib_tool_option_extras="\ @@ -66,10 +66,11 @@ SKIP_PO=t # Build prerequisites buildreq="\ -autoconf 2.63 -automake 1.11 -gettext 0.18.3 +autoconf 2.64 +automake 1.14 +gettext - git 1.5.5 +patch - tar - " @@ -79,11 +80,12 @@ cp -a INSTALL INSTALL.grub bootstrap_post_import_hook () { set -e - for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \ - fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do - patch -d grub-core/lib/gnulib -p2 \ - < "grub-core/lib/gnulib-patches/$patchname.patch" - done + + # Instead of patching our gnulib and therefore maintaining a fork, submit + # changes to gnulib and update the hash above when they've merged. Do not + # add new patches here. + patch -d grub-core/lib/gnulib -p2 < grub-core/lib/gnulib-patches/fix-width.patch + for patchname in \ 0001-Support-POTFILES-shell \ 0002-Handle-gettext_printf-shell-function \ diff --git a/do-rebase b/do-rebase index 1f9b21c2..8af199e2 100755 --- a/do-rebase +++ b/do-rebase @@ -1,6 +1,7 @@ #!/bin/bash set -e set -u + shopt -qu globstar shopt -qs expand_aliases export LC_COLLATE=C @@ -18,24 +19,33 @@ usage() exec 1>&2 retcode=$1 fi - echo usage: "do-rebase [OPTIONS] [--dist RELEASEVER | RELEASEVER ] [GITREPO]" - echo OPTIONS: --dist=RELEASEVER --repo=REPO --amend --nocommit --nobumpspec - exit $retcode + echo usage: "do-rebase [OPTIONS] --dist= --repo= --branch=" + echo OPTIONS: "--amend --commit --nocommit --bumpspec --nobumpspec" + exit "$retcode" } -if ! git status | grep -q 'nothing to commit, working .* clean' ; then +on_error() { + exec 1>&2 + echo "An error occurred. Exiting..." + git reset --hard + exit 1 +} + +trap 'on_error' ERR + +# Check if the working directory is clean (no changes) +if ! git diff-index --quiet HEAD --; then echo "Working directory is not clean, cannot rebase." 1>&2 exit 1 fi -gitrepo="git@github.com:rhboot/grub2.git" +gitrepo="" +branch="" releasever="" amend="" commit=1 bumpspec=1 -declare -a savedargs -savedargs=() while [ $# -gt 0 ]; do case $1 in --help|-h|--usage|-?|-u) @@ -55,6 +65,13 @@ while [ $# -gt 0 ]; do shift gitrepo=$1 ;; + --branch=*) + branch=${1##--branch=} + ;; + --branch) + shift + branch=$1 + ;; --amend) amend="--amend" ;; @@ -74,107 +91,44 @@ while [ $# -gt 0 ]; do bumpspec=0 ;; *) - savedargs[${#savedargs[@]}]="$1" + echo "Unknown parameter $1" ;; esac shift done -set -- "${savedargs[@]}" -if [ -z "${releasever}" -a $# -gt 0 ]; then - releasever=$1 - shift -else - dist=$(git status | grep "On branch" | cut -d\ -f3-) - if [ -z "$dist" ]; then - echo "Could not figure out distro release version" 1>&2 - usage 1 - fi - case "$(eval echo \${dist})" in - .fc*) - releasever=$(echo ${dist} | \ - sed 's/^\.fc\([[:digit:]]\+\)$/fedora-\1/') - ;; - .*) - releasever=$(echo $dist | \ - sed 's/^\.\([[:alpha:]]\+\)\([[:digit:]]\+\)$/\1-\2/') - ;; - rhel*) - releasever=${dist} - dist=.el${releasever##rhel-} - ;; - esac - if [ -z "${releasever}" -o "${releasever}" = "${dist}" ]; then - echo "Could not figure out distro release version" 1>&2 - usage 1 - fi +# check must params +if [ -z "$releasever" ] || [ -z "$gitrepo" ] || [ -z "$branch" ]; then + usage fi -if [ -z "$releasever" ]; then - echo "Could not figure out distro release version" 1>&2 - usage 1 -fi - -if [ -n "${1:-}" ]; then - gitrepo=$1 - shift -fi - -if [ $# -ge 1 ]; then - echo "Unknown argument \"$1\"" 1>&2 - usage 1 -fi - -if [ ! -d $PWD/.rhboot.git ]; then +if [ ! -d "$PWD/.rhboot.git" ]; then othergit init othergit config core.abbrev 11 - if ! othergit remote add \ - rhboot $gitrepo \ - >/dev/null 2>&1 ; then + if ! othergit remote add rhboot "$gitrepo" >/dev/null 2>&1 ; then echo "Could not add remote: rhboot" 1>&2 exit 1 fi elif othergit remote show -n rhboot | grep -q "URL: github$" ; then - if ! othergit remote add \ - rhboot $gitrepo \ - >/dev/null 2>&1 ; then + if ! othergit remote add rhboot "$gitrepo" >/dev/null 2>&1 ; then echo "Could not add remote: rhboot" 1>&2 exit 1 fi else - othergit remote set-url rhboot ${gitrepo} + othergit remote set-url rhboot "${gitrepo}" fi othergit fetch rhboot -remote=$(othergit branch --list -r "rhboot/${releasever}" 2>/dev/null) -if [ "${remote}" != " rhboot/${releasever}" ]; then - echo branch \"${releasever}\" does not appear to exist 1>&2 - exit 1 -fi unset LC_ALL git rm -q 0*.patch -# No need for this patch anymore, the package is rebased on latest release now. -#> release-to-master.patch -#othergit diff --full-index --binary $diff_ops grub-2.04..refs/remotes/rhboot/master > release-to-master.patch -#git add release-to-master.patch - -fedpkg sources -curl -L https://github.com/rhboot/gnulib/archive/fixes.tar.gz > gnulib-fixes.tar.gz.new -if cmp -s gnulib-fixes.tar.gz gnulib-fixes.tar.gz.new; then - rm gnulib-fixes.tar.gz.new -else - mv gnulib-fixes.tar.gz.new gnulib-fixes.tar.gz - sed -i -e '/gnulib-/d' sources - fedpkg upload gnulib-fixes.tar.gz - git add sources -fi +fedpkg --release "$releasever" sources > grub.patches -patches=$(formatpatch refs/remotes/rhboot/master..refs/remotes/rhboot/${releasever}) +patches=$(formatpatch refs/remotes/rhboot/master..refs/remotes/rhboot/"${branch}") for x in $patches ; do - echo Patch$(echo ${x} | cut -d- -f1): ${x} >> grub.patches + echo "Patch$(echo "${x}" | cut -d- -f1): ${x}" >> grub.patches done if [[ -z "$amend" && ${bumpspec} -gt 0 ]] || [[ ${bumpspec} -ge 2 ]] ; then rpmdev-bumpspec -c "- Rebased to newer upstream for ${releasever}" grub2.spec @@ -182,7 +136,7 @@ fi git add 0*.patch grub2.spec grub.patches if [[ ${commit} -eq 1 ]] ; then if [ -z "$amend" ]; then - fedpkg commit -s -c + fedpkg --release "$releasever" commit -s -c else git commit --amend fi diff --git a/do-sync b/do-sync new file mode 100755 index 00000000..bfb2371c --- /dev/null +++ b/do-sync @@ -0,0 +1,89 @@ +#!/bin/bash + +set -o nounset +set -o errexit + +usage() { + echo "Usage $0 :::" + echo "Generates a (rhboot) grub2 branch which contains latest patches from dist-git based on specific Fedora/RHEL version" + echo "Command expects a single parameter delimited with colons, with the following meanings:" + echo " pkgtool: Package tool, e.g. fedpkg, rhpkg, etc." + echo " dist_git_branch: The dist-git branch/release to sync" + echo " git_branch: The git branch/release to sync" + echo " git_base_commit: base commit where git_branch is based on" + echo + echo "Examples:" + echo + echo " $0 fedpkg:rawhide:fedora-43:grub-2.12" + echo " $0 fedpkg:f42:fedora-42:grub-2.12" + echo " $0 fedpkg:f41:fedora-41:grub-2.12" + echo " $0 fedpkg:f40:fedora-40:grub-2.12" + echo + echo "Also handles RHEL branches:" + echo + echo " $0 rhpkg:rhel-10-main:rhel-10-main:grub-2.12" + echo " $0 rhpkg:rhel-9-main:rhel-9-main:grub-2.06" + echo " $0 rhpkg:rhel-8-main:rhel-8-main:f28-branchpoint" + exit 1 +} + +# check params +[ $# -eq 1 ] || usage + +args=$1 + +pkgtool=$(echo "$args" | awk -F ':' '{print $1}') +dist_git_branch=$(echo "$args" | awk -F ':' '{print $2}') +git_branch=$(echo "$args" | awk -F ':' '{print $3}') +git_base_commit=$(echo "$args" | awk -F ':' '{print $4}') + +# working dirs +dist_git_dir=/tmp/grub/dist-git +git_dir=/tmp/grub/git + +rm -rf $dist_git_dir $git_dir +mkdir -p $dist_git_dir $git_dir + + +pushd $dist_git_dir > /dev/null +{ + # clone grub2 package anonymously + $pkgtool clone -a grub2 . 2>/dev/null + + # create a local branch, all fine if already exists + git checkout -q -b "$dist_git_branch" origin/"$dist_git_branch" 2> /dev/null || true +} +popd > /dev/null + + +pushd $git_dir > /dev/null +{ + git clone -q git@github.com:rhboot/grub2.git . 2>/dev/null + + dist_git_sync_branch=${git_branch}-dist-git-$(date +"%Y-%m-%d-%H_%M_%S") + git checkout -q -b "$dist_git_sync_branch" "$git_base_commit" + while read -r line; do + p=$(echo "$line" | awk '{print $2}') + git am -q "$dist_git_dir/$p" 2>/dev/null + done < $dist_git_dir/grub.patches + + # brach current git_branch based on upstream git_branch + git branch -D "$git_branch" 2>/dev/null || true + git checkout -q -b "$git_branch" origin/"$git_branch" + + missing_commits=$(git cherry "${git_branch}" "${dist_git_sync_branch}" | grep ^+ | wc -l) + if [[ $missing_commits -eq 0 ]]; then + echo "Branch $git_branch is up-to-date, no need to sync" + else + echo "Missing commits ($missing_commits) which would be integrated in final branch" + git cherry "$git_branch" "$dist_git_sync_branch" -v | grep ^+ + # finally cherry pick those missing patches + git cherry "$git_branch" "$dist_git_sync_branch" 2>/dev/null | grep ^+ | sed 's/\+ //' | xargs git cherry-pick 2>/dev/null + + echo "Pushing latest commits" + cd "$git_dir" + git push -v origin "$git_branch" + fi +} +popd > /dev/null + diff --git a/gen_grub_cfgstub b/gen_grub_cfgstub new file mode 100644 index 00000000..8f77c0f5 --- /dev/null +++ b/gen_grub_cfgstub @@ -0,0 +1,26 @@ +#!/bin/sh +set -eu + +if [ $# -ne 2 ] + then + echo "Missing argument" + echo "Usage: script.sh GRUB_HOME EFI_HOME" + exit 1 +fi + +GRUB_HOME=$1 +EFI_HOME=$2 + +# create a stub grub2 config in EFI +BOOT_UUID=$(grub2-probe --target=fs_uuid "${GRUB_HOME}") +GRUB_DIR=$(grub2-mkrelpath "${GRUB_HOME}") + +cat << EOF > "${EFI_HOME}"/grub.cfg.stb +search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID} +set prefix=(\$dev)${GRUB_DIR} +export \$prefix +configfile \$prefix/grub.cfg +EOF + +mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg +chmod 0600 ${EFI_HOME}/grub.cfg diff --git a/gitignore b/gitignore index f6a1bd05..4d0dfb70 100644 --- a/gitignore +++ b/gitignore @@ -11,11 +11,13 @@ *.img *.log *.lst +!/grub-core/extra_deps.lst *.marker *.mod *.o *.pf2 *.pp +*.pyc *.trs *~ .deps-core/ @@ -230,6 +232,8 @@ widthspec.bin /lib/libgcrypt-grub /libgrub_a_init.c /lzocompress_test +/luks1_test +/luks2_test /m4/ /minixfs_test /missing diff --git a/grub.macros b/grub.macros index 865ade3c..dd06d94c 100644 --- a/grub.macros +++ b/grub.macros @@ -1,6 +1,12 @@ # vim:filetype=spec # Modules always contain just 32-bit code +%global evr %{epoch}:%{version}-%{release} %global _libdir %{_exec_prefix}/lib + +%global os_id %(eval echo $(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/')) +%global grub_evr_dir %{_libdir}/efi/grub2/%{evr} +%global grub_efi_dir %{grub_evr_dir}/EFI/%{os_id} + %global _binaries_in_noarch_packages_terminate_build 0 #%%undefine _missing_build_ids_terminate_build %{expand:%%{!?buildsubdir:%%global buildsubdir grub-%{tarversion}}} @@ -9,18 +15,26 @@ %global _configure ../configure %if %{?_with_ccache: 1}%{?!_with_ccache: 0} -%global cc_equals CC=/usr/%{_lib}/ccache/gcc +%global ccpath /usr/%{_lib}/ccache/gcc %else -%global cc_equals %{nil} +%global ccpath %{__cc} +%endif + +# gnulib actively ignores CFLAGS because it's terrible +# build aarch64 gnulib with branch protection +%ifarch aarch64 +%global cc_equals "CC=%{ccpath} -fPIE -Wl,-z,noexecstack -Wl,--no-warn-rwx-segments -mbranch-protection=standard" +%else +%global cc_equals "CC=%{ccpath} -fPIE -Wl,-z,noexecstack -Wl,--no-warn-rwx-segments" %endif %global cflags_sed \\\ sed \\\ -e 's/-O. //g' \\\ - -e 's/-fplugin=annobin //g' \\\ - -e 's,-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 ,,g' \\\ + -e 's/-fplugin=annobin//g' \\\ + -e 's,-specs=[[:alnum:]/_-]*annobin[[:alnum:]_-]*,,g' \\\ -e 's/-fstack-protector[[:alpha:]-]\\+//g' \\\ - -e 's/-Wp,-D_FORTIFY_SOURCE=[[:digit:]]\\+//g' \\\ + -e 's/-[^ ]*D_FORTIFY_SOURCE=[[:digit:]][^ ]*\\+//g' \\\ -e 's/--param=ssp-buffer-size=4//g' \\\ -e 's/-mregparm=3/-mregparm=4/g' \\\ -e 's/-fexceptions//g' \\\ @@ -29,14 +43,21 @@ -e 's/^/ -fno-strict-aliasing /' \\\ %{nil} -%global host_cflags %{expand:%%(echo %{build_cflags} %{?_hardening_cflags} | %{cflags_sed})} +%global host_cflags_ %{expand:%%(echo %{build_cflags} %{?_hardening_cflags} | %{cflags_sed})} -fstack-protector-strong +%ifarch x86_64 +%global host_cflags %{host_cflags_} -fcf-protection +%else +%global host_cflags %{host_cflags_} +%endif %global legacy_host_cflags \\\ %{expand:%%(echo %{host_cflags} | \\\ - %{cflags_sed} \\\ + sed \\\ -e 's/-m64//g' \\\ -e 's/-mcpu=power[[:alnum:]]\\+/-mcpu=power6/g' \\\ )} %global efi_host_cflags %{expand:%%(echo %{host_cflags})} +%global xen_host_cflags %{expand:%%(echo %{host_cflags})} +%global xen_pvh_host_cflags %{expand:%%(echo %{host_cflags})} %global target_cflags %{expand:%%(echo %{build_cflags} | %{cflags_sed})} %global legacy_target_cflags \\\ @@ -46,9 +67,12 @@ -e 's/-mcpu=power[[:alnum:]]\\+/-mcpu=power6/g' \\\ )} %global efi_target_cflags %{expand:%%(echo %{target_cflags})} +%global xen_target_cflags %{expand:%%(echo %{target_cflags})} +%global xen_pvh_target_cflags %{expand:%%(echo %{target_cflags})} %global ldflags_sed \\\ sed \\\ + -e 's,-specs=[[:alnum:]/_-]*annobin[[:alnum:]_-]*,,g' \\\ -e 's/^$//' \\\ %{nil} @@ -58,21 +82,30 @@ %{ldflags_sed} \\\ )} %global efi_host_ldflags %{expand:%%(echo %{host_ldflags})} +%global xen_host_ldflags %{expand:%%(echo %{host_ldflags})} +%global xen_pvh_host_ldflags %{expand:%%(echo %{host_ldflags})} -%global target_ldflags %{expand:%%(echo %{build_ldflags} -static | %{ldflags_sed})} +%global target_ldflags %{expand:%%(echo %{build_ldflags} -Wl,--no-warn-rwx-segments -static | %{ldflags_sed})} %global legacy_target_ldflags \\\ %{expand:%%(echo %{target_ldflags} | \\\ %{ldflags_sed} \\\ )} %global efi_target_ldflags %{expand:%%(echo %{target_ldflags})} +%global xen_target_ldflags %{expand:%%(echo %{target_ldflags})} +%global xen_pvh_target_ldflags %{expand:%%(echo %{target_ldflags})} %global with_efi_arch 0 %global with_alt_efi_arch 0 %global with_legacy_arch 0 %global with_emu_arch 1 +%global with_xen_arch 0 +%global with_xen_pvh_arch 0 %global emuarch %{_arch} %global grubefiarch %{nil} %global grublegacyarch %{nil} +%global grubelfname %{nil} +%global xen_package_arch %{nil} +%global xen_pvh_package_arch %{nil} # sparc is always compiled 64 bit %ifarch %{sparc} @@ -112,11 +145,38 @@ %{!?with_efi_only:%global without_efi_only 0} %{?with_efi_only:%global without_efi_only 1} -### fixme -%ifarch aarch64 %{arm} riscv64 -%global efi_modules " " +%ifarch %{efi_arch} +%global efi_modules " efi_netfs efifwsetup efinet lsefi lsefimmap connectefi bli " +%endif + +%global xen_arch x86_64 +%ifarch %{xen_arch} +%global with_xen_arch 1 %else -%global efi_modules " backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug keylayouts at_keyboard " +%global with_xen_arch 0 +%endif +%{!?with_xen_arch:%global without_xen_arch 0} +%{?with_xen_arch:%global without_xen_arch 1} + +%global xen_pvh_arch x86_64 +%ifarch %{xen_pvh_arch} +%global with_xen_pvh_arch 1 +%else +%global with_xen_pvh_arch 0 +%endif +%{!?with_xen_pvh_arch:%global without_xen_pvh_arch 0} +%{?with_xen_pvh_arch:%global without_xen_pvh_arch 1} + +%ifarch x86_64 %{ix86} +%global platform_modules " backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug keylayouts at_keyboard " +%endif + +%ifarch ppc64le +%global platform_modules " appendedsig tpm ofnet " +%endif + +%ifarch aarch64 %{arm} riscv64 +%global platform_modules " " %endif %ifarch aarch64 %{arm} riscv64 @@ -139,11 +199,18 @@ %global target_cpu_name %{_arch} %global grub_target_name %{_arch}-efi %global package_arch efi-x64 +%global xen_package_arch xen-x64 +%global xen_pvh_package_arch xen_pvh-i386 %global legacy_target_cpu_name i386 %global legacy_package_arch pc %global platform pc +%global xen_grub_target_name %{_arch}-xen +%global xen_pvh_grub_target_name i386-xen_pvh +%global grubxenarch %{xen_grub_target_name} +%global grubxenpvharch %{xen_pvh_grub_target_name} + %global alt_efi_arch ia32 %global alt_target_cpu_name i386 %global alt_grub_target_name i386-efi @@ -216,14 +283,13 @@ %global with_legacy_arch 1 %global grublegacyarch %{legacy_target_cpu_name}-%{platform} %global moduledir %{legacy_target_cpu_name}-%{platform} +%global grubelfname core.elf %endif -%global evr %{epoch}:%{version}-%{release} - %ifarch x86_64 %global with_efi_common 1 -%global with_legacy_modules 0 -%global with_legacy_common 0 +%global with_legacy_modules 1 +%global with_legacy_common 1 %else %global with_efi_common 0 %global with_legacy_common 1 @@ -233,13 +299,13 @@ %define define_legacy_variant() \ %{expand:%%package %%{1}} \ Summary: Bootloader with support for Linux, Multiboot, and more \ -Provides: %{name} = %{evr} \ -Obsoletes: %{name} < %{evr} \ -Requires: %{name}-common = %{evr} \ -Requires: %{name}-tools-minimal = %{evr} \ -Requires: %{name}-%{1}-modules = %{evr} \ -Requires: gettext which file \ -Requires: %{name}-tools = %{evr} \ +Provides: grub2 = %{evr} \ +Obsoletes: grub2 < %{evr} \ +Requires: grub2-common = %{evr} \ +Requires: grub2-tools-minimal = %{evr} \ +Requires: grub2-%{1}-modules = %{evr} \ +Requires: gettext-runtime which file \ +Requires: grub2-tools = %{evr} \ Requires(pre): dracut \ Requires(post): dracut \ %{expand:%%description %%{1}} \ @@ -251,7 +317,7 @@ This subpackage provides support for %{1} systems. \ %%package %%{1}-modules \ Summary: Modules used to build custom grub images \ BuildArch: noarch \ -Requires: %%{name}-common = %%{evr} \ +Requires: grub2-common = %%{evr} \ %%description %%{1}-modules \ %%{desc} \ This subpackage provides support for rebuilding your own grub.efi. \ @@ -261,11 +327,10 @@ This subpackage provides support for rebuilding your own grub.efi. \ %{expand:%%{?!buildsubdir:%%define buildsubdir grub-%%{1}-%{tarversion}}}\ %{expand:%%package %%{1}-tools} \ Summary: Support tools for GRUB. \ -Requires: gettext os-prober which file system-logos \ -Requires: %{name}-common = %{evr} \ -Requires: %{name}-tools-minimal = %{evr} \ +Requires: gettext-runtime os-prober file system-logos \ +Requires: grub2-common = %{evr} \ +Requires: grub2-tools-minimal = %{evr} \ Requires: os-prober >= 1.58-11 \ -Requires: gettext which file \ \ %{expand:%%description %%{1}-tools} \ %{desc} \ @@ -276,12 +341,12 @@ This subpackage provides tools for support of %%{1} platforms. \ %{expand:%%package %{1}} \ Summary: GRUB for EFI systems. \ Requires: efi-filesystem \ -Requires: %{name}-common = %{evr} \ -Requires: %{name}-tools-minimal >= %{evr} \ -Requires: %{name}-tools = %{evr} \ -Provides: %{name}-efi = %{evr} \ -%{?legacy_provides:Provides: %{name} = %{evr}} \ -%{-o:Obsoletes: %{name}-efi < %{evr}} \ +Requires: grub2-common = %{evr} \ +Requires: grub2-tools-minimal >= %{evr} \ +Requires: grub2-tools = %{evr} \ +Provides: grub2-efi = %{evr} \ +%{?legacy_provides:Provides: grub2 = %{evr}} \ +%{-o:Obsoletes: grub2-efi < %{evr}} \ \ %{expand:%%description %{1}} \ %{desc} \ @@ -292,9 +357,9 @@ This subpackage provides support for %{1} systems. \ %{expand:%%package %{1}-modules} \ Summary: Modules used to build custom grub.efi images \ BuildArch: noarch \ -Requires: %{name}-common = %{evr} \ -Provides: %{name}-efi-modules = %{evr} \ -Obsoletes: %{name}-efi-modules < %{evr} \ +Requires: grub2-common = %{evr} \ +Provides: grub2-efi-modules = %{evr} \ +Obsoletes: grub2-efi-modules < %{evr} \ %{expand:%%description %{1}-modules} \ %{desc} \ This subpackage provides support for rebuilding your own grub.efi. \ @@ -302,13 +367,39 @@ This subpackage provides support for rebuilding your own grub.efi. \ \ %{expand:%%package %{1}-cdboot} \ Summary: Files used to boot removeable media with EFI \ -Requires: %{name}-common = %{evr} \ -Provides: %{name}-efi-cdboot = %{evr} \ +Requires: grub2-common = %{evr} \ +Provides: grub2-efi-cdboot = %{evr} \ %{expand:%%description %{1}-cdboot} \ %{desc} \ This subpackage provides optional components of grub used with removeable media on %{1} systems.\ %{nil} +%define define_xen_variant(o) \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%{1}-%{tarversion}}}\ +%{expand:%%package %{1}-modules} \ +Summary: Modules used to build custom grub-%{xen_grub_target_name}.bin images \ +BuildArch: noarch \ +Requires: grub2-tools = %{evr} \ +Provides: grub2-xen-modules = %{evr} \ +Obsoletes: grub2-xen-modules < %{evr} \ +%{expand:%%description %{1}-modules} \ +%{desc} \ +This subpackage provides support for rebuilding your own grub-%{xen_grub_target_name}.bin. \ +%{nil} + +%define define_xen_pvh_variant(o) \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%{1}-%{tarversion}}}\ +%{expand:%%package %{1}-modules} \ +Summary: Modules used to build custom grub-%{xen_pvh_grub_target_name}.bin images \ +BuildArch: noarch \ +Requires: grub2-tools = %{evr} \ +Provides: grub2-xen_pvh-modules = %{evr} \ +Obsoletes: grub2-xen_pvh-modules < %{evr} \ +%{expand:%%description %{1}-modules} \ +%{desc} \ +This subpackage provides support for rebuilding your own grub-%{xen_pvh_grub_target_name}.bin. \ +%{nil} + %global do_common_setup() \ %setup -q -n grub-%{tarversion} \ rm -fv docs/*.info \ @@ -323,15 +414,14 @@ git init \ echo '![[:digit:]][[:digit:]]_*.in' > util/grub.d/.gitignore \ echo '!*.[[:digit:]]' > util/.gitignore \ echo '!config.h' > include/grub/emu/.gitignore \ -git config user.email "%{name}-owner@fedoraproject.org" \ +git config user.email "grub2-owner@fedoraproject.org" \ git config user.name "Fedora Ninjas" \ git config gc.auto 0 \ rm -f configure \ git add . \ git commit -a -q -m "%{tarversion} baseline." \ -#git apply --index --whitespace=nowarn %{SOURCE3} \ -#git commit -a -q -m "%{tarversion} master." \ git am --whitespace=nowarn %%{patches} %{1}.conf \ @@ -377,48 +518,108 @@ install -m 644 %{1}.conf ${RPM_BUILD_ROOT}/etc/dnf/protected.d/ \ rm -f %{1}.conf \ %{nil} -%ifarch x86_64 aarch64 %{arm} riscv64 -%define mkimage() \ +%global grub_modules " all_video boot blscfg btrfs blsuki \\\ + cat configfile cryptodisk \\\ + echo ext2 f2fs fat font \\\ + gcry_rijndael gcry_rsa gcry_serpent \\\ + gcry_sha256 gcry_twofish gcry_whirlpool \\\ + gfxmenu gfxterm gzio \\\ + halt hfsplus http increment iso9660 \\\ + jpeg loadenv loopback linux lvm luks \\\ + luks2 \\\ + memdisk \\\ + mdraid09 mdraid1x minicmd net \\\ + normal part_apple part_msdos part_gpt \\\ + password_pbkdf2 pgp png reboot regexp \\\ + search search_fs_uuid search_fs_file \\\ + search_label serial sleep \\\ + squash4 \\\ + syslinuxcfg \\\ + test tftp version video xfs zstd " \ + +%ifarch %{efi_arch} +%define efi_mkimage() \ +mkdir -p memdisk/fonts \ +cp %{4}/unicode.pf2 memdisk/fonts \ +mksquashfs memdisk memdisk.squashfs -comp lzo \ %{4}./grub-mkimage -O %{1} -o %{2}.orig \\\ - -p /EFI/%{efi_vendor} -d grub-core ${GRUB_MODULES} \\\ - --sbat %{4}./sbat.csv \ + -d grub-core \\\ + --sbat %{4}./sbat.csv \\\ + -m memdisk.squashfs \\\ + -p /EFI/%{efi_vendor} \\\ + ${GRUB_MODULES} \ %{4}./grub-mkimage -O %{1} -o %{3}.orig \\\ - -p /EFI/BOOT -d grub-core ${GRUB_MODULES} \\\ - --sbat %{4}./sbat.csv \ + -d grub-core \\\ + --sbat %{4}./sbat.csv \\\ + -m memdisk.squashfs \\\ + -p /EFI/BOOT \\\ + ${GRUB_MODULES} \ %{expand:%%define ___pesign_client_cert %{?___pesign_client_cert}%{!?___pesign_client_cert:%{__pesign_client_cert}}} \ %{?__pesign_client_cert:%{expand:%%define __pesign_client_cert %{___pesign_client_cert}}} \ %{expand:%%{pesign -s -i %%{2}.orig -o %%{2}.onesig -a %%{5} -c %%{6} -n %%{7}}} \ %{expand:%%{pesign -s -i %%{3}.orig -o %%{3}.onesig -a %%{5} -c %%{6} -n %%{7}}} \ -%{expand:%%define __pesign_client_cert %{name}-signer} \ +%{expand:%%define __pesign_client_cert grub2-signer} \ %{expand:%%{pesign -s -i %%{2}.onesig -o %%{2} -a %%{5} -c %%{6} -n %%{7}}} \ %{expand:%%{pesign -s -i %%{3}.onesig -o %%{3} -a %%{5} -c %%{6} -n %%{7}}} \ %{nil} -%else -%define mkimage() \ -%{4}./grub-mkimage -O %{1} -o %{2} \\\ - -p /EFI/%{efi_vendor} -d grub-core ${GRUB_MODULES} \ -%{4}./grub-mkimage -O %{1} -o %{3} \\\ - -p /EFI/BOOT -d grub-core ${GRUB_MODULES} \ +%endif + +%ifarch ppc64le +# RHEL signs, Fedora + ELN don't (but ELN defines rhel) +%if 0%{?fedora} || 0%{?eln} +%define ieee1275_mkimage() \ +mkdir -p memdisk/fonts \ +cp %{5}/unicode.pf2 memdisk/fonts \ +mksquashfs memdisk memdisk.squashfs -comp lzo \ +./grub-mkimage -O %{1} -o %{2} -p '/grub2' -d grub-core ${GRUB_MODULES} \ %{nil} +%else +%define ieee1275_mkimage() \ +mkdir -p memdisk/fonts \ +cp %{5}/unicode.pf2 memdisk/fonts \ +mksquashfs memdisk memdisk.squashfs -comp lzo \ +APPENDED_SIG_SIZE=0 \ +if [ -x /usr/bin/rpm-sign ]; then \ + touch empty.unsigned \ + rpm-sign --key %{4} \\\ + --lkmsign empty.unsigned \\\ + --output empty.signed \ + APPENDED_SIG_SIZE="$(stat -c '%s' empty.signed)" \ + rm empty.{un,}signed \ +fi \ +# FIXME: using this prefix is fragile, must be done properly \ +./grub-mkimage -O %{1} -o %{2}.orig \\\ + -d grub-core \\\ + -m memdisk.squashfs \\\ + -p '/grub2' \\\ + -x %{3} \\\ + --appended-signature-size ${APPENDED_SIG_SIZE} \\\ + ${GRUB_MODULES} \ +if [ -x /usr/bin/rpm-sign ]; then \ + truncate -s -${APPENDED_SIG_SIZE} %{2}.orig \ + rpm-sign --key %{4} \\\ + --lkmsign %{2}.orig \\\ + --output %{2} \ +else \ + mv %{2}.orig %{2} \ +fi \ +%{nil} +%endif %endif %define do_efi_build_images() \ -GRUB_MODULES=" all_video boot blscfg btrfs \\\ - cat configfile cryptodisk \\\ - echo efi_netfs efifwsetup efinet ext2 f2fs \\\ - fat font gcry_rijndael gcry_rsa gcry_serpent \\\ - gcry_sha256 gcry_twofish gcry_whirlpool \\\ - gfxmenu gfxterm gzio \\\ - halt hfsplus http increment iso9660 jpeg \\\ - loadenv loopback linux lvm lsefi lsefimmap luks \\\ - luks2 mdraid09 mdraid1x minicmd net \\\ - normal part_apple part_msdos part_gpt \\\ - password_pbkdf2 pgp png reboot \\\ - regexp search search_fs_uuid search_fs_file \\\ - search_label serial sleep syslinuxcfg test tftp \\\ - version video xfs zstd " \ +GRUB_MODULES+=%{grub_modules} \ GRUB_MODULES+=%{efi_modules} \ -%{expand:%%{mkimage %{1} %{2} %{3} %{4}}} \ +GRUB_MODULES+=%{platform_modules} \ +%{expand:%%{efi_mkimage %{1} %{2} %{3} %{4}}} \ +%{nil} + +%define do_ieee1275_build_images() \ +GRUB_MODULES+=%{grub_modules} \ +GRUB_MODULES+=%{platform_modules} \ +cd grub-%{1}-%{tarversion} \ +%{expand:%%ieee1275_mkimage %%{1} %%{2} %%{3} %%{4} ./ }\ +cd .. \ %{nil} %define do_primary_efi_build() \ @@ -451,8 +652,8 @@ cd grub-%{1}-%{tarversion} \ --with-platform=%{platform} \\\ --with-utils=host \\\ --target=%{_target_platform} \\\ - --with-grubdir=%{name} \\\ - --program-transform-name=s,grub,%{name}, \\\ + --with-grubdir=grub2 \\\ + --program-transform-name=s,grub,grub2, \\\ --disable-werror || ( cat config.log ; exit 1 ) \ git add . \ git commit -m "After legacy configure" \ @@ -468,8 +669,8 @@ cd grub-emu-%{tarversion} \ HOST_CPPFLAGS="-I$(pwd)" \\\ HOST_LDFLAGS="%{legacy_host_ldflags}" \\\ --with-platform=emu \\\ - --with-grubdir=%{name} \\\ - --program-transform-name=s,grub,%{name}, \\\ + --with-grubdir=grub2 \\\ + --program-transform-name=s,grub,grub2, \\\ --disable-werror || ( cat config.log ; exit 1 ) \ git add . \ git commit -m "After emu configure" \ @@ -479,6 +680,20 @@ make %{?_smp_mflags} -C grub-core \ cd .. \ %{nil} +%define do_xen_build() \ +cd grub-%{1}-%{tarversion} \ +%{expand:%%do_xen_configure %%{2} %%{3} %%{4}} \ +%do_xen_build_modules \ +cd .. \ +%{nil} + +%define do_xen_pvh_build() \ +cd grub-%{1}-%{tarversion} \ +%{expand:%%do_xen_pvh_configure %%{2} %%{3} %%{4}} \ +%do_xen_pvh_build_modules \ +cd .. \ +%{nil} + %define do_alt_efi_install() \ cd grub-%{1}-%{tarversion} \ install -d -m 755 $RPM_BUILD_ROOT/usr/lib/grub/%{grubaltefiarch}/ \ @@ -493,9 +708,10 @@ find . '(' -iname gdb_grub \\\ ')' \\\ -exec cp {} $RPM_BUILD_ROOT/usr/lib/grub/%{grubaltefiarch}/ \\\; \ find $RPM_BUILD_ROOT -type f -iname "*.mod*" -exec chmod a-x {} '\;' \ -install -m 700 %{2} $RPM_BUILD_ROOT%{efi_esp_dir}/%{2} \ -install -m 700 %{3} $RPM_BUILD_ROOT%{efi_esp_dir}/%{3} \ -%{expand:%%do_install_protected_file %{name}-%{alt_package_arch}} \ +install -d -m 0700 ${RPM_BUILD_ROOT}%{grub_efi_dir}/ \ +install -m 700 %{2} $RPM_BUILD_ROOT%{grub_efi_dir}/%{2} \ +install -m 700 %{3} $RPM_BUILD_ROOT%{grub_efi_dir}/%{3} \ +%{expand:%%do_install_protected_file grub2-%{alt_package_arch}} \ cd .. \ %{nil} @@ -509,18 +725,21 @@ if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ fi \ find $RPM_BUILD_ROOT -iname "*.module" -exec chmod a-x {} '\;' \ -ln -s ../boot/%{name}/grub.cfg \\\ - $RPM_BUILD_ROOT%{_sysconfdir}/%{name}-efi.cfg \ -install -m 700 %{2} $RPM_BUILD_ROOT%{efi_esp_dir}/%{2} \ -install -m 700 %{3} $RPM_BUILD_ROOT%{efi_esp_dir}/%{3} \ +ln -s ../boot/grub2/grub.cfg \\\ + $RPM_BUILD_ROOT%{_sysconfdir}/grub2-efi.cfg \ +install -d -m 0700 ${RPM_BUILD_ROOT}%{grub_efi_dir}/ \ +install -m 700 %{2} $RPM_BUILD_ROOT%{grub_efi_dir}/%{2} \ +install -m 700 %{3} $RPM_BUILD_ROOT%{grub_efi_dir}/%{3} \ %ifarch %{arm} \ install -D -m 700 %{2} $RPM_BUILD_ROOT%{efi_esp_boot}/BOOTARM.EFI \ %endif \ +install -D -m 700 %{SOURCE13} \\\ + ${RPM_BUILD_ROOT}/usr/bin/gen_grub_cfgstub \ install -D -m 700 unicode.pf2 \\\ - ${RPM_BUILD_ROOT}/boot/%{name}/fonts/unicode.pf2 \ -${RPM_BUILD_ROOT}/%{_bindir}/%{name}-editenv \\\ - ${RPM_BUILD_ROOT}/boot/%{name}/grubenv create \ -%{expand:%%do_install_protected_file %{name}-%{package_arch}} \ + ${RPM_BUILD_ROOT}/boot/grub2/fonts/unicode.pf2 \ +${RPM_BUILD_ROOT}/%{_bindir}/grub2-editenv \\\ + ${RPM_BUILD_ROOT}/boot/grub2/grubenv create \ +%{expand:%%do_install_protected_file grub2-%{package_arch}} \ cd .. \ %{nil} @@ -533,15 +752,30 @@ fi \ if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ fi \ -if [ -f $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/%{name}.chrp ]; then \ - mv $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/%{name}.chrp \\\ - $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/%{name}.chrp \ +%{expand:%ifarch ppc64le \ + install -m 700 %{grubelfname} $RPM_BUILD_ROOT/%{_libdir}/grub/%{1} \ +%endif} \ +if [ -f $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/grub2.chrp ]; then \ + mv $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/grub2.chrp \\\ + $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/grub.chrp \ fi \ if [ %{3} -eq 0 ]; then \ - ${RPM_BUILD_ROOT}/%{_bindir}/%{name}-editenv \\\ - ${RPM_BUILD_ROOT}/boot/%{name}/grubenv create \ + ${RPM_BUILD_ROOT}/%{_bindir}/grub2-editenv \\\ + ${RPM_BUILD_ROOT}/boot/grub2/grubenv create \ fi \ -%{expand:%%do_install_protected_file %{name}-%{legacy_package_arch}} \ +%{expand:%ifnarch ppc64le \ +mkdir pxe \ +./grub-mknetdir \\\ + --directory ./grub-core \\\ + --fonts="" \\\ + --locales="" \\\ + --themes="" \\\ + --modules="configfile gzio linux reboot test" \\\ + --net-directory=pxe \\\ + --subdir . \ +mv pxe/*/core.0 $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/ \ +%endif} \ +%{expand:%%do_install_protected_file grub2-%{legacy_package_arch}} \ cd .. \ %{nil} @@ -554,13 +788,39 @@ fi \ if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ fi \ -if [ -f $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/%{name}.chrp ]; then \ - mv $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/%{name}.chrp \\\ +if [ -f $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/grub2.chrp ]; then \ + mv $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/grub2.chrp \\\ $RPM_BUILD_ROOT/%{_libdir}/grub/%{1}/grub.chrp \ fi \ cd .. \ %{nil} +%define do_xen_install() \ +cd grub-%{1}-%{tarversion} \ +make DESTDIR=$RPM_BUILD_ROOT install \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub.info \ +fi \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ +fi \ +find $RPM_BUILD_ROOT -iname "*.module" -exec chmod a-x {} '\;' \ +cd .. \ +%{nil} + +%define do_xen_pvh_install() \ +cd grub-%{1}-%{tarversion} \ +make DESTDIR=$RPM_BUILD_ROOT install \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub.info \ +fi \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ +fi \ +find $RPM_BUILD_ROOT -iname "*.module" -exec chmod a-x {} '\;' \ +cd .. \ +%{nil} + %define do_common_install() \ install -d -m 0755 \\\ $RPM_BUILD_ROOT%{_datarootdir}/locale/en\@quot \\\ @@ -568,36 +828,44 @@ install -d -m 0755 \\\ $RPM_BUILD_ROOT%{_infodir}/ \ cp -a $RPM_BUILD_ROOT%{_datarootdir}/locale/en\@quot \\\ $RPM_BUILD_ROOT%{_datarootdir}/locale/en \ -cp docs/grub.info $RPM_BUILD_ROOT%{_infodir}/%{name}.info \ +cp docs/grub.info $RPM_BUILD_ROOT%{_infodir}/grub2.info \ cp docs/grub-dev.info \\\ - $RPM_BUILD_ROOT%{_infodir}/%{name}-dev.info \ + $RPM_BUILD_ROOT%{_infodir}/grub2-dev.info \ install -d -m 0700 ${RPM_BUILD_ROOT}%{efi_esp_dir}/ \ -install -d -m 0700 ${RPM_BUILD_ROOT}/boot/%{name}/ \ +install -d -m 0700 ${RPM_BUILD_ROOT}/boot/grub2/ \ install -d -m 0700 ${RPM_BUILD_ROOT}/boot/loader/entries \ -install -d -m 0700 ${RPM_BUILD_ROOT}/boot/%{name}/themes/system \ +install -d -m 0700 ${RPM_BUILD_ROOT}/boot/grub2/themes/system \ install -d -m 0700 ${RPM_BUILD_ROOT}%{_sysconfdir}/default \ install -d -m 0700 ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig \ touch ${RPM_BUILD_ROOT}%{_sysconfdir}/default/grub \ ln -sf ../default/grub \\\ ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/grub \ -touch ${RPM_BUILD_ROOT}/boot/%{name}/grub.cfg \ -ln -s ../boot/%{name}/grub.cfg \\\ - ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}.cfg \ +touch grub.cfg \ +install -m 0600 grub.cfg ${RPM_BUILD_ROOT}/boot/grub2/ \ +ln -s ../boot/grub2/grub.cfg \\\ + ${RPM_BUILD_ROOT}%{_sysconfdir}/grub2.cfg \ %{nil} %define define_legacy_variant_files() \ %{expand:%%files %{1}} \ %defattr(-,root,root,-) \ -%config(noreplace) %{_sysconfdir}/%{name}.cfg \ -%ghost %config(noreplace) /boot/%{name}/grub.cfg \ +%config(noreplace) %{_sysconfdir}/grub2.cfg \ +%ghost %config(noreplace) %attr(0600,root,root)/boot/grub2/grub.cfg \ %dir %attr(0700,root,root)/boot/loader/entries \ -%attr(0644,root,root) %config(noreplace) /etc/dnf/protected.d/%{name}-%{1}.conf \ +%attr(0644,root,root) %config(noreplace) /etc/dnf/protected.d/grub2-%{1}.conf \ +%ifarch ppc64le \ +%dir %{_libdir}/grub/%{2}/ \ +%{_libdir}/grub/%{2}/%{grubelfname} \ +%endif \ \ %{expand:%if 0%{?with_legacy_modules} \ %{expand:%%files %{1}-modules} \ %defattr(-,root,root) \ %dir %{_libdir}/grub/%{2}/ \ %{_libdir}/grub/%{2}/* \ +%ifarch ppc64le \ +%exclude %{_libdir}/grub/%{2}/%{grubelfname} \ +%endif \ %exclude %{_libdir}/grub/%{2}/*.module \ %exclude %{_libdir}/grub/%{2}/{boot,boot_hybrid,cdboot,diskboot,lzma_decompress,pxeboot}.image \ %exclude %{_libdir}/grub/%{2}/*.o \ @@ -609,18 +877,22 @@ ln -s ../boot/%{name}/grub.cfg \\\ %define define_efi_variant_files() \ %{expand:%%files %{1}} \ %defattr(-,root,root,-) \ -%config(noreplace) %{_sysconfdir}/%{name}.cfg \ -%config(noreplace) %{_sysconfdir}/%{name}-efi.cfg \ -%attr(0700,root,root)%{efi_esp_dir}/%{2} \ +%config(noreplace) %{_sysconfdir}/grub2.cfg \ +%config(noreplace) %{_sysconfdir}/grub2-efi.cfg \ +%ghost %attr(0700,root,root) %{efi_esp_dir}/%{2} \ +%dir %attr(0700,root,root) %{grub_efi_dir} \ +%attr(0700,root,root) %{grub_efi_dir}/%{2} \ %ifarch %{arm} \ -%attr(0700,root,root)%{efi_esp_boot}/BOOTARM.EFI \ +%attr(0700,root,root) %verify(not mtime) %{efi_esp_boot}/BOOTARM.EFI \ %endif \ -%attr(0700,root,root)/boot/%{name}/fonts \ +%attr(0700,root,root)/boot/grub2/fonts \ +%attr(0700,root,root)/usr/bin/gen_grub_cfgstub \ %dir %attr(0700,root,root)/boot/loader/entries \ -%ghost %config(noreplace) /boot/%{name}/grub.cfg \ +%ghost %config(noreplace) %attr(0600,root,root)/boot/grub2/grub.cfg \ %ghost %config(noreplace) %attr(0700,root,root)%{efi_esp_dir}/grub.cfg \ -%config(noreplace) %verify(not size mode md5 mtime) /boot/%{name}/grubenv \ -%attr(0644,root,root) %config(noreplace) /etc/dnf/protected.d/%{name}-%{1}.conf \ +%ghost %config(noreplace) %attr(0600,root,root)%{grub_efi_dir}/grub.cfg \ +%config(noreplace) %verify(not size mode md5 mtime) /boot/grub2/grubenv \ +%attr(0644,root,root) %config(noreplace) /etc/dnf/protected.d/grub2-%{1}.conf \ %{expand:%if 0%{?without_efi_modules} \ %exclude %{_libdir}/grub/%{6} \ %exclude %{_libdir}/grub/%{6}/* \ @@ -636,6 +908,23 @@ ln -s ../boot/%{name}/grub.cfg \\\ \ %{expand:%%files %{1}-cdboot} \ %defattr(-,root,root,-) \ -%attr(0700,root,root)%{efi_esp_dir}/%{3} \ -%attr(0700,root,root)/boot/%{name}/fonts \ +%ghost %attr(0700,root,root) %{efi_esp_dir}/%{3} \ +%attr(0700,root,root) %{grub_efi_dir}/%{3} \ +%attr(0700,root,root)/boot/grub2/fonts \ +%{nil} + +%define define_xen_variant_files() \ +%{expand:%%files %{1}-modules} \ +%defattr(-,root,root,-) \ +%dir %{_libdir}/grub/%{2}/ \ +%{_libdir}/grub/%{2}/* \ +%exclude %{_libdir}/grub/%{2}/*.module \ +%{nil} + +%define define_xen_pvh_variant_files() \ +%{expand:%%files %{1}-modules} \ +%defattr(-,root,root,-) \ +%dir %{_libdir}/grub/%{2}/ \ +%{_libdir}/grub/%{2}/* \ +%exclude %{_libdir}/grub/%{2}/*.module \ %{nil} diff --git a/grub.patches b/grub.patches index 92158946..67c06e16 100644 --- a/grub.patches +++ b/grub.patches @@ -1,215 +1,406 @@ Patch0001: 0001-Revert-templates-Fix-user-facing-typo-with-an-incorr.patch Patch0002: 0002-Revert-templates-Properly-disable-the-os-prober-by-d.patch Patch0003: 0003-Revert-templates-Disable-the-os-prober-by-default.patch -Patch0004: 0004-Add-support-for-Linux-EFI-stub-loading.patch -Patch0005: 0005-Rework-linux-command.patch -Patch0006: 0006-Rework-linux16-command.patch -Patch0007: 0007-Add-secureboot-support-on-efi-chainloader.patch -Patch0008: 0008-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch -Patch0009: 0009-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch -Patch0010: 0010-re-write-.gitignore.patch -Patch0011: 0011-IBM-client-architecture-CAS-reboot-support.patch -Patch0012: 0012-for-ppc-reset-console-display-attr-when-clear-screen.patch -Patch0013: 0013-Disable-GRUB-video-support-for-IBM-power-machines.patch -Patch0014: 0014-Move-bash-completion-script-922997.patch -Patch0015: 0015-Allow-fallback-to-include-entries-by-title-not-just-.patch -Patch0016: 0016-Make-exit-take-a-return-code.patch -Patch0017: 0017-Make-efi-machines-load-an-env-block-from-a-variable.patch -Patch0018: 0018-Migrate-PPC-from-Yaboot-to-Grub2.patch -Patch0019: 0019-Add-fw_path-variable-revised.patch -Patch0020: 0020-Pass-x-hex-hex-straight-through-unmolested.patch -Patch0021: 0021-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch -Patch0022: 0022-Add-devicetree-loading.patch -Patch0023: 0023-Don-t-write-messages-to-the-screen.patch -Patch0024: 0024-Don-t-print-GNU-GRUB-header.patch -Patch0025: 0025-Don-t-add-to-highlighted-row.patch -Patch0026: 0026-Message-string-cleanups.patch -Patch0027: 0027-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch -Patch0028: 0028-Use-the-correct-indentation-for-the-term-help-text.patch -Patch0029: 0029-Indent-menu-entries.patch -Patch0030: 0030-Fix-margins.patch -Patch0031: 0031-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch -Patch0032: 0032-Enable-pager-by-default.-985860.patch -Patch0033: 0033-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch -Patch0034: 0034-Don-t-say-GNU-Linux-in-generated-menus.patch -Patch0035: 0035-Don-t-draw-a-border-around-the-menu.patch -Patch0036: 0036-Use-the-standard-margin-for-the-timeout-string.patch -Patch0037: 0037-Add-.eh_frame-to-list-of-relocations-stripped.patch -Patch0038: 0038-Don-t-require-a-password-to-boot-entries-generated-b.patch -Patch0039: 0039-Don-t-emit-Booting-.-message.patch -Patch0040: 0040-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch -Patch0041: 0041-use-fw_path-prefix-when-fallback-searching-for-grub-.patch -Patch0042: 0042-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch -Patch0043: 0043-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch -Patch0044: 0044-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch -Patch0045: 0045-Try-prefix-if-fw_path-doesn-t-work.patch -Patch0046: 0046-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch -Patch0047: 0047-Make-grub2-mkconfig-construct-titles-that-look-like-.patch -Patch0048: 0048-Add-friendly-grub2-password-config-tool-985962.patch -Patch0049: 0049-tcp-add-window-scaling-support.patch -Patch0050: 0050-efinet-and-bootp-add-support-for-dhcpv6.patch -Patch0051: 0051-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch -Patch0052: 0052-bz1374141-fix-incorrect-mask-for-ppc64.patch -Patch0053: 0053-Make-grub_fatal-also-backtrace.patch -Patch0054: 0054-Fix-up-some-man-pages-rpmdiff-noticed.patch -Patch0055: 0055-Make-our-info-pages-say-grub2-where-appropriate.patch -Patch0056: 0056-macos-just-build-chainloader-entries-don-t-try-any-x.patch -Patch0057: 0057-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch -Patch0058: 0058-export-btrfs_subvol-and-btrfs_subvolid.patch -Patch0059: 0059-grub2-btrfs-03-follow_default.patch -Patch0060: 0060-grub2-btrfs-04-grub2-install.patch -Patch0061: 0061-grub2-btrfs-05-grub2-mkconfig.patch -Patch0062: 0062-grub2-btrfs-06-subvol-mount.patch -Patch0063: 0063-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch -Patch0064: 0064-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch -Patch0065: 0065-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch -Patch0066: 0066-Use-grub_efi_.-memory-helpers-where-reasonable.patch -Patch0067: 0067-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch -Patch0068: 0068-don-t-use-int-for-efi-status.patch -Patch0069: 0069-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch -Patch0070: 0070-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch -Patch0071: 0071-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch -Patch0072: 0072-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch -Patch0073: 0073-align-struct-efi_variable-better.patch -Patch0074: 0074-Add-BLS-support-to-grub-mkconfig.patch -Patch0075: 0075-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch -Patch0076: 0076-Add-linux-and-initrd-commands-for-grub-emu.patch -Patch0077: 0077-Add-grub2-switch-to-blscfg.patch -Patch0078: 0078-make-better-backtraces.patch -Patch0079: 0079-normal-don-t-draw-our-startup-message-if-debug-is-se.patch -Patch0080: 0080-Work-around-some-minor-include-path-weirdnesses.patch -Patch0081: 0081-Make-it-possible-to-enabled-build-id-sha1.patch -Patch0082: 0082-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch -Patch0083: 0083-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch -Patch0084: 0084-Fixup-for-newer-compiler.patch -Patch0085: 0085-Don-t-attempt-to-export-the-start-and-_start-symbols.patch -Patch0086: 0086-Fixup-for-newer-compiler.patch -Patch0087: 0087-Add-support-for-non-Ethernet-network-cards.patch -Patch0088: 0088-net-read-bracketed-ipv6-addrs-and-port-numbers.patch -Patch0089: 0089-bootp-New-net_bootp6-command.patch -Patch0090: 0090-efinet-UEFI-IPv6-PXE-support.patch -Patch0091: 0091-grub.texi-Add-net_bootp6-doument.patch -Patch0092: 0092-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch -Patch0093: 0093-efinet-Setting-network-from-UEFI-device-path.patch -Patch0094: 0094-efinet-Setting-DNS-server-from-UEFI-protocol.patch -Patch0095: 0095-Support-UEFI-networking-protocols.patch -Patch0096: 0096-AUDIT-0-http-boot-tracker-bug.patch -Patch0097: 0097-grub-editenv-Add-incr-command-to-increment-integer-v.patch -Patch0098: 0098-Add-auto-hide-menu-support.patch -Patch0099: 0099-Add-grub-set-bootflag-utility.patch -Patch0100: 0100-docs-Add-grub-boot-indeterminate.service-example.patch -Patch0101: 0101-gentpl-add-disable-support.patch -Patch0102: 0102-gentpl-add-pc-firmware-type.patch -Patch0103: 0103-efinet-also-use-the-firmware-acceleration-for-http.patch -Patch0104: 0104-efi-http-Make-root_url-reflect-the-protocol-hostname.patch -Patch0105: 0105-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch -Patch0106: 0106-module-verifier-make-it-possible-to-run-checkers-on-.patch -Patch0107: 0107-Rework-how-the-fdt-command-builds.patch -Patch0108: 0108-Disable-non-wordsize-allocations-on-arm.patch -Patch0109: 0109-Prepend-prefix-when-HTTP-path-is-relative.patch -Patch0110: 0110-Make-grub_error-more-verbose.patch -Patch0111: 0111-Make-reset-an-alias-for-the-reboot-command.patch -Patch0112: 0112-Add-a-version-command.patch -Patch0113: 0113-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch -Patch0114: 0114-arm-arm64-loader-Better-memory-allocation-and-error-.patch -Patch0115: 0115-Try-to-pick-better-locations-for-kernel-and-initrd.patch -Patch0116: 0116-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch -Patch0117: 0117-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch -Patch0118: 0118-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch -Patch0119: 0119-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch -Patch0120: 0120-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch -Patch0121: 0121-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch -Patch0122: 0122-Fix-getroot.c-s-trampolines.patch -Patch0123: 0123-Do-not-allow-stack-trampolines-anywhere.patch -Patch0124: 0124-Reimplement-boot_counter.patch -Patch0125: 0125-Fix-menu-entry-selection-based-on-ID-and-title.patch -Patch0126: 0126-Make-the-menu-entry-users-option-argument-to-be-opti.patch -Patch0127: 0127-Add-efi-export-env-and-efi-load-env-commands.patch -Patch0128: 0128-Make-it-possible-to-subtract-conditions-from-debug.patch -Patch0129: 0129-Export-all-variables-from-the-initial-context-when-c.patch -Patch0130: 0130-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch -Patch0131: 0131-Fix-systemctl-kexec-exit-status-check.patch -Patch0132: 0132-Print-grub-emu-linux-loader-messages-as-debug.patch -Patch0133: 0133-Don-t-assume-that-boot-commands-will-only-return-on-.patch -Patch0134: 0134-Fix-undefined-references-for-fdt-when-building-with-.patch -Patch0135: 0135-Do-better-in-bootstrap.conf.patch -Patch0136: 0136-Use-git-to-apply-gnulib-patches.patch -Patch0137: 0137-Fix-build-error-with-the-fdt-module-on-risc-v.patch -Patch0138: 0138-grub-set-bootflag-Update-comment-about-running-as-ro.patch -Patch0139: 0139-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch -Patch0140: 0140-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch -Patch0141: 0141-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch -Patch0142: 0142-chainloader-Define-machine-types-for-RISC-V.patch -Patch0143: 0143-Add-start-symbol-for-RISC-V.patch -Patch0144: 0144-bootstrap.conf-Force-autogen.sh-to-use-python3.patch -Patch0145: 0145-efi-http-Export-fw-http-_path-variables-to-make-them.patch -Patch0146: 0146-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch -Patch0147: 0147-efi-net-Allow-to-specify-a-port-number-in-addresses.patch -Patch0148: 0148-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch -Patch0149: 0149-efi-net-Print-a-debug-message-if-parsing-the-address.patch -Patch0150: 0150-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch -Patch0151: 0151-efi-Set-image-base-address-before-jumping-to-the-PE-.patch -Patch0152: 0152-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch -Patch0153: 0153-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch -Patch0154: 0154-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch -Patch0155: 0155-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch -Patch0156: 0156-efi-dhcp-fix-some-allocation-error-checking.patch -Patch0157: 0157-efi-http-fix-some-allocation-error-checking.patch -Patch0158: 0158-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch -Patch0159: 0159-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch -Patch0160: 0160-linuxefi-fail-kernel-validation-without-shim-protoco.patch -Patch0161: 0161-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch -Patch0162: 0162-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch -Patch0163: 0163-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch -Patch0164: 0164-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch -Patch0165: 0165-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch -Patch0166: 0166-Add-systemd-integration-scripts-to-make-systemctl-re.patch -Patch0167: 0167-systemd-integration.sh-Also-set-old-menu_show_once-g.patch -Patch0168: 0168-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch -Patch0169: 0169-grub-install-disable-support-for-EFI-platforms.patch -Patch0170: 0170-New-with-debug-timestamps-configure-flag-to-prepend-.patch -Patch0171: 0171-Added-debug-statements-to-grub_disk_open-and-grub_di.patch -Patch0172: 0172-Introduce-function-grub_debug_is_enabled-void-return.patch -Patch0173: 0173-Don-t-clear-screen-when-debugging-is-enabled.patch -Patch0174: 0174-grub_file_-instrumentation-new-file-debug-tag.patch -Patch0175: 0175-ieee1275-Avoiding-many-unecessary-open-close.patch -Patch0176: 0176-ieee1275-powerpc-implements-fibre-channel-discovery-.patch -Patch0177: 0177-ieee1275-powerpc-enables-device-mapper-discovery.patch -Patch0178: 0178-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch -Patch0179: 0179-Add-suport-for-signing-grub-with-an-appended-signatu.patch -Patch0180: 0180-docs-grub-Document-signing-grub-under-UEFI.patch -Patch0181: 0181-docs-grub-Document-signing-grub-with-an-appended-sig.patch -Patch0182: 0182-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch -Patch0183: 0183-pgp-factor-out-rsa_pad.patch -Patch0184: 0184-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch -Patch0185: 0185-posix_wrap-tweaks-in-preparation-for-libtasn1.patch -Patch0186: 0186-libtasn1-import-libtasn1-4.16.0.patch -Patch0187: 0187-libtasn1-disable-code-not-needed-in-grub.patch -Patch0188: 0188-libtasn1-changes-for-grub-compatibility.patch -Patch0189: 0189-libtasn1-compile-into-asn1-module.patch -Patch0190: 0190-test_asn1-test-module-for-libtasn1.patch -Patch0191: 0191-grub-install-support-embedding-x509-certificates.patch -Patch0192: 0192-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch -Patch0193: 0193-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch -Patch0194: 0194-appended-signatures-support-verifying-appended-signa.patch -Patch0195: 0195-appended-signatures-verification-tests.patch -Patch0196: 0196-appended-signatures-documentation.patch -Patch0197: 0197-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch -Patch0198: 0198-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch -Patch0199: 0199-ieee1275-claim-more-memory.patch -Patch0200: 0200-ieee1275-request-memory-with-ibm-client-architecture.patch -Patch0201: 0201-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch -Patch0202: 0202-ieee1275-ofdisk-retry-on-open-failure.patch -Patch0203: 0203-01_menu_auto_hide.in-fix-a-then-than-typo.patch -Patch0204: 0204-Fix-disabling-grub-rpm-sort.patch -Patch0205: 0205-Don-t-check-for-rpmvercmp-in-librpm.patch -Patch0206: 0206-Allow-chainloading-EFI-apps-from-loop-mounts.patch -Patch0207: 0207-efinet-Add-DHCP-proxy-support.patch -Patch0208: 0208-fs-ext2-Ignore-checksum-seed-incompat-feature.patch -Patch0209: 0209-Don-t-update-the-cmdline-when-generating-legacy-menu.patch -Patch0210: 0210-Suppress-gettext-error-message.patch -Patch0211: 0211-grub-boot-success.timer-Only-run-if-not-in-a-contain.patch -Patch0212: 0212-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch -Patch0213: 0213-Remove-outdated-URL-for-BLS-document.patch -Patch0214: 0214-templates-Check-for-EFI-at-runtime-instead-of-config.patch -Patch0215: 0215-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.patch +Patch0004: 0004-Rework-linux-command.patch +Patch0005: 0005-Rework-linux16-command.patch +Patch0006: 0006-re-write-.gitignore.patch +Patch0007: 0007-IBM-client-architecture-CAS-reboot-support.patch +Patch0008: 0008-for-ppc-reset-console-display-attr-when-clear-screen.patch +Patch0009: 0009-Disable-GRUB-video-support-for-IBM-power-machines.patch +Patch0010: 0010-Move-bash-completion-script-922997.patch +Patch0011: 0011-Allow-fallback-to-include-entries-by-title-not-just-.patch +Patch0012: 0012-Make-exit-take-a-return-code.patch +Patch0013: 0013-Make-efi-machines-load-an-env-block-from-a-variable.patch +Patch0014: 0014-Migrate-PPC-from-Yaboot-to-Grub2.patch +Patch0015: 0015-Add-fw_path-variable-revised.patch +Patch0016: 0016-Pass-x-hex-hex-straight-through-unmolested.patch +Patch0017: 0017-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch +Patch0018: 0018-Add-devicetree-loading.patch +Patch0019: 0019-Enable-pager-by-default.-985860.patch +Patch0020: 0020-Don-t-say-GNU-Linux-in-generated-menus.patch +Patch0021: 0021-Add-.eh_frame-to-list-of-relocations-stripped.patch +Patch0022: 0022-Don-t-require-a-password-to-boot-entries-generated-b.patch +Patch0023: 0023-use-fw_path-prefix-when-fallback-searching-for-grub-.patch +Patch0024: 0024-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch +Patch0025: 0025-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch +Patch0026: 0026-Try-prefix-if-fw_path-doesn-t-work.patch +Patch0027: 0027-Make-grub2-mkconfig-construct-titles-that-look-like-.patch +Patch0028: 0028-Add-friendly-grub2-password-config-tool-985962.patch +Patch0029: 0029-tcp-add-window-scaling-support.patch +Patch0030: 0030-efinet-and-bootp-add-support-for-dhcpv6.patch +Patch0031: 0031-bootp-New-net_bootp6-command.patch +Patch0032: 0032-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch +Patch0033: 0033-Make-grub_fatal-also-backtrace.patch +Patch0034: 0034-Make-our-info-pages-say-grub2-where-appropriate.patch +Patch0035: 0035-macos-just-build-chainloader-entries-don-t-try-any-x.patch +Patch0036: 0036-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch +Patch0037: 0037-btrfs-fix-a-bad-null-check.patch +Patch0038: 0038-export-btrfs_subvol-and-btrfs_subvolid.patch +Patch0039: 0039-grub2-btrfs-03-follow_default.patch +Patch0040: 0040-grub2-btrfs-04-grub2-install.patch +Patch0041: 0041-grub2-btrfs-05-grub2-mkconfig.patch +Patch0042: 0042-grub2-btrfs-06-subvol-mount.patch +Patch0043: 0043-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch +Patch0044: 0044-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch +Patch0045: 0045-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch +Patch0046: 0046-Use-grub_efi_.-memory-helpers-where-reasonable.patch +Patch0047: 0047-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch +Patch0048: 0048-don-t-use-int-for-efi-status.patch +Patch0049: 0049-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch +Patch0050: 0050-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch +Patch0051: 0051-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch +Patch0052: 0052-align-struct-efi_variable-better.patch +Patch0053: 0053-Add-BLS-support-to-grub-mkconfig.patch +Patch0054: 0054-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch +Patch0055: 0055-Add-grub2-switch-to-blscfg.patch +Patch0056: 0056-normal-don-t-draw-our-startup-message-if-debug-is-se.patch +Patch0057: 0057-Work-around-some-minor-include-path-weirdnesses.patch +Patch0058: 0058-Make-it-possible-to-enabled-build-id-sha1.patch +Patch0059: 0059-make-better-backtraces.patch +Patch0060: 0060-Fixup-for-newer-compiler.patch +Patch0061: 0061-Don-t-attempt-to-export-the-start-and-_start-symbols.patch +Patch0062: 0062-Fixup-for-newer-compiler.patch +Patch0063: 0063-Add-support-for-non-Ethernet-network-cards.patch +Patch0064: 0064-efinet-UEFI-IPv6-PXE-support.patch +Patch0065: 0065-grub.texi-Add-net_bootp6-doument.patch +Patch0066: 0066-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch +Patch0067: 0067-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch +Patch0068: 0068-efinet-Setting-network-from-UEFI-device-path.patch +Patch0069: 0069-efinet-Setting-DNS-server-from-UEFI-protocol.patch +Patch0070: 0070-Support-UEFI-networking-protocols.patch +Patch0071: 0071-AUDIT-0-http-boot-tracker-bug.patch +Patch0072: 0072-grub-editenv-Add-incr-command-to-increment-integer-v.patch +Patch0073: 0073-Add-auto-hide-menu-support.patch +Patch0074: 0074-Add-grub-set-bootflag-utility.patch +Patch0075: 0075-docs-Add-grub-boot-indeterminate.service-example.patch +Patch0076: 0076-gentpl-add-disable-support.patch +Patch0077: 0077-gentpl-add-pc-firmware-type.patch +Patch0078: 0078-efinet-also-use-the-firmware-acceleration-for-http.patch +Patch0079: 0079-efi-http-Make-root_url-reflect-the-protocol-hostname.patch +Patch0080: 0080-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch +Patch0081: 0081-Rework-how-the-fdt-command-builds.patch +Patch0082: 0082-Disable-non-wordsize-allocations-on-arm.patch +Patch0083: 0083-Prepend-prefix-when-HTTP-path-is-relative.patch +Patch0084: 0084-Make-grub_error-more-verbose.patch +Patch0085: 0085-Make-reset-an-alias-for-the-reboot-command.patch +Patch0086: 0086-Add-a-version-command.patch +Patch0087: 0087-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch +Patch0088: 0088-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch +Patch0089: 0089-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch +Patch0090: 0090-Fix-getroot.c-s-trampolines.patch +Patch0091: 0091-Do-not-allow-stack-trampolines-anywhere.patch +Patch0092: 0092-Reimplement-boot_counter.patch +Patch0093: 0093-Fix-menu-entry-selection-based-on-ID-and-title.patch +Patch0094: 0094-Make-the-menu-entry-users-option-argument-to-be-opti.patch +Patch0095: 0095-Add-efi-export-env-and-efi-load-env-commands.patch +Patch0096: 0096-Export-all-variables-from-the-initial-context-when-c.patch +Patch0097: 0097-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch +Patch0098: 0098-Don-t-assume-that-boot-commands-will-only-return-on-.patch +Patch0099: 0099-grub-set-bootflag-Update-comment-about-running-as-ro.patch +Patch0100: 0100-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch +Patch0101: 0101-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch +Patch0102: 0102-Add-start-symbol-for-RISC-V.patch +Patch0103: 0103-bootstrap.conf-Force-autogen.sh-to-use-python3.patch +Patch0104: 0104-efi-http-Export-fw-http-_path-variables-to-make-them.patch +Patch0105: 0105-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch +Patch0106: 0106-efi-net-Allow-to-specify-a-port-number-in-addresses.patch +Patch0107: 0107-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch +Patch0108: 0108-efi-net-Print-a-debug-message-if-parsing-the-address.patch +Patch0109: 0109-kern-term-Also-accept-F8-as-a-user-interrupt-key.patch +Patch0110: 0110-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch +Patch0111: 0111-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch +Patch0112: 0112-efi-dhcp-fix-some-allocation-error-checking.patch +Patch0113: 0113-efi-http-fix-some-allocation-error-checking.patch +Patch0114: 0114-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch +Patch0115: 0115-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch +Patch0116: 0116-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch +Patch0117: 0117-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch +Patch0118: 0118-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch +Patch0119: 0119-Add-systemd-integration-scripts-to-make-systemctl-re.patch +Patch0120: 0120-systemd-integration.sh-Also-set-old-menu_show_once-g.patch +Patch0121: 0121-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch +Patch0122: 0122-grub-install-disable-support-for-EFI-platforms.patch +Patch0123: 0123-New-with-debug-timestamps-configure-flag-to-prepend-.patch +Patch0124: 0124-Added-debug-statements-to-grub_disk_open-and-grub_di.patch +Patch0125: 0125-Introduce-function-grub_debug_is_enabled-void-return.patch +Patch0126: 0126-Don-t-clear-screen-when-debugging-is-enabled.patch +Patch0127: 0127-grub_file_-instrumentation-new-file-debug-tag.patch +Patch0128: 0128-ieee1275-Avoiding-many-unecessary-open-close.patch +Patch0129: 0129-ieee1275-powerpc-implements-fibre-channel-discovery-.patch +Patch0130: 0130-ieee1275-powerpc-enables-device-mapper-discovery.patch +Patch0131: 0131-Add-at_keyboard_fallback_set-var-to-force-the-set-ma.patch +Patch0132: 0132-Add-suport-for-signing-grub-with-an-appended-signatu.patch +Patch0133: 0133-docs-grub-Document-signing-grub-under-UEFI.patch +Patch0134: 0134-docs-grub-Document-signing-grub-with-an-appended-sig.patch +Patch0135: 0135-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch +Patch0136: 0136-pgp-factor-out-rsa_pad.patch +Patch0137: 0137-crypto-move-storage-for-grub_crypto_pk_-to-crypto.c.patch +Patch0138: 0138-posix_wrap-tweaks-in-preparation-for-libtasn1.patch +Patch0139: 0139-libtasn1-import-libtasn1-4.16.0.patch +Patch0140: 0140-libtasn1-disable-code-not-needed-in-grub.patch +Patch0141: 0141-libtasn1-changes-for-grub-compatibility.patch +Patch0142: 0142-libtasn1-compile-into-asn1-module.patch +Patch0143: 0143-test_asn1-test-module-for-libtasn1.patch +Patch0144: 0144-grub-install-support-embedding-x509-certificates.patch +Patch0145: 0145-appended-signatures-import-GNUTLS-s-ASN.1-descriptio.patch +Patch0146: 0146-appended-signatures-parse-PKCS-7-signedData-and-X.50.patch +Patch0147: 0147-appended-signatures-support-verifying-appended-signa.patch +Patch0148: 0148-appended-signatures-verification-tests.patch +Patch0149: 0149-appended-signatures-documentation.patch +Patch0150: 0150-ieee1275-enter-lockdown-based-on-ibm-secure-boot.patch +Patch0151: 0151-ieee1275-drop-HEAP_MAX_ADDR-HEAP_MIN_SIZE.patch +Patch0152: 0152-appendedsig-x509-Also-handle-the-Extended-Key-Usage-.patch +Patch0153: 0153-ieee1275-ofdisk-retry-on-open-failure.patch +Patch0154: 0154-efinet-Add-DHCP-proxy-support.patch +Patch0155: 0155-Don-t-update-the-cmdline-when-generating-legacy-menu.patch +Patch0156: 0156-Suppress-gettext-error-message.patch +Patch0157: 0157-grub-set-password-Always-use-boot-grub2-user.cfg-as-.patch +Patch0158: 0158-normal-main-Discover-the-device-to-read-the-config-f.patch +Patch0159: 0159-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch +Patch0160: 0160-powerpc-ieee1275-load-grub-at-4MB-not-2MB.patch +Patch0161: 0161-Add-Fedora-location-of-DejaVu-SANS-font.patch +Patch0162: 0162-efi-new-connectefi-command.patch +Patch0163: 0163-powerpc-prefix-detection-support-device-names-with-c.patch +Patch0164: 0164-make-ofdisk_retries-optional.patch +Patch0165: 0165-misc-Make-grub_min-and-grub_max-more-resilient.patch +Patch0166: 0166-ReiserFS-switch-to-using-grub_min-grub_max.patch +Patch0167: 0167-misc-make-grub_boot_time-also-call-grub_dprintf-boot.patch +Patch0168: 0168-modules-make-.module_license-read-only.patch +Patch0169: 0169-modules-strip-.llvm_addrsig-sections-and-similar.patch +Patch0170: 0170-modules-Don-t-allocate-space-for-non-allocable-secti.patch +Patch0171: 0171-modules-load-module-sections-at-page-aligned-address.patch +Patch0172: 0172-nx-add-memory-attribute-get-set-API.patch +Patch0173: 0173-nx-set-page-permissions-for-loaded-modules.patch +Patch0174: 0174-nx-set-the-nx-compatible-flag-in-EFI-grub-images.patch +Patch0175: 0175-grub_fs_probe-dprint-errors-from-filesystems.patch +Patch0176: 0176-Make-debug-file-show-which-file-filters-get-run.patch +Patch0177: 0177-BLS-create-etc-kernel-cmdline-during-mkconfig.patch +Patch0178: 0178-squish-don-t-dup-rhgb-quiet-check-mtimes.patch +Patch0179: 0179-squish-give-up-on-rhgb-quiet.patch +Patch0180: 0180-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch +Patch0181: 0181-blscfg-Don-t-root-device-in-emu-builds.patch +Patch0182: 0182-ppc64le-signed-boot-media-changes.patch +Patch0183: 0183-core-Fix-several-implicit-function-declarations.patch +Patch0184: 0184-ieee1275-request-memory-with-ibm-client-architecture.patch +Patch0185: 0185-hostdisk-work-around-proc-not-reporting-size.patch +Patch0186: 0186-blscfg-check-for-mounted-boot-in-emu.patch +Patch0187: 0187-grub_dl_set_mem_attrs-fix-format-string.patch +Patch0188: 0188-grub_dl_set_mem_attrs-add-self-check-for-the-tramp-G.patch +Patch0189: 0189-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch +Patch0190: 0190-emu-Add-switch-root-to-grub-emu.patch +Patch0191: 0191-util-Enable-default-kernel-for-updates.patch +Patch0192: 0192-efi-http-change-uint32_t-to-uintn_t.patch +Patch0193: 0193-Add-Install-section-to-aux-systemd-units.patch +Patch0194: 0194-Fix-missing-include-in-ofdisk.c.patch +Patch0195: 0195-add-flag-to-only-search-root-dev.patch +Patch0196: 0196-cryptdisk-fix-incorrect-sign-comparison.patch +Patch0197: 0197-grub-install-fix-a-sign-comparison-error.patch +Patch0198: 0198-grub-mount-work-around-bad-integer-comparison.patch +Patch0199: 0199-power-Fix-use-after-free-in-get_slave_from_dm.patch +Patch0200: 0200-Fix-some-sign-comparison-errors.patch +Patch0201: 0201-normal-Fix-a-discarded-const.patch +Patch0202: 0202-at_keyboard-mark-grub_keyboard_controller_write-unus.patch +Patch0203: 0203-Fix-another-minor-sign-comparison-error.patch +Patch0204: 0204-Track-explicit-module-dependencies-in-Makefile.core..patch +Patch0205: 0205-Revert-mm-Assert-that-we-preserve-header-vs-region-a.patch +Patch0206: 0206-make-use-the-_CPU-variety-of-build-flags-for-PROGRAM.patch +Patch0207: 0207-Work-around-extra_deps.lst-issue.patch +Patch0208: 0208-include-proper-attribute-for-an-EFI-API-call-definit.patch +Patch0209: 0209-cast-grub_error-status-parameter.patch +Patch0210: 0210-remove-unused-varible.patch +Patch0211: 0211-cast-grub_net_bootp_packet-pointer.patch +Patch0212: 0212-libtasn1-fix-string-overflow-warning.patch +Patch0213: 0213-Add-support-for-Linux-EFI-stub-loading.patch +Patch0214: 0214-fix-i386_pc-on-legacycfg-module.patch +Patch0215: 0215-Add-secureboot-support-on-efi-chainloader.patch +Patch0216: 0216-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch +Patch0217: 0217-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch +Patch0218: 0218-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch +Patch0219: 0219-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch +Patch0220: 0220-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch +Patch0221: 0221-Try-to-pick-better-locations-for-kernel-and-initrd.patch +Patch0222: 0222-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch +Patch0223: 0223-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch +Patch0224: 0224-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch +Patch0225: 0225-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch +Patch0226: 0226-efi-Set-image-base-address-before-jumping-to-the-PE-.patch +Patch0227: 0227-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch +Patch0228: 0228-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch +Patch0229: 0229-linuxefi-fail-kernel-validation-without-shim-protoco.patch +Patch0230: 0230-Allow-chainloading-EFI-apps-from-loop-mounts.patch +Patch0231: 0231-grub-core-loader-i386-efi-linux.c-do-not-validate-ke.patch +Patch0232: 0232-grub-core-loader-efi-chainloader.c-do-not-validate-c.patch +Patch0233: 0233-grub-core-loader-efi-linux.c-drop-now-unused-grub_li.patch +Patch0234: 0234-loader-efi-chainloader-grub_load_and_start_image-doe.patch +Patch0235: 0235-loader-efi-chainloader-simplify-the-loader-state.patch +Patch0236: 0236-loader-efi-chainloader-Use-grub_loader_set_ex.patch +Patch0237: 0237-loader-i386-efi-linux-Avoid-a-use-after-free-in-the-.patch +Patch0238: 0238-loader-i386-efi-linux-Use-grub_loader_set_ex.patch +Patch0239: 0239-loader-i386-efi-linux-Fix-a-memory-leak-in-the-initr.patch +Patch0240: 0240-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_CODE-ins.patch +Patch0241: 0241-efi-use-enumerated-array-positions-for-our-allocatio.patch +Patch0242: 0242-efi-split-allocation-policy-for-kernel-vs-initrd-mem.patch +Patch0243: 0243-efi-allocate-the-initrd-within-the-bounds-expressed-.patch +Patch0244: 0244-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch +Patch0245: 0245-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch +Patch0246: 0246-grub-install-on-EFI-if-forced.patch +Patch0247: 0247-Remove-Install-section-from-aux-systemd-units.patch +Patch0248: 0248-chainloader-remove-device-path-debug-message.patch +Patch0249: 0249-grub-set-bootflag-Conservative-partial-fix-for-CVE-2.patch +Patch0250: 0250-grub-set-bootflag-More-complete-fix-for-CVE-2024-104.patch +Patch0251: 0251-grub-set-bootflag-Exit-calmly-when-not-running-as-ro.patch +Patch0252: 0252-Makefile.core.def-fix-linux-module.patch +Patch0253: 0253-Add-support-for-Linux-EFI-stub-loading-on-arm-archit.patch +Patch0254: 0254-arm-arm64-loader-Better-memory-allocation-and-error-.patch +Patch0255: 0255-arm64-Fix-EFI-loader-kernel-image-allocation.patch +Patch0256: 0256-pe-add-the-DOS-header-struct-and-fix-some-bad-naming.patch +Patch0257: 0257-Correct-BSS-zeroing-on-aarch64.patch +Patch0258: 0258-arm64-Use-proper-memory-type-for-kernel-allocation.patch +Patch0259: 0259-normal-Remove-grub_env_set-prefix-in-grub_try_normal.patch +Patch0260: 0260-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch +Patch0261: 0261-Ignore-warnings-for-incompatible-types.patch +Patch0262: 0262-cmd-search-Rework-of-CVE-2023-4001-fix.patch +Patch0263: 0263-loader-efi-linux.c-read-the-kernel-image-before-head.patch +Patch0264: 0264-nx-set-attrs-in-our-kernel-loaders.patch +Patch0265: 0265-efi-Provide-wrappers-for-load_image-start_image.patch +Patch0266: 0266-efi-Disallow-fallback-to-legacy-Linux-loader-when-sh.patch +Patch0267: 0267-Set-non-executable-stack-sections-on-EFI-assembly-fi.patch +Patch0268: 0268-grub-mkconfig.in-turn-off-executable-owner-bit.patch +Patch0269: 0269-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch +Patch0270: 0270-grub2-mkconfig-Ensure-grub-cfg-stub-is-not-overwritt.patch +Patch0271: 0271-grub2-mkconfig-Simplify-os_name-detection.patch +Patch0272: 0272-grub-mkconfig-Remove-check-for-mount-point-for-grub-.patch +Patch0273: 0273-efi-api.h-include-missing-__grub_efi_api-macros-on-E.patch +Patch0274: 0274-grub-core-net-arp.c-fix-variable-name.patch +Patch0275: 0275-load-EFI-commands-inside-test-expressions.patch +Patch0276: 0276-efi-loader-Check-if-NX-is-required-in-grub_efi_linux.patch +Patch0277: 0277-Stop-grub.efi-from-always-printing-dynamic_load_symb.patch +Patch0278: 0278-acpi-Fix-out-of-bounds-access-in-grub_acpi_xsdt_find.patch +Patch0279: 0279-cmd-search-Fix-a-possible-NULL-ptr-dereference.patch +Patch0280: 0280-Enable-building-blscfg-module-on-xen-and-xen_pvh.patch +Patch0281: 0281-loader-efi-Fix-RISC-V-build.patch +Patch0282: 0282-kern-riscv-efi-init-Use-time-register-in-grub_efi_ge.patch +Patch0283: 0283-Use-medany-instead-of-large-model-for-RISCV.patch +Patch0284: 0284-fs-xfs-Fix-large-extent-counters-incompat-feature-su.patch +Patch0285: 0285-term-nns8250-spcr-return-if-redirection-is-disabled.patch +Patch0286: 0286-commands-legacycfg-Avoid-closing-file-twice.patch +Patch0287: 0287-disk-ahci.c-remove-conditional-operator-for-endtime.patch +Patch0288: 0288-commands-bli-Fix-crash-in-get_part_uuid.patch +Patch0289: 0289-misc-Implement-grub_strlcpy.patch +Patch0290: 0290-fs-ufs-Fix-a-heap-OOB-write.patch +Patch0291: 0291-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch +Patch0292: 0292-fs-tar-Initialize-name-in-grub_cpio_find_file.patch +Patch0293: 0293-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch +Patch0294: 0294-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch +Patch0295: 0295-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch +Patch0296: 0296-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch +Patch0297: 0297-fs-iso9660-Fix-invalid-free.patch +Patch0298: 0298-fs-jfs-Fix-OOB-read-in-jfs_getent.patch +Patch0299: 0299-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch +Patch0300: 0300-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch +Patch0301: 0301-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch +Patch0302: 0302-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch +Patch0303: 0303-fs-ntfs-Fix-out-of-bounds-read.patch +Patch0304: 0304-fs-ntfs-Track-the-end-of-the-MFT-attribute-buffer.patch +Patch0305: 0305-fs-ntfs-Use-a-helper-function-to-access-attributes.patch +Patch0307: 0307-fs-xfs-Fix-out-of-bounds-read.patch +Patch0308: 0308-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch +Patch0309: 0309-kern-file-Ensure-file-data-is-set.patch +Patch0310: 0310-kern-file-Implement-filesystem-reference-counting.patch +Patch0311: 0311-cli_lock-Add-build-option-to-block-command-line-inte.patch +Patch0312: 0312-disk-cryptodisk-Require-authentication-after-TPM-unl.patch +Patch0313: 0313-disk-loopback-Reference-tracking-for-the-loopback.patch +Patch0314: 0314-kern-disk-Limit-recursion-depth.patch +Patch0315: 0315-kern-partition-Limit-recursion-in-part_iterate.patch +Patch0316: 0316-script-execute-Limit-the-recursion-depth.patch +Patch0317: 0317-net-Unregister-net_default_ip-and-net_default_mac-va.patch +Patch0318: 0318-net-Remove-variables-hooks-when-interface-is-unregis.patch +Patch0319: 0319-net-Fix-OOB-write-in-grub_net_search_config_file.patch +Patch0320: 0320-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch +Patch0321: 0321-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch +Patch0322: 0322-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch +Patch0323: 0323-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch +Patch0324: 0324-commands-extcmd-Missing-check-for-failed-allocation.patch +Patch0325: 0325-commands-ls-Fix-NULL-dereference.patch +Patch0326: 0326-commands-pgp-Unregister-the-check_signatures-hooks-o.patch +Patch0327: 0327-normal-Remove-variables-hooks-on-module-unload.patch +Patch0328: 0328-gettext-Remove-variables-hooks-on-module-unload.patch +Patch0329: 0329-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch +Patch0330: 0330-gettext-Integer-overflow-leads-to-heap-OOB-write.patch +Patch0331: 0331-commands-read-Fix-an-integer-overflow-when-supplying.patch +Patch0332: 0332-commands-test-Stack-overflow-due-to-unlimited-recurs.patch +Patch0333: 0333-commands-minicmd-Block-the-dump-command-in-lockdown-.patch +Patch0334: 0334-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch +Patch0335: 0335-commands-hexdump-Disable-memory-reading-in-lockdown-.patch +Patch0336: 0336-fs-bfs-Disable-under-lockdown.patch +Patch0337: 0337-fs-Disable-many-filesystems-under-lockdown.patch +Patch0338: 0338-disk-Use-safe-math-macros-to-prevent-overflows.patch +Patch0339: 0339-disk-Prevent-overflows-when-allocating-memory-for-ar.patch +Patch0340: 0340-disk-Check-if-returned-pointer-for-allocated-memory-.patch +Patch0341: 0341-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch +Patch0342: 0342-fs-Use-safe-math-macros-to-prevent-overflows.patch +Patch0343: 0343-fs-Prevent-overflows-when-allocating-memory-for-arra.patch +Patch0344: 0344-fs-Prevent-overflows-when-assigning-returned-values-.patch +Patch0345: 0345-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch +Patch0346: 0346-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch +Patch0347: 0347-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch +Patch0348: 0348-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch +Patch0349: 0349-net-Use-safe-math-macros-to-prevent-overflows.patch +Patch0350: 0350-net-Prevent-overflows-when-allocating-memory-for-arr.patch +Patch0351: 0351-net-Check-if-returned-pointer-for-allocated-memory-i.patch +Patch0352: 0352-fs-sfs-Check-if-allocated-memory-is-NULL.patch +Patch0353: 0353-script-execute-Fix-potential-underflow-and-NULL-dere.patch +Patch0354: 0354-osdep-unix-getroot-Fix-potential-underflow.patch +Patch0355: 0355-misc-Ensure-consistent-overflow-error-messages.patch +Patch0356: 0356-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch +Patch0357: 0357-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch +Patch0358: 0358-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch +Patch0359: 0359-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch +Patch0360: 0360-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch +Patch0361: 0361-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch +Patch0362: 0362-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch +Patch0363: 0363-powerpc-increase-MIN-RMA-size-for-CAS-negotiation.patch +Patch0364: 0364-script-execute-Don-t-let-trailing-blank-lines-determ.patch +Patch0365: 0365-normal-menu-Check-return-code-of-the-script-when-exe.patch +Patch0366: 0366-ieee1275-ofnet-Fix-grub_malloc-removed-after-added-s.patch +Patch0367: 0367-grub-mkimage-Create-new-ELF-note-for-SBAT.patch +Patch0368: 0368-grub-mkimage-Add-SBAT-metadata-into-ELF-note-for-Pow.patch +Patch0369: 0369-10_linux.in-escape-kernel-option-characters-properly.patch +Patch0370: 0370-blscfg-check-if-variable-is-escaped-before-consideri.patch +Patch0371: 0371-kern-rescue_reader-Block-the-rescue-mode-until-the-C.patch +Patch0372: 0372-commands-search-Introduce-the-cryptodisk-only-argume.patch +Patch0373: 0373-disk-diskfilter-Introduce-the-cryptocheck-command.patch +Patch0374: 0374-commands-search-Add-the-diskfilter-support.patch +Patch0375: 0375-docs-Document-available-crypto-disks-checks.patch +Patch0376: 0376-disk-cryptodisk-Add-the-erase-secrets-function.patch +Patch0377: 0377-disk-cryptodisk-Wipe-the-passphrase-from-memory.patch +Patch0378: 0378-cryptocheck-Add-quiet-option.patch +Patch0379: 0379-loader-efi-chainloader-Fix-double-free.patch +Patch0380: 0380-loader-efi-chainloader-Fix-null-pointer-dereference.patch +Patch0381: 0381-osdep-linux-getroot-Detect-DDF-container-similar-to-.patch +Patch0382: 0382-Set-correctly-the-memory-attributes-for-the-kernel-P.patch +Patch0383: 0383-Include-function-name-on-debug-print-function.patch +Patch0384: 0384-kern-misc-Implement-grub_strtok.patch +Patch0385: 0385-blsuki-Add-blscfg-command-to-parse-Boot-Loader-Speci.patch +Patch0386: 0386-util-misc.c-Change-offset-type-for-grub_util_write_i.patch +Patch0387: 0387-blsuki-Check-for-mounted-boot-in-emu.patch +Patch0388: 0388-blsuki-Add-uki-command-to-load-Unified-Kernel-Image-.patch +Patch0389: 0389-posix_wrap-Tweaks-in-preparation-for-libtasn1.patch +Patch0390: 0390-blsuki-do-not-register-blscfg-command.patch +Patch0391: 0391-misc-add-z-length-modifier-support.patch +Patch0392: 0392-tests-add-z-modifier-printf-tests.patch +Patch0393: 0393-util-grub-editenv-add-fs_envblk-open-helper.patch +Patch0394: 0394-util-grub-editenv-add-fs_envblk-write-helper.patch +Patch0395: 0395-util-grub-editenv-wire-set_variables-to-optional-fs_.patch +Patch0396: 0396-util-grub-editenv-wire-unset_variables-to-optional-f.patch +Patch0397: 0397-util-grub-editenv-wire-list_variables-to-optional-fs.patch +Patch0398: 0398-util-grub-editenv-add-probe-call-for-external-envblk.patch +Patch0399: 0399-btrfs-add-environment-block-to-reserved-header-area.patch +Patch0400: 0400-00_header.in-wire-grub.cfg-to-use-env_block-when-pre.patch +Patch0401: 0401-btrfs-update-doc-link-for-bootloader-support.patch +Patch0402: 0402-docs-add-Btrfs-env-block-and-special-env-vars.patch +Patch0403: 0403-kern-fs-Honour-file-read_hook-in-grub_fs_blocklist_r.patch +Patch0404: 0404-util-grub.d-00_header.in-Prefer-dev-instead-of-root-.patch +Patch0405: 0405-grub.d-Support-the-external-environment-block-for-au.patch +Patch0406: 0406-grub-editenv-Make-automatic-hidden-menu-and-boot-cou.patch +Patch0407: 0407-Increase-EFI-max-allocation-to-max-usable-address.patch diff --git a/grub2.spec b/grub2.spec index 907cae88..8f73768c 100644 --- a/grub2.spec +++ b/grub2.spec @@ -4,19 +4,22 @@ %global _lto_cflags %{nil} %undefine _hardened_build +%undefine _package_note_file -%global tarversion 2.06 +%global tarversion 2.12 %undefine _missing_build_ids_terminate_build %global _configure_gnuconfig_hack 0 -%global gnulibversion fixes +# It's a commit from their gnulib's development tree. They don't do releases, +# and it is *awful* to update this. +%global gnulibversion 9f48fb992a3d7e96610c4ce8be969cff2d61a01b Name: grub2 Epoch: 1 -Version: 2.06 -Release: 3%{?dist} +Version: 2.12 +Release: 50%{?dist} Summary: Bootloader with support for Linux, Multiboot and more -License: GPLv3+ +License: GPL-3.0-or-later URL: http://www.gnu.org/software/grub/ Obsoletes: grub < 1:0.98 Source0: https://ftp.gnu.org/gnu/grub/grub-%{tarversion}.tar.xz @@ -32,36 +35,53 @@ Source9: strtoull_test.c Source10: 20-grub.install Source11: grub.patches Source12: sbat.csv.in +Source13: gen_grub_cfgstub +Source14: 95-set-boot-entry.install %include %{SOURCE1} -BuildRequires: gcc efi-srpm-macros -BuildRequires: flex bison binutils python3 -BuildRequires: ncurses-devel xz-devel bzip2-devel -BuildRequires: freetype-devel libusb-devel -BuildRequires: fuse-devel -BuildRequires: rpm-devel rpm-libs -BuildRequires: autoconf automake device-mapper-devel -BuildRequires: freetype-devel gettext-devel git -BuildRequires: texinfo +BuildRequires: autoconf +BuildRequires: automake +BuildRequires: binutils +BuildRequires: bison +BuildRequires: bzip2-devel BuildRequires: dejavu-sans-fonts +BuildRequires: device-mapper-devel +BuildRequires: efi-srpm-macros +BuildRequires: flex +BuildRequires: freetype-devel +BuildRequires: freetype-devel +BuildRequires: fuse3-devel +BuildRequires: gcc +BuildRequires: gettext-devel +BuildRequires: git BuildRequires: help2man -# For %%_userunitdir macro -BuildRequires: systemd +BuildRequires: ncurses-devel +BuildRequires: python3 +BuildRequires: rpm-devel +BuildRequires: rpm-libs +BuildRequires: squashfs-tools +BuildRequires: texinfo +BuildRequires: xz-devel + +# For %%_userunitdir and %%systemd_* macros +BuildRequires: systemd-rpm-macros + %ifarch %{efi_arch} BuildRequires: pesign >= 0.99-8 %endif + %if %{?_with_ccache: 1}%{?!_with_ccache: 0} BuildRequires: ccache %endif -ExcludeArch: s390 s390x -Obsoletes: %{name} <= %{evr} +ExcludeArch: s390 s390x %{ix86} +Obsoletes: grub2 <= %{evr} %if 0%{with_legacy_arch} -Requires: %{name}-%{legacy_package_arch} = %{evr} +Requires: grub2-%{legacy_package_arch} = %{evr} %else -Requires: %{name}-%{package_arch} = %{evr} +Requires: grub2-%{package_arch} = %{evr} %endif %global desc \ @@ -81,7 +101,9 @@ hardware devices.\ Summary: grub2 common layout BuildArch: noarch Conflicts: grubby < 8.40-18 -Requires(post): util-linux +Requires(posttrans): util-linux-core +Requires(posttrans): coreutils +Requires(posttrans): grep %description common This package provides some directories which are required by various grub2 @@ -89,11 +111,12 @@ subpackages. %package tools Summary: Support tools for GRUB. -Obsoletes: %{name}-tools < %{evr} -Requires: %{name}-common = %{epoch}:%{version}-%{release} -Requires: gettext os-prober which file +Requires: grub2-common = %{epoch}:%{version}-%{release} +Requires: gettext-runtime os-prober file Requires(pre): dracut -Requires(post): dracut +Requires(pre): grep +Requires(pre): sed +%{?systemd_requires} %description tools %{desc} @@ -102,9 +125,8 @@ This subpackage provides tools for support of all platforms. %ifarch x86_64 %package tools-efi Summary: Support tools for GRUB. -Requires: gettext os-prober which file -Requires: %{name}-common = %{epoch}:%{version}-%{release} -Obsoletes: %{name}-tools < %{evr} +Requires: gettext-runtime os-prober file +Requires: grub2-common = %{epoch}:%{version}-%{release} %description tools-efi %{desc} @@ -113,9 +135,8 @@ This subpackage provides tools for support of EFI platforms. %package tools-minimal Summary: Support tools for GRUB. -Requires: gettext -Requires: %{name}-common = %{epoch}:%{version}-%{release} -Obsoletes: %{name}-tools < %{evr} +Requires: gettext-runtime +Requires: grub2-common = %{epoch}:%{version}-%{release} %description tools-minimal %{desc} @@ -123,10 +144,10 @@ This subpackage provides tools for support of all platforms. %package tools-extra Summary: Support tools for GRUB. -Requires: gettext os-prober which file -Requires: %{name}-tools-minimal = %{epoch}:%{version}-%{release} -Requires: %{name}-common = %{epoch}:%{version}-%{release} -Obsoletes: %{name}-tools < %{evr} +Requires: gettext-runtime os-prober file +Requires: grub2-tools-minimal = %{epoch}:%{version}-%{release} +Requires: grub2-common = %{epoch}:%{version}-%{release} +Requires: mtools %description tools-extra %{desc} @@ -141,11 +162,17 @@ This subpackage provides tools for support of all platforms. %if 0%{with_legacy_arch} %{expand:%define_legacy_variant %%{legacy_package_arch}} %endif +%if 0%{with_xen_arch} +%{expand:%define_xen_variant %%{xen_package_arch} -o} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%define_xen_pvh_variant %%{xen_pvh_package_arch} -o} +%endif %if 0%{with_emu_arch} %package emu Summary: GRUB user-space emulation. -Requires: %{name}-tools-minimal = %{epoch}:%{version}-%{release} +Requires: grub2-tools-minimal = %{epoch}:%{version}-%{release} %description emu %{desc} @@ -153,7 +180,7 @@ This subpackage provides the GRUB user-space emulation support of all platforms. %package emu-modules Summary: GRUB user-space emulation modules. -Requires: %{name}-tools-minimal = %{epoch}:%{version}-%{release} +Requires: grub2-tools-minimal = %{epoch}:%{version}-%{release} %description emu-modules %{desc} @@ -188,6 +215,22 @@ grep -A100000 '# stuff "make" creates' .gitignore > grub-emu-%{tarversion}/.giti cp %{SOURCE4} grub-emu-%{tarversion}/unifont.pcf.gz git add grub-emu-%{tarversion} %endif +%if 0%{with_xen_arch} +mkdir grub-%{grubxenarch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grubxenarch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grubxenarch}-%{tarversion}/unifont.pcf.gz +sed -e "s,@@VERSION@@,%{version},g" -e "s,@@VERSION_RELEASE@@,%{version}-%{release},g" \ + %{SOURCE12} > grub-%{grubxenarch}-%{tarversion}/sbat.csv +git add grub-%{grubxenarch}-%{tarversion} +%endif +%if 0%{with_xen_pvh_arch} +mkdir grub-%{grubxenpvharch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grubxenpvharch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grubxenpvharch}-%{tarversion}/unifont.pcf.gz +sed -e "s,@@VERSION@@,%{version},g" -e "s,@@VERSION_RELEASE@@,%{version}-%{release},g" \ + %{SOURCE12} > grub-%{grubxenpvharch}-%{tarversion}/sbat.csv +git add grub-%{grubxenpvharch}-%{tarversion} +%endif git commit -m "After making subdirs" %build @@ -203,6 +246,15 @@ git commit -m "After making subdirs" %if 0%{with_emu_arch} %{expand:%do_emu_build} %endif +%if 0%{with_xen_arch} +%{expand:%do_xen_build %%{grubxenarch} %%{_target_platform} %%{xen_target_cflags} %%{xen_host_cflags}} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%do_xen_pvh_build %%{grubxenpvharch} %%{_target_platform} %%{xen_pvh_target_cflags} %%{xen_pvh_host_cflags}} +%endif +%ifarch ppc64le +%{expand:%do_ieee1275_build_images %%{grublegacyarch} %{grubelfname} %{sb_cer} %{sb_key}} +%endif makeinfo --info --no-split -I docs -o docs/grub-dev.info \ docs/grub-dev.texi makeinfo --info --no-split -I docs -o docs/grub.info \ @@ -229,36 +281,40 @@ rm -fr $RPM_BUILD_ROOT %if 0%{with_emu_arch} %{expand:%do_emu_install %%{package_arch}} %endif -rm -f $RPM_BUILD_ROOT%{_infodir}/dir -ln -s %{name}-set-password ${RPM_BUILD_ROOT}/%{_sbindir}/%{name}-setpassword -echo '.so man8/%{name}-set-password.8' > ${RPM_BUILD_ROOT}/%{_datadir}/man/man8/%{name}-setpassword.8 -%ifnarch x86_64 -rm -vf ${RPM_BUILD_ROOT}/%{_bindir}/%{name}-render-label -rm -vf ${RPM_BUILD_ROOT}/%{_sbindir}/%{name}-bios-setup -rm -vf ${RPM_BUILD_ROOT}/%{_sbindir}/%{name}-macbless +%if 0%{with_xen_arch} +%{expand:%do_xen_install %%{grubxenarch}} %endif -%{expand:%%do_install_protected_file %{name}-tools-minimal} +%if 0%{with_xen_pvh_arch} +%{expand:%do_xen_pvh_install %%{grubxenpvharch}} +%endif +rm -f $RPM_BUILD_ROOT%{_infodir}/dir +ln -s grub2-set-password ${RPM_BUILD_ROOT}/%{_sbindir}/grub2-setpassword +echo '.so man8/grub2-set-password.8' > ${RPM_BUILD_ROOT}/%{_datadir}/man/man8/grub2-setpassword.8 +%ifnarch x86_64 +rm -vf ${RPM_BUILD_ROOT}/%{_bindir}/grub2-render-label +rm -vf ${RPM_BUILD_ROOT}/%{_sbindir}/grub2-bios-setup +rm -vf ${RPM_BUILD_ROOT}/%{_sbindir}/grub2-macbless +%endif +%{expand:%%do_install_protected_file grub2-tools-minimal} %find_lang grub # Install kernel-install scripts install -d -m 0755 %{buildroot}%{_prefix}/lib/kernel/install.d/ install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE10} +install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE14} install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE3} install -d -m 0755 %{buildroot}%{_sysconfdir}/kernel/install.d/ # Install systemd user service to set the boot_success flag install -D -m 0755 -t %{buildroot}%{_userunitdir} \ docs/grub-boot-success.{timer,service} -install -d -m 0755 %{buildroot}%{_userunitdir}/timers.target.wants -ln -s ../grub-boot-success.timer \ - %{buildroot}%{_userunitdir}/timers.target.wants # Install systemd system-update unit to set boot_indeterminate for offline-upd install -D -m 0755 -t %{buildroot}%{_unitdir} docs/grub-boot-indeterminate.service install -d -m 0755 %{buildroot}%{_unitdir}/system-update.target.wants install -d -m 0755 %{buildroot}%{_unitdir}/reboot.target.wants ln -s ../grub-boot-indeterminate.service \ %{buildroot}%{_unitdir}/system-update.target.wants -ln -s ../%{name}-systemd-integration.service \ +ln -s ../grub2-systemd-integration.service \ %{buildroot}%{_unitdir}/reboot.target.wants # Don't run debuginfo on all the grub modules and whatnot; it just @@ -268,8 +324,9 @@ ln -s ../%{name}-systemd-integration.service \ %global dip RPM_BUILD_ROOT=%{finddebugroot} %{__debug_install_post} %define __debug_install_post ( \ mkdir -p %{finddebugroot}/usr \ - mv ${RPM_BUILD_ROOT}/usr/bin %{finddebugroot}/usr/bin \ - mv ${RPM_BUILD_ROOT}/usr/sbin %{finddebugroot}/usr/sbin \ + mv %{buildroot}/usr/bin %{finddebugroot}/usr/bin \ + [ "%{_sbindir}" != "%{_bindir}" ] && \\\ + mv %{buildroot}/usr/sbin %{finddebugroot}/usr/sbin \ %{dip} \ install -m 0755 -d %{buildroot}/usr/lib/ %{buildroot}/usr/src/ \ cp -al %{finddebugroot}/usr/lib/debug/ \\\ @@ -277,15 +334,16 @@ ln -s ../%{name}-systemd-integration.service \ cp -al %{finddebugroot}/usr/src/debug/ \\\ %{buildroot}/usr/src/debug/ ) \ mv %{finddebugroot}/usr/bin %{buildroot}/usr/bin \ - mv %{finddebugroot}/usr/sbin %{buildroot}/usr/sbin \ + [ "%{_sbindir}" != "%{_bindir}" ] && \\\ + mv %{finddebugroot}/usr/sbin %{buildroot}/usr/sbin \ %{nil} %undefine buildsubdir %pre tools -if [ -f /boot/%{name}/user.cfg ]; then - if grep -q '^GRUB_PASSWORD=' /boot/%{name}/user.cfg ; then - sed -i 's/^GRUB_PASSWORD=/GRUB2_PASSWORD=/' /boot/%{name}/user.cfg +if [ -f /boot/grub2/user.cfg ]; then + if grep -q '^GRUB_PASSWORD=' /boot/grub2/user.cfg ; then + sed -i 's/^GRUB_PASSWORD=/GRUB2_PASSWORD=/' /boot/grub2/user.cfg fi elif [ -f %{efi_esp_dir}/user.cfg ]; then if grep -q '^GRUB_PASSWORD=' %{efi_esp_dir}/user.cfg ; then @@ -301,71 +359,95 @@ elif [ -f /etc/grub.d/01_users ] && \ sed 's/^password_pbkdf2 root \(.*\)$/GRUB2_PASSWORD=\1/' \ > %{efi_esp_dir}/user.cfg fi - if [ -f /boot/%{name}/grub.cfg ]; then - install -m 0600 /dev/null /boot/%{name}/user.cfg - chmod 0600 /boot/%{name}/user.cfg + if [ -f /boot/grub2/grub.cfg ]; then + install -m 0600 /dev/null /boot/grub2/user.cfg + chmod 0600 /boot/grub2/user.cfg grep '^password_pbkdf2 root' /etc/grub.d/01_users | \ sed 's/^password_pbkdf2 root \(.*\)$/GRUB2_PASSWORD=\1/' \ - > /boot/%{name}/user.cfg + > /boot/grub2/user.cfg fi fi +# ensure we exit 0 +: + +%post tools +%systemd_user_post grub-boot-success.timer + +%preun tools +%systemd_user_preun grub-boot-success.timer + +%postun tools +%systemd_user_postun_with_restart grub-boot-success.timer + +%triggerpostun tools -- grub2-tools < 1:2.06-107 +# grub-boot-success.timer was moved from a hard symlink under /lib/systemd +# to a preset, apply the preset when upgrading from pre-preset versions +/usr/lib/systemd/systemd-update-helper install-user-units grub-boot-success.timer %posttrans common set -eu -EFI_HOME=%{efi_esp_dir} -GRUB_HOME=/boot/%{name} +EFI_HOME=%{grub_efi_dir} +GRUB_HOME=/boot/grub2 ESP_PATH=/boot/efi if ! mountpoint -q ${ESP_PATH}; then exit 0 # no ESP mounted, nothing to do fi -if test ! -f ${EFI_HOME}/grub.cfg; then - # there's no config in ESP, create one - grub2-mkconfig -o ${EFI_HOME}/grub.cfg +if test ! -f ${GRUB_HOME}/grub.cfg; then + # there's no config in GRUB home, create one + grub2-mkconfig -o ${GRUB_HOME}/grub.cfg +else + GRUB_CFG_MODE=$(stat --format="%a" ${GRUB_HOME}/grub.cfg) + if ! test "${GRUB_CFG_MODE}" = "600"; then + # when upgrading from <=2.06-126 to newer versions, the grub config stub + # may have different mode than 0600, so set the latter if this is the case + chmod 0600 ${GRUB_HOME}/grub.cfg + fi fi -if grep -q "configfile" ${EFI_HOME}/grub.cfg; then - exit 0 # already unified, nothing to do +if test -f ${EFI_HOME}/grub.cfg; then + if (((grep -q "configfile" ${EFI_HOME}/grub.cfg && grep -q "root-dev-only" ${EFI_HOME}/grub.cfg) || grep -q "source" ${EFI_HOME}/grub.cfg) && ! grep -q "# It is automatically generated by grub2-mkconfig using templates" ${EFI_HOME}/grub.cfg); then + exit 0 #Already unified + fi fi # create a stub grub2 config in EFI -BOOT_UUID=$(%{name}-probe --target=fs_uuid ${GRUB_HOME}) -GRUB_DIR=$(%{name}-mkrelpath ${GRUB_HOME}) - -cat << EOF > ${EFI_HOME}/grub.cfg.stb -search --no-floppy --fs-uuid --set=dev ${BOOT_UUID} -set prefix=(\$dev)${GRUB_DIR} -export \$prefix -configfile \$prefix/grub.cfg -EOF +gen_grub_cfgstub $GRUB_HOME $EFI_HOME || : if test -f ${EFI_HOME}/grubenv; then cp -a ${EFI_HOME}/grubenv ${EFI_HOME}/grubenv.rpmsave mv --force ${EFI_HOME}/grubenv ${GRUB_HOME}/grubenv fi -cp -a ${EFI_HOME}/grub.cfg ${EFI_HOME}/grub.cfg.rpmsave -cp -a ${EFI_HOME}/grub.cfg ${GRUB_HOME}/ -mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg +%if 0%{with_efi_arch} +%posttrans efi-%{efiarch} +set -eu + +# On image mode, bootupd takes care of installing bootloader updates to the ESP +if [[ ! -e "/run/ostree-booted" ]]; then + cp -a %{grub_efi_dir}/. %{efi_esp_dir} || : +fi + +%endif %files common -f grub.lang %dir %{_libdir}/grub/ %dir %{_datarootdir}/grub/ %attr(0700,root,root) %dir %{_sysconfdir}/grub.d %{_prefix}/lib/kernel/install.d/20-grub.install +%{_prefix}/lib/kernel/install.d/95-set-boot-entry.install %{_prefix}/lib/kernel/install.d/99-grub-mkconfig.install %dir %{_datarootdir}/grub %exclude %{_datarootdir}/grub/* -%dir /boot/%{name} -%dir /boot/%{name}/themes/ -%dir /boot/%{name}/themes/system -%attr(0700,root,root) %dir /boot/%{name} -%exclude /boot/%{name}/* -%dir %attr(0700,root,root) %{efi_esp_dir} -%exclude %{efi_esp_dir}/* -%ghost %config(noreplace) %verify(not size mode md5 mtime) /boot/%{name}/grubenv +%dir /boot/grub2 +%dir /boot/grub2/themes/ +%dir /boot/grub2/themes/system +%attr(0700,root,root) %dir /boot/grub2 +%exclude /boot/grub2/* +%exclude %{grub_efi_dir}/* +%ghost %config(noreplace) %verify(not size mode md5 mtime) /boot/grub2/grubenv %license COPYING %doc THANKS %doc docs/grub.html @@ -373,30 +455,30 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %doc docs/font_char_metrics.png %files tools-minimal -%{_sbindir}/%{name}-get-kernel-settings -%{_sbindir}/%{name}-probe -%attr(4755, root, root) %{_sbindir}/%{name}-set-bootflag -%{_sbindir}/%{name}-set-default -%{_sbindir}/%{name}-set*password -%{_bindir}/%{name}-editenv -%{_bindir}/%{name}-mkpasswd-pbkdf2 -%{_bindir}/%{name}-mount -%attr(0644,root,root) %config(noreplace) /etc/dnf/protected.d/%{name}-tools-minimal.conf +%{_sbindir}/grub2-get-kernel-settings +%{_sbindir}/grub2-probe +%attr(4755, root, root) %{_sbindir}/grub2-set-bootflag +%{_sbindir}/grub2-set-default +%{_sbindir}/grub2-set*password +%{_bindir}/grub2-editenv +%{_bindir}/grub2-mkpasswd-pbkdf2 +%{_bindir}/grub2-mount +%attr(0644,root,root) %config(noreplace) /etc/dnf/protected.d/grub2-tools-minimal.conf -%{_datadir}/man/man3/%{name}-get-kernel-settings* -%{_datadir}/man/man8/%{name}-set-default* -%{_datadir}/man/man8/%{name}-set*password* -%{_datadir}/man/man1/%{name}-editenv* -%{_datadir}/man/man1/%{name}-mkpasswd-* +%{_datadir}/man/man3/grub2-get-kernel-settings* +%{_datadir}/man/man8/grub2-set-default* +%{_datadir}/man/man8/grub2-set*password* +%{_datadir}/man/man1/grub2-editenv* +%{_datadir}/man/man1/grub2-mkpasswd-* %ifarch x86_64 %files tools-efi -%{_bindir}/%{name}-glue-efi -%{_bindir}/%{name}-render-label -%{_sbindir}/%{name}-macbless -%{_datadir}/man/man1/%{name}-glue-efi* -%{_datadir}/man/man1/%{name}-render-label* -%{_datadir}/man/man8/%{name}-macbless* +%{_bindir}/grub2-glue-efi +%{_bindir}/grub2-render-label +%{_sbindir}/grub2-macbless +%{_datadir}/man/man1/grub2-glue-efi* +%{_datadir}/man/man1/grub2-render-label* +%{_datadir}/man/man8/grub2-macbless* %endif %files tools @@ -405,101 +487,98 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %{_sysconfdir}/grub.d/README %{_userunitdir}/grub-boot-success.timer %{_userunitdir}/grub-boot-success.service -%{_userunitdir}/timers.target.wants %{_unitdir}/grub-boot-indeterminate.service %{_unitdir}/system-update.target.wants -%{_unitdir}/%{name}-systemd-integration.service +%{_unitdir}/grub2-systemd-integration.service %{_unitdir}/reboot.target.wants %{_unitdir}/systemd-logind.service.d -%{_infodir}/%{name}* +%{_infodir}/grub2* %{_datarootdir}/grub/* -%{_sbindir}/%{name}-install +%{_sbindir}/grub2-install %exclude %{_datarootdir}/grub/themes %exclude %{_datarootdir}/grub/*.h %{_datarootdir}/bash-completion/completions/grub -%{_sbindir}/%{name}-mkconfig -%{_sbindir}/%{name}-switch-to-blscfg -%{_sbindir}/%{name}-rpm-sort -%{_sbindir}/%{name}-reboot -%{_bindir}/%{name}-file -%{_bindir}/%{name}-menulst2cfg -%{_bindir}/%{name}-mkimage -%{_bindir}/%{name}-mkrelpath -%{_bindir}/%{name}-script-check -%{_libexecdir}/%{name} +%{_sbindir}/grub2-mkconfig +%{_sbindir}/grub2-switch-to-blscfg +%{_sbindir}/grub2-reboot +%{_bindir}/grub2-file +%{_bindir}/grub2-menulst2cfg +%{_bindir}/grub2-mkimage +%{_bindir}/grub2-mkrelpath +%{_bindir}/grub2-script-check +%{_libexecdir}/grub2 %{_datadir}/man/man?/* # exclude man pages from tools-extra -%exclude %{_datadir}/man/man8/%{name}-sparc64-setup* -%exclude %{_datadir}/man/man1/%{name}-fstest* -%exclude %{_datadir}/man/man1/%{name}-glue-efi* -%exclude %{_datadir}/man/man1/%{name}-kbdcomp* -%exclude %{_datadir}/man/man1/%{name}-mkfont* -%exclude %{_datadir}/man/man1/%{name}-mklayout* -%exclude %{_datadir}/man/man1/%{name}-mknetdir* -%exclude %{_datadir}/man/man1/%{name}-mkrescue* -%exclude %{_datadir}/man/man1/%{name}-mkstandalone* -%exclude %{_datadir}/man/man1/%{name}-syslinux2cfg* +%exclude %{_datadir}/man/man8/grub2-sparc64-setup* +%exclude %{_datadir}/man/man1/grub2-fstest* +%exclude %{_datadir}/man/man1/grub2-glue-efi* +%exclude %{_datadir}/man/man1/grub2-kbdcomp* +%exclude %{_datadir}/man/man1/grub2-mkfont* +%exclude %{_datadir}/man/man1/grub2-mklayout* +%exclude %{_datadir}/man/man1/grub2-mknetdir* +%exclude %{_datadir}/man/man1/grub2-mkrescue* +%exclude %{_datadir}/man/man1/grub2-mkstandalone* +%exclude %{_datadir}/man/man1/grub2-syslinux2cfg* # exclude man pages from tools-minimal -%exclude %{_datadir}/man/man3/%{name}-get-kernel-settings* -%exclude %{_datadir}/man/man8/%{name}-set-default* -%exclude %{_datadir}/man/man8/%{name}-set*password* -%exclude %{_datadir}/man/man1/%{name}-editenv* -%exclude %{_datadir}/man/man1/%{name}-mkpasswd-* -%exclude %{_datadir}/man/man8/%{name}-macbless* -%exclude %{_datadir}/man/man1/%{name}-render-label* +%exclude %{_datadir}/man/man3/grub2-get-kernel-settings* +%exclude %{_datadir}/man/man8/grub2-set-default* +%exclude %{_datadir}/man/man8/grub2-set*password* +%exclude %{_datadir}/man/man1/grub2-editenv* +%exclude %{_datadir}/man/man1/grub2-mkpasswd-* +%exclude %{_datadir}/man/man8/grub2-macbless* +%exclude %{_datadir}/man/man1/grub2-render-label* %if %{with_legacy_arch} -%{_sbindir}/%{name}-install %ifarch x86_64 -%{_sbindir}/%{name}-bios-setup +%{_sbindir}/grub2-bios-setup %else -%exclude %{_sbindir}/%{name}-bios-setup -%exclude %{_datadir}/man/man8/%{name}-bios-setup* +%exclude %{_sbindir}/grub2-bios-setup +%exclude %{_datadir}/man/man8/grub2-bios-setup* %endif %ifarch %{sparc} -%{_sbindir}/%{name}-sparc64-setup +%{_sbindir}/grub2-sparc64-setup %else -%exclude %{_sbindir}/%{name}-sparc64-setup -%exclude %{_datadir}/man/man8/%{name}-sparc64-setup* +%exclude %{_sbindir}/grub2-sparc64-setup +%exclude %{_datadir}/man/man8/grub2-sparc64-setup* %endif %ifarch %{sparc} ppc ppc64 ppc64le -%{_sbindir}/%{name}-ofpathname +%{_sbindir}/grub2-ofpathname %else -%exclude %{_sbindir}/%{name}-ofpathname -%exclude %{_datadir}/man/man8/%{name}-ofpathname* +%exclude %{_sbindir}/grub2-ofpathname +%exclude %{_datadir}/man/man8/grub2-ofpathname* %endif %endif %files tools-extra -%{_bindir}/%{name}-fstest -%{_bindir}/%{name}-kbdcomp -%{_bindir}/%{name}-mkfont -%{_bindir}/%{name}-mklayout -%{_bindir}/%{name}-mknetdir +%{_bindir}/grub2-fstest +%{_bindir}/grub2-kbdcomp +%{_bindir}/grub2-mkfont +%{_bindir}/grub2-mklayout +%{_bindir}/grub2-mknetdir %ifnarch %{sparc} -%{_bindir}/%{name}-mkrescue -%{_datadir}/man/man1/%{name}-mkrescue* +%{_bindir}/grub2-mkrescue +%{_datadir}/man/man1/grub2-mkrescue* %else -%exclude %{_datadir}/man/man1/%{name}-mkrescue* +%exclude %{_datadir}/man/man1/grub2-mkrescue* %endif -%{_bindir}/%{name}-mkstandalone -%{_bindir}/%{name}-syslinux2cfg +%{_bindir}/grub2-mkstandalone +%{_bindir}/grub2-syslinux2cfg %{_sysconfdir}/sysconfig/grub -%{_datadir}/man/man1/%{name}-fstest* -%{_datadir}/man/man1/%{name}-kbdcomp* -%{_datadir}/man/man1/%{name}-mkfont* -%{_datadir}/man/man1/%{name}-mklayout* -%{_datadir}/man/man1/%{name}-mknetdir* -%{_datadir}/man/man1/%{name}-mkstandalone* -%{_datadir}/man/man1/%{name}-syslinux2cfg* -%exclude %{_bindir}/%{name}-glue-efi -%exclude %{_sbindir}/%{name}-sparc64-setup -%exclude %{_sbindir}/%{name}-ofpathname -%exclude %{_datadir}/man/man1/%{name}-glue-efi* -%exclude %{_datadir}/man/man8/%{name}-ofpathname* -%exclude %{_datadir}/man/man8/%{name}-sparc64-setup* +%{_datadir}/man/man1/grub2-fstest* +%{_datadir}/man/man1/grub2-kbdcomp* +%{_datadir}/man/man1/grub2-mkfont* +%{_datadir}/man/man1/grub2-mklayout* +%{_datadir}/man/man1/grub2-mknetdir* +%{_datadir}/man/man1/grub2-mkstandalone* +%{_datadir}/man/man1/grub2-syslinux2cfg* +%exclude %{_bindir}/grub2-glue-efi +%exclude %{_sbindir}/grub2-sparc64-setup +%exclude %{_sbindir}/grub2-ofpathname +%exclude %{_datadir}/man/man1/grub2-glue-efi* +%exclude %{_datadir}/man/man8/grub2-ofpathname* +%exclude %{_datadir}/man/man8/grub2-sparc64-setup* %exclude %{_datarootdir}/grub/themes/starfield %if 0%{with_efi_arch} @@ -511,11 +590,17 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %if 0%{with_legacy_arch} %{expand:%define_legacy_variant_files %%{legacy_package_arch} %%{grublegacyarch}} %endif +%if 0%{with_xen_arch} +%{expand:%define_xen_variant_files %%{xen_package_arch} %%{xen_grub_target_name}} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%define_xen_pvh_variant_files %%{xen_pvh_package_arch} %%{xen_pvh_grub_target_name}} +%endif %if 0%{with_emu_arch} %files emu -%{_bindir}/%{name}-emu* -%{_datadir}/man/man1/%{name}-emu* +%{_bindir}/grub2-emu* +%{_datadir}/man/man1/grub2-emu* %files emu-modules %{_libdir}/grub/%{emuarch}-emu/* @@ -523,6 +608,628 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %endif %changelog +* Wed Dec 10 2025 Joel Capitao - 2.12-50 +- Do not include EFI dir in common subpackage +- Resolves: rhbz#2420430 + +* Thu Nov 27 2025 Leo Sandoval - 2.12-49 +- Increase EFI max allocation to max usable address +- Resolves: #2263643 + +* Fri Nov 21 2025 Leo Sandoval - 2.12-48 +- Add support for external environment block on Btrfs + +* Thu Nov 13 2025 Leo Sandoval - 2.12-47 +- blsuki: do not register blscfg command + +* Tue Nov 4 2025 Tom Callaway - 2.12-46 +- rebuild for new fuse3 + +* Wed Oct 15 2025 Leo Sandoval - 2.12-45 +- Include upstream blsuki related patches + +* Mon Sep 15 2025 Leo Sandoval - 2.12-44 +- Include function name on debug print function + +* Fri Aug 29 2025 Nicolas Frayer - 2.12-43 +- gen_grub_cfgstub: Removed output messages + +* Wed Aug 20 2025 Jan Stancek - 2.12-42 +- move 55-set-boot-entry.install to 95 +- Related: #2389020 + +* Mon Aug 11 2025 Marta Lewandowska - 2.12-41 +- Phase 1 of the bootloader updates proposal implementation +- https://fedoraproject.org/wiki/Changes/BootLoaderUpdatesPhase1 + +* Wed Aug 6 2025 Jan Stancek - 2.12-40 +- 55-set-boot-entry.install: fix initrd check +- Resolves: #2386118 + +* Fri Aug 1 2025 FeRD (Frank Dana) - 2.12-39 +- kernel-install: Suppress warnings about missing /etc/default/grub + file when attempting to grep its contents + +* Tue Jul 29 2025 Leo Sandoval 2.12-38 +- Set correctly the memory attributes for the kernel PE sections + +* Tue Jul 8 2025 Nicolas Frayer - 2.12-37 +- spec: fix grub stub cfg creation script + +* Thu Jun 12 2025 Nicolas Frayer - 2.12-36 +- spec: moved grub stub cfg creation into a script + +* Thu Jun 5 2025 Nicolas Frayer - 2.12-35 +- osdep/linux/getroot: Detect DDF container similar to IMSM + +* Wed May 28 2025 Nicolas Frayer - 2.12-34 +- Some fixes addressing memory freeing and dereferencing +- Resolves: #2368939 +- Resolves: #2368945 + +* Fri May 16 2025 Nicolas Frayer - 2.12-33 +- sbat: bump grub sbat + +* Tue May 06 2025 Leo Sandoval - 2.12-32 +- Fix several cryptodisk vulnerabilities +- Resolves: CVE-2025-4382 + +* Tue May 6 2025 Leo Sandoval 2.12-31 +- Handle special kernel parameter characters properly +- Resolves: #2362821 + +* Fri Apr 18 2025 Nicolas Frayer - 2.12-30 +- ppc/mkimage: SBAT support on powerpc + +* Tue Mar 25 2025 Nicolas Frayer 2.12-29 +- ieee1275/ofnet: Fix grub_malloc() removed after added safe + +* Tue Mar 25 2025 Nicolas Frayer 2.12-28 +- Fix the fallback mechanism when menu entries fail to boot + +* Wed Mar 19 2025 Nicolas Frayer 2.12-27 +- powerpc: increase MIN RMA size for CAS negotiation + +* Mon Mar 10 2025 Leo Sandoval 2.12-26 +- Remove 'fs/ntfs: Implement attribute verification' patch +- Resolves: #2350327 + +* Tue Feb 25 2025 Nicolas Frayer 2.12-25 +- fs/ext2: Rework out-of-bounds read for inline and external extents +- Resolves: #2346804 + +* Tue Feb 18 2025 Leo Sandoval - 2.02-24 +- Add Several CVE fixes +- Resolves: CVE-2024-45781 CVE-2024-45783 CVE-2024-45778 +- Resolves: CVE-2024-45775 CVE-2024-45780 CVE-2024-45774 +- Resolves: CVE-2025-0690 CVE-2025-1118 CVE-2024-45782 +- Resolves: CVE-2025-0624 CVE-2024-45779 CVE-2024-45776 +- Resolves: CVE-2025-0622 CVE-2025-0677 +- Related: #RHEL-79703 +- Related: #RHEL-79708 +- Related: #RHEL-79340 +- Related: #RHEL-73786 +- Related: #RHEL-79701 +- Related: #RHEL-73784 +- Related: #RHEL-79856 +- Related: #RHEL-79874 +- Related: #RHEL-79706 +- Related: #RHEL-79836 +- Related: #RHEL-79699 +- Related: #RHEL-75736 +- Related: #RHEL-79712 +- Related: #RHEL-79848 + +* Tue Feb 11 2025 Nicolas Frayer 2.12-23 +- Revert commit for bootloader update proposal for now as not all components are ready + +* Tue Feb 4 2025 Marta Lewandowska - 2.12-22 +- Phase 1 of the bootloader updates proposal implementation +- https://fedoraproject.org/wiki/Changes/BootLoaderUpdatesPhase1 + +* Tue Jan 28 2025 Nicolas Frayer 2.12-21 +- commands/bli: Fix crash in get_part_uuid() +- Resolves: #2339164 + +* Wed Jan 22 2025 Leo Sandoval 2.12-20 +- fix pending SAST issues +- Related: #RHEL-50504 + +* Mon Jan 13 2025 Leo Sandoval 2.12-19 +- term/nns8250-spcr: return if redirection is disabled + +* Thu Jan 9 2025 Nicolas Frayer - 2.12-18 +- fs/xfs: fix large extent counters incompat feature support + +* Wed Nov 27 2024 Marta Lewandowska - 2.12-17 +- 99-grub-mkconfig.install: on PPC systems, remove petiboot's version checks + +* Wed Nov 27 2024 Marta Lewandowska - 2.12-16 +- 99-grub-mkconfig.install: Disable BLS and run grub2-mkconfig when GRUB_ENABLE_BLSCFG is disable +- Resolves: #2325960 + +* Thu Nov 21 2024 Andrea Bolognani 2.12-15 +- Add riscv64 support (thanks Jason Montleon) + +* Wed Nov 20 2024 Nicolas Frayer 2.12-14 +- Build modules for Xen PV and PVH + +* Fri Nov 15 2024 Nicolas Frayer 2.12-13 +- posttrans: added check for efi_home/grub.cfg +- Resolves: #2326502 + +* Wed Oct 23 2024 Leo Sandoval 2.12-12 +- do-rebase: refactor command line parameters + +* Wed Oct 23 2024 Nicolas Frayer 2.12-11 +- cmd/search: Fix a possible NULL ptr dereference + +* Thu Oct 17 2024 Nicolas Frayer 2.12-10 +- acpi: Fix out of bounds access in grub_acpi_xsdt_find_table() +- Resolves: #2317048 + +* Thu Oct 3 2024 Nicolas Frayer 2.12-9 +- Stop grub.efi from always printing "dynamic_load_symbols %p\n" during boot +- Resolves: #2316279 + +* Wed Sep 25 2024 Nicolas Frayer 2.12-8 +- NX: efi/loader, add a call to grub_efi_check_nx_required() + +* Tue Sep 17 2024 Nicolas Frayer - 2.12-7 +- aarch64/macros: Build gnulib with -mbranch-protection=standard + +* Thu Sep 5 2024 Leo Sandoval - 2.12-6 +- load EFI commands inside test expressions +- Resolves: #2305291 + +* Thu Aug 29 2024 Leo Sandoval - 2.12-5 +- Fix netbooting regressions introduced at 2.12-1 +- Resolves: #2303727 + +* Thu Aug 08 2024 Peter Robinson 2.12-4 +- Build using fuse3 + +* Tue Aug 6 2024 Leo Sandoval - 2.12-3 +- Remove 'efi: Use shim's loader protocol for EFI image verification' + +* Tue Aug 6 2024 Nicolas Frayer - 2.12-2 +- mkconfig: More hardening to prevent overwriting grub cfg stub + +* Mon Aug 5 2024 Leo Sandoval - 2.12-1 +- Rebased to release grub2-2.12 + +* Fri Aug 2 2024 Leo Sandoval - 2.06-127 +- Set /boot/grub2/grub.cfg to 0600 mode if present + +* Mon Jul 22 2024 Leo Sandoval - 2.06.126 +- grub.cfg: Fix rpm grub.cfg verification issues + +* Tue Jul 16 2024 Nicolas Frayer - 2.06-125 +- grub2-mkconfig: Prevent mkconfig from overwriting grub cfg stub + +* Tue Jul 2 2024 Nicolas Frayer - 2.06-124 +- KVM/PowerVM: Add support for KVM on PowerVM +- Resolved: #2294883 + +* Tue May 28 2024 Leo Sandoval - 2.06.123 +- grub-mkconfig.in: turn off executable owner bit +- Resolves: #2281464 + +* Thu May 23 2024 Nicolas Frayer - 2.06-122 +- cmd/search: Rework of CVE-2023-4001 fix +- Related: #2224951 +- Resolved: #2263369 + +* Fri Apr 12 2024 Nicolas Frayer - 2.06-121 +- fs/xfs: Handle non-continuous data blocks in directory extents +- Related: #2254370 + +* Fri Mar 8 2024 Nicolas Frayer - 2.06-120 +- GRUB2 NTFS driver vulnerabilities +- (CVE-2023-4692) +- (CVE-2023-4693) +- Resolves: #2236613 +- Resolves: #2241978 +- Resolves: #2241976 +- Resolves: #2238343 + +* Wed Feb 7 2024 Nicolas Frayer - 2.06-119 +- grub-set-bootflag: Fix for CVE-2024-1048 +- (CVE-2024-1048) +- Resolves: #2256678 + +* Tue Jan 23 2024 Leo Sandoval - 2.06-118 +- xfs: include the 'directory extent parsing patch', otherwise +XFS-formatted partitions do not boot. This change effectively +reverts 2.06-115 +- Resolves: #2259266 + +* Wed Jan 17 2024 Nicolas Frayer - 2.06-117 +- Compiler flags: ignore incompatible types for now as it prevents +CI builds + +* Wed Jan 17 2024 Nicolas Frayer - 2.06-116 +- grub-core/commands: add flag to only search root dev +- Resolves: #2223437 +- Resolves: #2224951 +- Resolves: #2258096 +- Resolves: CVE-2023-4001 + +* Wed Jan 17 2024 Nicolas Frayer - 2.06-115 +- xfs: some bios systems can't boot with one of the xfs upstream patches +- Resolves: #2254370 + +* Sat Jan 13 2024 Hector Martin - 2.06-114 +- Switch memdisk compression to lzop + +* Thu Jan 11 2024 Daan De Meyer - 2.06-113 +- Don't obsolete the tools package with minimal + +* Tue Dec 19 2023 Nicolas Frayer - 2.06-112 +- normal: fix prefix when loading modules +- Resolves: #2209435 +- Resolves: #2173015 + +* Tue Dec 12 2023 leo sandoval - 2.06-111 +- chainloader: remove device path debug message + +* Fri Dec 1 2023 Nicolas Frayer - 2.06-110 +- fs/xfs: Add several fixes/improvements to xfs fs from upstream +- Resolves: #2247926 + +* Wed Nov 15 2023 Nicolas Frayer - 2.06-109 +- Linker: added --no-warn-rwx-segments as build will fail after +ld.bfd default options have been changed. +https://fedoraproject.org/wiki/Changes/Linker_Error_On_Security_Issues + +* Tue Nov 14 2023 Nicolas Frayer - 2.06-108 +- Remove [Install] section from aux systemd units +- Related: #2247635 + +* Tue Nov 14 2023 Hans de Goede - 2.06-107 +- spec: Switch back to static enablement for grub services in tools package +- spec: Add %%triggerpostun to apply grub-boot-success.timer preset + when upgrading from older versions where this was not a preset +- Resolves: #2247635 + +* Mon Nov 6 2023 Nicolas Frayer - 2.06-106 +- util: grub-install on EFI if forced +- Resolves: #1917213 +- Resolves: #2240994 + +* Fri Oct 20 2023 Nicolas Frayer - 2.06-105 +- kern/ieee1275/init: ppc64: Restrict high memory in presence + of fadump + +* Wed Oct 11 2023 Janne Grunau - 2.06-104 +- 20-grub.install: Copy device-tree directory recursively +- Resolves: #2243060 + +* Fri Sep 29 2023 Zbigniew Jedrzejewski-Szmek - 1:2.06-103 +- Rename installed kernel to match name used in boot entry +- Resolves: #2239008 + +* Fri Sep 29 2023 Nicolas Frayer - 2.06-102 +- ofdisk: Fix missing #include in ofdisk.c + +* Thu Sep 28 2023 Christian Glombek - 2.06-101 +- spec: Fix grub2-systemd-integration.service name + +* Wed Sep 13 2023 Nicolas Frayer - 2.06-100 +- arm64: Use proper memory type for kernel allocation +- Resolves: #2149020 + +* Fri Sep 01 2023 Christian Glombek - 2.06-99 +- spec: Use systemd presets and macros for units in tools package +- Resolves: #2230575 + +* Thu Aug 31 2023 Nicolas Frayer - 2.06-98 +- spec: Modified posttrans to harden grub config detection +- Resolves: #2235692 + +* Tue Aug 22 2023 Nicolas Frayer - 2.06-97 +- efi/http: change uint32_t to uintn_t + +* Tue Aug 22 2023 Nicolas Frayer - 2.06-96 +- util: Enable default kernel for updates + +* Wed Apr 12 2023 Robbie Harwood - 2.06-95 +- Add switch-root support to grub-emu + +* Mon Apr 10 2023 Robbie Harwood - 2.06-94 +- Fix aa64 page fault with EFI_MEMORY_ATTRIBUTE_PROTOCOL + +* Fri Mar 31 2023 Robbie Harwood - 2.06-93 +- Add legacy pxe core.0 (cmadams) + +* Thu Mar 30 2023 Robbie Harwood - 2.06-92 +- Disable the tpm verifier if the TPM device is not present + +* Thu Mar 30 2023 Robbie Harwood - 2.06-91 +- ppc64le: more cas vec5 shenanigans + +* Wed Mar 22 2023 Robbie Harwood - 2.06-90 +- emu: work around systemctl bad behavior + +* Thu Mar 09 2023 Robbie Harwood - 2.06-89 +- emu: handle BLS /boot weirdness + +* Mon Feb 20 2023 Robbie Harwood - 2.06-88 +- Update mm fixes from upstream + +* Thu Feb 16 2023 Robbie Harwood - 2.06-87 +- Fix disk sector size computation + +* Fri Feb 10 2023 Robbie Harwood - 2.06-86 +- Override the linker and force nonexecutable stacks + +* Wed Feb 08 2023 Robbie Harwood - 2.06-85 +- ppc64le: sync cas/tpm patchset with upstream + +* Mon Feb 06 2023 Robbie Harwood - 2.06-84 +- emu: support newer kexec syscall + +* Mon Feb 06 2023 Robbie Harwood - 2.06-83 +- ppc64le: cas5, take 3 + +* Mon Feb 06 2023 Robbie Harwood - 2.06-82 +- Fix implicit function declaration warnings + +* Wed Feb 01 2023 Javier Martinez Canillas - 2.06-81 +- 20-grub-install: Explicitly check '+debug' suffix for debug kernels +- Resolves: #2148351 + +* Wed Feb 01 2023 Robbie Harwood - 2.06-80 +- Bump to re-run signing + +* Tue Jan 31 2023 Robbie Harwood - 2.06-79 +- Disable mdraid < 1.1 on ppc64le + +* Fri Jan 27 2023 Robbie Harwood - 2.06-78 +- Fix grub2-probe issue with previous commit +- Resolves: #2165136 + +* Fri Jan 27 2023 Robbie Harwood - 2.06-77 +- ppc64le: update signed media fixes + +* Fri Jan 13 2023 Robbie Harwood - 2.06-76 +- ppc64le: fix issues using core.elf on boot media + +* Wed Jan 11 2023 Robbie Harwood - 2.06-75 +- Pull allocator improvements from upstream + +* Wed Jan 11 2023 Robbie Harwood - 2.06-74 +- Apply more hardening to host binaries + +* Tue Jan 10 2023 Robbie Harwood - 2.06-73 +- Allow internal grub allocations over 4GB + +* Wed Dec 21 2022 Robbie Harwood - 2.06-72 +- Fix prefix setting with memdisk creation for network boot + +* Mon Dec 19 2022 Robbie Harwood - 2.06-71 +- Attempt to fix eln build + +* Wed Dec 14 2022 Robbie Harwood - 2.06-70 +- ppc64le: fix lpar cas5 +- Resolves: #2152547 + +* Tue Dec 06 2022 Robbie Harwood - 2.06-69 +- Fix error handling in grub_file_open() + +* Mon Dec 05 2022 Robbie Harwood - 2.06-68 +- Allow for xz'd symvers file (prarit) + +* Wed Nov 23 2022 Tomas Hrcka - 1:2.06-67 +- install unicode.pf2 into place so lorax works + +* Tue Nov 22 2022 Robbie Harwood - 2.06-66 +- Bundle unicode.pf2 with images +- Resolves: #2143725 +- Resolves: #2144113 + +* Tue Nov 22 2022 Robbie Harwood - 1:2.06-65 +- Don't obsolete the tools package with extra/efi (pbrobinson) + +* Mon Nov 21 2022 Robbie Harwood - 1:2.06-64 +- Forward-port ppc64le image creation (with nerfed signing) + +* Tue Nov 08 2022 Robbie Harwood - 1:2.06-63 +- Font fixes (CVE-2022-2601 batch) + +* Tue Nov 01 2022 Robbie Harwood - 1:2.06-62 +- Try dropping custom sort again +- See-also: https://github.com/rpm-software-management/rpm/pull/2249 + +* Fri Oct 28 2022 Robbie Harwood - 2.06-61 +- TDX measurements to RTMR + +* Wed Oct 12 2022 Robbie Harwood - 2.06-60 +- x86-efi: Fix an incorrect array size in kernel allocation + +* Tue Oct 04 2022 Robbie Harwood - 2.06-59 +- Flush instruction cache before starting aa64 kernel + +* Fri Sep 09 2022 Robbie Harwood - 2.06-58 +- Bump spec for grub.macros gettext changes from Jens + +* Thu Sep 08 2022 Robbie Harwood - 2.06-57 +- aa64: support pe/coff decompressor + +* Wed Sep 07 2022 Robbie Harwood - 2.06-56 +- Revert patches to claim more memory for the arena + +* Thu Aug 25 2022 Robbie Harwood - 2.06-55 +- Fix root definition for blscfg in emu + +* Thu Aug 25 2022 Robbie Harwood - 2.06-54 +- gettext to gettext-runtime migration from Jens + +* Thu Aug 25 2022 Robbie Harwood - 2.06-53 +- ieee1275: implement vec5 for cas negotiation + +* Wed Aug 17 2022 Robbie Harwood - 2.06-52 +- Handle ostree's non-writable /etc/kernel + +* Wed Aug 17 2022 Robbie Harwood - 2.06-51 +- Give up on rhgb quiet + +* Wed Aug 17 2022 Robbie Harwood - 2.06-50 +- Fix duplicated args and cope with /etc/default/grub modification + +* Mon Aug 15 2022 Robbie Harwood - 2.06-49 +- Skip rpm mtime verification on likely-vfat filesystems + +* Mon Aug 15 2022 Robbie Harwood - 2.06-48 +- Use --with-rpm-version +- Resolves: #2118390 + +* Mon Aug 08 2022 Robbie Harwood - 2.06-47 +- Try reserving less RAM to fix windows booting +- Related: #2115202 + +* Tue Aug 02 2022 Robbie Harwood - 2.06-46 +- Populate /etc/kernel/cmdline during mkconfig + +* Tue Aug 02 2022 Robbie Harwood - 2.06-45 +- Rest of allocator fixes + +* Mon Aug 01 2022 Robbie Harwood - 2.06-44 +- Some allocator fixes for kernel + +* Tue Jul 19 2022 Robbie Harwood - 2.06-43 +- Handle FAT mtime of 0 +- Resolves: #2096192 + +* Mon May 16 2022 Robbie Harwood - 1:2.06-42 +- CVE fixes for 2022-05-24 +- Resolves: CVE-2022-28736 CVE-2022-28735 CVE-2022-28734 CVE-2022-28733 +- Resolves: CVE-2021-3697 CVE-2021-3696 CVE-2021-3695 + +* Mon May 16 2022 Robbie Harwood - 1:2.06-41 +- ppc64le: make ofdisk retries optional + +* Thu May 05 2022 Robbie Harwood - 1:2.06-40 +- Fix missing declaration of strchrnul in rpm-sort + +* Wed May 04 2022 Robbie Harwood - 1:2.06-39 +- ppc64le: CAS improvements, prefix detection, and vTPM support + +* Tue Apr 19 2022 Dominik Mierzejewski - 1:2.06-38 +- fix "grub2-mkrescue: error: `mformat` invocation failed" + +* Mon Apr 18 2022 Robbie Harwood - 1:2.06-37 +- Attempt to fix version display + +* Mon Apr 18 2022 Robbie Harwood - 2.06-36 +- Fix permission change report from rpm verification on grub.cfg + +* Wed Apr 13 2022 Robbie Harwood - 2.06-35 +- Enable "read" module +- Resolves: #2071644 + +* Tue Apr 12 2022 Robbie Harwood - 2.06-34 +- Bump for requirements updates; no code changes + +* Thu Mar 31 2022 Robbie Harwood - 1:2.06-33 +- Drop i32 build for real this time + +* Thu Mar 31 2022 Robbie Harwood - 1:2.06-32 +- Switch to upstream man pages + +* Wed Mar 30 2022 Robbie Harwood - 2.06-31 +- Revert previous change (grub2-pc-modules is built on i32) + +* Tue Mar 29 2022 Robbie Harwood - 2.06-30 +- Drop i32 support + +* Wed Mar 23 2022 Adam Williamson - 2.06-29 +- Fix a syntax error in the ostree BLS fix attempt + +* Wed Mar 23 2022 Peter Robinson 2.06-28 +- Rebuild for secure-boot signing + +* Tue Mar 22 2022 Adam Williamson - 2.06-27 +- Revert "Use my sort patch instead", it broke Rawhide +- Tweak BLS skipping on ostree to work in chroots (I hope) +- Resolves: #2066969 +- Resolves: #2059776 + +* Tue Mar 22 2022 Robbie Harwood - 2.06-26 +- Fix rebase on x509 embedding patch + +* Mon Mar 21 2022 Robbie Harwood - 2.06-25 +- Use my sort patch instead + +* Mon Mar 21 2022 Robbie Harwood - 2.06-24 +- Fix missing format specifier in appended signature commit + +* Fri Mar 18 2022 Robbie Harwood - 2.06-23 +- Don't verify kernels twice + +* Thu Mar 10 2022 Robbie Harwood - 2.06-22 +- Skip updating BLS on ostree installations +- Resolves: #2059776 + +* Wed Mar 09 2022 Robbie Harwood - 2.06-21 +- Fix initialization in efidisk patch + +* Mon Feb 28 2022 Robbie Harwood - 2.06-20 +- Disable the .package_note awfulness +- Resolves: #2058712 +- Resolves: #2058527 + +* Fri Feb 25 2022 Robbie Harwood - 2.06-19 +- Fix stripping of annobin -spec + +* Thu Feb 24 2022 Robbie Harwood - 2.06-18 +- Add efidisk/connectefi patches + +* Thu Feb 24 2022 Robbie Harwood - 2.06-17 +- Fix appended signature support commit (thanks: pjones) + +* Thu Feb 24 2022 Robbie Harwood - 2.06-16 +- Suffer through updating gnulib + +* Thu Jan 20 2022 Robbie Harwood - 2.06-15 +- Skip machine ID check when updating BLS + +* Tue Jan 18 2022 Robbie Harwood - 2.06-14 +- Add location of DejaVu Sans font + +* Mon Jan 17 2022 Robbie Harwood - 2.06-13 +- Update patches; minor changes at most, if correct + +* Thu Jan 06 2022 Robbie Harwood - 2.06-12 +- btrfs: use full bootloader area + +* Fri Dec 10 2021 Robbie Harwood - 2.06-11 +- Bump to rerun signing (no code changes) + +* Thu Dec 09 2021 Robbie Harwood - 2.06-10 +- restore umask for grub.cfg (CVE-2021-3981) + +* Thu Nov 04 2021 Robbie Harwood - 2.06-9 +- Drop UI patches and update provenance information + +* Thu Oct 07 2021 Peter Jones - 2.06-8 +- Fix "grub2-mkimage --appended-signature-size" parsing. + +* Wed Sep 29 2021 Robbie Harwood - 2.06-7 +- Rebuild; no code changes + +* Wed Sep 29 2021 Robbie Harwood - 2.06-6 +- fs/xfs: Fix unreadable filesystem with v4 superblock +- Arm: check for the PE magic for the compiled arch +- Resolves: rhbz#2008819 + +* Mon Aug 30 2021 Javier Martinez Canillas - 2.06-5 +- A few fixes for ppc64le LPAR Secure Boot support + +* Tue Aug 24 2021 Peter Jones - 2.06-4 +- Fix aarch64 kernel alignment. +- Fix annobin regexp on ppc64le + * Tue Jul 06 2021 Javier Martinez Canillas - 2.06-3 - Add luks2 to GRUB_MODULES - 20-grub-install: Create a symvers.gz symbolic link diff --git a/rpminspect.dson b/rpminspect.dson new file mode 100644 index 00000000..8c98989c --- /dev/null +++ b/rpminspect.dson @@ -0,0 +1,10 @@ +such "inspections" is such "javabytecode" is "off", + "changedfiles" is "off". + "filesize" is "off"? + "patches" is "off"! + "upstream" is "off"? + "permissions" is "off". + "debuginfo" is "off" wow, + "elf" is such "ignore" is so + "/usr/lib/grub/i386-pc/kernel.*" and + "/usr/lib/grub/i386-pc/lnxboot.image" many wow wow diff --git a/sbat.csv.in b/sbat.csv.in index ea697f51..f8372dfd 100755 --- a/sbat.csv.in +++ b/sbat.csv.in @@ -1,3 +1,3 @@ sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md -grub,1,Free Software Foundation,grub,@@VERSION@@,https//www.gnu.org/software/grub/ -grub.fedora,1,The Fedora Project,grub2,@@VERSION_RELEASE@@,https://src.fedoraproject.org/rpms/grub2 +grub,5,Free Software Foundation,grub,@@VERSION@@,https//www.gnu.org/software/grub/ +grub.rh,2,Red Hat,grub2,@@VERSION_RELEASE@@,mailto:secalert@redhat.com diff --git a/sources b/sources index 9a24a530..d510fb5f 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ SHA512 (unifont-13.0.06.pcf.gz) = 25f1ea4e316cd77b65cf4f60aa10ed054db6df2195be7344216673dee6628ab055ebcdeea186996d931fd1e9e4f519f4a2e4b4544b8a9ad2fe410aadc4eecd2d SHA512 (theme.tar.bz2) = 0f6f914d5f801509403094b28b8cfe5169cb56ae9bdd808ae21a6780a8236b434161a068351508dd78729c25ee2fed066c124c1eef9e15102750b409b4576a5c -SHA512 (grub-2.06.tar.xz) = 4f11c648f3078567e53fc0c74d5026fdc6da4be27d188975e79d9a4df817ade0fe5ad2ddd694238a07edc45adfa02943d83c57767dd51548102b375e529e8efe -SHA512 (gnulib-fixes.tar.gz) = 7aa933812de10f54196c7ed02079d7edeb92672a528baf83201ca4c62aa3e6b119f61c45469d2c4623c4efc5d4a08d20b029403f1f2c6e35fb7cb15789ff54b2 +SHA512 (grub-2.12.tar.xz) = 761c060a4c3da9c0e810b0ea967e3ebc66baa4ddd682a503ae3d30a83707626bccaf49359304a16b3a26fc4435fe6bea1ee90be910c84de3c2b5485a31a15be3 +SHA512 (gnulib-9f48fb992a3d7e96610c4ce8be969cff2d61a01b.tar.gz) = 6887dede2d4a403422ea045329ee9bd7ca4c1561bcaf39e805e1d1ce8f4c050a65ce286e7d8362fb8e815b5fab0b405730a3f93194e343e2aedcf9b4411a285e