u-boot/fs
Miquel Raynal 7f7fb9937c fs/squashfs: Use kcalloc when relevant
A crafted squashfs image could embed a huge number of empty metadata
blocks in order to make the amount of malloc()'d memory overflow and be
much smaller than expected. Because of this flaw, any random code
positioned at the right location in the squashfs image could be memcpy'd
from the squashfs structures into U-Boot code location while trying to
access the rearmost blocks, before being executed.

In order to prevent this vulnerability from being exploited in eg. a
secure boot environment, let's add a check over the amount of data
that is going to be allocated. Such a check could look like:

if (!elem_size || n > SIZE_MAX / elem_size)
	return NULL;

The right way to do it would be to enhance the calloc() implementation
but this is quite an impacting change for such a small fix. Another
solution would be to add the check before the malloc call in the
squashfs implementation, but this does not look right. So for now, let's
use the kcalloc() compatibility function from Linux, which has this
check.

Fixes: c510061303 ("fs/squashfs: new filesystem")
Reported-by: Tatsuhiko Yasumatsu <Tatsuhiko.Yasumatsu@sony.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Tatsuhiko Yasumatsu <Tatsuhiko.Yasumatsu@sony.com>
2022-06-28 15:51:56 -04:00
..
btrfs btrfs: Fix compilation on big endian systems 2022-04-19 14:52:34 -04:00
cbfs doc: replace @return by Return: 2022-01-19 18:11:34 +01:00
cramfs common: Drop flash.h from common header 2020-05-18 14:53:28 -04:00
erofs fs/erofs: add lz4 decompression support 2022-03-15 16:19:29 -04:00
ext4 fs: ext4: Use CRC-16 implementation from linux/crc16.h 2022-04-21 14:32:40 -04:00
fat doc: replace @return by Return: 2022-01-19 18:11:34 +01:00
jffs2 Convert CONFIG_JFFS2_DEV et al to Kconfig 2021-12-27 16:20:19 -05:00
reiserfs common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
sandbox bootstd: sandbox: Add a hostfs bootdev 2022-04-25 10:00:04 -04:00
squashfs fs/squashfs: Use kcalloc when relevant 2022-06-28 15:51:56 -04:00
ubifs ubifs: Fix lockup/crash when reading files 2022-06-03 10:23:22 -04:00
yaffs2 fs: yaffs2: Finish Kconfig migration 2021-11-05 11:23:29 -04:00
zfs common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
fs.c fs: Add a function to set the filesystem type 2022-04-25 10:00:03 -04:00
fs_internal.c fs: convert error and debug messages to log 2020-09-06 21:21:41 +02:00
Kconfig bootstd: sandbox: Add a hostfs bootdev 2022-04-25 10:00:04 -04:00
Makefile fs: Add semihosting filesystem 2022-04-01 15:03:13 -04:00
semihostingfs.c fs: Add semihosting filesystem 2022-04-01 15:03:13 -04:00