diff options
author | Pali Rohár <pali@kernel.org> | 2022-05-17 23:45:28 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-06-03 17:23:22 +0300 |
commit | 339f652992919be11e3f1b791515140de646a3ef (patch) | |
tree | 53af4db451621e7ca5f9cd93db44c3c5782076c9 | |
parent | 3053b781465711fd05b88ab141b1f2b55a875516 (diff) | |
download | u-boot-339f652992919be11e3f1b791515140de646a3ef.tar.xz |
ubifs: Fix lockup/crash when reading files
Commit b1a14f8a1c2e ("UBIFS: Change ubifsload to not read beyond the
requested size") added optimization to do not read more bytes than it is
really needed. But this commit introduced incorrect handling of the hole at
the end of file. This logic cause U-Boot to crash or lockup when trying to
read from the ubifs filesystem.
When read_block() call returns -ENOENT error (not an error, but the hole)
then dn-> structure is not filled and contain garbage. So using of dn->size
for memcpy() argument cause that U-Boot tries to copy unspecified amount of
bytes from possible unmapped memory. Which randomly cause lockup of P2020
CPU.
Fix this issue by copying UBIFS_BLOCK_SIZE bytes from read buffer when
dn->size is not available. UBIFS_BLOCK_SIZE is the size of the buffer
itself and read_block() fills buffer by zeros when it returns -ENOENT.
This patch fixes ubifsload on P2020.
Fixes: b1a14f8a1c2e ("UBIFS: Change ubifsload to not read beyond the requested size")
Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
-rw-r--r-- | fs/ubifs/ubifs.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index d6be5c947d..d3026e3101 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -788,6 +788,8 @@ static int do_readpage(struct ubifs_info *c, struct inode *inode, if (last_block_size) dlen = last_block_size; + else if (ret) + dlen = UBIFS_BLOCK_SIZE; else dlen = le32_to_cpu(dn->size); |