summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-bsp/u-boot/files/0001-fs-squashfs-Use-kcalloc-when-relevant.patch64
-rw-r--r--meta/recipes-bsp/u-boot/u-boot_2022.01.bb1
2 files changed, 65 insertions, 0 deletions
diff --git a/meta/recipes-bsp/u-boot/files/0001-fs-squashfs-Use-kcalloc-when-relevant.patch b/meta/recipes-bsp/u-boot/files/0001-fs-squashfs-Use-kcalloc-when-relevant.patch
new file mode 100644
index 0000000000..70fdbb1031
--- /dev/null
+++ b/meta/recipes-bsp/u-boot/files/0001-fs-squashfs-Use-kcalloc-when-relevant.patch
@@ -0,0 +1,64 @@
1From 50d4b8b9effcf9dc9e5a90034de2f0003fb063f0 Mon Sep 17 00:00:00 2001
2From: Miquel Raynal <miquel.raynal@bootlin.com>
3Date: Mon, 27 Jun 2022 12:20:03 +0200
4Subject: [PATCH] fs/squashfs: Use kcalloc when relevant
5
6A crafted squashfs image could embed a huge number of empty metadata
7blocks in order to make the amount of malloc()'d memory overflow and be
8much smaller than expected. Because of this flaw, any random code
9positioned at the right location in the squashfs image could be memcpy'd
10from the squashfs structures into U-Boot code location while trying to
11access the rearmost blocks, before being executed.
12
13In order to prevent this vulnerability from being exploited in eg. a
14secure boot environment, let's add a check over the amount of data
15that is going to be allocated. Such a check could look like:
16
17if (!elem_size || n > SIZE_MAX / elem_size)
18 return NULL;
19
20The right way to do it would be to enhance the calloc() implementation
21but this is quite an impacting change for such a small fix. Another
22solution would be to add the check before the malloc call in the
23squashfs implementation, but this does not look right. So for now, let's
24use the kcalloc() compatibility function from Linux, which has this
25check.
26
27Fixes: c5100613037 ("fs/squashfs: new filesystem")
28Reported-by: Tatsuhiko Yasumatsu <Tatsuhiko.Yasumatsu@sony.com>
29Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
30Tested-by: Tatsuhiko Yasumatsu <Tatsuhiko.Yasumatsu@sony.com>
31
32Upstream-Status: Backport [7f7fb9937c6cb49dd35153bd6708872b390b0a44]
33CVE: CVE-2022-33967
34
35Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
36---
37 fs/squashfs/sqfs.c | 4 +++-
38 1 file changed, 3 insertions(+), 1 deletion(-)
39
40diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
41index e2d91c654c..10e63afbce 100644
42--- a/fs/squashfs/sqfs.c
43+++ b/fs/squashfs/sqfs.c
44@@ -13,6 +13,7 @@
45 #include <linux/types.h>
46 #include <linux/byteorder/little_endian.h>
47 #include <linux/byteorder/generic.h>
48+#include <linux/compat.h>
49 #include <memalign.h>
50 #include <stdlib.h>
51 #include <string.h>
52@@ -725,7 +726,8 @@ static int sqfs_read_inode_table(unsigned char **inode_table)
53 goto free_itb;
54 }
55
56- *inode_table = malloc(metablks_count * SQFS_METADATA_BLOCK_SIZE);
57+ *inode_table = kcalloc(metablks_count, SQFS_METADATA_BLOCK_SIZE,
58+ GFP_KERNEL);
59 if (!*inode_table) {
60 ret = -ENOMEM;
61 goto free_itb;
62--
632.33.0
64
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 04f60adaa5..54033698be 100644
--- a/meta/recipes-bsp/u-boot/u-boot_2022.01.bb
+++ b/meta/recipes-bsp/u-boot/u-boot_2022.01.bb
@@ -6,6 +6,7 @@ SRC_URI:append = " file://0001-riscv32-Use-double-float-ABI-for-rv32.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 file://0001-fs-squashfs-sqfs_read-Prevent-arbitrary-code-executi.patch \
8 file://0001-net-Check-for-the-minimum-IP-fragmented-datagram-siz.patch \ 8 file://0001-net-Check-for-the-minimum-IP-fragmented-datagram-siz.patch \
9 file://0001-fs-squashfs-Use-kcalloc-when-relevant.patch \
9 " 10 "
10 11
11DEPENDS += "bc-native dtc-native python3-setuptools-native" 12DEPENDS += "bc-native dtc-native python3-setuptools-native"