]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
u-boot: fix CVE-2024-57255
authorHongxu Jia <hongxu.jia@windriver.com>
Wed, 19 Feb 2025 08:18:15 +0000 (16:18 +0800)
committerSteve Sakoman <steve@sakoman.com>
Wed, 19 Feb 2025 15:05:14 +0000 (07:05 -0800)
An integer overflow in sqfs_resolve_symlink in Das U-Boot before 2025.01-rc1
occurs via a crafted squashfs filesystem with an inode size of 0xffffffff,
resulting in a malloc of zero and resultant memory overwrite.

https://nvd.nist.gov/vuln/detail/CVE-2024-57255

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
meta/recipes-bsp/u-boot/files/CVE-2024-57255.patch [new file with mode: 0644]
meta/recipes-bsp/u-boot/u-boot_2022.01.bb

diff --git a/meta/recipes-bsp/u-boot/files/CVE-2024-57255.patch b/meta/recipes-bsp/u-boot/files/CVE-2024-57255.patch
new file mode 100644 (file)
index 0000000..4ca72da
--- /dev/null
@@ -0,0 +1,53 @@
+From 5d7ca74388544bf8c95e104517a9120e94bfe40d Mon Sep 17 00:00:00 2001
+From: Richard Weinberger <richard@nod.at>
+Date: Fri, 2 Aug 2024 18:36:44 +0200
+Subject: [PATCH 2/8] squashfs: Fix integer overflow in sqfs_resolve_symlink()
+
+A carefully crafted squashfs filesystem can exhibit an inode size of 0xffffffff,
+as a consequence malloc() will do a zero allocation.
+Later in the function the inode size is again used for copying data.
+So an attacker can overwrite memory.
+Avoid the overflow by using the __builtin_add_overflow() helper.
+
+Signed-off-by: Richard Weinberger <richard@nod.at>
+Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
+
+CVE: CVE-2024-57255
+Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/233945eba63e24061dffeeaeb7cd6fe985278356]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ fs/squashfs/sqfs.c | 10 ++++++----
+ 1 file changed, 6 insertions(+), 4 deletions(-)
+
+diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
+index 1430e671..16a07c06 100644
+--- a/fs/squashfs/sqfs.c
++++ b/fs/squashfs/sqfs.c
+@@ -422,8 +422,10 @@ static char *sqfs_resolve_symlink(struct squashfs_symlink_inode *sym,
+       char *resolved, *target;
+       u32 sz;
+-      sz = get_unaligned_le32(&sym->symlink_size);
+-      target = malloc(sz + 1);
++      if (__builtin_add_overflow(get_unaligned_le32(&sym->symlink_size), 1, &sz))
++              return NULL;
++
++      target = malloc(sz);
+       if (!target)
+               return NULL;
+@@ -431,9 +433,9 @@ static char *sqfs_resolve_symlink(struct squashfs_symlink_inode *sym,
+        * There is no trailling null byte in the symlink's target path, so a
+        * copy is made and a '\0' is added at its end.
+        */
+-      target[sz] = '\0';
++      target[sz - 1] = '\0';
+       /* Get target name (relative path) */
+-      strncpy(target, sym->symlink, sz);
++      strncpy(target, sym->symlink, sz - 1);
+       /* Relative -> absolute path conversion */
+       resolved = sqfs_get_abs_path(base_path, target);
+-- 
+2.34.1
+
index d9c6fcb993a8250b61cdbf06822b7784d3fec5a7..cfe36256f330ebe9b715fc9e933e1daaf89b5837 100644 (file)
@@ -12,6 +12,7 @@ SRC_URI +=       " file://0001-riscv32-Use-double-float-ABI-for-rv32.patch \
                    file://CVE-2022-2347_1.patch \
                    file://CVE-2022-2347_2.patch \
                    file://CVE-2024-57254.patch \
+                   file://CVE-2024-57255.patch \
                  "
 
 DEPENDS += "bc-native dtc-native python3-setuptools-native"