mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-01 21:23:51 -09:00
This patch brings the entire stack of Debian patches on grub2 titled "cve-2025-jan" and available at: https://salsa.debian.org/grub-team/grub/-/tree/debian/2.12-9/debian/patches/cve-2025-jan?ref_type=tags 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-45777 CVE-2024-45778 CVE-2024-45779 CVE-2024-45780 CVE-2024-45782 CVE-2024-56737 CVE-2024-56738 CVE-2025-0678 CVE-2025-0684 CVE-2025-0685 CVE-2025-0686 CVE-2025-0689 CVE-2025-1125 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 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> [Julien: also tested by building and booting - qemu_aarch64_sbsa_defconfig - qemu_arm_ebbr_defconfig - qemu_loongarch64_virt_efi_defconfig - qemu_riscv64_virt_efi_defconfig - pc_x86_64_bios_defconfig - pc_x86_64_efi_defconfig ] Tested-by: Julien Olivain <ju.o@free.fr> [Julien: - fix patch #72 upstream link to point to the initial patch sumbission 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. ] Signed-off-by: Julien Olivain <ju.o@free.fr>
111 lines
4.2 KiB
Diff
111 lines
4.2 KiB
Diff
From 639711967a296edb0704c3d2c31691076d46f565 Mon Sep 17 00:00:00 2001
|
|
From: Lidong Chen <lidong.chen@oracle.com>
|
|
Date: Tue, 21 Jan 2025 19:02:38 +0000
|
|
Subject: [PATCH] fs: Prevent overflows when assigning returned values from
|
|
read_number()
|
|
|
|
The direct assignment of the unsigned long long value returned by
|
|
read_number() can potentially lead to an overflow on a 32-bit systems.
|
|
The fix replaces the direct assignments with calls to grub_cast()
|
|
which detects the overflows and safely assigns the values if no
|
|
overflow is detected.
|
|
|
|
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
|
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
Upstream: cde9f7f338f8f5771777f0e7dfc423ddf952ad31
|
|
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
|
|
---
|
|
grub-core/fs/cpio_common.c | 18 ++++++++++++++----
|
|
grub-core/fs/tar.c | 23 ++++++++++++++++-------
|
|
2 files changed, 30 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/grub-core/fs/cpio_common.c b/grub-core/fs/cpio_common.c
|
|
index 6ba58b354..45ac119a8 100644
|
|
--- a/grub-core/fs/cpio_common.c
|
|
+++ b/grub-core/fs/cpio_common.c
|
|
@@ -62,11 +62,21 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
|
|
#endif
|
|
)
|
|
return grub_error (GRUB_ERR_BAD_FS, "invalid cpio archive");
|
|
- data->size = read_number (hd.filesize, ARRAY_SIZE (hd.filesize));
|
|
+
|
|
+ if (grub_cast (read_number (hd.filesize, ARRAY_SIZE (hd.filesize)), &data->size))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("data size overflow"));
|
|
+
|
|
if (mtime)
|
|
- *mtime = read_number (hd.mtime, ARRAY_SIZE (hd.mtime));
|
|
- modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode));
|
|
- namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize));
|
|
+ {
|
|
+ if (grub_cast (read_number (hd.mtime, ARRAY_SIZE (hd.mtime)), mtime))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("mtime overflow"));
|
|
+ }
|
|
+
|
|
+ if (grub_cast (read_number (hd.mode, ARRAY_SIZE (hd.mode)), &modeval))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("mode overflow"));
|
|
+
|
|
+ if (grub_cast (read_number (hd.namesize, ARRAY_SIZE (hd.namesize)), &namesize))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("namesize overflow"));
|
|
|
|
/* Don't allow negative numbers. */
|
|
if (namesize >= 0x80000000)
|
|
diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c
|
|
index fd2ec1f74..1eaa5349f 100644
|
|
--- a/grub-core/fs/tar.c
|
|
+++ b/grub-core/fs/tar.c
|
|
@@ -99,9 +99,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
|
|
if (hd.typeflag == 'L')
|
|
{
|
|
grub_err_t err;
|
|
- grub_size_t namesize = read_number (hd.size, sizeof (hd.size));
|
|
+ grub_size_t namesize;
|
|
|
|
- if (grub_add (namesize, 1, &sz))
|
|
+ if (grub_cast (read_number (hd.size, sizeof (hd.size)), &namesize) ||
|
|
+ grub_add (namesize, 1, &sz))
|
|
return grub_error (GRUB_ERR_BAD_FS, N_("name size overflow"));
|
|
|
|
*name = grub_malloc (sz);
|
|
@@ -123,9 +124,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
|
|
if (hd.typeflag == 'K')
|
|
{
|
|
grub_err_t err;
|
|
- grub_size_t linksize = read_number (hd.size, sizeof (hd.size));
|
|
+ grub_size_t linksize;
|
|
|
|
- if (grub_add (linksize, 1, &sz))
|
|
+ if (grub_cast (read_number (hd.size, sizeof (hd.size)), &linksize) ||
|
|
+ grub_add (linksize, 1, &sz))
|
|
return grub_error (GRUB_ERR_BAD_FS, N_("link size overflow"));
|
|
|
|
if (data->linkname_alloc < sz)
|
|
@@ -174,15 +176,22 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
|
|
(*name)[extra_size + sizeof (hd.name)] = 0;
|
|
}
|
|
|
|
- data->size = read_number (hd.size, sizeof (hd.size));
|
|
+ if (grub_cast (read_number (hd.size, sizeof (hd.size)), &data->size))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("data size overflow"));
|
|
+
|
|
data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE;
|
|
data->next_hofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) &
|
|
~(GRUB_DISK_SECTOR_SIZE - 1));
|
|
if (mtime)
|
|
- *mtime = read_number (hd.mtime, sizeof (hd.mtime));
|
|
+ {
|
|
+ if (grub_cast (read_number (hd.mtime, sizeof (hd.mtime)), mtime))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("mtime overflow"));
|
|
+ }
|
|
if (mode)
|
|
{
|
|
- *mode = read_number (hd.mode, sizeof (hd.mode));
|
|
+ if (grub_cast (read_number (hd.mode, sizeof (hd.mode)), mode))
|
|
+ return grub_error (GRUB_ERR_BAD_FS, N_("mode overflow"));
|
|
+
|
|
switch (hd.typeflag)
|
|
{
|
|
/* Hardlink. */
|
|
--
|
|
2.50.1
|
|
|