2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an ext4 filesystem, corrupt a xattr block, then
8 # see how the kernel and e2fsck deal with it.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
30 # real QA test starts here
34 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
38 TESTDIR="${SCRATCH_MNT}/scratchdir"
39 TESTFILE="${TESTDIR}/testfile"
41 echo "+ create scratch fs"
42 _scratch_mkfs_ext4 > /dev/null 2>&1
44 echo "+ mount fs image"
46 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
48 echo "+ make some files"
49 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${SCRATCH_MNT}/attrfile" >> $seqres.full
50 setfattr -n user.key -v "$(perl -e 'print "v" x 300;')" "${SCRATCH_MNT}/attrfile"
51 umount "${SCRATCH_MNT}"
54 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
56 echo "+ corrupt image"
57 blk="$(debugfs -R 'stat /attrfile' "${SCRATCH_DEV}" 2> /dev/null | grep 'File ACL:' | sed -e 's/^.*File ACL: \([0-9]*\).*/\1/g')"
58 $XFS_IO_PROG -f -c "pwrite -S 0x62 $((blk * blksz + 20)) 8" "${SCRATCH_DEV}" >> $seqres.full
64 setfattr -n user.newkey -v "$(perl -e 'print "v" x 300;')" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "xattr should be corrupt"
65 umount "${SCRATCH_MNT}"
68 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
70 echo "+ mount image (2)"
73 echo "+ modify attrs (2)"
74 setfattr -n user.newkey -v "$(perl -e 'print "v" x 300;')" "${SCRATCH_MNT}/attrfile" || _fail "xattr should not be corrupt"
75 umount "${SCRATCH_MNT}"
78 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"