diff --git a/backport-commands-usbtest-Ensure-string-length-is-sufficient-.patch b/backport-commands-usbtest-Ensure-string-length-is-sufficient-.patch new file mode 100644 index 0000000000000000000000000000000000000000..ef3b3fc058930f4b0d6c5705a74339db69e0d032 --- /dev/null +++ b/backport-commands-usbtest-Ensure-string-length-is-sufficient-.patch @@ -0,0 +1,32 @@ +From 07d50fdc7e425c6df174e49f98e693d05fc9ae2c Mon Sep 17 00:00:00 2001 +From: Jamie +Date: Mon, 14 Jul 2025 10:07:47 +0100 +Subject: [PATCH 5/5] commands/usbtest: Ensure string length is sufficient in + usb string processing + +If descstrp->length is less than 2 this will result in underflow in +"descstrp->length / 2 - 1" math. Let's fix the check to make sure the +value is sufficient. + +Signed-off-by: Jamie +Reviewed-by: Daniel Kiper +--- + grub-core/commands/usbtest.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c +index 8ef187a..3184ac9 100644 +--- a/grub-core/commands/usbtest.c ++++ b/grub-core/commands/usbtest.c +@@ -90,7 +90,7 @@ grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid, + 0x06, (3 << 8) | index, + langid, descstr.length, (char *) descstrp); + +- if (descstrp->length == 0) ++ if (descstrp->length < 2) + { + grub_free (descstrp); + *string = grub_strdup (""); +-- +2.33.0 + diff --git a/backport-commands-usbtest-Use-correct-string-length-field.patch b/backport-commands-usbtest-Use-correct-string-length-field.patch new file mode 100644 index 0000000000000000000000000000000000000000..a006038e33e14974e9ed13c0bb4667ab2e34ed1a --- /dev/null +++ b/backport-commands-usbtest-Use-correct-string-length-field.patch @@ -0,0 +1,34 @@ +From 423d7783d61054b02b876561762efa5e0c6503d2 Mon Sep 17 00:00:00 2001 +From: Jamie +Date: Mon, 14 Jul 2025 09:52:59 +0100 +Subject: [PATCH 4/5] commands/usbtest: Use correct string length field + +An incorrect length field is used for buffer allocation. This leads to +grub_utf16_to_utf8() receiving an incorrect/different length and possibly +causing OOB write. This makes sure to use the correct length. + +Fixes: CVE-2025-61661 + +Reported-by: Jamie +Signed-off-by: Jamie +Reviewed-by: Daniel Kiper +--- + grub-core/commands/usbtest.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c +index 2c6d93f..8ef187a 100644 +--- a/grub-core/commands/usbtest.c ++++ b/grub-core/commands/usbtest.c +@@ -99,7 +99,7 @@ grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid, + return GRUB_USB_ERR_NONE; + } + +- *string = grub_malloc (descstr.length * 2 + 1); ++ *string = grub_malloc (descstrp->length * 2 + 1); + if (! *string) + { + grub_free (descstrp); +-- +2.33.0 + diff --git a/backport-gettext-gettext-Unregister-gettext-command-on-module.patch b/backport-gettext-gettext-Unregister-gettext-command-on-module.patch new file mode 100644 index 0000000000000000000000000000000000000000..ea9a58c60169dab42de794367318b1996b4c90f1 --- /dev/null +++ b/backport-gettext-gettext-Unregister-gettext-command-on-module.patch @@ -0,0 +1,66 @@ +From ded33629df7d3b5ff6d3839b27a332a755ebaf1f Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Thu, 21 Aug 2025 21:14:06 +0000 +Subject: [PATCH 1/5] gettext/gettext: Unregister gettext command on module + unload + +When the gettext module is loaded, the gettext command is registered but +isn't unregistered when the module is unloaded. We need to add a call to +grub_unregister_command() when unloading the module. + +Fixes: CVE-2025-61662 + +Reported-by: Alec Brown +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/gettext/gettext.c | 19 ++++++++++++------- + 1 file changed, 12 insertions(+), 7 deletions(-) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index 9654bb3..fd46cc9 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -491,6 +491,8 @@ grub_cmd_translate (grub_command_t cmd __attribute__ ((unused)), + return 0; + } + ++static grub_command_t cmd; ++ + GRUB_MOD_INIT (gettext) + { + const char *lang; +@@ -506,13 +508,14 @@ GRUB_MOD_INIT (gettext) + grub_register_variable_hook ("locale_dir", NULL, read_main); + grub_register_variable_hook ("secondary_locale_dir", NULL, read_secondary); + +- grub_register_command_p1 ("gettext", grub_cmd_translate, +- N_("STRING"), +- /* TRANSLATORS: It refers to passing the string through gettext. +- So it's "translate" in the same meaning as in what you're +- doing now. +- */ +- N_("Translates the string with the current settings.")); ++ cmd = grub_register_command_p1 ("gettext", grub_cmd_translate, ++ N_("STRING"), ++ /* ++ * TRANSLATORS: It refers to passing the string through gettext. ++ * So it's "translate" in the same meaning as in what you're ++ * doing now. ++ */ ++ N_("Translates the string with the current settings.")); + + /* Reload .mo file information if lang changes. */ + grub_register_variable_hook ("lang", NULL, grub_gettext_env_write_lang); +@@ -529,6 +532,8 @@ GRUB_MOD_FINI (gettext) + grub_register_variable_hook ("secondary_locale_dir", NULL, NULL); + grub_register_variable_hook ("lang", NULL, NULL); + ++ grub_unregister_command (cmd); ++ + grub_gettext_delete_list (&main_context); + grub_gettext_delete_list (&secondary_context); + +-- +2.33.0 + diff --git a/backport-normal-main-Unregister-commands-on-module-unload.patch b/backport-normal-main-Unregister-commands-on-module-unload.patch new file mode 100644 index 0000000000000000000000000000000000000000..ccccb1d3a2dc47cc54014f57b990ec51631a4185 --- /dev/null +++ b/backport-normal-main-Unregister-commands-on-module-unload.patch @@ -0,0 +1,58 @@ +From db5f3e881477590533441eee55cfda5172f34556 Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Thu, 21 Aug 2025 21:14:07 +0000 +Subject: [PATCH 2/5] normal/main: Unregister commands on module unload + +When the normal module is loaded, the normal and normal_exit commands +are registered but aren't unregistered when the module is unloaded. We +need to add calls to grub_unregister_command() when unloading the module +for these commands. + +Fixes: CVE-2025-61663 +Fixes: CVE-2025-61664 + +Reported-by: Alec Brown +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/normal/main.c | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index d3a7f9a..a5e9d34 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -553,7 +553,7 @@ grub_mini_cmd_clear (struct grub_command *cmd __attribute__ ((unused)), + return 0; + } + +-static grub_command_t cmd_clear; ++static grub_command_t cmd_clear, cmd_normal, cmd_normal_exit; + + static void (*grub_xputs_saved) (const char *str); + static const char *features[] = { +@@ -595,10 +595,10 @@ GRUB_MOD_INIT(normal) + grub_env_export ("pager"); + + /* Register a command "normal" for the rescue mode. */ +- grub_register_command ("normal", grub_cmd_normal, +- 0, N_("Enter normal mode.")); +- grub_register_command ("normal_exit", grub_cmd_normal_exit, +- 0, N_("Exit from normal mode.")); ++ cmd_normal = grub_register_command ("normal", grub_cmd_normal, ++ 0, N_("Enter normal mode.")); ++ cmd_normal_exit = grub_register_command ("normal_exit", grub_cmd_normal_exit, ++ 0, N_("Exit from normal mode.")); + + /* Reload terminal colors when these variables are written to. */ + grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal); +@@ -640,4 +640,6 @@ GRUB_MOD_FINI(normal) + grub_register_variable_hook ("color_highlight", NULL, NULL); + grub_fs_autoload_hook = 0; + grub_unregister_command (cmd_clear); ++ grub_unregister_command (cmd_normal); ++ grub_unregister_command (cmd_normal_exit); + } +-- +2.33.0 + diff --git a/backport-tests-lib-functional_test-Unregister-commands-on-mod.patch b/backport-tests-lib-functional_test-Unregister-commands-on-mod.patch new file mode 100644 index 0000000000000000000000000000000000000000..2694362f764b5018438df4381e2c044248c4a7de --- /dev/null +++ b/backport-tests-lib-functional_test-Unregister-commands-on-mod.patch @@ -0,0 +1,47 @@ +From a9a7153dacc5129965e36b2992678b9fbfee130b Mon Sep 17 00:00:00 2001 +From: Alec Brown +Date: Thu, 21 Aug 2025 21:14:08 +0000 +Subject: [PATCH 3/5] tests/lib/functional_test: Unregister commands on module + unload + +When the functional_test module is loaded, both the functional_test and +all_functional_test commands are registered but only the all_functional_test +command is being unregistered since it was the last to set the cmd variable +that gets unregistered when the module is unloaded. To unregister both +commands, we need to create an additional grub_extcmd_t variable. + +Signed-off-by: Alec Brown +Reviewed-by: Daniel Kiper +--- + grub-core/tests/lib/functional_test.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c +index 96781fb..b0f6845 100644 +--- a/grub-core/tests/lib/functional_test.c ++++ b/grub-core/tests/lib/functional_test.c +@@ -89,17 +89,18 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)), + return GRUB_ERR_NONE; + } + +-static grub_extcmd_t cmd; ++static grub_extcmd_t cmd, cmd_all; + + GRUB_MOD_INIT (functional_test) + { + cmd = grub_register_extcmd ("functional_test", grub_functional_test, 0, 0, + "Run all loaded functional tests.", 0); +- cmd = grub_register_extcmd ("all_functional_test", grub_functional_all_tests, 0, 0, +- "Run all functional tests.", 0); ++ cmd_all = grub_register_extcmd ("all_functional_test", grub_functional_all_tests, 0, 0, ++ "Run all functional tests.", 0); + } + + GRUB_MOD_FINI (functional_test) + { + grub_unregister_extcmd (cmd); ++ grub_unregister_extcmd (cmd_all); + } +-- +2.33.0 + diff --git a/grub.patches b/grub.patches index 5b587d499a4288d3473d3b99f193108c1f0ab5c1..fb78280295a9e04a140b10b7ef36fc0fdee75c2b 100644 --- a/grub.patches +++ b/grub.patches @@ -495,3 +495,8 @@ Patch0494: backport-0028-fs-bfs-Disable-under-lockdown.patch Patch0495: backport-0029-fs-Disable-many-filesystems-under-lockdown.patch Patch0496: backport-0030-fs-Prevent-overflows-when-allocating-memory-for-arra.patch Patch0497: backport-fix-CVE-2024-56738.patch +Patch0498: backport-gettext-gettext-Unregister-gettext-command-on-module.patch +Patch0499: backport-normal-main-Unregister-commands-on-module-unload.patch +Patch0500: backport-tests-lib-functional_test-Unregister-commands-on-mod.patch +Patch0501: backport-commands-usbtest-Use-correct-string-length-field.patch +Patch0502: backport-commands-usbtest-Ensure-string-length-is-sufficient-.patch diff --git a/grub2.spec b/grub2.spec index fb2b6c98d83baa882581587a01ee7c772252cea1..cee907497c5481248b22710ad01f027ab9e02626 100644 --- a/grub2.spec +++ b/grub2.spec @@ -8,7 +8,7 @@ Name: grub2 Epoch: 1 Version: 2.04 -Release: 41 +Release: 42 Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -442,6 +442,16 @@ rm -r /boot/grub2.tmp/ || : %{_datadir}/man/man* %changelog +* Fri Nov 21 2025 zhangqiumiao - 1:2.04-42 +- Type:CVE +- CVE:CVE-2025-61661,CVE-2025-61662,CVE-2025-61663,CVE-2025-61664 +- SUG:NA +- DESC:commands/usbtest: Ensure string length is sufficient in usb string processing + commands/usbtest: Use correct string length field + tests/lib/functional_test: Unregister commands on module unload + normal/main: Unregister commands on module unload + gettext/gettext: Unregister gettext command on module unload + * Tue Apr 8 2025 zhangqiumiao - 1:2.04-41 - Type:CVE - CVE:CVE-2024-56738