Squashfs: Compute expected length from inode size rather than block length
authorPhillip Lougher <phillip@squashfs.org.uk>
Thu, 2 Aug 2018 15:45:15 +0000 (16:45 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Sep 2018 07:20:03 +0000 (09:20 +0200)
commit6b9882c69ee12e1a1437e3ea9fa71edb1d36313f
tree037d48c348ddcef0dce4f6a706980080a6bef382
parentab99a2bac2ea8ff6fc55437523e29a984040f505
Squashfs: Compute expected length from inode size rather than block length

[ Upstream commit a3f94cb99a854fa381fe7fadd97c4f61633717a5 ]

Previously in squashfs_readpage() when copying data into the page
cache, it used the length of the datablock read from the filesystem
(after decompression).  However, if the filesystem has been corrupted
this data block may be short, which will leave pages unfilled.

The fix for this is to compute the expected number of bytes to copy
from the inode size, and use this to detect if the block is short.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Tested-by: Willy Tarreau <w@1wt.eu>
Cc: Анатолий Тросиненко <anatoly.trosinenko@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/squashfs/file.c
fs/squashfs/file_cache.c
fs/squashfs/file_direct.c
fs/squashfs/squashfs.h