fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / shared / 007
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 007
6 #
7 # Since loff_t is a signed type, it is invalid for a filesystem to load
8 # an inode with i_size = -1ULL.  Unfortunately, nobody checks this,
9 # which means that we can trivially DoS the VFS by creating such a file
10 # and appending to it.  This causes an integer overflow in the routines
11 # underlying writeback, which results in the kernel locking up.
12 #
13 # So, create this malformed inode and try a dio append to make sure we
14 # catch this situation.
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 PIDS=""
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35 _supported_os Linux
36 _supported_fs ext2 ext3 ext4
37 _require_scratch_nocheck
38 _disable_dmesg_check
39 _require_command "$DEBUGFS_PROG"
40
41 rm -f $seqres.full
42
43 echo "Format and mount"
44 _scratch_mkfs  >> $seqres.full 2>&1
45 _scratch_mount
46
47 testdir=$SCRATCH_MNT
48 echo m > $testdir/a
49
50 echo "Corrupt filesystem"
51 _scratch_unmount
52 # Set the file size to the highest multiple of 512 below
53 # -1 so that we can perform a dio write.
54 $DEBUGFS_PROG -w -R "sif /a size 0xFFFFFFFFFFFFFE00" $SCRATCH_DEV >> $seqres.full 2>&1
55
56 # check whether debugfs succeeds to set i_size to -512 or not
57 $DEBUGFS_PROG -R "stat /a" $SCRATCH_DEV 2>&1 | grep -q "Size: 18446744073709551104" || \
58         _notrun "Could not set i_size to -512 successfully, skip test."
59
60 echo "Remount, try to append"
61 _scratch_mount
62 dd if=/dev/zero of=$testdir/a bs=512 count=1 oflag=direct,append conv=notrunc >> $seqres.full 2>&1 || echo "Write did not succeed (ok)."
63 sync
64
65 # success, all done
66 status=0
67 exit