Backport security fixes to grub2
cover Backport security fixes to grub2
Hello,
According to our pkg-stats results at [1], grub2 is affected by a large number of CVEs.
Unfortunately, grub2 upstream doesn't do any "maintenance" releases, and there is no newer stable release than the one we're using:
2.12. In their master branch, there are hundreds of commits mixing new features and fixes.
Luckily, Debian did the tedious work of backporting those fixes, and keeping them as a nicely separate/isolated patch series in their stack of patches. This patch series simply takes this whole series of Debian fixes into Buildroot.
Note that we do copy the patches in Buildroot rather than applying the Debian patch stack, because the Debian patch stack also contain feature patches.
In addition, the Debian patch stack is mixing the fix for one particular CVE, that we are taking from OpenSUSE.
As part of this effort, we tested the grub2 unit tests, and they were broken for various reasons, so we switch those tests to use a different toolchain.
Best regards,
Thomas Petazzoni
[1] https://autobuild.buildroot.net/stats/master.html
Thomas Petazzoni (3):
support/testing/tests/fs/test_iso9660.py: use a more recent toolchain support/testing/tests/boot/test_grub.py: use glibc toolchain boot/grub2: add patches to fix numerous CVEs
.../0002-misc-Implement-grub_strlcpy.patch | 70 +++ .../0003-fs-ufs-Fix-a-heap-OOB-write.patch | 36 ++ ...Fix-stack-OOB-write-with-grub_strcpy.patch | 36 ++ ...itialize-name-in-grub_cpio_find_file.patch | 45 ++ ...ger-overflow-leads-to-heap-OOB-write.patch | 94 +++ ...f2fs-Set-a-grub_errno-if-mount-fails.patch | 36 ++ ...plus-Set-a-grub_errno-if-mount-fails.patch | 40 ++ ...9660-Set-a-grub_errno-if-mount-fails.patch | 38 ++ .../0010-fs-iso9660-Fix-invalid-free.patch | 55 ++ ...11-fs-jfs-Fix-OOB-read-in-jfs_getent.patch | 68 +++ ...ead-caused-by-invalid-dir-slot-index.patch | 69 +++ ...40-bits-offset-and-address-for-a-dat.patch | 133 +++++ ...ent-signed-unsigned-types-usage-in-r.patch | 90 +++ ...ut-of-bounds-read-for-inline-extents.patch | 51 ++ .../0016-fs-xfs-Fix-out-of-bounds-read.patch | 48 ++ ...g-failing-to-mount-sets-a-grub_errno.patch | 47 ++ ...18-kern-file-Ensure-file-data-is-set.patch | 37 ++ ...lement-filesystem-reference-counting.patch | 449 ++++++++++++++ ...-Reference-tracking-for-the-loopback.patch | 108 ++++ ...0021-kern-disk-Limit-recursion-depth.patch | 125 ++++ ...tion-Limit-recursion-in-part_iterate.patch | 49 ++ ...pt-execute-Limit-the-recursion-depth.patch | 60 ++ ...et_default_ip-and-net_default_mac-va.patch | 34 ++ ...bles-hooks-when-interface-is-unregis.patch | 93 +++ ...write-in-grub_net_search_config_file.patch | 89 +++ ...x-stack-buffer-overflow-in-tftp_open.patch | 120 ++++ ...eg-Do-not-permit-duplicate-SOF0-mark.patch | 38 ++ ...r-an-integer-overflow-in-grub_dl_ref.patch | 143 +++++ ...r-the-SHF_INFO_LINK-flag-in-grub_dl_.patch | 46 ++ ...-Missing-check-for-failed-allocation.patch | 39 ++ ...032-commands-ls-Fix-NULL-dereference.patch | 37 ++ ...egister-the-check_signatures-hooks-o.patch | 36 ++ ...ove-variables-hooks-on-module-unload.patch | 42 ++ ...ove-variables-hooks-on-module-unload.patch | 39 ++ ...overflow-leads-to-heap-OOB-write-or-.patch | 40 ++ ...ger-overflow-leads-to-heap-OOB-write.patch | 58 ++ ...x-an-integer-overflow-when-supplying.patch | 74 +++ ...ack-overflow-due-to-unlimited-recurs.patch | 88 +++ ...-Block-the-dump-command-in-lockdown-.patch | 38 ++ ...isable-memory-reading-in-lockdown-mo.patch | 55 ++ ...-Disable-memory-reading-in-lockdown-.patch | 42 ++ .../0043-fs-bfs-Disable-under-lockdown.patch | 57 ++ ...able-many-filesystems-under-lockdown.patch | 396 +++++++++++++ ...afe-math-macros-to-prevent-overflows.patch | 551 ++++++++++++++++++ ...rflows-when-allocating-memory-for-ar.patch | 47 ++ ...turned-pointer-for-allocated-memory-.patch | 157 +++++ ...disk-Call-grub_ieee1275_close-when-g.patch | 36 ++ ...afe-math-macros-to-prevent-overflows.patch | 362 ++++++++++++ ...lows-when-allocating-memory-for-arra.patch | 87 +++ ...lows-when-assigning-returned-values-.patch | 110 ++++ ...afe-math-macros-to-prevent-overflows.patch | 143 +++++ ...verflows-when-allocating-memory-for-.patch | 45 ++ ...returned-pointer-for-allocated-memor.patch | 93 +++ ...ng-NULL-check-after-grub_strdup-call.patch | 29 + ...afe-math-macros-to-prevent-overflows.patch | 250 ++++++++ ...flows-when-allocating-memory-for-arr.patch | 50 ++ ...urned-pointer-for-allocated-memory-i.patch | 36 ++ ...fs-Check-if-allocated-memory-is-NULL.patch | 37 ++ ...ix-potential-underflow-and-NULL-dere.patch | 37 ++ ...unix-getroot-Fix-potential-underflow.patch | 40 ++ ...e-consistent-overflow-error-messages.patch | 60 ++ ...ine-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch | 35 ++ ...safe-math-to-avoid-an-integer-overfl.patch | 46 ++ ...dd-sanity-check-after-grub_strtoul-c.patch | 51 ++ ...sanity-check-after-grub_strtoul-call.patch | 62 ++ ...nux-Cast-left-shift-to-grub_uint32_t.patch | 35 ++ ...bsd-Use-safe-math-to-avoid-underflow.patch | 61 ++ ...ut-of-bounds-read-for-inline-and-ext.patch | 69 +++ ...xfs_iterate_dir-return-value-in-case.patch | 53 ++ ...-incorrect-inode-error-from-grub_xfs.patch | 77 +++ ...ot-inode-read-failure-in-grub_xfs_mo.patch | 29 + ...ee1275-ofnet-Add-missing-grub_malloc.patch | 36 ++ ...074-Constant-time-grub_crypto_memcmp.patch | 62 ++ boot/grub2/grub2.mk | 32 + support/testing/tests/boot/test_grub.py | 6 +- support/testing/tests/fs/test_iso9660.py | 11 +- 76 files changed, 6211 insertions(+), 12 deletions(-) create mode 100644 boot/grub2/0002-misc-Implement-grub_strlcpy.patch create mode 100644 boot/grub2/0003-fs-ufs-Fix-a-heap-OOB-write.patch create mode 100644 boot/grub2/0004-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch create mode 100644 boot/grub2/0005-fs-tar-Initialize-name-in-grub_cpio_find_file.patch create mode 100644 boot/grub2/0006-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch create mode 100644 boot/grub2/0007-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0008-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0009-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0010-fs-iso9660-Fix-invalid-free.patch create mode 100644 boot/grub2/0011-fs-jfs-Fix-OOB-read-in-jfs_getent.patch create mode 100644 boot/grub2/0012-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch create mode 100644 boot/grub2/0013-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch create mode 100644 boot/grub2/0014-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch create mode 100644 boot/grub2/0015-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch create mode 100644 boot/grub2/0016-fs-xfs-Fix-out-of-bounds-read.patch create mode 100644 boot/grub2/0017-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch create mode 100644 boot/grub2/0018-kern-file-Ensure-file-data-is-set.patch create mode 100644 boot/grub2/0019-kern-file-Implement-filesystem-reference-counting.patch create mode 100644 boot/grub2/0020-disk-loopback-Reference-tracking-for-the-loopback.patch create mode 100644 boot/grub2/0021-kern-disk-Limit-recursion-depth.patch create mode 100644 boot/grub2/0022-kern-partition-Limit-recursion-in-part_iterate.patch create mode 100644 boot/grub2/0023-script-execute-Limit-the-recursion-depth.patch create mode 100644 boot/grub2/0024-net-Unregister-net_default_ip-and-net_default_mac-va.patch create mode 100644 boot/grub2/0025-net-Remove-variables-hooks-when-interface-is-unregis.patch create mode 100644 boot/grub2/0026-net-Fix-OOB-write-in-grub_net_search_config_file.patch create mode 100644 boot/grub2/0027-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch create mode 100644 boot/grub2/0028-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch create mode 100644 boot/grub2/0029-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch create mode 100644 boot/grub2/0030-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch create mode 100644 boot/grub2/0031-commands-extcmd-Missing-check-for-failed-allocation.patch create mode 100644 boot/grub2/0032-commands-ls-Fix-NULL-dereference.patch create mode 100644 boot/grub2/0033-commands-pgp-Unregister-the-check_signatures-hooks-o.patch create mode 100644 boot/grub2/0034-normal-Remove-variables-hooks-on-module-unload.patch create mode 100644 boot/grub2/0035-gettext-Remove-variables-hooks-on-module-unload.patch create mode 100644 boot/grub2/0036-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch create mode 100644 boot/grub2/0037-gettext-Integer-overflow-leads-to-heap-OOB-write.patch create mode 100644 boot/grub2/0038-commands-read-Fix-an-integer-overflow-when-supplying.patch create mode 100644 boot/grub2/0039-commands-test-Stack-overflow-due-to-unlimited-recurs.patch create mode 100644 boot/grub2/0040-commands-minicmd-Block-the-dump-command-in-lockdown-.patch create mode 100644 boot/grub2/0041-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch create mode 100644 boot/grub2/0042-commands-hexdump-Disable-memory-reading-in-lockdown-.patch create mode 100644 boot/grub2/0043-fs-bfs-Disable-under-lockdown.patch create mode 100644 boot/grub2/0044-fs-Disable-many-filesystems-under-lockdown.patch create mode 100644 boot/grub2/0045-disk-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0046-disk-Prevent-overflows-when-allocating-memory-for-ar.patch create mode 100644 boot/grub2/0047-disk-Check-if-returned-pointer-for-allocated-memory-.patch create mode 100644 boot/grub2/0048-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch create mode 100644 boot/grub2/0049-fs-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0050-fs-Prevent-overflows-when-allocating-memory-for-arra.patch create mode 100644 boot/grub2/0051-fs-Prevent-overflows-when-assigning-returned-values-.patch create mode 100644 boot/grub2/0052-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0053-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch create mode 100644 boot/grub2/0054-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch create mode 100644 boot/grub2/0055-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch create mode 100644 boot/grub2/0056-net-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0057-net-Prevent-overflows-when-allocating-memory-for-arr.patch create mode 100644 boot/grub2/0058-net-Check-if-returned-pointer-for-allocated-memory-i.patch create mode 100644 boot/grub2/0059-fs-sfs-Check-if-allocated-memory-is-NULL.patch create mode 100644 boot/grub2/0060-script-execute-Fix-potential-underflow-and-NULL-dere.patch create mode 100644 boot/grub2/0061-osdep-unix-getroot-Fix-potential-underflow.patch create mode 100644 boot/grub2/0062-misc-Ensure-consistent-overflow-error-messages.patch create mode 100644 boot/grub2/0063-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch create mode 100644 boot/grub2/0064-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch create mode 100644 boot/grub2/0065-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch create mode 100644 boot/grub2/0066-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch create mode 100644 boot/grub2/0067-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch create mode 100644 boot/grub2/0068-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch create mode 100644 boot/grub2/0069-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch create mode 100644 boot/grub2/0070-fs-xfs-Fix-grub_xfs_iterate_dir-return-value-in-case.patch create mode 100644 boot/grub2/0071-fs-xfs-Propagate-incorrect-inode-error-from-grub_xfs.patch create mode 100644 boot/grub2/0072-fs-xfs-Handle-root-inode-read-failure-in-grub_xfs_mo.patch create mode 100644 boot/grub2/0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch create mode 100644 boot/grub2/0074-Constant-time-grub_crypto_memcmp.patch
Signature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 1/3 support/testing/tests/fs/test_iso9660.py: use a more recent toolchain
The ISO9660 tests are currently using an old 2017 toolchain. Let's switch to a modern toolchain, which is regularly updated. Also, we use a toolchain based on glibc since grub2 doesn't build with recent uClibc toolchains.
It will work around build issues with syslinux.
Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828975
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828871
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828770
(Even though those should be fixed separately, as syslinux should continue to build with old compilers not supporting std=gnu17)
--- support/testing/tests/fs/test_iso9660.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
support/testing/tests/fs/test_iso9660.py +2 -9
@@ -4,16 +4,9 @@ import infra.basetest BASIC_CONFIG = \ """ - BR2_x86_pentium4=y + BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y - BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y - BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-i386-pentium4-full-2017.05-1078-g95b1dae.tar.bz2" - BR2_TOOLCHAIN_EXTERNAL_GCC_6=y - BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_2=y - BR2_TOOLCHAIN_EXTERNAL_LOCALE=y - # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set - BR2_TOOLCHAIN_EXTERNAL_CXX=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" BR2_TARGET_GENERIC_GETTY_BAUDRATE_115200=y BR2_LINUX_KERNEL=y
Signature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH 1/3] support/testing/tests/fs/test_iso9660.py: use a more recent toolchain
Hi Thomas,
Quoted 9 lines · Thomas Petazzoni via buildroot
The ISO9660 tests are currently using an old 2017 toolchain. Let's switch to a modern toolchain, which is regularly updated. Also, we use a toolchain based on glibc since grub2 doesn't build with recent uClibc toolchains.
It will work around build issues with syslinux.
Fixes:
Quoted 8 lines
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828975
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828871
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828770(Even though those should be fixed separately, as syslinux should continue to build with old compilers not supporting std=gnu17)
Signed-off-by Thomas Petazzoni <[email protected]>
I applied this series to master, after a complete review and some more testing.
I also made few minor cosmetic changes in patch #3:
- fix patch #72 upstream link to point to the initial patch submission rather than a reply
- merge two _IGNORE_CVES blocks for patch #50 into a single one
- order _IGNORE_CVES blocks by numerical patch order
- order numerically the CVE list in commit log
- add a "Fixes:" tag in patch #74 since its commit log does not mention the CVE.
See:
https://gitlab.com/buildroot.org/buildroot/-/commit/ded3e0045aeeab226d2770fe8de522422c174434
Thanks a lot for this series!
Best regards,
Julien.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH 1/3] support/testing/tests/fs/test_iso9660.py: use a more recent toolchain
Hello Julien,
Quoted 11 lines · On Tue, 19 Aug 2025 04:06:07 +0200 Julien Olivain <[email protected]> wrote:
I applied this series to master, after a complete review and some more testing.
I also made few minor cosmetic changes in patch #3:
- fix patch #72 upstream link to point to the initial patch submission rather than a reply
- merge two_IGNORE_CVESblocks for patch #50 into a single one
- order_IGNORE_CVESblocks by numerical patch order
- order numerically the CVE list in commit log
- add a "Fixes:" tag in patch #74 since its commit log does not mention the CVE.
Thanks a lot for having taken care of all those very relevant improvements!
Best regards,
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedRe: [Buildroot] [PATCH 1/3] support/testing/tests/fs/test_iso9660.py: use a more recent toolchain
In reply to Thomas Petazzoni via buildrootIn reply of:
Quoted 9 lines
The ISO9660 tests are currently using an old 2017 toolchain. Let's switch to a modern toolchain, which is regularly updated. Also, we use a toolchain based on glibc since grub2 doesn't build with recent uClibc toolchains.
It will work around build issues with syslinux.
Fixes:
Quoted 8 lines
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828975
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828871
https://gitlab.com/buildroot.org/buildroot/-/jobs/10975828770(Even though those should be fixed separately, as syslinux should continue to build with old compilers not supporting std=gnu17)
Signed-off-by Thomas Petazzoni <[email protected]>
Applied to 2025.02.x & 2025.05.x. Thanks
Quoted 34 lines
--- support/testing/tests/fs/test_iso9660.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)support/testing/tests/fs/test_iso9660.py +2
-9@@ -4,16 +4,9 @@ import infra.basetest BASIC_CONFIG = \ """ - BR2_x86_pentium4=y + BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y - BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y - BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-i386-pentium4-full-2017.05-1078-g95b1dae.tar.bz2" - BR2_TOOLCHAIN_EXTERNAL_GCC_6=y - BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_2=y - BR2_TOOLCHAIN_EXTERNAL_LOCALE=y - # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set - BR2_TOOLCHAIN_EXTERNAL_CXX=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" BR2_TARGET_GENERIC_GETTY_BAUDRATE_115200=y BR2_LINUX_KERNEL=ySignature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 2/3 support/testing/tests/boot/test_grub.py: use glibc toolchain
In reply to Thomas Petazzoni via buildrootSince the recent bump of Bootlin toolchains in 947dbc92a20c5acea7882166cae7893e6ea661e1 ("toolchain/toolchain-external/toolchain-external-bootlin:
update to Bootlin toolchains 2025.08-1"), our grub2 tests are failing
as the new uClibc toolchains based on gcc 14.x have an issue building
grub.
Until this issue gets fixed at the uClibc level and since anyway glibc is now the default in Buildroot, let's switch to using glibc toolchains.
Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/10972858692
https://gitlab.com/buildroot.org/buildroot/-/jobs/10972858686
https://gitlab.com/buildroot.org/buildroot/-/jobs/10972858680
--- support/testing/tests/boot/test_grub.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
support/testing/tests/boot/test_grub.py +3 -3
@@ -8,7 +8,7 @@ class TestGrubi386BIOS(infra.basetest.BRTest): """ BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg"
@@ -37,7 +37,7 @@ class TestGrubi386EFI(infra.basetest.BRTest): """ BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" BR2_LINUX_KERNEL=y
@@ -88,7 +88,7 @@ class TestGrubX8664EFI(infra.basetest.BRTest): BR2_x86_64=y BR2_x86_corei7=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_UCLIBC_STABLE=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_GLIBC_STABLE=y BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" BR2_LINUX_KERNEL=y
Signature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedRe: [Buildroot] [PATCH 2/3] support/testing/tests/boot/test_grub.py: use glibc toolchain
In reply of:
Quoted 10 lines
Since the recent bump of Bootlin toolchains in
947dbc92a20c5acea7882166cae7893e6ea661e1("toolchain/toolchain-external/toolchain-external-bootlin:
update to Bootlin toolchains 2025.08-1"), our grub2 tests are failing
as the new uClibc toolchains based on gcc 14.x have an issue building
grub.Until this issue gets fixed at the uClibc level and since anyway glibc is now the default in Buildroot, let's switch to using glibc toolchains.
Quoted 7 lines
Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/10972858692
https://gitlab.com/buildroot.org/buildroot/-/jobs/10972858686
https://gitlab.com/buildroot.org/buildroot/-/jobs/10972858680Signed-off-by Thomas Petazzoni <[email protected]>
Applied to 2025.02.x & 2025.05.x. Thanks
Quoted 42 lines
--- support/testing/tests/boot/test_grub.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)support/testing/tests/boot/test_grub.py +3
-3@@ -8,7 +8,7 @@ class TestGrubi386BIOS(infra.basetest.BRTest): """ BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg"@@ -37,7 +37,7 @@ class TestGrubi386EFI(infra.basetest.BRTest): """ BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" BR2_LINUX_KERNEL=y@@ -88,7 +88,7 @@ class TestGrubX8664EFI(infra.basetest.BRTest): BR2_x86_64=y BR2_x86_corei7=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_UCLIBC_STABLE=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_GLIBC_STABLE=y BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" BR2_LINUX_KERNEL=ySignature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 3/3 boot/grub2: add patches to fix numerous CVEs
In reply to Thomas Petazzoni via buildrootThis patch brings the entire stack of Debian patches on grub2 titled "cve-2025-jan" and available at:
As of this exact Debian grub2 version 2.12-9. Some minor conflicts had to be fixed. All patches are in upstream Grub master, but mixed with hundreds of other changes, which is why Debian's effort to backport them has been leveraged here.
In addition to those patches, 2 extra patches are added:
0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch 0074-Constant-time-grub_crypto_memcmp.patch
The first one fixes an issue in one of the earlier patches. The fix is not in Debian, but is in upstream Grub.
The second one fixes another CVE, not fixed in Debian, but fixed in OpenSUSE. This fix is not upstream as upstream has decided to move to libgcrypt instead to avoid the problem, but that's a fairly large change.
Overall, this patch fixes all CVEs currently reported by pkg-stats against our grub2 package, namely:
CVE-2024-56737
CVE-2024-45782
CVE-2024-45778
CVE-2024-45779
CVE-2024-45777
CVE-2024-45780
CVE-2025-1125
CVE-2025-0684
CVE-2025-0689
CVE-2025-0686
CVE-2025-0685
CVE-2025-0678
CVE-2024-56738
With the previous fixes on runtime tests added (to use glibc toolchains to build grub2 tests), this commit successfully passes all tests:
- The ISO9660 tests that use grub2:
https://gitlab.com/tpetazzoni/buildroot/-/pipelines/1985234563
- The grub2 tests:
https://gitlab.com/tpetazzoni/buildroot/-/pipelines/1985234685
--- .../0002-misc-Implement-grub_strlcpy.patch | 70 +++ .../0003-fs-ufs-Fix-a-heap-OOB-write.patch | 36 ++ ...Fix-stack-OOB-write-with-grub_strcpy.patch | 36 ++ ...itialize-name-in-grub_cpio_find_file.patch | 45 ++ ...ger-overflow-leads-to-heap-OOB-write.patch | 94 +++ ...f2fs-Set-a-grub_errno-if-mount-fails.patch | 36 ++ ...plus-Set-a-grub_errno-if-mount-fails.patch | 40 ++ ...9660-Set-a-grub_errno-if-mount-fails.patch | 38 ++ .../0010-fs-iso9660-Fix-invalid-free.patch | 55 ++ ...11-fs-jfs-Fix-OOB-read-in-jfs_getent.patch | 68 +++ ...ead-caused-by-invalid-dir-slot-index.patch | 69 +++ ...40-bits-offset-and-address-for-a-dat.patch | 133 +++++ ...ent-signed-unsigned-types-usage-in-r.patch | 90 +++ ...ut-of-bounds-read-for-inline-extents.patch | 51 ++ .../0016-fs-xfs-Fix-out-of-bounds-read.patch | 48 ++ ...g-failing-to-mount-sets-a-grub_errno.patch | 47 ++ ...18-kern-file-Ensure-file-data-is-set.patch | 37 ++ ...lement-filesystem-reference-counting.patch | 449 ++++++++++++++ ...-Reference-tracking-for-the-loopback.patch | 108 ++++ ...0021-kern-disk-Limit-recursion-depth.patch | 125 ++++ ...tion-Limit-recursion-in-part_iterate.patch | 49 ++ ...pt-execute-Limit-the-recursion-depth.patch | 60 ++ ...et_default_ip-and-net_default_mac-va.patch | 34 ++ ...bles-hooks-when-interface-is-unregis.patch | 93 +++ ...write-in-grub_net_search_config_file.patch | 89 +++ ...x-stack-buffer-overflow-in-tftp_open.patch | 120 ++++ ...eg-Do-not-permit-duplicate-SOF0-mark.patch | 38 ++ ...r-an-integer-overflow-in-grub_dl_ref.patch | 143 +++++ ...r-the-SHF_INFO_LINK-flag-in-grub_dl_.patch | 46 ++ ...-Missing-check-for-failed-allocation.patch | 39 ++ ...032-commands-ls-Fix-NULL-dereference.patch | 37 ++ ...egister-the-check_signatures-hooks-o.patch | 36 ++ ...ove-variables-hooks-on-module-unload.patch | 42 ++ ...ove-variables-hooks-on-module-unload.patch | 39 ++ ...overflow-leads-to-heap-OOB-write-or-.patch | 40 ++ ...ger-overflow-leads-to-heap-OOB-write.patch | 58 ++ ...x-an-integer-overflow-when-supplying.patch | 74 +++ ...ack-overflow-due-to-unlimited-recurs.patch | 88 +++ ...-Block-the-dump-command-in-lockdown-.patch | 38 ++ ...isable-memory-reading-in-lockdown-mo.patch | 55 ++ ...-Disable-memory-reading-in-lockdown-.patch | 42 ++ .../0043-fs-bfs-Disable-under-lockdown.patch | 57 ++ ...able-many-filesystems-under-lockdown.patch | 396 +++++++++++++ ...afe-math-macros-to-prevent-overflows.patch | 551 ++++++++++++++++++ ...rflows-when-allocating-memory-for-ar.patch | 47 ++ ...turned-pointer-for-allocated-memory-.patch | 157 +++++ ...disk-Call-grub_ieee1275_close-when-g.patch | 36 ++ ...afe-math-macros-to-prevent-overflows.patch | 362 ++++++++++++ ...lows-when-allocating-memory-for-arra.patch | 87 +++ ...lows-when-assigning-returned-values-.patch | 110 ++++ ...afe-math-macros-to-prevent-overflows.patch | 143 +++++ ...verflows-when-allocating-memory-for-.patch | 45 ++ ...returned-pointer-for-allocated-memor.patch | 93 +++ ...ng-NULL-check-after-grub_strdup-call.patch | 29 + ...afe-math-macros-to-prevent-overflows.patch | 250 ++++++++ ...flows-when-allocating-memory-for-arr.patch | 50 ++ ...urned-pointer-for-allocated-memory-i.patch | 36 ++ ...fs-Check-if-allocated-memory-is-NULL.patch | 37 ++ ...ix-potential-underflow-and-NULL-dere.patch | 37 ++ ...unix-getroot-Fix-potential-underflow.patch | 40 ++ ...e-consistent-overflow-error-messages.patch | 60 ++ ...ine-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch | 35 ++ ...safe-math-to-avoid-an-integer-overfl.patch | 46 ++ ...dd-sanity-check-after-grub_strtoul-c.patch | 51 ++ ...sanity-check-after-grub_strtoul-call.patch | 62 ++ ...nux-Cast-left-shift-to-grub_uint32_t.patch | 35 ++ ...bsd-Use-safe-math-to-avoid-underflow.patch | 61 ++ ...ut-of-bounds-read-for-inline-and-ext.patch | 69 +++ ...xfs_iterate_dir-return-value-in-case.patch | 53 ++ ...-incorrect-inode-error-from-grub_xfs.patch | 77 +++ ...ot-inode-read-failure-in-grub_xfs_mo.patch | 29 + ...ee1275-ofnet-Add-missing-grub_malloc.patch | 36 ++ ...074-Constant-time-grub_crypto_memcmp.patch | 62 ++ boot/grub2/grub2.mk | 32 + 74 files changed, 6206 insertions(+) create mode 100644 boot/grub2/0002-misc-Implement-grub_strlcpy.patch create mode 100644 boot/grub2/0003-fs-ufs-Fix-a-heap-OOB-write.patch create mode 100644 boot/grub2/0004-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch create mode 100644 boot/grub2/0005-fs-tar-Initialize-name-in-grub_cpio_find_file.patch create mode 100644 boot/grub2/0006-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch create mode 100644 boot/grub2/0007-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0008-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0009-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0010-fs-iso9660-Fix-invalid-free.patch create mode 100644 boot/grub2/0011-fs-jfs-Fix-OOB-read-in-jfs_getent.patch create mode 100644 boot/grub2/0012-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch create mode 100644 boot/grub2/0013-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch create mode 100644 boot/grub2/0014-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch create mode 100644 boot/grub2/0015-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch create mode 100644 boot/grub2/0016-fs-xfs-Fix-out-of-bounds-read.patch create mode 100644 boot/grub2/0017-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch create mode 100644 boot/grub2/0018-kern-file-Ensure-file-data-is-set.patch create mode 100644 boot/grub2/0019-kern-file-Implement-filesystem-reference-counting.patch create mode 100644 boot/grub2/0020-disk-loopback-Reference-tracking-for-the-loopback.patch create mode 100644 boot/grub2/0021-kern-disk-Limit-recursion-depth.patch create mode 100644 boot/grub2/0022-kern-partition-Limit-recursion-in-part_iterate.patch create mode 100644 boot/grub2/0023-script-execute-Limit-the-recursion-depth.patch create mode 100644 boot/grub2/0024-net-Unregister-net_default_ip-and-net_default_mac-va.patch create mode 100644 boot/grub2/0025-net-Remove-variables-hooks-when-interface-is-unregis.patch create mode 100644 boot/grub2/0026-net-Fix-OOB-write-in-grub_net_search_config_file.patch create mode 100644 boot/grub2/0027-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch create mode 100644 boot/grub2/0028-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch create mode 100644 boot/grub2/0029-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch create mode 100644 boot/grub2/0030-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch create mode 100644 boot/grub2/0031-commands-extcmd-Missing-check-for-failed-allocation.patch create mode 100644 boot/grub2/0032-commands-ls-Fix-NULL-dereference.patch create mode 100644 boot/grub2/0033-commands-pgp-Unregister-the-check_signatures-hooks-o.patch create mode 100644 boot/grub2/0034-normal-Remove-variables-hooks-on-module-unload.patch create mode 100644 boot/grub2/0035-gettext-Remove-variables-hooks-on-module-unload.patch create mode 100644 boot/grub2/0036-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch create mode 100644 boot/grub2/0037-gettext-Integer-overflow-leads-to-heap-OOB-write.patch create mode 100644 boot/grub2/0038-commands-read-Fix-an-integer-overflow-when-supplying.patch create mode 100644 boot/grub2/0039-commands-test-Stack-overflow-due-to-unlimited-recurs.patch create mode 100644 boot/grub2/0040-commands-minicmd-Block-the-dump-command-in-lockdown-.patch create mode 100644 boot/grub2/0041-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch create mode 100644 boot/grub2/0042-commands-hexdump-Disable-memory-reading-in-lockdown-.patch create mode 100644 boot/grub2/0043-fs-bfs-Disable-under-lockdown.patch create mode 100644 boot/grub2/0044-fs-Disable-many-filesystems-under-lockdown.patch create mode 100644 boot/grub2/0045-disk-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0046-disk-Prevent-overflows-when-allocating-memory-for-ar.patch create mode 100644 boot/grub2/0047-disk-Check-if-returned-pointer-for-allocated-memory-.patch create mode 100644 boot/grub2/0048-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch create mode 100644 boot/grub2/0049-fs-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0050-fs-Prevent-overflows-when-allocating-memory-for-arra.patch create mode 100644 boot/grub2/0051-fs-Prevent-overflows-when-assigning-returned-values-.patch create mode 100644 boot/grub2/0052-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0053-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch create mode 100644 boot/grub2/0054-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch create mode 100644 boot/grub2/0055-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch create mode 100644 boot/grub2/0056-net-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0057-net-Prevent-overflows-when-allocating-memory-for-arr.patch create mode 100644 boot/grub2/0058-net-Check-if-returned-pointer-for-allocated-memory-i.patch create mode 100644 boot/grub2/0059-fs-sfs-Check-if-allocated-memory-is-NULL.patch create mode 100644 boot/grub2/0060-script-execute-Fix-potential-underflow-and-NULL-dere.patch create mode 100644 boot/grub2/0061-osdep-unix-getroot-Fix-potential-underflow.patch create mode 100644 boot/grub2/0062-misc-Ensure-consistent-overflow-error-messages.patch create mode 100644 boot/grub2/0063-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch create mode 100644 boot/grub2/0064-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch create mode 100644 boot/grub2/0065-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch create mode 100644 boot/grub2/0066-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch create mode 100644 boot/grub2/0067-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch create mode 100644 boot/grub2/0068-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch create mode 100644 boot/grub2/0069-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch create mode 100644 boot/grub2/0070-fs-xfs-Fix-grub_xfs_iterate_dir-return-value-in-case.patch create mode 100644 boot/grub2/0071-fs-xfs-Propagate-incorrect-inode-error-from-grub_xfs.patch create mode 100644 boot/grub2/0072-fs-xfs-Handle-root-inode-read-failure-in-grub_xfs_mo.patch create mode 100644 boot/grub2/0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch create mode 100644 boot/grub2/0074-Constant-time-grub_crypto_memcmp.patch
boot/grub2/0002-misc-Implement-grub_strlcpy.patch new file +70 -0
@@ -0,0 +1,70 @@ +From 67241595d3dae392589ee74b65cd40ea090d1837 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: ea703528a8581a2ea7e0bad424a70fdf0aec7d8f +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + include/grub/misc.h | 39 +++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 1b35a167f..103175480 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -64,6 +64,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) +-- +2.50.1 +
boot/grub2/0003-fs-ufs-Fix-a-heap-OOB-write.patch new file +36 -0
@@ -0,0 +1,36 @@ +From ab0f52dadcda56782b3e82be0b15fa6eb0e9cee1 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: c1a291b01f4f1dcd6a22b61f1c81a45a966d16ba +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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) +-- +2.50.1 +
boot/grub2/0004-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch new file +36 -0
@@ -0,0 +1,36 @@ +From 157e6e2a3da139dc2e08cf41b49115965cdaa1d3 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 417547c10410b714e43f08f74137c24015f8f4c3 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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) +-- +2.50.1 +
boot/grub2/0005-fs-tar-Initialize-name-in-grub_cpio_find_file.patch new file +45 -0
45 lines not on this page · raw message
boot/grub2/0006-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch new file +94 -0
94 lines not on this page · raw message
boot/grub2/0007-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch new file +36 -0
@@ -0,0 +1,36 @@ +From 95f391673c0a08c2410454536614ef543cac6629 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 563436258cde64da6b974880abff1bf0959f4da3 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +
boot/grub2/0008-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch new file +40 -0
@@ -0,0 +1,40 @@ +From 947e9e98d35edd7b359498b5f31338dc228f5081 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: f7c070a2e28dfab7137db0739fb8db1dc02d8898 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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); +-- +2.50.1 +
boot/grub2/0009-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch new file +38 -0
@@ -0,0 +1,38 @@ +From a0e37c98e6f330110e4009f8e5ba73ca0c2eaff5 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 965db5970811d18069b34f28f5f31ddadde90a97 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; + } +-- +2.50.1 +
boot/grub2/0010-fs-iso9660-Fix-invalid-free.patch new file +55 -0
55 lines not on this page · raw message
boot/grub2/0011-fs-jfs-Fix-OOB-read-in-jfs_getent.patch new file +68 -0
68 lines not on this page · raw message
boot/grub2/0012-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch new file +69 -0
69 lines not on this page · raw message
boot/grub2/0013-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch new file +133 -0
133 lines not on this page · raw message
boot/grub2/0014-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch new file +90 -0
90 lines not on this page · raw message
boot/grub2/0015-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch new file +51 -0
51 lines not on this page · raw message
boot/grub2/0016-fs-xfs-Fix-out-of-bounds-read.patch new file +48 -0
48 lines not on this page · raw message
boot/grub2/0017-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch new file +47 -0
47 lines not on this page · raw message
boot/grub2/0018-kern-file-Ensure-file-data-is-set.patch new file +37 -0
@@ -0,0 +1,37 @@ +From 816fb20ed0a80032e2eaf4c4ccaf989bf20908be Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: a7910687294b29288ac649e71b47493c93294f17 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 750177248..e990507fc 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -114,6 +114,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; + +-- +2.50.1 +
boot/grub2/0019-kern-file-Implement-filesystem-reference-counting.patch new file +449 -0
449 lines not on this page · raw message
boot/grub2/0020-disk-loopback-Reference-tracking-for-the-loopback.patch new file +108 -0
108 lines not on this page · raw message
boot/grub2/0021-kern-disk-Limit-recursion-depth.patch new file +125 -0
125 lines not on this page · raw message
boot/grub2/0022-kern-partition-Limit-recursion-in-part_iterate.patch new file +49 -0
49 lines not on this page · raw message
boot/grub2/0023-script-execute-Limit-the-recursion-depth.patch new file +60 -0
60 lines not on this page · raw message
boot/grub2/0024-net-Unregister-net_default_ip-and-net_default_mac-va.patch new file +34 -0
@@ -0,0 +1,34 @@ +From b9a8d2cb984f0a5fd92fe7275dfa280466dd82ce Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Thu, 28 Nov 2024 04:05:04 +0000 +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: a1dd8e59da26f1a9608381d3a1a6c0f465282b1d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 8cad4fb6d..f69c67b64 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -2072,6 +2072,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 (); +-- +2.50.1 +
boot/grub2/0025-net-Remove-variables-hooks-when-interface-is-unregis.patch new file +93 -0
93 lines not on this page · raw message
boot/grub2/0026-net-Fix-OOB-write-in-grub_net_search_config_file.patch new file +89 -0
89 lines not on this page · raw message
boot/grub2/0027-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch new file +120 -0
120 lines not on this page · raw message
boot/grub2/0028-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch new file +38 -0
@@ -0,0 +1,38 @@ +From 8368710fbce5c040227fca8bf10828ad1632f84f Mon Sep 17 00:00:00 2001 +From: Daniel Axtens <[email protected]> +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 <[email protected]> +Signed-off-by: Daniel Axtens <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 2c34af908ebf4856051ed29e46d88abd2b20387f +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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"); +-- +2.50.1 +
boot/grub2/0029-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch new file +143 -0
143 lines not on this page · raw message
boot/grub2/0030-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch new file +46 -0
46 lines not on this page · raw message
boot/grub2/0031-commands-extcmd-Missing-check-for-failed-allocation.patch new file +39 -0
@@ -0,0 +1,39 @@ +From 239a16a303228574f61a82c6fbb041688dff65d0 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: 05be856a8c3aae41f5df90cab7796ab7ee34b872 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +
boot/grub2/0032-commands-ls-Fix-NULL-dereference.patch new file +37 -0
@@ -0,0 +1,37 @@ +From 322d82364cc0db30b1ae4fc0adfdf7a43adc91ef Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 0bf56bce47489c059e50e61a3db7f682d8c44b56 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +
boot/grub2/0033-commands-pgp-Unregister-the-check_signatures-hooks-o.patch new file +36 -0
@@ -0,0 +1,36 @@ +From c05c4d591ef5f21fefd95fc928fe123a12f2bfb0 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 2123c5bca7e21fbeb0263df4597ddd7054700726 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 c6766f044..5fadc33c4 100644 +--- a/grub-core/commands/pgp.c ++++ b/grub-core/commands/pgp.c +@@ -1010,6 +1010,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); +-- +2.50.1 +
boot/grub2/0034-normal-Remove-variables-hooks-on-module-unload.patch new file +42 -0
42 lines not on this page · raw message
boot/grub2/0035-gettext-Remove-variables-hooks-on-module-unload.patch new file +39 -0
@@ -0,0 +1,39 @@ +From 69e0cb299c479e01e1c13a032172d29293db8e69 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 7580addfc8c94cedb0cdfd7a1fd65b539215e637 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 7a1c14e4f..e4f4f8ee6 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -535,6 +535,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); + +-- +2.50.1 +
boot/grub2/0036-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch new file +40 -0
@@ -0,0 +1,40 @@ +From 31b3e24947c6dbb65ea2eca30ddd168dc47513ce Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: 09bd6eb58b0f71ec273916070fa1e2de16897a91 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 e4f4f8ee6..63bb1ab73 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); +-- +2.50.1 +
boot/grub2/0037-gettext-Integer-overflow-leads-to-heap-OOB-write.patch new file +58 -0
58 lines not on this page · raw message
boot/grub2/0038-commands-read-Fix-an-integer-overflow-when-supplying.patch new file +74 -0
74 lines not on this page · raw message
boot/grub2/0039-commands-test-Stack-overflow-due-to-unlimited-recurs.patch new file +88 -0
88 lines not on this page · raw message
boot/grub2/0040-commands-minicmd-Block-the-dump-command-in-lockdown-.patch new file +38 -0
@@ -0,0 +1,38 @@ +From 2864e6ca7ac492d5215c369a6a52a57c6e602f55 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Reported-by: Jonathan Bar Or <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 34824806ac6302f91e8cabaa41308eaced25725f +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 286290866..8c5ee3e60 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -203,8 +203,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.")); +-- +2.50.1 +
boot/grub2/0041-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch new file +55 -0
55 lines not on this page · raw message
boot/grub2/0042-commands-hexdump-Disable-memory-reading-in-lockdown-.patch new file +42 -0
42 lines not on this page · raw message
boot/grub2/0043-fs-bfs-Disable-under-lockdown.patch new file +57 -0
57 lines not on this page · raw message
boot/grub2/0044-fs-Disable-many-filesystems-under-lockdown.patch new file +396 -0
8 lines not on this page · raw message
boot/grub2/0045-disk-Use-safe-math-macros-to-prevent-overflows.patch new file +551 -0
551 lines not on this page · raw message
boot/grub2/0046-disk-Prevent-overflows-when-allocating-memory-for-ar.patch new file +47 -0
47 lines not on this page · raw message
boot/grub2/0047-disk-Check-if-returned-pointer-for-allocated-memory-.patch new file +157 -0
157 lines not on this page · raw message
boot/grub2/0048-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch new file +36 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0049-fs-Use-safe-math-macros-to-prevent-overflows.patch new file +362 -0
362 lines not on this page · raw message
boot/grub2/0050-fs-Prevent-overflows-when-allocating-memory-for-arra.patch new file +87 -0
87 lines not on this page · raw message
boot/grub2/0051-fs-Prevent-overflows-when-assigning-returned-values-.patch new file +110 -0
110 lines not on this page · raw message
boot/grub2/0052-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch new file +143 -0
143 lines not on this page · raw message
boot/grub2/0053-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch new file +45 -0
45 lines not on this page · raw message
boot/grub2/0054-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch new file +93 -0
93 lines not on this page · raw message
boot/grub2/0055-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch new file +29 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0056-net-Use-safe-math-macros-to-prevent-overflows.patch new file +250 -0
250 lines not on this page · raw message
boot/grub2/0057-net-Prevent-overflows-when-allocating-memory-for-arr.patch new file +50 -0
50 lines not on this page · raw message
boot/grub2/0058-net-Check-if-returned-pointer-for-allocated-memory-i.patch new file +36 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0059-fs-sfs-Check-if-allocated-memory-is-NULL.patch new file +37 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0060-script-execute-Fix-potential-underflow-and-NULL-dere.patch new file +37 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0061-osdep-unix-getroot-Fix-potential-underflow.patch new file +40 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0062-misc-Ensure-consistent-overflow-error-messages.patch new file +60 -0
60 lines not on this page · raw message
boot/grub2/0063-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch new file +35 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0064-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch new file +46 -0
46 lines not on this page · raw message
boot/grub2/0065-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch new file +51 -0
51 lines not on this page · raw message
boot/grub2/0066-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch new file +62 -0
62 lines not on this page · raw message
boot/grub2/0067-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch new file +35 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0068-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch new file +61 -0
61 lines not on this page · raw message
boot/grub2/0069-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch new file +69 -0
69 lines not on this page · raw message
boot/grub2/0070-fs-xfs-Fix-grub_xfs_iterate_dir-return-value-in-case.patch new file +53 -0
53 lines not on this page · raw message
boot/grub2/0071-fs-xfs-Propagate-incorrect-inode-error-from-grub_xfs.patch new file +77 -0
77 lines not on this page · raw message
boot/grub2/0072-fs-xfs-Handle-root-inode-read-failure-in-grub_xfs_mo.patch new file +29 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch new file +36 -0
Lines of this file are not shown. View the raw message.
boot/grub2/0074-Constant-time-grub_crypto_memcmp.patch new file +62 -0
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Part of the diff is not shown here. View the raw message.
Thomas Perale via buildroot
AppliedRe: [Buildroot] [PATCH 3/3] boot/grub2: add patches to fix numerous CVEs
In reply of:
Quoted 44 lines
This patch brings the entire stack of Debian patches on grub2 titled "cve-2025-jan" and available at:
As of this exact Debian grub2 version 2.12-9. Some minor conflicts had to be fixed. All patches are in upstream Grub master, but mixed with hundreds of other changes, which is why Debian's effort to backport them has been leveraged here.
In addition to those patches, 2 extra patches are added:
0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch 0074-Constant-time-grub_crypto_memcmp.patch
The first one fixes an issue in one of the earlier patches. The fix is not in Debian, but is in upstream Grub.
The second one fixes another CVE, not fixed in Debian, but fixed in OpenSUSE. This fix is not upstream as upstream has decided to move to libgcrypt instead to avoid the problem, but that's a fairly large change.
Overall, this patch fixes all CVEs currently reported by pkg-stats against our grub2 package, namely:
CVE-2024-56737
CVE-2024-45782
CVE-2024-45778
CVE-2024-45779
CVE-2024-45777
CVE-2024-45780
CVE-2025-1125
CVE-2025-0684
CVE-2025-0689
CVE-2025-0686
CVE-2025-0685
CVE-2025-0678
CVE-2024-56738With the previous fixes on runtime tests added (to use glibc toolchains to build grub2 tests), this commit successfully passes all tests:
Quoted 7 lines
- The ISO9660 tests that use grub2:
https://gitlab.com/tpetazzoni/buildroot/-/pipelines/1985234563- The grub2 tests:
https://gitlab.com/tpetazzoni/buildroot/-/pipelines/1985234685Signed-off-by Thomas Petazzoni <[email protected]>
Applied to 2025.02.x & 2025.05.x. Thanks
Quoted 6,812 lines
--- .../0002-misc-Implement-grub_strlcpy.patch | 70 +++ .../0003-fs-ufs-Fix-a-heap-OOB-write.patch | 36 ++ ...Fix-stack-OOB-write-with-grub_strcpy.patch | 36 ++ ...itialize-name-in-grub_cpio_find_file.patch | 45 ++ ...ger-overflow-leads-to-heap-OOB-write.patch | 94 +++ ...f2fs-Set-a-grub_errno-if-mount-fails.patch | 36 ++ ...plus-Set-a-grub_errno-if-mount-fails.patch | 40 ++ ...9660-Set-a-grub_errno-if-mount-fails.patch | 38 ++ .../0010-fs-iso9660-Fix-invalid-free.patch | 55 ++ ...11-fs-jfs-Fix-OOB-read-in-jfs_getent.patch | 68 +++ ...ead-caused-by-invalid-dir-slot-index.patch | 69 +++ ...40-bits-offset-and-address-for-a-dat.patch | 133 +++++ ...ent-signed-unsigned-types-usage-in-r.patch | 90 +++ ...ut-of-bounds-read-for-inline-extents.patch | 51 ++ .../0016-fs-xfs-Fix-out-of-bounds-read.patch | 48 ++ ...g-failing-to-mount-sets-a-grub_errno.patch | 47 ++ ...18-kern-file-Ensure-file-data-is-set.patch | 37 ++ ...lement-filesystem-reference-counting.patch | 449 ++++++++++++++ ...-Reference-tracking-for-the-loopback.patch | 108 ++++ ...0021-kern-disk-Limit-recursion-depth.patch | 125 ++++ ...tion-Limit-recursion-in-part_iterate.patch | 49 ++ ...pt-execute-Limit-the-recursion-depth.patch | 60 ++ ...et_default_ip-and-net_default_mac-va.patch | 34 ++ ...bles-hooks-when-interface-is-unregis.patch | 93 +++ ...write-in-grub_net_search_config_file.patch | 89 +++ ...x-stack-buffer-overflow-in-tftp_open.patch | 120 ++++ ...eg-Do-not-permit-duplicate-SOF0-mark.patch | 38 ++ ...r-an-integer-overflow-in-grub_dl_ref.patch | 143 +++++ ...r-the-SHF_INFO_LINK-flag-in-grub_dl_.patch | 46 ++ ...-Missing-check-for-failed-allocation.patch | 39 ++ ...032-commands-ls-Fix-NULL-dereference.patch | 37 ++ ...egister-the-check_signatures-hooks-o.patch | 36 ++ ...ove-variables-hooks-on-module-unload.patch | 42 ++ ...ove-variables-hooks-on-module-unload.patch | 39 ++ ...overflow-leads-to-heap-OOB-write-or-.patch | 40 ++ ...ger-overflow-leads-to-heap-OOB-write.patch | 58 ++ ...x-an-integer-overflow-when-supplying.patch | 74 +++ ...ack-overflow-due-to-unlimited-recurs.patch | 88 +++ ...-Block-the-dump-command-in-lockdown-.patch | 38 ++ ...isable-memory-reading-in-lockdown-mo.patch | 55 ++ ...-Disable-memory-reading-in-lockdown-.patch | 42 ++ .../0043-fs-bfs-Disable-under-lockdown.patch | 57 ++ ...able-many-filesystems-under-lockdown.patch | 396 +++++++++++++ ...afe-math-macros-to-prevent-overflows.patch | 551 ++++++++++++++++++ ...rflows-when-allocating-memory-for-ar.patch | 47 ++ ...turned-pointer-for-allocated-memory-.patch | 157 +++++ ...disk-Call-grub_ieee1275_close-when-g.patch | 36 ++ ...afe-math-macros-to-prevent-overflows.patch | 362 ++++++++++++ ...lows-when-allocating-memory-for-arra.patch | 87 +++ ...lows-when-assigning-returned-values-.patch | 110 ++++ ...afe-math-macros-to-prevent-overflows.patch | 143 +++++ ...verflows-when-allocating-memory-for-.patch | 45 ++ ...returned-pointer-for-allocated-memor.patch | 93 +++ ...ng-NULL-check-after-grub_strdup-call.patch | 29 + ...afe-math-macros-to-prevent-overflows.patch | 250 ++++++++ ...flows-when-allocating-memory-for-arr.patch | 50 ++ ...urned-pointer-for-allocated-memory-i.patch | 36 ++ ...fs-Check-if-allocated-memory-is-NULL.patch | 37 ++ ...ix-potential-underflow-and-NULL-dere.patch | 37 ++ ...unix-getroot-Fix-potential-underflow.patch | 40 ++ ...e-consistent-overflow-error-messages.patch | 60 ++ ...ine-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch | 35 ++ ...safe-math-to-avoid-an-integer-overfl.patch | 46 ++ ...dd-sanity-check-after-grub_strtoul-c.patch | 51 ++ ...sanity-check-after-grub_strtoul-call.patch | 62 ++ ...nux-Cast-left-shift-to-grub_uint32_t.patch | 35 ++ ...bsd-Use-safe-math-to-avoid-underflow.patch | 61 ++ ...ut-of-bounds-read-for-inline-and-ext.patch | 69 +++ ...xfs_iterate_dir-return-value-in-case.patch | 53 ++ ...-incorrect-inode-error-from-grub_xfs.patch | 77 +++ ...ot-inode-read-failure-in-grub_xfs_mo.patch | 29 + ...ee1275-ofnet-Add-missing-grub_malloc.patch | 36 ++ ...074-Constant-time-grub_crypto_memcmp.patch | 62 ++ boot/grub2/grub2.mk | 32 + 74 files changed, 6206 insertions(+) create mode 100644 boot/grub2/0002-misc-Implement-grub_strlcpy.patch create mode 100644 boot/grub2/0003-fs-ufs-Fix-a-heap-OOB-write.patch create mode 100644 boot/grub2/0004-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch create mode 100644 boot/grub2/0005-fs-tar-Initialize-name-in-grub_cpio_find_file.patch create mode 100644 boot/grub2/0006-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch create mode 100644 boot/grub2/0007-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0008-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0009-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch create mode 100644 boot/grub2/0010-fs-iso9660-Fix-invalid-free.patch create mode 100644 boot/grub2/0011-fs-jfs-Fix-OOB-read-in-jfs_getent.patch create mode 100644 boot/grub2/0012-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch create mode 100644 boot/grub2/0013-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch create mode 100644 boot/grub2/0014-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch create mode 100644 boot/grub2/0015-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch create mode 100644 boot/grub2/0016-fs-xfs-Fix-out-of-bounds-read.patch create mode 100644 boot/grub2/0017-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch create mode 100644 boot/grub2/0018-kern-file-Ensure-file-data-is-set.patch create mode 100644 boot/grub2/0019-kern-file-Implement-filesystem-reference-counting.patch create mode 100644 boot/grub2/0020-disk-loopback-Reference-tracking-for-the-loopback.patch create mode 100644 boot/grub2/0021-kern-disk-Limit-recursion-depth.patch create mode 100644 boot/grub2/0022-kern-partition-Limit-recursion-in-part_iterate.patch create mode 100644 boot/grub2/0023-script-execute-Limit-the-recursion-depth.patch create mode 100644 boot/grub2/0024-net-Unregister-net_default_ip-and-net_default_mac-va.patch create mode 100644 boot/grub2/0025-net-Remove-variables-hooks-when-interface-is-unregis.patch create mode 100644 boot/grub2/0026-net-Fix-OOB-write-in-grub_net_search_config_file.patch create mode 100644 boot/grub2/0027-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch create mode 100644 boot/grub2/0028-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch create mode 100644 boot/grub2/0029-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch create mode 100644 boot/grub2/0030-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch create mode 100644 boot/grub2/0031-commands-extcmd-Missing-check-for-failed-allocation.patch create mode 100644 boot/grub2/0032-commands-ls-Fix-NULL-dereference.patch create mode 100644 boot/grub2/0033-commands-pgp-Unregister-the-check_signatures-hooks-o.patch create mode 100644 boot/grub2/0034-normal-Remove-variables-hooks-on-module-unload.patch create mode 100644 boot/grub2/0035-gettext-Remove-variables-hooks-on-module-unload.patch create mode 100644 boot/grub2/0036-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch create mode 100644 boot/grub2/0037-gettext-Integer-overflow-leads-to-heap-OOB-write.patch create mode 100644 boot/grub2/0038-commands-read-Fix-an-integer-overflow-when-supplying.patch create mode 100644 boot/grub2/0039-commands-test-Stack-overflow-due-to-unlimited-recurs.patch create mode 100644 boot/grub2/0040-commands-minicmd-Block-the-dump-command-in-lockdown-.patch create mode 100644 boot/grub2/0041-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch create mode 100644 boot/grub2/0042-commands-hexdump-Disable-memory-reading-in-lockdown-.patch create mode 100644 boot/grub2/0043-fs-bfs-Disable-under-lockdown.patch create mode 100644 boot/grub2/0044-fs-Disable-many-filesystems-under-lockdown.patch create mode 100644 boot/grub2/0045-disk-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0046-disk-Prevent-overflows-when-allocating-memory-for-ar.patch create mode 100644 boot/grub2/0047-disk-Check-if-returned-pointer-for-allocated-memory-.patch create mode 100644 boot/grub2/0048-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch create mode 100644 boot/grub2/0049-fs-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0050-fs-Prevent-overflows-when-allocating-memory-for-arra.patch create mode 100644 boot/grub2/0051-fs-Prevent-overflows-when-assigning-returned-values-.patch create mode 100644 boot/grub2/0052-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0053-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch create mode 100644 boot/grub2/0054-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch create mode 100644 boot/grub2/0055-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch create mode 100644 boot/grub2/0056-net-Use-safe-math-macros-to-prevent-overflows.patch create mode 100644 boot/grub2/0057-net-Prevent-overflows-when-allocating-memory-for-arr.patch create mode 100644 boot/grub2/0058-net-Check-if-returned-pointer-for-allocated-memory-i.patch create mode 100644 boot/grub2/0059-fs-sfs-Check-if-allocated-memory-is-NULL.patch create mode 100644 boot/grub2/0060-script-execute-Fix-potential-underflow-and-NULL-dere.patch create mode 100644 boot/grub2/0061-osdep-unix-getroot-Fix-potential-underflow.patch create mode 100644 boot/grub2/0062-misc-Ensure-consistent-overflow-error-messages.patch create mode 100644 boot/grub2/0063-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch create mode 100644 boot/grub2/0064-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch create mode 100644 boot/grub2/0065-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch create mode 100644 boot/grub2/0066-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch create mode 100644 boot/grub2/0067-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch create mode 100644 boot/grub2/0068-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch create mode 100644 boot/grub2/0069-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch create mode 100644 boot/grub2/0070-fs-xfs-Fix-grub_xfs_iterate_dir-return-value-in-case.patch create mode 100644 boot/grub2/0071-fs-xfs-Propagate-incorrect-inode-error-from-grub_xfs.patch create mode 100644 boot/grub2/0072-fs-xfs-Handle-root-inode-read-failure-in-grub_xfs_mo.patch create mode 100644 boot/grub2/0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch create mode 100644 boot/grub2/0074-Constant-time-grub_crypto_memcmp.patchboot/grub2/0002-misc-Implement-grub_strlcpy.patch new file +70
-0@@ -0,0 +1,70 @@ +From 67241595d3dae392589ee74b65cd40ea090d1837 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: ea703528a8581a2ea7e0bad424a70fdf0aec7d8f +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + include/grub/misc.h | 39 +++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 1b35a167f..103175480 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -64,6 +64,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) +-- +2.50.1 +boot/grub2/0003-fs-ufs-Fix-a-heap-OOB-write.patch new file +36
-0@@ -0,0 +1,36 @@ +From ab0f52dadcda56782b3e82be0b15fa6eb0e9cee1 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: c1a291b01f4f1dcd6a22b61f1c81a45a966d16ba +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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) +-- +2.50.1 +boot/grub2/0004-fs-hfs-Fix-stack-OOB-write-with-grub_strcpy.patch new file +36
-0@@ -0,0 +1,36 @@ +From 157e6e2a3da139dc2e08cf41b49115965cdaa1d3 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 417547c10410b714e43f08f74137c24015f8f4c3 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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) +-- +2.50.1 +boot/grub2/0005-fs-tar-Initialize-name-in-grub_cpio_find_file.patch new file +45
-0@@ -0,0 +1,45 @@ +From 2233c409ada20d1ab4a6a00a50cdde35e5a36589 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 2c8ac08c99466c0697f704242363fc687f492a0d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; + } + +-- +2.50.1 +boot/grub2/0006-fs-tar-Integer-overflow-leads-to-heap-OOB-write.patch new file +94
-0@@ -0,0 +1,94 @@ +From 472e180b6aac8cb4f25affa687e68f9be4e3df79 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: 0087bc6902182fe5cedce2d034c75a79cf6dd4f3 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 <grub/mm.h> + #include <grub/dl.h> + #include <grub/i18n.h> ++#include <grub/safemath.h> + + 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]) +-- +2.50.1 +boot/grub2/0007-fs-f2fs-Set-a-grub_errno-if-mount-fails.patch new file +36
-0@@ -0,0 +1,36 @@ +From 95f391673c0a08c2410454536614ef543cac6629 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 563436258cde64da6b974880abff1bf0959f4da3 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +boot/grub2/0008-fs-hfsplus-Set-a-grub_errno-if-mount-fails.patch new file +40
-0@@ -0,0 +1,40 @@ +From 947e9e98d35edd7b359498b5f31338dc228f5081 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: f7c070a2e28dfab7137db0739fb8db1dc02d8898 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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); +-- +2.50.1 +boot/grub2/0009-fs-iso9660-Set-a-grub_errno-if-mount-fails.patch new file +38
-0@@ -0,0 +1,38 @@ +From a0e37c98e6f330110e4009f8e5ba73ca0c2eaff5 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 965db5970811d18069b34f28f5f31ddadde90a97 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; + } +-- +2.50.1 +boot/grub2/0010-fs-iso9660-Fix-invalid-free.patch new file +55
-0@@ -0,0 +1,55 @@ +From 3acd964eafdd32e8ab7d7c04b18171052a859d3a Mon Sep 17 00:00:00 2001 +From: Michael Chang <[email protected]> +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 <[email protected]> +Signed-off-by: Michael Chang <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 1443833a9535a5873f7de3798cf4d8389f366611 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +boot/grub2/0011-fs-jfs-Fix-OOB-read-in-jfs_getent.patch new file +68
-0@@ -0,0 +1,68 @@ +From b01accc4d132a252f02bf57c31f5fff8ce98a339 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: 66175696f3a385b14bdf1ebcda7755834bd2d5fb +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +boot/grub2/0012-fs-jfs-Fix-OOB-read-caused-by-invalid-dir-slot-index.patch new file +69
-0@@ -0,0 +1,69 @@ +From b35b73b9d779e88fb4e6f53fb10a5bfebf3475aa Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: ab09fd0531f3523ac0ef833404526c98c08248f7 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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); + +-- +2.50.1 +boot/grub2/0013-fs-jfs-Use-full-40-bits-offset-and-address-for-a-dat.patch new file +133
-0@@ -0,0 +1,133 @@ +From 978c4c79935a375cb16d94e8114d96fee013c288 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Reviewed-by: Ross Philipson <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: bd999310fe67f35a66de3bfa2836da91589d04ef +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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)); +-- +2.50.1 +boot/grub2/0014-fs-jfs-Inconsistent-signed-unsigned-types-usage-in-r.patch new file +90
-0@@ -0,0 +1,90 @@ +From 32f319d100c3b8f9b04e6a175f599c7411a54555 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Reviewed-by: Ross Philipson <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: edd995a26ec98654d907a9436a296c2d82bc4b28 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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) + { +-- +2.50.1 +boot/grub2/0015-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch new file +51
-0@@ -0,0 +1,51 @@ +From 7da8e2e23db5f1ddb9c4dc992c69349149163c4c Mon Sep 17 00:00:00 2001 +From: Michael Chang <[email protected]> +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 <[email protected]> +Signed-off-by: Michael Chang <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 7e2f750f0a795c4d64ec7dc7591edac8da2e978c +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +boot/grub2/0016-fs-xfs-Fix-out-of-bounds-read.patch new file +48
-0@@ -0,0 +1,48 @@ +From 854503d76e7dbc25f999d6be3e2ef4e8067f4152 Mon Sep 17 00:00:00 2001 +From: Michael Chang <[email protected]> +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 <[email protected]> +Signed-off-by: Michael Chang <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 6ccc77b59d16578b10eaf8a4fe85c20b229f0d8a +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 bc2224dbb..d2d533531 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++) + { +-- +2.50.1 +boot/grub2/0017-fs-xfs-Ensuring-failing-to-mount-sets-a-grub_errno.patch new file +47
-0@@ -0,0 +1,47 @@ +From 9a5c23756f2e2d4ee8438bf449881c8f854e59ab Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: d1d6b7ea58aa5a80a4c4d0666b49460056c8ef0a +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 d2d533531..56738a135 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; + } + +@@ -1058,7 +1060,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); +-- +2.50.1 +boot/grub2/0018-kern-file-Ensure-file-data-is-set.patch new file +37
-0@@ -0,0 +1,37 @@ +From 816fb20ed0a80032e2eaf4c4ccaf989bf20908be Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: a7910687294b29288ac649e71b47493c93294f17 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 750177248..e990507fc 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -114,6 +114,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; + +-- +2.50.1 +boot/grub2/0019-kern-file-Implement-filesystem-reference-counting.patch new file +449
-0@@ -0,0 +1,449 @@ +From a27c4b6da2f4a014e5d096e75790e860bcdb2472 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Sun, 12 May 2024 10:15:03 +0100 +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> + +Conflicts: + grub-core/fs/erofs.c + +Upstream: 16f196874fbe360a1b3c66064ec15adadf94c57b +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 ba0c58352..aae81482b 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2413,6 +2413,7 @@ static struct grub_fs grub_btrfs_fs = { + + GRUB_MOD_INIT (btrfs) + { ++ grub_btrfs_fs.mod = mod; + grub_fs_register (&grub_btrfs_fs); + } + +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 de435aa14..560917dc2 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -1320,6 +1320,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 36b26ac98..c3850e013 100644 +--- a/grub-core/fs/reiserfs.c ++++ b/grub-core/fs/reiserfs.c +@@ -1417,6 +1417,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 56738a135..74feeb86a 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -1294,6 +1294,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 e990507fc..6e7efe89a 100644 +--- a/grub-core/kern/file.c ++++ b/grub-core/kern/file.c +@@ -25,6 +25,7 @@ + #include <grub/fs.h> + #include <grub/device.h> + #include <grub/i18n.h> ++#include <grub/dl.h> + + void (*EXPORT_VAR (grub_grubnet_fini)) (void); + +@@ -117,6 +118,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; + +@@ -197,6 +201,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); ++ + 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 <grub/device.h> + #include <grub/symbol.h> + #include <grub/types.h> ++#include <grub/dl.h> + + #include <grub/list.h> + /* 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); +-- +2.50.1 +boot/grub2/0020-disk-loopback-Reference-tracking-for-the-loopback.patch new file +108
-0@@ -0,0 +1,108 @@ +From a81ef3044791e7ee02bd349b5ec0adcbf6947555 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Sun, 12 May 2024 03:26:19 +0100 +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 67f70f70a36b6e87a65f928fe1e840a12eafb7ae +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + grub-core/disk/loopback.c | 18 ++++++++++++++++++ + include/grub/err.h | 3 ++- + 2 files changed, 20 insertions(+), 1 deletion(-) + +diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c +index 4635dcfde..2bea4e922 100644 +--- a/grub-core/disk/loopback.c ++++ b/grub-core/disk/loopback.c +@@ -24,6 +24,7 @@ + #include <grub/mm.h> + #include <grub/extcmd.h> + #include <grub/i18n.h> ++#include <grub/safemath.h> + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -33,6 +34,7 @@ struct grub_loopback + grub_file_t file; + struct grub_loopback *next; + unsigned long id; ++ grub_uint64_t refcnt; + }; + + static struct grub_loopback *loopback_list; +@@ -64,6 +66,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; + +@@ -120,6 +124,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; +@@ -161,6 +166,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) +@@ -178,6 +186,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) +@@ -220,6 +237,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 1c07034cd..b0e54e0a0 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; + +-- +2.50.1 +boot/grub2/0021-kern-disk-Limit-recursion-depth.patch new file +125
-0@@ -0,0 +1,125 @@ +From 195331a7a64c2a4ba754e2527ca8973012db68c9 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 18212f0648b6de7d71d4c8f41eb4d8b78b3a299b +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 1eda58fe9..82e04fd00 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; + +@@ -417,6 +421,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) + { +@@ -427,12 +433,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); +@@ -444,7 +455,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; +@@ -457,7 +468,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 +@@ -493,7 +503,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, +@@ -527,13 +537,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 b0e54e0a0..202fa8a7a 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; + +-- +2.50.1 +boot/grub2/0022-kern-partition-Limit-recursion-in-part_iterate.patch new file +49
-0@@ -0,0 +1,49 @@ +From 3f1c5f55e7ef7b872c3ae59c0c41f1e07508a943 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 8a7103fddfd6664f41081f3bb88eebbf2871da2a +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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) +-- +2.50.1 +boot/grub2/0023-script-execute-Limit-the-recursion-depth.patch new file +60
-0@@ -0,0 +1,60 @@ +From 2a094a7116c56519a42a13c96e77bdeda6069076 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: d8a937ccae5c6d86dc4375698afca5cefdcd01e1 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 14ff09094..e1450f45d 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -33,10 +33,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 +@@ -816,7 +824,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); +-- +2.50.1 +boot/grub2/0024-net-Unregister-net_default_ip-and-net_default_mac-va.patch new file +34
-0@@ -0,0 +1,34 @@ +From b9a8d2cb984f0a5fd92fe7275dfa280466dd82ce Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Thu, 28 Nov 2024 04:05:04 +0000 +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: a1dd8e59da26f1a9608381d3a1a6c0f465282b1d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 8cad4fb6d..f69c67b64 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -2072,6 +2072,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 (); +-- +2.50.1 +boot/grub2/0025-net-Remove-variables-hooks-when-interface-is-unregis.patch new file +93
-0@@ -0,0 +1,93 @@ +From 883c8721591c1f7a186e2f3cdc8a4f140bd81ce9 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Fri, 1 Nov 2024 23:49:48 +0000 +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 <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> + +Conflicts: + grub-core/net/net.c + +Upstream: aa8b4d7facef7b75a2703274b1b9d4e0e734c401 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 f69c67b64..8dbb0eada 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1094,6 +1094,39 @@ grub_cmd_delroute (struct grub_command *cmd __attribute__ ((unused)), + return GRUB_ERR_NONE; + } + ++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_route (const char *name, + grub_net_network_level_netaddress_t target, +diff --git a/include/grub/net.h b/include/grub/net.h +index 844e501c1..228d04963 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -540,16 +540,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); +-- +2.50.1 +boot/grub2/0026-net-Fix-OOB-write-in-grub_net_search_config_file.patch new file +89
-0@@ -0,0 +1,89 @@ +From 7ad4117be44d8cf0443bbc58d49e592a33aaac89 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Fri, 15 Nov 2024 13:12:09 +0000 +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 + +Reported-by: B Horn <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> + +Conflicts: + grub-core/normal/main.c + +Upstream: 5eef88152833062a3f7e017535372d64ac8ef7e1 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 8dbb0eada..2bd490279 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1942,14 +1942,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) +@@ -1975,7 +1976,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 bd4431000..3b48cd333 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -344,7 +344,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + + if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 && + !disable_net_search) +- grub_net_search_config_file (config); ++ grub_net_search_config_file (config, config_len); + + grub_enter_normal_mode (config); + grub_free (config); +diff --git a/include/grub/net.h b/include/grub/net.h +index 228d04963..58a4f83fc 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -570,7 +570,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; + +-- +2.50.1 +boot/grub2/0027-net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch new file +120
-0@@ -0,0 +1,120 @@ +From 8284fca0f096d01f566eadfdc790232df9f2934e Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 0707accab1b9be5d3645d4700dde3f99209f9367 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 409b1d09b..336b78691 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; + +-- +2.50.1 +boot/grub2/0028-video-readers-jpeg-Do-not-permit-duplicate-SOF0-mark.patch new file +38
-0@@ -0,0 +1,38 @@ +From 8368710fbce5c040227fca8bf10828ad1632f84f Mon Sep 17 00:00:00 2001 +From: Daniel Axtens <[email protected]> +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 <[email protected]> +Signed-off-by: Daniel Axtens <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 2c34af908ebf4856051ed29e46d88abd2b20387f +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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"); +-- +2.50.1 +boot/grub2/0029-kern-dl-Fix-for-an-integer-overflow-in-grub_dl_ref.patch new file +143
-0@@ -0,0 +1,143 @@ +From 4d70ddc5255b6d3f752da4120f593d7007222ca2 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Thu, 18 Apr 2024 15:59:26 +0100 +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 500e5fdd82ca40412b0b73f5e5dda38e4a3af96d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 fa498931e..286290866 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 0bf40caa6..1a38742e6 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -32,6 +32,7 @@ + #include <grub/env.h> + #include <grub/cache.h> + #include <grub/i18n.h> ++#include <grub/safemath.h> + + /* Platforms where modules are in a readonly area of memory. */ + #if defined(GRUB_MACHINE_QEMU) +@@ -532,7 +533,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; +@@ -543,10 +544,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; +@@ -557,10 +561,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 cd1f46c8b..f0a94e273 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -174,7 +174,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; +@@ -203,9 +203,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; +-- +2.50.1 +boot/grub2/0030-kern-dl-Check-for-the-SHF_INFO_LINK-flag-in-grub_dl_.patch new file +46
-0@@ -0,0 +1,46 @@ +From 91c2e44d3d29d11b339bec954142521148924ed1 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Thu, 7 Nov 2024 06:00:36 +0000 +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> + +Conflicts: + grub-core/kern/dl.c + +Conflicts: + grub-core/kern/dl.c + +Upstream: 98ad84328dcabfa603dcf5bd217570aa6b4bdd99 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 1a38742e6..958de3bf1 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -599,6 +599,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; ++ + /* Find the target segment. */ + for (seg = mod->segment; seg; seg = seg->next) + if (seg->section == s->sh_info) +-- +2.50.1 +boot/grub2/0031-commands-extcmd-Missing-check-for-failed-allocation.patch new file +39
-0@@ -0,0 +1,39 @@ +From 239a16a303228574f61a82c6fbb041688dff65d0 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: 05be856a8c3aae41f5df90cab7796ab7ee34b872 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +boot/grub2/0032-commands-ls-Fix-NULL-dereference.patch new file +37
-0@@ -0,0 +1,37 @@ +From 322d82364cc0db30b1ae4fc0adfdf7a43adc91ef Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 0bf56bce47489c059e50e61a3db7f682d8c44b56 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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; +-- +2.50.1 +boot/grub2/0033-commands-pgp-Unregister-the-check_signatures-hooks-o.patch new file +36
-0@@ -0,0 +1,36 @@ +From c05c4d591ef5f21fefd95fc928fe123a12f2bfb0 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 2123c5bca7e21fbeb0263df4597ddd7054700726 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 c6766f044..5fadc33c4 100644 +--- a/grub-core/commands/pgp.c ++++ b/grub-core/commands/pgp.c +@@ -1010,6 +1010,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); +-- +2.50.1 +boot/grub2/0034-normal-Remove-variables-hooks-on-module-unload.patch new file +42
-0@@ -0,0 +1,42 @@ +From 6290cc499f0fcaa82b3764cf1d9beb2ff27d82a1 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 9c16197734ada8d0838407eebe081117799bfe67 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 3b48cd333..5d848c864 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -582,7 +582,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); + } +-- +2.50.1 +boot/grub2/0035-gettext-Remove-variables-hooks-on-module-unload.patch new file +39
-0@@ -0,0 +1,39 @@ +From 69e0cb299c479e01e1c13a032172d29293db8e69 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 7580addfc8c94cedb0cdfd7a1fd65b539215e637 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 7a1c14e4f..e4f4f8ee6 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -535,6 +535,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); + +-- +2.50.1 +boot/grub2/0036-gettext-Integer-overflow-leads-to-heap-OOB-write-or-.patch new file +40
-0@@ -0,0 +1,40 @@ +From 31b3e24947c6dbb65ea2eca30ddd168dc47513ce Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: 09bd6eb58b0f71ec273916070fa1e2de16897a91 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 e4f4f8ee6..63bb1ab73 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); +-- +2.50.1 +boot/grub2/0037-gettext-Integer-overflow-leads-to-heap-OOB-write.patch new file +58
-0@@ -0,0 +1,58 @@ +From dfe673e457e9eb5c7c0c68d8385ba176476de7d7 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Reviewed-by: Alec Brown <[email protected]> +Upstream: b970a5ed967816bbca8225994cd0ee2557bad515 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 63bb1ab73..9ffc73428 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -26,6 +26,7 @@ + #include <grub/file.h> + #include <grub/kernel.h> + #include <grub/i18n.h> ++#include <grub/safemath.h> + + 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; + +-- +2.50.1 +boot/grub2/0038-commands-read-Fix-an-integer-overflow-when-supplying.patch new file +74
-0@@ -0,0 +1,74 @@ +From 762eda67c7b0e83011040d5dbcc2ddc9a03b90cd Mon Sep 17 00:00:00 2001 +From: Jonathan Bar Or <[email protected]> +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 <[email protected]> +Signed-off-by: Jonathan Bar Or <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: dad8f502974ed9ad0a70ae6820d17b4b142558fc +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 <grub/types.h> + #include <grub/extcmd.h> + #include <grub/i18n.h> ++#include <grub/safemath.h> + + 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); +-- +2.50.1 +boot/grub2/0039-commands-test-Stack-overflow-due-to-unlimited-recurs.patch new file +88
-0@@ -0,0 +1,88 @@ +From 926fe49003b6b46d595d5900893c8ca79710bbd2 Mon Sep 17 00:00:00 2001 +From: Lidong Chen <[email protected]> +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 <[email protected]> +Signed-off-by: Lidong Chen <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: c68b7d23628a19da67ebe2e06f84165ee04961af +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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")); + } + +-- +2.50.1 +boot/grub2/0040-commands-minicmd-Block-the-dump-command-in-lockdown-.patch new file +38
-0@@ -0,0 +1,38 @@ +From 2864e6ca7ac492d5215c369a6a52a57c6e602f55 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +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 <[email protected]> +Reported-by: Jonathan Bar Or <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 34824806ac6302f91e8cabaa41308eaced25725f +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 286290866..8c5ee3e60 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -203,8 +203,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.")); +-- +2.50.1 +boot/grub2/0041-commands-memrw-Disable-memory-reading-in-lockdown-mo.patch new file +55
-0@@ -0,0 +1,55 @@ +From 51c3e37bb23b3ce1919f3ff582cb31fc32a10b4b Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Thu, 18 Apr 2024 20:37:10 +0100 +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 <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 340e4d058f584534f4b90b7dbea2b64a9f8c418c +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 d401a6db0..3542683d1 100644 +--- a/grub-core/commands/memrw.c ++++ b/grub-core/commands/memrw.c +@@ -122,17 +122,20 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) + GRUB_MOD_INIT(memrw) + { + 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]"), +-- +2.50.1 +boot/grub2/0042-commands-hexdump-Disable-memory-reading-in-lockdown-.patch new file +42
-0@@ -0,0 +1,42 @@ +From d5028a608b21c6fa6ff02e4d84a96ab28034d170 Mon Sep 17 00:00:00 2001 +From: B Horn <[email protected]> +Date: Fri, 19 Apr 2024 22:31:45 +0100 +Subject: [PATCH] commands/hexdump: Disable memory reading in lockdown mode + +Reported-by: B Horn <[email protected]> +Signed-off-by: B Horn <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 5f31164aed51f498957cdd6ed733ec71a8592c99 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 <grub/lib/hexdump.h> + #include <grub/extcmd.h> + #include <grub/i18n.h> ++#include <grub/lockdown.h> + + 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; +-- +2.50.1 +boot/grub2/0043-fs-bfs-Disable-under-lockdown.patch new file +57
-0@@ -0,0 +1,57 @@ +From 71487b0cf0f7c3fa45f450ed1f3ea4cedd8002a1 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens <[email protected]> +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 <[email protected]> +Signed-off-by: Daniel Axtens <[email protected]> +Reviewed-by: Daniel Kiper <[email protected]> +Upstream: 26db6605036bd9e5b16d9068a8cc75be63b8b630 +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + 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 <grub/types.h> + #include <grub/i18n.h> + #include <grub/fshelp.h> ++#include <grub/lockdown.h> + + 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); + } +-- +2.50.1 +boot/grub2/0044-fs-Disable-many-filesystems-under-lockdown.patch new file +396
-0@@ -0,0 +1,396 @@ +From f0846530aef66583064a6707430437912dda5fa9 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens <[email protected]> +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. +Lines of this file are not shown. View the raw message.
boot/grub2/0045-disk-Use-safe-math-macros-to-prevent-overflows.patch new file +551
-0Lines of this file are not shown. View the raw message.
boot/grub2/0046-disk-Prevent-overflows-when-allocating-memory-for-ar.patch new file +47
-0Lines of this file are not shown. View the raw message.
boot/grub2/0047-disk-Check-if-returned-pointer-for-allocated-memory-.patch new file +157
-0Lines of this file are not shown. View the raw message.
boot/grub2/0048-disk-ieee1275-ofdisk-Call-grub_ieee1275_close-when-g.patch new file +36
-0Lines of this file are not shown. View the raw message.
boot/grub2/0049-fs-Use-safe-math-macros-to-prevent-overflows.patch new file +362
-0Lines of this file are not shown. View the raw message.
boot/grub2/0050-fs-Prevent-overflows-when-allocating-memory-for-arra.patch new file +87
-0Lines of this file are not shown. View the raw message.
boot/grub2/0051-fs-Prevent-overflows-when-assigning-returned-values-.patch new file +110
-0Lines of this file are not shown. View the raw message.
boot/grub2/0052-fs-zfs-Use-safe-math-macros-to-prevent-overflows.patch new file +143
-0Lines of this file are not shown. View the raw message.
boot/grub2/0053-fs-zfs-Prevent-overflows-when-allocating-memory-for-.patch new file +45
-0Lines of this file are not shown. View the raw message.
boot/grub2/0054-fs-zfs-Check-if-returned-pointer-for-allocated-memor.patch new file +93
-0Lines of this file are not shown. View the raw message.
boot/grub2/0055-fs-zfs-Add-missing-NULL-check-after-grub_strdup-call.patch new file +29
-0Lines of this file are not shown. View the raw message.
boot/grub2/0056-net-Use-safe-math-macros-to-prevent-overflows.patch new file +250
-0Lines of this file are not shown. View the raw message.
boot/grub2/0057-net-Prevent-overflows-when-allocating-memory-for-arr.patch new file +50
-0Lines of this file are not shown. View the raw message.
boot/grub2/0058-net-Check-if-returned-pointer-for-allocated-memory-i.patch new file +36
-0Lines of this file are not shown. View the raw message.
boot/grub2/0059-fs-sfs-Check-if-allocated-memory-is-NULL.patch new file +37
-0Lines of this file are not shown. View the raw message.
boot/grub2/0060-script-execute-Fix-potential-underflow-and-NULL-dere.patch new file +37
-0Lines of this file are not shown. View the raw message.
boot/grub2/0061-osdep-unix-getroot-Fix-potential-underflow.patch new file +40
-0Lines of this file are not shown. View the raw message.
boot/grub2/0062-misc-Ensure-consistent-overflow-error-messages.patch new file +60
-0Lines of this file are not shown. View the raw message.
boot/grub2/0063-bus-usb-ehci-Define-GRUB_EHCI_TOGGLE-as-grub_uint32_.patch new file +35
-0Lines of this file are not shown. View the raw message.
boot/grub2/0064-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch new file +46
-0Lines of this file are not shown. View the raw message.
boot/grub2/0065-kern-partition-Add-sanity-check-after-grub_strtoul-c.patch new file +51
-0Lines of this file are not shown. View the raw message.
boot/grub2/0066-kern-misc-Add-sanity-check-after-grub_strtoul-call.patch new file +62
-0Lines of this file are not shown. View the raw message.
boot/grub2/0067-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch new file +35
-0Lines of this file are not shown. View the raw message.
boot/grub2/0068-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch new file +61
-0Lines of this file are not shown. View the raw message.
boot/grub2/0069-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch new file +69
-0Lines of this file are not shown. View the raw message.
boot/grub2/0070-fs-xfs-Fix-grub_xfs_iterate_dir-return-value-in-case.patch new file +53
-0Lines of this file are not shown. View the raw message.
boot/grub2/0071-fs-xfs-Propagate-incorrect-inode-error-from-grub_xfs.patch new file +77
-0Lines of this file are not shown. View the raw message.
boot/grub2/0072-fs-xfs-Handle-root-inode-read-failure-in-grub_xfs_mo.patch new file +29
-0Lines of this file are not shown. View the raw message.
boot/grub2/0073-net-drivers-ieee1275-ofnet-Add-missing-grub_malloc.patch new file +36
-0Lines of this file are not shown. View the raw message.
boot/grub2/0074-Constant-time-grub_crypto_memcmp.patch new file +62
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.50.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Part of the diff is not shown here. View the raw message.