Message ID | 93f40b68c7beafb546e3cda328a78b2ab088d85c.1644883592.git.boris@bur.io (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | tests for btrfs fsverity | expand |
On Mon, Feb 14, 2022 at 04:09:56PM -0800, Boris Burkov wrote: > generic/574 has tests for corrupting the merkle tree data stored by the > filesystem. Since btrfs uses a different scheme for storing this data, > the existing logic for corrupting it doesn't work out of the box. Adapt > it to properly corrupt btrfs merkle items. > > This test relies on the btrfs implementation of fsverity in the patch: > btrfs: initial fsverity support > > and on btrfs-corrupt-block for corruption in the patches titled: > btrfs-progs: corrupt generic item data with btrfs-corrupt-block > btrfs-progs: expand corrupt_file_extent in btrfs-corrupt-block > > Signed-off-by: Boris Burkov <boris@bur.io> > --- > common/verity | 18 ++++++++++++++++++ > tests/generic/574 | 1 + > 2 files changed, 19 insertions(+) > > diff --git a/common/verity b/common/verity > index eec8ae72..07d9d3fe 100644 > --- a/common/verity > +++ b/common/verity > @@ -322,6 +322,24 @@ _fsv_scratch_corrupt_merkle_tree() > (( offset += ($(_get_filesize $file) + 65535) & ~65535 )) > _fsv_scratch_corrupt_bytes $file $offset > ;; > + btrfs) > + local ino=$(stat -c '%i' $file) > + _scratch_unmount > + local byte="" > + while read -n 1 byte; do > + if [ -z $byte ]; then > + break > + fi '[ -z $byte ]' could use quotes around $byte. But isn't that check unneeded at all, given that 'read' will fail when EOF is reached? - Eric
diff --git a/common/verity b/common/verity index eec8ae72..07d9d3fe 100644 --- a/common/verity +++ b/common/verity @@ -322,6 +322,24 @@ _fsv_scratch_corrupt_merkle_tree() (( offset += ($(_get_filesize $file) + 65535) & ~65535 )) _fsv_scratch_corrupt_bytes $file $offset ;; + btrfs) + local ino=$(stat -c '%i' $file) + _scratch_unmount + local byte="" + while read -n 1 byte; do + if [ -z $byte ]; then + break + fi + local ascii=$(printf "%d" "'$byte'") + # This command will find a Merkle tree item for the inode (-I $ino,37,0) + # in the default filesystem tree (-r 5) and corrupt one byte (-b 1) at + # $offset (-o $offset) with the ascii representation of the byte we read + # (-v $ascii) + $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,37,0 -v $ascii -o $offset -b 1 $SCRATCH_DEV + (( offset += 1 )) + done + _scratch_mount + ;; *) _fail "_fsv_scratch_corrupt_merkle_tree() unimplemented on $FSTYP" ;; diff --git a/tests/generic/574 b/tests/generic/574 index 882baa21..6cb7eff6 100755 --- a/tests/generic/574 +++ b/tests/generic/574 @@ -27,6 +27,7 @@ _cleanup() # real QA test starts here _supported_fs generic _require_scratch_verity +_require_fsverity_corruption _disable_fsverity_signatures _scratch_mkfs_verity &>> $seqres.full
generic/574 has tests for corrupting the merkle tree data stored by the filesystem. Since btrfs uses a different scheme for storing this data, the existing logic for corrupting it doesn't work out of the box. Adapt it to properly corrupt btrfs merkle items. This test relies on the btrfs implementation of fsverity in the patch: btrfs: initial fsverity support and on btrfs-corrupt-block for corruption in the patches titled: btrfs-progs: corrupt generic item data with btrfs-corrupt-block btrfs-progs: expand corrupt_file_extent in btrfs-corrupt-block Signed-off-by: Boris Burkov <boris@bur.io> --- common/verity | 18 ++++++++++++++++++ tests/generic/574 | 1 + 2 files changed, 19 insertions(+)