generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 680
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 680
6 #
7 # Test for the Dirty Pipe vulnerability (CVE-2022-0847) caused by an
8 # uninitialized  "pipe_buffer.flags" variable, which fixed by:
9 #   9d2231c5d74e ("lib/iov_iter: initialize "flags" in new pipe_buffer")
10 #
11 . ./common/preamble
12 _begin_fstest auto quick
13
14 # real QA test starts here
15 _supported_fs generic
16 _require_test
17 _require_user
18 _require_chmod
19 _require_test_program "splice2pipe"
20
21 localfile=$TEST_DIR/testfile.$seq
22 rm -f $localfile
23
24 # Create a file with 4k 0xff data, then make sure unprivileged user has readonly
25 # permission on it
26 $XFS_IO_PROG -f -t -c "pwrite 0 4k -S 0xff" $localfile >> $seqres.full 2>&1
27 chmod 0644 $localfile
28 # Test privileged user (xfstests generally run with root)
29 echo "Test privileged user:"
30 $here/src/splice2pipe $localfile 1 "AAAAAAAABBBBBBBB"
31 # Part of 0xff will be overwritten if there's CVE-2022-0847 bug
32 _hexdump $localfile
33
34 # Create a file with 4k 0xff data, then make sure unprivileged user has readonly
35 # permission on it
36 $XFS_IO_PROG -f -t -c "pwrite 0 4k -S 0xff" $localfile >> $seqres.full 2>&1
37 chmod 0644 $localfile
38 # Copy splice2pipe to a place which can be run by an unprivileged user (avoid
39 # something likes /root/xfstests/src/splice2pipe)
40 cp $here/src/splice2pipe $tmp.splice2pipe
41 # Test unprivileged user's privilege escalation
42 echo "Test unprivileged user:"
43 su ${qa_user} -c "$tmp.splice2pipe $localfile 1 AAAAAAAABBBBBBBB"
44 _hexdump $localfile
45
46 # success, all done
47 status=0
48 exit