WSL2-Linux-Kernel/fs/verity
Eric Biggers 80f6e3080b fs-verity: fix signed integer overflow with i_size near S64_MAX
If the file size is almost S64_MAX, the calculated number of Merkle tree
levels exceeds FS_VERITY_MAX_LEVELS, causing FS_IOC_ENABLE_VERITY to
fail.  This is unintentional, since as the comment above the definition
of FS_VERITY_MAX_LEVELS states, it is enough for over U64_MAX bytes of
data using SHA-256 and 4K blocks.  (Specifically, 4096*128**8 >= 2**64.)

The bug is actually that when the number of blocks in the first level is
calculated from i_size, there is a signed integer overflow due to i_size
being signed.  Fix this by treating i_size as unsigned.

This was found by the new test "generic: test fs-verity EFBIG scenarios"
(https://lkml.kernel.org/r/b1d116cd4d0ea74b9cd86f349c672021e005a75c.1631558495.git.boris@bur.io).

This didn't affect ext4 or f2fs since those have a smaller maximum file
size, but it did affect btrfs which allows files up to S64_MAX bytes.

Reported-by: Boris Burkov <boris@bur.io>
Fixes: 3fda4c617e ("fs-verity: implement FS_IOC_ENABLE_VERITY ioctl")
Fixes: fd2d1acfca ("fs-verity: add the hook for file ->open()")
Cc: <stable@vger.kernel.org> # v5.4+
Reviewed-by: Boris Burkov <boris@bur.io>
Link: https://lore.kernel.org/r/20210916203424.113376-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
2021-09-22 10:56:34 -07:00
..
Kconfig fsverity: relax build time dependency on CRYPTO_SHA256 2021-04-22 17:31:32 +10:00
Makefile fs-verity: add FS_IOC_READ_VERITY_METADATA ioctl 2021-02-07 14:51:11 -08:00
enable.c fs-verity: fix signed integer overflow with i_size near S64_MAX 2021-09-22 10:56:34 -07:00
fsverity_private.h fs-verity: don't pass whole descriptor to fsverity_verify_signature() 2021-02-07 14:51:09 -08:00
hash_algs.c fs-verity: remove filenames from file comments 2020-11-16 11:40:10 -08:00
init.c fs-verity: remove filenames from file comments 2020-11-16 11:40:10 -08:00
measure.c fs-verity: rename "file measurement" to "file digest" 2020-11-16 11:40:12 -08:00
open.c fs-verity: fix signed integer overflow with i_size near S64_MAX 2021-09-22 10:56:34 -07:00
read_metadata.c fs-verity: support reading signature with ioctl 2021-02-07 14:51:19 -08:00
signature.c fs-verity: don't pass whole descriptor to fsverity_verify_signature() 2021-02-07 14:51:09 -08:00
verify.c fs-verity: remove filenames from file comments 2020-11-16 11:40:10 -08:00