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>
144 lines
4.8 KiB
Diff
144 lines
4.8 KiB
Diff
From bd4fcbdbd9835716213debce07f08c81311ce9a6 Mon Sep 17 00:00:00 2001
|
|
From: Lidong Chen <lidong.chen@oracle.com>
|
|
Date: Wed, 22 Jan 2025 07:17:02 +0000
|
|
Subject: [PATCH] fs/zfs: Use safe math macros to prevent overflows
|
|
|
|
Replace direct arithmetic operations with macros from include/grub/safemath.h
|
|
to prevent potential overflow issues when calculating the memory sizes.
|
|
|
|
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
|
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
Upstream: 88e491a0f744c6b19b6d4caa300a576ba56db7c9
|
|
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
|
|
---
|
|
grub-core/fs/zfs/zfs.c | 50 +++++++++++++++++++++++++++++++++++++-----
|
|
1 file changed, 44 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
|
|
index a497b1869..2f303d655 100644
|
|
--- a/grub-core/fs/zfs/zfs.c
|
|
+++ b/grub-core/fs/zfs/zfs.c
|
|
@@ -2387,6 +2387,7 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap,
|
|
zap_dnode->endian) << DNODE_SHIFT);
|
|
grub_err_t err;
|
|
grub_zfs_endian_t endian;
|
|
+ grub_size_t sz;
|
|
|
|
if (zap_verify (zap, zap_dnode->endian))
|
|
return 0;
|
|
@@ -2448,8 +2449,14 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap,
|
|
if (le->le_type != ZAP_CHUNK_ENTRY)
|
|
continue;
|
|
|
|
- buf = grub_malloc (grub_zfs_to_cpu16 (le->le_name_length, endian)
|
|
- * name_elem_length + 1);
|
|
+ if (grub_mul (grub_zfs_to_cpu16 (le->le_name_length, endian), name_elem_length, &sz) ||
|
|
+ grub_add (sz, 1, &sz))
|
|
+ {
|
|
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("buffer size overflow"));
|
|
+ grub_free (l);
|
|
+ return grub_errno;
|
|
+ }
|
|
+ buf = grub_malloc (sz);
|
|
if (zap_leaf_array_get (l, endian, blksft,
|
|
grub_zfs_to_cpu16 (le->le_name_chunk,
|
|
endian),
|
|
@@ -2872,6 +2879,7 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn,
|
|
&& ((grub_zfs_to_cpu64(((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_mode, dnode_path->dn.endian) >> 12) & 0xf) == 0xa)
|
|
{
|
|
char *sym_value;
|
|
+ grub_size_t sz;
|
|
grub_size_t sym_sz;
|
|
int free_symval = 0;
|
|
char *oldpath = path, *oldpathbuf = path_buf;
|
|
@@ -2923,7 +2931,18 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn,
|
|
break;
|
|
free_symval = 1;
|
|
}
|
|
- path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1);
|
|
+
|
|
+ if (grub_add (sym_sz, grub_strlen (oldpath), &sz) ||
|
|
+ grub_add (sz, 1, &sz))
|
|
+ {
|
|
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("path buffer size overflow"));
|
|
+ grub_free (oldpathbuf);
|
|
+ if (free_symval)
|
|
+ grub_free (sym_value);
|
|
+ err = grub_errno;
|
|
+ break;
|
|
+ }
|
|
+ path = path_buf = grub_malloc (sz);
|
|
if (!path_buf)
|
|
{
|
|
grub_free (oldpathbuf);
|
|
@@ -2960,6 +2979,7 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn,
|
|
{
|
|
void *sahdrp;
|
|
int hdrsize;
|
|
+ grub_size_t sz;
|
|
|
|
if (dnode_path->dn.dn.dn_bonuslen != 0)
|
|
{
|
|
@@ -2993,7 +3013,15 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn,
|
|
+ SA_SIZE_OFFSET),
|
|
dnode_path->dn.endian);
|
|
char *oldpath = path, *oldpathbuf = path_buf;
|
|
- path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1);
|
|
+ if (grub_add (sym_sz, grub_strlen (oldpath), &sz) ||
|
|
+ grub_add (sz, 1, &sz))
|
|
+ {
|
|
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("path buffer size overflow"));
|
|
+ grub_free (oldpathbuf);
|
|
+ err = grub_errno;
|
|
+ break;
|
|
+ }
|
|
+ path = path_buf = grub_malloc (sz);
|
|
if (!path_buf)
|
|
{
|
|
grub_free (oldpathbuf);
|
|
@@ -3568,6 +3596,7 @@ grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist, const char *name,
|
|
unsigned i;
|
|
grub_size_t nelm;
|
|
int elemsize = 0;
|
|
+ int sz;
|
|
|
|
found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST_ARRAY, &nvpair,
|
|
&size, &nelm);
|
|
@@ -3602,7 +3631,12 @@ grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist, const char *name,
|
|
return 0;
|
|
}
|
|
|
|
- ret = grub_zalloc (elemsize + sizeof (grub_uint32_t));
|
|
+ if (grub_add (elemsize, sizeof (grub_uint32_t), &sz))
|
|
+ {
|
|
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("elemsize overflow"));
|
|
+ return 0;
|
|
+ }
|
|
+ ret = grub_zalloc (sz);
|
|
if (!ret)
|
|
return 0;
|
|
grub_memcpy (ret, nvlist, sizeof (grub_uint32_t));
|
|
@@ -4193,6 +4227,7 @@ iterate_zap_snap (const char *name, grub_uint64_t val,
|
|
struct grub_dirhook_info info;
|
|
char *name2;
|
|
int ret;
|
|
+ grub_size_t sz;
|
|
|
|
dnode_end_t mdn;
|
|
|
|
@@ -4213,7 +4248,10 @@ iterate_zap_snap (const char *name, grub_uint64_t val,
|
|
return 0;
|
|
}
|
|
|
|
- name2 = grub_malloc (grub_strlen (name) + 2);
|
|
+ if (grub_add (grub_strlen (name), 2, &sz))
|
|
+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("name length overflow"));
|
|
+
|
|
+ name2 = grub_malloc (sz);
|
|
name2[0] = '@';
|
|
grub_memcpy (name2 + 1, name, grub_strlen (name) + 1);
|
|
ret = ctx->hook (name2, &info, ctx->hook_data);
|
|
--
|
|
2.50.1
|
|
|