linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eryu Guan <guan@eryu.me>
To: Boris Burkov <boris@bur.io>
Cc: fstests@vger.kernel.org, linux-fscrypt@vger.kernel.org,
	linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH v4 2/4] generic/574: corrupt btrfs merkle tree data
Date: Mon, 17 May 2021 00:38:03 +0800	[thread overview]
Message-ID: <YKFKa9n4Porh3/gp@desktop> (raw)
In-Reply-To: <1fce7bfd74d15ddc4492a642d275eec284910950.1620248200.git.boris@bur.io>

On Wed, May 05, 2021 at 02:04:44PM -0700, 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 patches
> titled:
> btrfs: initial fsverity support
> btrfs: check verity for reads of inline extents and holes
> btrfs: fallback to buffered io for verity files
> 
> A fix for fiemap in the patch titled:
> btrfs: return whole extents in fiemap
> 
> 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 |  5 +++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/common/verity b/common/verity
> index d2c1ea24..1636e88b 100644
> --- a/common/verity
> +++ b/common/verity
> @@ -315,6 +315,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 1e296618..e4370dae 100755
> --- a/tests/generic/574
> +++ b/tests/generic/574
> @@ -43,6 +43,11 @@ _scratch_mount
>  fsv_orig_file=$SCRATCH_MNT/file
>  fsv_file=$SCRATCH_MNT/file.fsv
>  
> +# utility needed for corrupting Merkle data itself in btrfs
> +if [ $FSTYP == "btrfs" ]; then
> +	_require_command "$BTRFS_CORRUPT_BLOCK_PROG" btrfs_corrupt_block
> +fi

I don't think this is needed, as _require_scratch_verity() already did
this check.

Thanks,
Eryu

> +
>  setup_zeroed_file()
>  {
>  	local len=$1
> -- 
> 2.30.2

  reply	other threads:[~2021-05-16 16:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 21:04 [PATCH v4 0/4] tests for btrfs fsverity Boris Burkov
2021-05-05 21:04 ` [PATCH v4 1/4] btrfs: test btrfs specific fsverity corruption Boris Burkov
2021-05-16 16:34   ` Eryu Guan
2021-05-05 21:04 ` [PATCH v4 2/4] generic/574: corrupt btrfs merkle tree data Boris Burkov
2021-05-16 16:38   ` Eryu Guan [this message]
2021-05-05 21:04 ` [PATCH v4 3/4] btrfs: test verity orphans with dmlogwrites Boris Burkov
2021-05-16 16:43   ` Eryu Guan
2021-05-05 21:04 ` [PATCH v4 4/4] generic: test fs-verity EFBIG scenarios Boris Burkov
2021-05-16 16:47   ` Eryu Guan
2021-05-25 20:24   ` Eric Biggers
2021-09-10 23:26     ` Boris Burkov
2021-09-10 23:32       ` Eric Biggers
2021-05-25 18:13 ` [PATCH v4 0/4] tests for btrfs fsverity 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=YKFKa9n4Porh3/gp@desktop \
    --to=guan@eryu.me \
    --cc=boris@bur.io \
    --cc=fstests@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --subject='Re: [PATCH v4 2/4] generic/574: corrupt btrfs merkle tree data' \
    /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

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 NNTP newsgroup(s).