summaryrefslogtreecommitdiff
path: root/tests/generic/675
blob: 189251f20c0d9893f7b461306466fac7c6e18aa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2022 Oracle.  All Rights Reserved.
#
# FS QA Test No. 675
#
# Functional test for dropping suid and sgid capabilities as part of a reflink.
#
. ./common/preamble
_begin_fstest auto clone quick

# Import common functions.
. ./common/filter
. ./common/reflink

# real QA test starts here

# Modify as appropriate.
_supported_fs generic
_require_user
_require_command "$GETCAP_PROG" getcap
_require_command "$SETCAP_PROG" setcap
_require_scratch_reflink

_scratch_mkfs >> $seqres.full
_scratch_mount
_require_congruent_file_oplen $SCRATCH_MNT 1048576
chmod a+rw $SCRATCH_MNT/

setup_testfile() {
	rm -f $SCRATCH_MNT/a $SCRATCH_MNT/b
	_pwrite_byte 0x58 0 1m $SCRATCH_MNT/a >> $seqres.full
	_pwrite_byte 0x57 0 1m $SCRATCH_MNT/b >> $seqres.full
	chmod a+rwx $SCRATCH_MNT/a $SCRATCH_MNT/b
	$SETCAP_PROG cap_setgid,cap_setuid+ep $SCRATCH_MNT/a
	sync
}

commit_and_check() {
	local user="$1"

	stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
	_getcap -v $SCRATCH_MNT/a | _filter_scratch

	local cmd="$XFS_IO_PROG -c 'reflink $SCRATCH_MNT/b 0 0 1m' $SCRATCH_MNT/a"
	if [ -n "$user" ]; then
		su - "$user" -c "$cmd" >> $seqres.full
	else
		$SHELL -c "$cmd" >> $seqres.full
	fi

	stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
	_getcap -v $SCRATCH_MNT/a | _filter_scratch

	# Blank line in output
	echo
}

# Commit by an unprivileged user clears capability bits.
echo "Test 1 - qa_user"
setup_testfile
commit_and_check "$qa_user"

# Commit by root leaves capability bits.
echo "Test 2 - root"
setup_testfile
commit_and_check

# success, all done
status=0
exit