u-boot/fs/squashfs
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
..
Kconfig include/u-boot, lib/zlib: add sources for zlib decompression 2020-08-07 22:31:32 -04:00
Makefile fs/squashfs: new filesystem 2020-08-07 22:31:32 -04:00
sqfs_decompressor.c fs/squashfs: add support for LZO decompression 2020-08-24 14:11:31 -04:00
sqfs_decompressor.h fs/squashfs: replace sqfs_decompress() parameter 2020-08-24 14:11:31 -04:00
sqfs_dir.c squashfs: Fix compilation on big endian systems 2022-06-03 11:15:24 -04:00
sqfs_filesystem.h fs/squashfs: Fix some hardlinks reading the wrong inode 2021-08-04 15:58:31 -04:00
sqfs_inode.c fs/squashfs: Fix compilation error 2021-03-04 14:40:52 -05:00
sqfs_utils.h fs/squashfs: new filesystem 2020-08-07 22:31:32 -04:00
sqfs.c fs/squashfs: Use kcalloc when relevant 2022-06-28 15:51:56 -04:00