From: Eric Biggers <ebiggers@kernel.org>
To: fstests@vger.kernel.org
Cc: linux-fscrypt@vger.kernel.org
Subject: [PATCH 02/10] common/verity: set FSV_BLOCK_SIZE to an appropriate value
Date: Sat, 10 Dec 2022 23:06:55 -0800 [thread overview]
Message-ID: <20221211070704.341481-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20221211070704.341481-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
In order to maximize the chance that the verity tests can actually be
run, FSV_BLOCK_SIZE (the default Merkle tree size for the verity tests)
needs to be min(fs_block_size, page_size), not simply page_size. The
only reason that page_size was okay before was because the kernel only
supported merkle_tree_block_size == fs_block_size == page_size anyway.
But that is changing.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
common/verity | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/common/verity b/common/verity
index 1a53a7ea..a94ebf8e 100644
--- a/common/verity
+++ b/common/verity
@@ -13,6 +13,11 @@ if [ "$FSTYP" == "btrfs" ]; then
fi
fi
+# Require fs-verity support on the scratch filesystem.
+#
+# FSV_BLOCK_SIZE will be set to a Merkle tree block size that is supported by
+# the filesystem. Other sizes may be supported too, but FSV_BLOCK_SIZE is the
+# only size that is guaranteed to work without any additional checks.
_require_scratch_verity()
{
_require_scratch
@@ -27,7 +32,7 @@ _require_scratch_verity()
# Try to mount the filesystem. If this fails then either the kernel
# isn't aware of fs-verity, or the mkfs options were not compatible with
- # verity (e.g. ext4 with block size != PAGE_SIZE).
+ # verity (e.g. ext4 with block size != PAGE_SIZE on old kernels).
if ! _try_scratch_mount &>>$seqres.full; then
_notrun "kernel is unaware of $FSTYP verity feature," \
"or mkfs options are not compatible with verity"
@@ -39,6 +44,27 @@ _require_scratch_verity()
_notrun "kernel $FSTYP isn't configured with verity support"
fi
+ # Select a default Merkle tree block size for when tests don't
+ # explicitly specify one.
+ #
+ # For consistency reasons, all 'fsverity' subcommands, including
+ # 'fsverity enable', default to 4K Merkle tree blocks. That's generally
+ # not ideal for tests, since it's possible that the filesystem doesn't
+ # support 4K blocks but does support another size. Specifically, the
+ # kernel originally supported only merkle_tree_block_size ==
+ # fs_block_size == page_size, and later it was updated to support
+ # merkle_tree_block_size <= min(fs_block_size, page_size).
+ #
+ # Therefore, we default to merkle_tree_block_size == min(fs_block_size,
+ # page_size). That maximizes the chance of verity actually working.
+ local fs_block_size=$(_get_block_size $SCRATCH_MNT)
+ local page_size=$(get_page_size)
+ if (( fs_block_size <= page_size )); then
+ FSV_BLOCK_SIZE=$fs_block_size
+ else
+ FSV_BLOCK_SIZE=$page_size
+ fi
+
# The filesystem may have fs-verity enabled but not actually usable by
# default. E.g., ext4 only supports verity on extent-based files, so it
# doesn't work on ext3-style filesystems. So, try actually using it.
@@ -47,10 +73,6 @@ _require_scratch_verity()
fi
_scratch_unmount
-
- # Merkle tree block size. Currently all filesystems only support
- # PAGE_SIZE for this. This is also the default for 'fsverity enable'.
- FSV_BLOCK_SIZE=$(get_page_size)
}
# Check for CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y, as well as the userspace
--
2.38.1
next prev parent reply other threads:[~2022-12-11 7:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-11 7:06 [PATCH 00/10] xfstests: update verity tests for non-4K block and page size Eric Biggers
2022-12-11 7:06 ` [PATCH 01/10] common/verity: add and use _fsv_can_enable() Eric Biggers
2022-12-11 7:06 ` Eric Biggers [this message]
2022-12-11 7:06 ` [PATCH 03/10] common/verity: use FSV_BLOCK_SIZE by default Eric Biggers
2022-12-11 7:06 ` [PATCH 04/10] common/verity: add _filter_fsverity_digest() Eric Biggers
2022-12-11 7:06 ` [PATCH 05/10] generic/572: support non-4K Merkle tree block size Eric Biggers
2022-12-11 7:06 ` [PATCH 06/10] generic/573: " Eric Biggers
2022-12-11 7:07 ` [PATCH 07/10] generic/577: " Eric Biggers
2022-12-11 7:07 ` [PATCH 08/10] generic/574: test multiple Merkle tree block sizes Eric Biggers
2022-12-11 7:07 ` [PATCH 09/10] generic/624: " Eric Biggers
2022-12-20 6:56 ` Zorro Lang
2022-12-20 8:00 ` Eric Biggers
2022-12-20 20:40 ` Zorro Lang
2022-12-11 7:07 ` [PATCH 10/10] generic/575: test 1K Merkle tree block size Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221211070704.341481-3-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).