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 buffered append to make
14 # sure we catch this situation.
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # get standard environment, filters and checks
34 # real QA test starts here
36 _supported_fs ext2 ext3 ext4
37 _require_scratch_nocheck
39 _require_command "$DEBUGFS_PROG"
43 echo "Format and mount"
44 _scratch_mkfs >> $seqres.full 2>&1
50 echo "Corrupt filesystem"
52 $DEBUGFS_PROG -w -R "sif /a size -1" $SCRATCH_DEV >> $seqres.full 2>&1
54 # check whether debugfs succeeds to set i_size to -1 or not
55 $DEBUGFS_PROG -R "stat /a" $SCRATCH_DEV 2>&1 | grep -q "Size: 18446744073709551615" || \
56 _notrun "Could not set i_size to -1 successfully, skip test."
58 echo "Remount, try to append"
60 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)."