63b45fd4afdde6dbeef2b5bf9ead75160ecd925b
[xfstests-dev.git] / tests / xfs / 431
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Facebook, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 431
6 #
7 # Verify kernel doesn't panic when user attempts to set realtime flags
8 # on non-realtime FS, using kernel compiled with CONFIG_XFS_RT.  Unpatched
9 # kernels will panic during this test.  Kernels not compiled with
10 # CONFIG_XFS_RT should pass test.
11 #
12 # See CVE-2017-14340 for more information.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37
38 # Modify as appropriate.
39 _supported_fs xfs
40 _supported_os Linux
41 _require_xfs_io_command "chattr"
42 _require_xfs_io_command "fsync"
43 _require_xfs_io_command "pwrite"
44 _require_scratch
45
46 _scratch_mkfs >/dev/null 2>&1
47 _scratch_mount
48
49 # Set realtime inherit flag on scratch mount, suppress output
50 # as this may simply error out on future kernels
51 $XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT &> /dev/null
52
53 # Check if 't' is actually set, as xfs_io returns 0 even when it fails to set
54 # an attribute. And erroring out here is fine, this would be desired behavior
55 # for FSes without realtime devices present.
56 if $XFS_IO_PROG -c 'lsattr' $SCRATCH_MNT | grep -q 't'; then
57         # Attempt to write/fsync data to file
58         $XFS_IO_PROG -fc 'pwrite 0 1m' -c fsync $SCRATCH_MNT/testfile |
59                 tee -a $seqres.full | _filter_xfs_io
60
61         # Remove the testfile and rt inherit flag after we are done or
62         # xfs_repair will fail.
63         rm -f $SCRATCH_MNT/testfile
64         $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT | tee -a $seqres.full 2>&1
65 fi
66
67 # success, all done
68 status=0
69 exit