diff options
author | Eric Biggers <ebiggers@google.com> | 2018-04-18 13:09:10 -0700 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2018-04-18 13:09:10 -0700 |
commit | f5c61adf568ba2cbe58ee571a7bb550708b0cfcd (patch) | |
tree | 646e7f6d90f37eec3515b95291896be4fbd5d450 | |
parent | 4644ea88981e92c6d566b3f6e3ee6b27ed19500d (diff) | |
download | xfstests-f5c61adf568ba2cbe58ee571a7bb550708b0cfcd.tar.gz |
generic: test corrupting fs-verity files
Signed-off-by: Eric Biggers <ebiggers@google.com>
-rwxr-xr-x | tests/generic/903 | 150 | ||||
-rw-r--r-- | tests/generic/903.out | 91 | ||||
-rw-r--r-- | tests/generic/group | 1 |
3 files changed, 242 insertions, 0 deletions
diff --git a/tests/generic/903 b/tests/generic/903 new file mode 100755 index 0000000000..0bb29493db --- /dev/null +++ b/tests/generic/903 @@ -0,0 +1,150 @@ +#! /bin/bash +# FS QA Test generic/903 +# +# Test corrupting fs-verity files +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Google, Inc. All Rights Reserved. +# +# Author: Eric Biggers <ebiggers@google.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/verity + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch_verity + +_scratch_mkfs_verity &>> $seqres.full +_scratch_mount +fsv_orig_file=$SCRATCH_MNT/file +fsv_file=$SCRATCH_MNT/file.fsv + +setup_zeroed_file() +{ + local len=$1 + local measurement + + head -c $len /dev/zero > $fsv_orig_file + measurement=$(_fsv_setup_file $fsv_orig_file $fsv_file) + $FSVERITY_PROG enable $fsv_file + $FSVERITY_PROG set_measurement $fsv_file $measurement + md5sum $fsv_file |& _filter_scratch 1>&2 + echo $measurement +} + +filter_sigbus() +{ + sed -e 's/.*Bus error.*/Bus error/' +} + +page_boundary() +{ + local n=$1 + local page_size=$(getconf PAGE_SIZE) + + echo $(( (n + page_size - 1) & ~(page_size - 1) )) +} + +corruption_test() +{ + local file_len=$1 + local zap_offset=$2 + local zap_len=$3 + local metadata_offset=$(page_boundary $file_len) + local measurement + + _fsv_begin_subtest "Corruption test: file_len=$file_len zap_offset=$zap_offset zap_len=$zap_len" + measurement=$(setup_zeroed_file $file_len) + cmp $fsv_file $fsv_orig_file + echo "Corrupting bytes..." + head -c $zap_len /dev/zero | tr '\0' X \ + | _fsv_corrupt_bytes $fsv_file $zap_offset + + echo "Validating corruption (reading full file)..." + _scratch_cycle_mount + $FSVERITY_PROG set_measurement $fsv_file $measurement + md5sum $fsv_file |& _filter_scratch + + echo "Validating corruption (direct I/O)..." + _scratch_cycle_mount + $FSVERITY_PROG set_measurement $fsv_file $measurement + dd if=$fsv_file bs=$FSV_BLOCK_SIZE iflag=direct status=none \ + of=/dev/null |& _filter_scratch + + if (( zap_offset < metadata_offset )); then + echo "Validating corruption (reading just corrupted part)..." + _scratch_cycle_mount + $FSVERITY_PROG set_measurement $fsv_file $measurement + dd if=$fsv_file bs=1 skip=$zap_offset count=$zap_len \ + of=/dev/null status=none |& _filter_scratch + fi + + echo "Validating corruption (reading full file via mmap)..." + _scratch_cycle_mount + $FSVERITY_PROG set_measurement $fsv_file $measurement + bash -c "trap '' SIGBUS; $XFS_IO_PROG -r $fsv_file \ + -c 'mmap -r 0 $metadata_offset' \ + -c 'mread 0 $file_len'" |& filter_sigbus + + if (( zap_offset < metadata_offset )); then + echo "Validating corruption (reading just corrupted part via mmap)..." + _scratch_cycle_mount + $FSVERITY_PROG set_measurement $fsv_file $measurement + bash -c "trap '' SIGBUS; $XFS_IO_PROG -r $fsv_file \ + -c 'mmap -r 0 $metadata_offset' \ + -c 'mread $zap_offset $zap_len'" |& filter_sigbus + fi +} + +corruption_test 131072 0 1 +corruption_test 131072 4095 1 +corruption_test 131072 65536 65536 +corruption_test 131072 131071 1 + +# Non-zeroed bytes in the final partial block beyond EOF should cause reads to +# fail too. Such bytes would be visible via mmap(). +corruption_test 129999 131000 72 + +# Hash tree corruption +corruption_test 1048576 1052672 4096 +corruption_test 1048576 1056767 1 + +# success, all done +status=0 +exit diff --git a/tests/generic/903.out b/tests/generic/903.out new file mode 100644 index 0000000000..2006cf673d --- /dev/null +++ b/tests/generic/903.out @@ -0,0 +1,91 @@ +QA output created by 903 + +# Corruption test: file_len=131072 zap_offset=0 zap_len=1 +0dfbe8aa4c20b52e1b8bf3cb6cbdf193 SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading just corrupted part)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error +Validating corruption (reading just corrupted part via mmap)... +Bus error + +# Corruption test: file_len=131072 zap_offset=4095 zap_len=1 +0dfbe8aa4c20b52e1b8bf3cb6cbdf193 SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading just corrupted part)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error +Validating corruption (reading just corrupted part via mmap)... +Bus error + +# Corruption test: file_len=131072 zap_offset=65536 zap_len=65536 +0dfbe8aa4c20b52e1b8bf3cb6cbdf193 SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading just corrupted part)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error +Validating corruption (reading just corrupted part via mmap)... +Bus error + +# Corruption test: file_len=131072 zap_offset=131071 zap_len=1 +0dfbe8aa4c20b52e1b8bf3cb6cbdf193 SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading just corrupted part)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error +Validating corruption (reading just corrupted part via mmap)... +Bus error + +# Corruption test: file_len=129999 zap_offset=131000 zap_len=72 +0ed66e88b29ce0c585cedf35ee127213 SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading just corrupted part)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error +Validating corruption (reading just corrupted part via mmap)... +Bus error + +# Corruption test: file_len=1048576 zap_offset=1052672 zap_len=4096 +b6d81b360a5672d80c27430f39153e2c SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error + +# Corruption test: file_len=1048576 zap_offset=1056767 zap_len=1 +b6d81b360a5672d80c27430f39153e2c SCRATCH_MNT/file.fsv +Corrupting bytes... +Validating corruption (reading full file)... +md5sum: SCRATCH_MNT/file.fsv: Input/output error +Validating corruption (direct I/O)... +dd: error reading 'SCRATCH_MNT/file.fsv': Input/output error +Validating corruption (reading full file via mmap)... +Bus error diff --git a/tests/generic/group b/tests/generic/group index 6c24a1585e..2f29c15485 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -489,3 +489,4 @@ 900 auto quick verity 901 auto quick verity 902 auto quick verity +903 auto quick verity |