fsverity: support enabling with tree block size < PAGE_SIZE
authorEric Biggers <ebiggers@google.com>
Fri, 23 Dec 2022 20:36:34 +0000 (12:36 -0800)
committerEric Biggers <ebiggers@google.com>
Tue, 10 Jan 2023 03:06:06 +0000 (19:06 -0800)
commit56124d6c87fd749477425110d2564166621a89c4
tree091049a6dad33ae2f66c1b5a78b7b2376bdc6706
parent5306892a50bf4cd4cc945bad286c7c950078d65e
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
Documentation/filesystems/fsverity.rst
fs/verity/enable.c
include/linux/fsverity.h