summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSakib Sajal <sakib.sajal@windriver.com>2022-07-26 15:18:46 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-23 15:22:52 +0100
commitee5b810f66321d54602a5626b0a8dbf1c2a6bad6 (patch)
tree22929d4735fe2b92d3617e682232759506d91e98
parent1d9d4e54c9fe7b236f14dbff9bc5caf69e728e39 (diff)
downloadpoky-ee5b810f66321d54602a5626b0a8dbf1c2a6bad6.tar.gz
u-boot: fix CVE-2022-33103
Backport patch to resolve CVE-2022-33103. (From OE-Core rev: af701fde05f6c225a65223fddc6008c4d6444af1) Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com> Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-bsp/u-boot/files/0001-fs-squashfs-sqfs_read-Prevent-arbitrary-code-executi.patch80
-rw-r--r--meta/recipes-bsp/u-boot/u-boot_2022.01.bb1
2 files changed, 81 insertions, 0 deletions
diff --git a/meta/recipes-bsp/u-boot/files/0001-fs-squashfs-sqfs_read-Prevent-arbitrary-code-executi.patch b/meta/recipes-bsp/u-boot/files/0001-fs-squashfs-sqfs_read-Prevent-arbitrary-code-executi.patch
new file mode 100644
index 0000000000..b1650f6baa
--- /dev/null
+++ b/meta/recipes-bsp/u-boot/files/0001-fs-squashfs-sqfs_read-Prevent-arbitrary-code-executi.patch
@@ -0,0 +1,80 @@
1From 65f1066f5abe291c7b10b6075fd60776074a38a9 Mon Sep 17 00:00:00 2001
2From: Miquel Raynal <miquel.raynal@bootlin.com>
3Date: Thu, 9 Jun 2022 16:02:06 +0200
4Subject: [PATCH] fs/squashfs: sqfs_read: Prevent arbitrary code execution
5
6Following Jincheng's report, an out-of-band write leading to arbitrary
7code execution is possible because on one side the squashfs logic
8accepts directory names up to 65535 bytes (u16), while U-Boot fs logic
9accepts directory names up to 255 bytes long.
10
11Prevent such an exploit from happening by capping directory name sizes
12to 255. Use a define for this purpose so that developers can link the
13limitation to its source and eventually kill it some day by dynamically
14allocating this array (if ever desired).
15
16Link: https://lore.kernel.org/all/CALO=DHFB+yBoXxVr5KcsK0iFdg+e7ywko4-e+72kjbcS8JBfPw@mail.gmail.com
17Reported-by: Jincheng Wang <jc.w4ng@gmail.com>
18Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
19Tested-by: Jincheng Wang <jc.w4ng@gmail.com>
20
21CVE: CVE-2022-33103
22Upstream-Status: Backport [2ac0baab4aff1a0b45067d0b62f00c15f4e86856]
23
24Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
25---
26 fs/squashfs/sqfs.c | 8 +++++---
27 include/fs.h | 4 +++-
28 2 files changed, 8 insertions(+), 4 deletions(-)
29
30diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
31index e2d91c654c..a145d754cc 100644
32--- a/fs/squashfs/sqfs.c
33+++ b/fs/squashfs/sqfs.c
34@@ -973,6 +973,7 @@ int sqfs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp)
35 int i_number, offset = 0, ret;
36 struct fs_dirent *dent;
37 unsigned char *ipos;
38+ u16 name_size;
39
40 dirs = (struct squashfs_dir_stream *)fs_dirs;
41 if (!dirs->size) {
42@@ -1055,9 +1056,10 @@ int sqfs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp)
43 return -SQFS_STOP_READDIR;
44 }
45
46- /* Set entry name */
47- strncpy(dent->name, dirs->entry->name, dirs->entry->name_size + 1);
48- dent->name[dirs->entry->name_size + 1] = '\0';
49+ /* Set entry name (capped at FS_DIRENT_NAME_LEN which is a U-Boot limitation) */
50+ name_size = min_t(u16, dirs->entry->name_size + 1, FS_DIRENT_NAME_LEN - 1);
51+ strncpy(dent->name, dirs->entry->name, name_size);
52+ dent->name[name_size] = '\0';
53
54 offset = dirs->entry->name_size + 1 + SQFS_ENTRY_BASE_LENGTH;
55 dirs->entry_count--;
56diff --git a/include/fs.h b/include/fs.h
57index 1c79e299fd..6cb7ec89f4 100644
58--- a/include/fs.h
59+++ b/include/fs.h
60@@ -161,6 +161,8 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
61 #define FS_DT_REG 8 /* regular file */
62 #define FS_DT_LNK 10 /* symbolic link */
63
64+#define FS_DIRENT_NAME_LEN 256
65+
66 /**
67 * struct fs_dirent - directory entry
68 *
69@@ -181,7 +183,7 @@ struct fs_dirent {
70 /** change_time: time of last modification */
71 struct rtc_time change_time;
72 /** name: file name */
73- char name[256];
74+ char name[FS_DIRENT_NAME_LEN];
75 };
76
77 /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
78--
792.33.0
80
diff --git a/meta/recipes-bsp/u-boot/u-boot_2022.01.bb b/meta/recipes-bsp/u-boot/u-boot_2022.01.bb
index f2443723e2..a6a15d698f 100644
--- a/meta/recipes-bsp/u-boot/u-boot_2022.01.bb
+++ b/meta/recipes-bsp/u-boot/u-boot_2022.01.bb
@@ -4,6 +4,7 @@ require u-boot.inc
4SRC_URI:append = " file://0001-riscv32-Use-double-float-ABI-for-rv32.patch \ 4SRC_URI:append = " file://0001-riscv32-Use-double-float-ABI-for-rv32.patch \
5 file://0001-riscv-fix-build-with-binutils-2.38.patch \ 5 file://0001-riscv-fix-build-with-binutils-2.38.patch \
6 file://0001-i2c-fix-stack-buffer-overflow-vulnerability-in-i2c-m.patch \ 6 file://0001-i2c-fix-stack-buffer-overflow-vulnerability-in-i2c-m.patch \
7 file://0001-fs-squashfs-sqfs_read-Prevent-arbitrary-code-executi.patch \
7 " 8 "
8 9
9DEPENDS += "bc-native dtc-native python3-setuptools-native" 10DEPENDS += "bc-native dtc-native python3-setuptools-native"