d756d2e934d2c08c276a1cb8e6e4a45c3d113dda
[xfstests-dev.git] / tests / xfs / 133
1 #! /bin/bash
2 # FSQA Test No. 133
3 #
4 # Since loff_t is a signed type, it is invalid for a filesystem to load
5 # an inode with i_size = -1ULL.  Unfortunately, nobody checks this,
6 # which means that we can trivially DoS the VFS by creating such a file
7 # and appending to it.  This causes an integer overflow in the routines
8 # underlying writeback, which results in the kernel locking up.
9 #
10 # So, create this malformed inode and try a buffered append to make
11 # sure we catch this situation.
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2017 Oracle, Inc.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 PIDS=""
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_os Linux
50 _supported_fs xfs
51 _require_scratch_nocheck
52 _disable_dmesg_check
53
54 rm -f $seqres.full
55
56 echo "Format and mount"
57 _scratch_mkfs  >> $seqres.full 2>&1
58 _scratch_mount
59
60 testdir=$SCRATCH_MNT
61 echo m > $testdir/a
62 inum=$(stat -c "%i" $testdir/a)
63
64 echo "Corrupt filesystem"
65 _scratch_unmount
66 _scratch_xfs_db -x -c "inode ${inum}" -c 'write core.size -- -1' >> $seqres.full
67
68 echo "Remount, try to append"
69 _scratch_mount
70 dd if=/dev/zero of=$testdir/a bs=512 count=1 oflag=append conv=notrunc >> $seqres.full 2>&1 || echo "Write did not succeed (ok)."
71 sync
72
73 # success, all done
74 status=0
75 exit