common: print hints for reasons of test failures
[xfstests-dev.git] / tests / overlay / 074
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 074
6 #
7 # Test two overlayfs file handle bugs:
8 # 1. Failure to query file handle size
9 #    Fixed by kernel commit 144da23beab8:
10 #        ovl: return required buffer size for file handles
11 #
12 # 2. Kernel OOPS on open by hand crafted malformed file handle
13 #    Fixed by kernel commit 9aafc1b01873:
14 #        ovl: potential crash in ovl_fid_to_fh()
15 #
16 . ./common/preamble
17 _begin_fstest auto quick exportfs dangerous
18
19 # Import common functions.
20 . ./common/filter
21
22 # real QA test starts here
23
24 _supported_fs overlay
25 _fixed_by_kernel_commit 144da23beab8 \
26         "ovl: return required buffer size for file handles"
27 _fixed_by_kernel_commit 9aafc1b01873 \
28         "ovl: potential crash in ovl_fid_to_fh()"
29
30 _require_scratch
31 _require_test_program "open_by_handle"
32 # We need to require all features together, because nfs_export cannot
33 # be enabled when index is disabled
34 _require_scratch_overlay_features index nfs_export
35
36 _scratch_mkfs
37 _scratch_mount -o "index=on,nfs_export=on"
38
39 testdir=$SCRATCH_MNT/testdir
40
41 # Create directory with test file
42 $here/src/open_by_handle -cp $testdir
43
44 # Test query file handle size on dir and file
45 $here/src/open_by_handle -pz $testdir
46
47 # Export file handle into tmp file
48 $here/src/open_by_handle -o $tmp.file_handle $testdir
49
50 # Verify open by exported file handle
51 $here/src/open_by_handle -i $tmp.file_handle $testdir
52
53 # Mangle the exported file handle:
54 # handle_bytes = 1
55 # handle_type = OVL_FILEID_V0 (0xfb)
56 # File handle is encoded in host order
57 # The command below crafts this header for little endian.
58 # On different big endian architectures the file handle will still
59 # be malformed just not with the specific values to trigger the bug
60 cp $tmp.file_handle $tmp.file_handle_v0
61 $XFS_IO_PROG -c "pwrite -S 0 0 8" -c "pwrite -S 1 0 1" -c "pwrite -S 0xfb 4 1" \
62         $tmp.file_handle_v0 >> $seqres.full
63
64 # Craft malformed v1 file handle:
65 # handle_bytes = 1
66 # handle_type = OVL_FILEID_V1 (0xf8)
67 cp $tmp.file_handle $tmp.file_handle_v1
68 $XFS_IO_PROG -c "pwrite -S 0 0 8" -c "pwrite -S 1 0 1" -c "pwrite -S 0xf8 4 1" \
69         $tmp.file_handle_v1 >> $seqres.full
70
71 # Verify failure to open by mangled file handles
72 # This will trigger NULL pointer dereference on affected kernels
73 $here/src/open_by_handle -i $tmp.file_handle_v0 $testdir >> $seqres.full 2>&1 && \
74         _fail "open by mangaled file handle (v0) is expected to fail"
75 # This may trigger out of bound access warning on affected kernels
76 $here/src/open_by_handle -i $tmp.file_handle_v1 $testdir >> $seqres.full 2>&1 && \
77         _fail "open by mangaled file handle (v1) is expected to fail"
78
79 echo "Silence is golden"
80 status=0
81 exit