2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle, Inc. All Rights Reserved.
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.
13 # So, create this malformed inode and try a dio append to make sure we
14 # catch this situation.
17 _begin_fstest dangerous_fuzzers
21 # Import common functions.
24 # real QA test starts here
26 _require_scratch_nocheck
29 echo "Format and mount"
30 _scratch_mkfs >> $seqres.full 2>&1
34 # make sure the write offset is 512-aligned
36 inum=$(stat -c "%i" $testdir/a)
38 echo "Corrupt filesystem"
41 # 1) Set the file size to the highest multiple of 512 below -1 so
42 # that we can perform a dio write.
43 # 2) run two xfs_db commands to set core.size regardless of the special
44 # argument "--" is needed or not.
45 _scratch_xfs_db -x -c "inode ${inum}" -c 'write core.size -- -512' >> $seqres.full 2>&1
46 _scratch_xfs_db -x -c "inode ${inum}" -c 'write core.size -512' >> $seqres.full 2>&1
48 # check core.size and _notrun if it's not set correctly
49 i_size=`_scratch_xfs_db -c "inode ${inum}" -c "print core.size" | $AWK_PROG '{print $3}'`
50 if [ $i_size -ne -512 ]; then
51 _notrun "Could not set i_size to -512 successfully, skip test."
54 echo "Remount, try to append"
56 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)."