2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 CTERA Networks. All Rights Reserved.
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
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()
17 _begin_fstest auto quick exportfs dangerous
19 # Import common functions.
22 # real QA test starts here
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()"
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
37 _scratch_mount -o "index=on,nfs_export=on"
39 testdir=$SCRATCH_MNT/testdir
41 # Create directory with test file
42 $here/src/open_by_handle -cp $testdir
44 # Test query file handle size on dir and file
45 $here/src/open_by_handle -pz $testdir
47 # Export file handle into tmp file
48 $here/src/open_by_handle -o $tmp.file_handle $testdir
50 # Verify open by exported file handle
51 $here/src/open_by_handle -i $tmp.file_handle $testdir
53 # Mangle the exported file handle:
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
64 # Craft malformed v1 file handle:
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
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"
79 echo "Silence is golden"