WSL2-Linux-Kernel/fs/verity
Eric Biggers 56124d6c87 fsverity: support enabling with tree block size < PAGE_SIZE
Make FS_IOC_ENABLE_VERITY support values of
fsverity_enable_arg::block_size other than PAGE_SIZE.

To make this possible, rework build_merkle_tree(), which was reading
data and hash pages from the file and assuming that they were the same
thing as "blocks".

For reading the data blocks, just replace the direct pagecache access
with __kernel_read(), to naturally read one block at a time.

(A disadvantage of the above is that we lose the two optimizations of
hashing the pagecache pages in-place and forcing the maximum readahead.
That shouldn't be very important, though.)

The hash block reads are a bit more difficult to handle, as the only way
to do them is through fsverity_operations::read_merkle_tree_page().

Instead, let's switch to the single-pass tree construction algorithm
that fsverity-utils uses.  This eliminates the need to read back any
hash blocks while the tree is being built, at the small cost of an extra
block-sized memory buffer per Merkle tree level.  This is probably what
I should have done originally.

Taken together, the above two changes result in page-size independent
code that is also a bit simpler than what we had before.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Andrey Albershteyn <aalbersh@redhat.com>
Tested-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Link: https://lore.kernel.org/r/20221223203638.41293-8-ebiggers@kernel.org
2023-01-09 19:06:06 -08:00
..
Kconfig fsverity: remove debug messages and CONFIG_FS_VERITY_DEBUG 2023-01-01 15:46:48 -08:00
Makefile fs-verity: add FS_IOC_READ_VERITY_METADATA ioctl 2021-02-07 14:51:11 -08:00
enable.c fsverity: support enabling with tree block size < PAGE_SIZE 2023-01-09 19:06:06 -08:00
fsverity_private.h fsverity: support verification with tree block size < PAGE_SIZE 2023-01-09 19:06:03 -08:00
hash_algs.c fsverity: replace fsverity_hash_page() with fsverity_hash_block() 2023-01-09 19:06:01 -08:00
init.c fsverity: remove debug messages and CONFIG_FS_VERITY_DEBUG 2023-01-01 15:46:48 -08:00
measure.c fsverity: simplify fsverity_get_digest() 2022-11-29 21:07:41 -08:00
open.c fsverity: support verification with tree block size < PAGE_SIZE 2023-01-09 19:06:03 -08:00
read_metadata.c fs-verity: use kmap_local_page() instead of kmap() 2022-08-19 15:19:55 -07:00
signature.c fsverity: remove debug messages and CONFIG_FS_VERITY_DEBUG 2023-01-01 15:46:48 -08:00
verify.c fsverity: support verification with tree block size < PAGE_SIZE 2023-01-09 19:06:03 -08:00