Files
apfstests/tests/generic/569
T
Darrick J. Wong db8feee949 generic: check that we can't write to swap files
While active, the media backing a swap file is leased to the kernel.
Userspace has no business writing to it.  Make sure we can't do this.

The two kernel patches titled as below should fix the bug:

mm: set S_SWAPFILE on blockdev swap devices
vfs: don't allow writes to swap files

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
2019-10-02 18:51:16 +08:00

71 lines
1.5 KiB
Bash
Executable File

#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-newer
# Copyright (c) 2019, Oracle and/or its affiliates. All Rights Reserved.
#
# FS QA Test No. 569
#
# Check that we can't modify a file that's an active swap file.
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
here=`pwd`
tmp=/tmp/$$
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_cleanup()
{
cd /
swapoff $testfile
rm -rf $tmp.* $testfile
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
# real QA test starts here
_supported_os Linux
_supported_fs generic
_require_test_program swapon
_require_scratch_swapfile
rm -f $seqres.full
_scratch_mkfs > $seqres.full 2>&1
_scratch_mount >> $seqres.full 2>&1
testfile=$SCRATCH_MNT/$seq.swap
_format_swapfile $testfile 20m
# Can you modify the swapfile via previously open file descriptors?
for verb in 1 2 3 4; do
echo "verb $verb"
"$here/src/swapon" -v $verb $testfile
swapoff $testfile
done
# Now try writing with a new file descriptor.
swapon $testfile 2>&1 | _filter_scratch
# Can we write to it?
$XFS_IO_PROG -c 'pwrite -S 0x59 64k 64k' $testfile
$XFS_IO_PROG -d -c 'pwrite -S 0x60 64k 64k' $testfile
$XFS_IO_PROG -c 'mmap -rw 64k 64k' -c 'mwrite -S 0x61 64k 64k' $testfile
# Can we change the file size?
$XFS_IO_PROG -c 'truncate 18m' $testfile
# Can you fallocate the file?
$XFS_IO_PROG -c 'falloc 0 32m' $testfile
# We test that you can't reflink, dedupe, or copy_file_range into a swapfile
# in other tests.
# success, all done
status=0
exit