fstests: check for filesystem FS_IOC_FSSETXATTR support
[xfstests-dev.git] / tests / xfs / 134
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 134
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 xfs
37 _require_scratch_nocheck
38 _disable_dmesg_check
39
40 rm -f $seqres.full
41
42 echo "Format and mount"
43 _scratch_mkfs  >> $seqres.full 2>&1
44 _scratch_mount
45
46 testdir=$SCRATCH_MNT
47 # make sure the write offset is 512-aligned
48 touch $testdir/a
49 inum=$(stat -c "%i" $testdir/a)
50
51 echo "Corrupt filesystem"
52 _scratch_unmount
53
54 # 1) Set the file size to the highest multiple of 512 below -1 so
55 #    that we can perform a dio write.
56 # 2) run two xfs_db commands to set core.size regardless of the special
57 #    argument "--" is needed or not.
58 _scratch_xfs_db -x -c "inode ${inum}" -c 'write core.size -- -512' >> $seqres.full 2>&1
59 _scratch_xfs_db -x -c "inode ${inum}" -c 'write core.size -512' >> $seqres.full 2>&1
60
61 # check core.size and _notrun if it's not set correctly
62 i_size=`_scratch_xfs_db -c "inode ${inum}" -c "print core.size" | $AWK_PROG '{print $3}'`
63 if [ $i_size -ne -512 ]; then
64         _notrun "Could not set i_size to -512 successfully, skip test."
65 fi
66
67 echo "Remount, try to append"
68 _scratch_mount
69 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)."
70 sync
71
72 # success, all done
73 status=0
74 exit