btrfs: test if the capability is kept on incremental send
PATCH 1/1 btrfs: test if the capability is kept on incremental send
From: Marcos Paulo de Souza <[email protected]>
There is a situation where the incremental send can drop the capability from the receiving side. If you have a file that changed the group, but the capability was the same of before the group changed, the current kernel code will only emit a chown, since the capability is the same.
The steps bellow can reproduce the problem.
$ mount /dev/sda fs1 $ mount /dev/sdb fs2
$ touch fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar $ btrfs subvol snap -r fs1 fs1/snap_init $ btrfs send fs1/snap_init | btrfs receive fs2
$ chgrp adm fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar
$ btrfs subvol snap -r fs1 fs1/snap_complete $ btrfs subvol snap -r fs1 fs1/snap_incremental
$ btrfs send fs1/snap_complete | btrfs receive fs2 $ btrfs send -p fs1/snap_init fs1/snap_incremental | btrfs receive fs2
At this point, a chown was emitted by "btrfs send" since only the group was changed. This makes the cap_sys_nice capability to be dropped from fs2/snap_incremental/foo.bar
This test fails on current kernel, the fix was submitted to the btrfs mailing list titled:
"btrfs: send: Emit file capabilities after chown"
--- tests/btrfs/211 | 153 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/211.out | 6 ++ tests/btrfs/group | 1 + 3 files changed, 160 insertions(+) create mode 100755 tests/btrfs/211 create mode 100644 tests/btrfs/211.out
tests/btrfs/211 new file +153 -0
@@ -0,0 +1,153 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 211 +# +# Test if the file capabilities aren't lost after full and incremental send +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_command "$SETCAP_PROG" setcap +_require_command "$GETCAP_PROG" getcap + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +_check_xattr() +{ + local RET + local FILE + local CAP + FILE="$1" + CAP="$2" + RET=$($GETCAP_PROG "$FILE") + if [ -z "$RET" ]; then + echo "$RET" + _fail "missing capability in file $FILE" + fi + if [[ "$RET" != *$CAP* ]]; then + echo "$RET" + echo "$CAP" + _fail "Capability do not match. Output: $RET" + fi +} + +_setup() +{ + _scratch_mkfs >/dev/null + _scratch_mount + + FS1="$SCRATCH_MNT/fs1" + FS2="$SCRATCH_MNT/fs2" + + $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null + $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null +} + +_full_nocap_inc_withcap_send() +{ + _setup + + # Test full send containing a file with no capability + touch "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null + $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q + # ensure that we don't have caps set + RET=$($GETCAP_PROG "$FS2/snap_init/foo.bar") + if [ -n "$RET" ]; then + _fail "File contain capabilities when it shouldn't" + fi + + # Test if incremental send bring the newly added capability + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null + $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + _scratch_unmount +} + +_roundtrip_send() +{ + local FILES + local FS1 + local FS2 + + # FILES should include foo.bar + FILES="$1" + + _setup + + # create files on fs1, must contain foo.bar + for f in $FILES; do + touch "$FS1/$f" + done + + # Test full send, checking if the receiving side keeps the capability + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null + $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_init/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + # Test incremental send with different owner/group but same capability + chgrp 100 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null + _check_xattr "$FS1/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + # Test capability after incremental send with different capability and group + chgrp 0 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc2" >/dev/null + _check_xattr "$FS1/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep" + $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep" + + _scratch_unmount +} + +# real QA test starts here + +echo "Test full send + file without caps, then inc send bringing a new cap" +_full_nocap_inc_withcap_send + +echo "Testing if foo.bar alone can keep it's capability" +_roundtrip_send "foo.bar" + +echo "Test foo.bar being the first item among other files" +_roundtrip_send "foo.bar foo.bax foo.baz" + +echo "Test foo.bar with objectid between two other files" +_roundtrip_send "foo1 foo.bar foo3" + +echo "Test foo.bar being the last item among other files" +_roundtrip_send "foo1 foo2 foo.bar" + +status=0 +exit
tests/btrfs/211.out new file +6 -0
@@ -0,0 +1,6 @@ +QA output created by 211 +Test full send + file without caps, then inc send bringing a new cap +Testing if foo.bar alone can keep it's capability +Test foo.bar being the first item among other files +Test foo.bar with objectid between two other files +Test foo.bar being the last item among other files
tests/btrfs/group +1 -0
@@ -213,3 +213,4 @@ 208 auto quick subvol 209 auto quick log 210 auto quick qgroup snapshot +211 auto quick snapshot
Signature · 1 line
2.25.1
Quoted 18 lines · Marcos Paulo de Souza
From: Marcos Paulo de Souza <[email protected]>
There is a situation where the incremental send can drop the capability from the receiving side. If you have a file that changed the group, but the capability was the same of before the group changed, the current kernel code will only emit a chown, since the capability is the same.
The steps bellow can reproduce the problem.
$ mount /dev/sda fs1 $ mount /dev/sdb fs2$ touch fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar $ btrfs subvol snap -r fs1 fs1/snap_init $ btrfs send fs1/snap_init | btrfs receive fs2
Quoted 8 lines
$ chgrp adm fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar$ btrfs subvol snap -r fs1 fs1/snap_complete $ btrfs subvol snap -r fs1 fs1/snap_incremental$ btrfs send fs1/snap_complete | btrfs receive fs2 $ btrfs send -p fs1/snap_init fs1/snap_incremental | btrfs receive fs2
It's redundant to put here the steps to trigger the problem, that's what the test does.
You just want to say this test exercises full send and incremental send operations for cases where files have capabilities, to verify the capabilities aren't lost.
Quoted 4 lines
At this point, a chown was emitted by "btrfs send" since only the group was changed. This makes the
cap_sys_nicecapability to be dropped from fs2/snap_incremental/foo.bar
Explaining in a changelog for a test case why exactly the bug happens is out of scope.
We just want to know what bug are we testing for.
The gory details about why the bug happens usually go the in the changelog of the patch that fixes btrfs.
Quoted 48 lines
This test fails on current kernel, the fix was submitted to the btrfs mailing list titled:
"btrfs: send: Emit file capabilities after chown"
Signed-off-by Marcos Paulo de Souza <[email protected]>--- tests/btrfs/211 | 153 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/211.out | 6 ++ tests/btrfs/group | 1 + 3 files changed, 160 insertions(+) create mode 100755 tests/btrfs/211 create mode 100644 tests/btrfs/211.outtests/btrfs/211 new file +27
-0@@ -0,0 +1,153 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 211 +# +# Test if the file capabilities aren't lost after full and incremental send +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +_supported_fs btrfs +_supported_os Linux +_require_scratch
tests/btrfs/211 line 37
Quoted 10 lines
tests/btrfs/211 new file +10
-0+_require_command "$SETCAP_PROG" setcap +_require_command "$GETCAP_PROG" getcap + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +_check_xattr()
Function names starting with '_' are usually reserved for functions provided by fstests, global functions (like the ones in common/*). Same comment applies to all the other function names.
Also, a better name would be "check_capabilities" - that they are stored in a xattr it's irrelevant as we are using the getcap and setcap utilities to read and set them, and not accessing xattrs directly.
tests/btrfs/211 line 43
Quoted 6 lines
tests/btrfs/211 new file +6
-0+{ + local RET + local FILE + local CAP + FILE="$1" + CAP="$2"
Variables in uppercase are meant to be used for global variables. Same comment applies to all the other functions.
tests/btrfs/211 line 47
Quoted 4 lines
tests/btrfs/211 new file +4
-0+ RET=$($GETCAP_PROG "$FILE") + if [ -z "$RET" ]; then + echo "$RET" + _fail "missing capability in file $FILE"
This is a practice generally discouraged, we should avoid "_fail" unless absolutely necessary.
The right approach here is just to "echo" the message. That's enough to make the test fail as that message is not part of the golden output.
Furthermore, not using _fail allows the test to proceed and potentially find other problems.
tests/btrfs/211 line 52
Quoted 5 lines
tests/btrfs/211 new file +5
-0+ fi + if [[ "$RET" != *$CAP* ]]; then + echo "$RET" + echo "$CAP" + _fail "Capability do not match. Output: $RET"
Capability -> Capabilities
tests/btrfs/211 line 62
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ fi +} + +_setup() +{ + _scratch_mkfs >/dev/null + _scratch_mount + + FS1="$SCRATCH_MNT/fs1" + FS2="$SCRATCH_MNT/fs2"
To make it easier to follow, perhaps declare this outside this function, as they are used by the other functions.
Quoted 5 lines
tests/btrfs/211 new file +5
-0+ + $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null + $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null +} +
tests/btrfs/211 line 77
Quoted 10 lines
tests/btrfs/211 new file +10
-0+_full_nocap_inc_withcap_send() +{ + _setup + + # Test full send containing a file with no capability + touch "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null + $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q + # ensure that we don't have caps set + RET=$($GETCAP_PROG "$FS2/snap_init/foo.bar")
Should be declared local (and lower case name).
tests/btrfs/211 line 79
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ if [ -n "$RET" ]; then + _fail "File contain capabilities when it shouldn't"
echo and contain -> contains
Quoted 7 lines
tests/btrfs/211 new file +7
-0+ fi + + # Test if incremental send bring the newly added capability + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null + $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q
tests/btrfs/211 line 96
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ _check_xattr "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + _scratch_unmount +} + +_roundtrip_send() +{ + local FILES + local FS1 + local FS2
So FS1 and FS2 are declared local but never set. And they were previously set as global by "_setup".
So those two declarations should be removed here.
tests/btrfs/211 line 108
Quoted 12 lines
tests/btrfs/211 new file +12
-0+ + # FILES should include foo.bar + FILES="$1" + + _setup + + # create files on fs1, must contain foo.bar + for f in $FILES; do + touch "$FS1/$f" + done + + # Test full send, checking if the receiving side keeps the capability
capability -> capabilities (as the test sets 2)
tests/btrfs/211 line 114
Quoted 6 lines
tests/btrfs/211 new file +6
-0+ $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null + $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_init/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + # Test incremental send with different owner/group but same capability
capability -> capabilities (as the test sets 2)
tests/btrfs/211 line 123
Quoted 9 lines
tests/btrfs/211 new file +9
-0+ chgrp 100 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null + _check_xattr "$FS1/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + # Test capability after incremental send with different capability and group
capability -> capabilities (as the test sets 2)
Quoted 4 lines
tests/btrfs/211 new file +4
-0+ chgrp 0 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc2" >/dev/null + _check_xattr "$FS1/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep"
tests/btrfs/211 line 137
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep" + + _scratch_unmount +} + +# real QA test starts here + +echo "Test full send + file without caps, then inc send bringing a new cap"
inc -> incremental
Also, the abbreviation "caps" is used but in other messages (below) the non-abbreviated name "capabilities" is used.
We should be consistent and use only one form.
tests/btrfs/211 line 140
Quoted 3 lines
tests/btrfs/211 new file +3
-0+_full_nocap_inc_withcap_send + +echo "Testing if foo.bar alone can keep it's capability"
it's -> its
capability -> capabilities (as the test sets 2)
Quoted 30 lines
tests/btrfs/211 new file +13
-0+_roundtrip_send "foo.bar" + +echo "Test foo.bar being the first item among other files" +_roundtrip_send "foo.bar foo.bax foo.baz" + +echo "Test foo.bar with objectid between two other files" +_roundtrip_send "foo1 foo.bar foo3" + +echo "Test foo.bar being the last item among other files" +_roundtrip_send "foo1 foo2 foo.bar" + +status=0 +exittests/btrfs/211.out new file +6
-0@@ -0,0 +1,6 @@ +QA output created by 211 +Test full send + file without caps, then inc send bringing a new cap +Testing if foo.bar alone can keep it's capability +Test foo.bar being the first item among other files +Test foo.bar with objectid between two other files +Test foo.bar being the last item among other filestests/btrfs/group +0
-0
tests/btrfs/group line 216
Quoted 4 lines
tests/btrfs/group +1
-0@@ -213,3 +213,4 @@ 208 auto quick subvol 209 auto quick log 210 auto quick qgroup snapshot +211 auto quick snapshot
Missing the 'send' group.
Other that is looks good and it works as expected (with patched and unpatched btrfs)
Thanks.
Quoted 3 lines
--
2.25.1
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 308 lines · Filipe Manana
Quoted 18 lines · Marcos Paulo de Souza
From: Marcos Paulo de Souza <[email protected]>
There is a situation where the incremental send can drop the capability from the receiving side. If you have a file that changed the group, but the capability was the same of before the group changed, the current kernel code will only emit a chown, since the capability is the same.
The steps bellow can reproduce the problem.
$ mount /dev/sda fs1 $ mount /dev/sdb fs2$ touch fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar $ btrfs subvol snap -r fs1 fs1/snap_init $ btrfs send fs1/snap_init | btrfs receive fs2Quoted 8 lines
$ chgrp adm fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar$ btrfs subvol snap -r fs1 fs1/snap_complete $ btrfs subvol snap -r fs1 fs1/snap_incremental$ btrfs send fs1/snap_complete | btrfs receive fs2 $ btrfs send -p fs1/snap_init fs1/snap_incremental | btrfs receive fs2It's redundant to put here the steps to trigger the problem, that's what the test does.
You just want to say this test exercises full send and incremental send operations for cases where files have capabilities, to verify the capabilities aren't lost.
Quoted 4 lines
At this point, a chown was emitted by "btrfs send" since only the group was changed. This makes the
cap_sys_nicecapability to be dropped from fs2/snap_incremental/foo.barExplaining in a changelog for a test case why exactly the bug happens is out of scope.
We just want to know what bug are we testing for.The gory details about why the bug happens usually go the in the changelog of the patch that fixes btrfs.
Quoted 48 lines
This test fails on current kernel, the fix was submitted to the btrfs mailing list titled:
"btrfs: send: Emit file capabilities after chown"
Signed-off-by Marcos Paulo de Souza <[email protected]>--- tests/btrfs/211 | 153 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/211.out | 6 ++ tests/btrfs/group | 1 + 3 files changed, 160 insertions(+) create mode 100755 tests/btrfs/211 create mode 100644 tests/btrfs/211.outtests/btrfs/211 new file +27
-0@@ -0,0 +1,153 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 211 +# +# Test if the file capabilities aren't lost after full and incremental send +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +_supported_fs btrfs +_supported_os Linux +_require_scratchtests/btrfs/211 line 37
Quoted 10 lines
tests/btrfs/211 new file +10
-0+_require_command "$SETCAP_PROG" setcap +_require_command "$GETCAP_PROG" getcap + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +_check_xattr()Function names starting with '_' are usually reserved for functions provided by fstests, global functions (like the ones in common/*). Same comment applies to all the other function names.
Also, a better name would be "
check_capabilities" - that they are stored in a xattr it's irrelevant as we are using the getcap and setcap utilities to read and set them, and not accessing xattrs directly.tests/btrfs/211 line 43
Quoted 6 lines
tests/btrfs/211 new file +6
-0+{ + local RET + local FILE + local CAP + FILE="$1" + CAP="$2"Variables in uppercase are meant to be used for global variables. Same comment applies to all the other functions.
tests/btrfs/211 line 47
Quoted 4 lines
tests/btrfs/211 new file +4
-0+ RET=$($GETCAP_PROG "$FILE") + if [ -z "$RET" ]; then + echo "$RET" + _fail "missing capability in file $FILE"This is a practice generally discouraged, we should avoid "
_fail" unless absolutely necessary.
The right approach here is just to "echo" the message. That's enough to make the test fail as that message is not part of the golden output.
Furthermore, not using_failallows the test to proceed and potentially find other problems.tests/btrfs/211 line 52
Quoted 5 lines
tests/btrfs/211 new file +5
-0+ fi + if [[ "$RET" != *$CAP* ]]; then + echo "$RET" + echo "$CAP" + _fail "Capability do not match. Output: $RET"Capability -> Capabilities
tests/btrfs/211 line 62
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ fi +} + +_setup() +{ + _scratch_mkfs >/dev/null + _scratch_mount + + FS1="$SCRATCH_MNT/fs1" + FS2="$SCRATCH_MNT/fs2"To make it easier to follow, perhaps declare this outside this function, as they are used by the other functions.
Quoted 5 lines
tests/btrfs/211 new file +5
-0+ + $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null + $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null +} +tests/btrfs/211 line 77
Quoted 10 lines
tests/btrfs/211 new file +10
-0+_full_nocap_inc_withcap_send() +{ + _setup + + # Test full send containing a file with no capability + touch "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null + $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q + # ensure that we don't have caps set + RET=$($GETCAP_PROG "$FS2/snap_init/foo.bar")Should be declared local (and lower case name).
tests/btrfs/211 line 79
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ if [ -n "$RET" ]; then + _fail "File contain capabilities when it shouldn't"echo and contain -> contains
Quoted 7 lines
tests/btrfs/211 new file +7
-0+ fi + + # Test if incremental send bring the newly added capability + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null + $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -qtests/btrfs/211 line 96
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ _check_xattr "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + _scratch_unmount +} + +_roundtrip_send() +{ + local FILES + local FS1 + local FS2So FS1 and FS2 are declared local but never set. And they were previously set as global by "
_setup".
So those two declarations should be removed here.tests/btrfs/211 line 108
Quoted 12 lines
tests/btrfs/211 new file +12
-0+ + # FILES should include foo.bar + FILES="$1" + + _setup + + # create files on fs1, must contain foo.bar + for f in $FILES; do + touch "$FS1/$f" + done + + # Test full send, checking if the receiving side keeps the capabilitycapability -> capabilities (as the test sets 2)
tests/btrfs/211 line 114
Quoted 6 lines
tests/btrfs/211 new file +6
-0+ $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null + $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_init/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + # Test incremental send with different owner/group but same capabilitycapability -> capabilities (as the test sets 2)
tests/btrfs/211 line 123
Quoted 9 lines
tests/btrfs/211 new file +9
-0+ chgrp 100 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null + _check_xattr "$FS1/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep" + + # Test capability after incremental send with different capability and groupcapability -> capabilities (as the test sets 2)
Quoted 4 lines
tests/btrfs/211 new file +4
-0+ chgrp 0 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep" "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc2" >/dev/null + _check_xattr "$FS1/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep"tests/btrfs/211 line 137
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2" -q | \ + $BTRFS_UTIL_PROG receive "$FS2" -q + _check_xattr "$FS2/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep" + + _scratch_unmount +} + +# real QA test starts here + +echo "Test full send + file without caps, then inc send bringing a new cap"inc -> incremental
Also, the abbreviation "caps" is used but in other messages (below) the non-abbreviated name "capabilities" is used.
We should be consistent and use only one form.tests/btrfs/211 line 140
Quoted 3 lines
tests/btrfs/211 new file +3
-0+_full_nocap_inc_withcap_send + +echo "Testing if foo.bar alone can keep it's capability"it's -> its
capability -> capabilities (as the test sets 2)Quoted 30 lines
tests/btrfs/211 new file +13
-0+_roundtrip_send "foo.bar" + +echo "Test foo.bar being the first item among other files" +_roundtrip_send "foo.bar foo.bax foo.baz" + +echo "Test foo.bar with objectid between two other files" +_roundtrip_send "foo1 foo.bar foo3" + +echo "Test foo.bar being the last item among other files" +_roundtrip_send "foo1 foo2 foo.bar" + +status=0 +exittests/btrfs/211.out new file +6
-0@@ -0,0 +1,6 @@ +QA output created by 211 +Test full send + file without caps, then inc send bringing a new cap +Testing if foo.bar alone can keep it's capability +Test foo.bar being the first item among other files +Test foo.bar with objectid between two other files +Test foo.bar being the last item among other filestests/btrfs/group +0
-0tests/btrfs/group line 216
Quoted 4 lines
tests/btrfs/group +1
-0@@ -213,3 +213,4 @@ 208 auto quick subvol 209 auto quick log 210 auto quick qgroup snapshot +211 auto quick snapshotMissing the 'send' group.
Quoted 3 lines
Other that is looks good and it works as expected (with patched and unpatched btrfs)
Thanks.
Marcos, ping. Anything I can help with?
We should really have this test case in fstests.
Thanks.
Quoted 10 lines
Quoted 4 lines
--
2.25.1--
Filipe David Manana,“Whether you think you can, or you think you can't — you're right.”
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 355 lines · Filipe Manana
Quoted 7 lines · Filipe Manana
Quoted 4 lines · Marcos Paulo de Souza
From: Marcos Paulo de Souza <[email protected]>
There is a situation where the incremental send can drop the
capability
Quoted 1 line
Quoted 1 line
from the receiving side. If you have a file that changed the
group, but
Quoted 1 line
Quoted 1 line
the capability was the same of before the group changed, the
current
Quoted 1 line
Quoted 1 line
kernel code will only emit a chown, since the capability is the
same.
Quoted 11 lines
Quoted 11 lines
The steps bellow can reproduce the problem.
$ mount /dev/sda fs1 $ mount /dev/sdb fs2$ touch fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar $ btrfs subvol snap -r fs1 fs1/snap_init $ btrfs send fs1/snap_init | btrfs receive fs2Quoted 8 lines
Quoted 8 lines
$ chgrp adm fs1/foo.bar $ setcap cap_sys_nice+ep fs1/foo.bar$ btrfs subvol snap -r fs1 fs1/snap_complete $ btrfs subvol snap -r fs1 fs1/snap_incremental$ btrfs send fs1/snap_complete | btrfs receive fs2 $ btrfs send -p fs1/snap_init fs1/snap_incremental | btrfsreceive fs2
Quoted 6 lines
It's redundant to put here the steps to trigger the problem, that's what the test does.
You just want to say this test exercises full send and incremental send operations for cases where files have capabilities, to verify
the
Quoted 4 lines
capabilities aren't lost.
Quoted 2 lines
At this point, a chown was emitted by "btrfs send" since only the
group
Quoted 1 line
Quoted 1 line
was changed. This makes the
cap_sys_nicecapability to be droppedfrom
Quoted 3 lines
Quoted 1 line
fs2/snap_incremental/foo.bar
Explaining in a changelog for a test case why exactly the bug
happens
Quoted 8 lines
is out of scope.
We just want to know what bug are we testing for.The gory details about why the bug happens usually go the in the changelog of the patch that fixes btrfs.
Quoted 2 lines
This test fails on current kernel, the fix was submitted to the
btrfs
Quoted 7 lines
Quoted 7 lines
mailing list titled:
"btrfs: send: Emit file capabilities after chown"
Signed-off-by Marcos Paulo de Souza <[email protected]>--- tests/btrfs/211 | 153++++++++++++++++++++++++++++++++++++++++++++
Quoted 6 lines
Quoted 6 lines
tests/btrfs/211.out | 6 ++ tests/btrfs/group | 1 + 3 files changed, 160 insertions(+) create mode 100755 tests/btrfs/211 create mode 100644 tests/btrfs/211.outQuoted 9 lines
tests/btrfs/211 line 3
Quoted 9 lines
tests/btrfs/211 new file +3
-0@@ -0,0 +1,153 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 SUSE Linux Products GmbH. All RightsReserved.
Quoted 4 lines
tests/btrfs/211
Quoted 4 lines
tests/btrfs/211 new file +4
-0+# +# FS QA Test 211 +# +# Test if the file capabilities aren't lost after full andincremental send
Quoted 40 lines
Quoted 20 lines
tests/btrfs/211 new file +20
-0+# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +_supported_fs btrfs +_supported_os Linux +_require_scratchtests/btrfs/211 line 37
Quoted 10 lines
tests/btrfs/211 new file +10
-0+_require_command "$SETCAP_PROG" setcap +_require_command "$GETCAP_PROG" getcap + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +_check_xattr()Function names starting with '_' are usually reserved for functions provided by fstests, global functions (like the ones in common/*). Same comment applies to all the other function names.
Also, a better name would be "
check_capabilities" - that they are stored in a xattr it's irrelevant as we are using the getcap and setcap utilities to read and set them, and not accessing xattrs directly.Quoted 8 lines
tests/btrfs/211 line 43
Quoted 6 lines
tests/btrfs/211 new file +6
-0+{ + local RET + local FILE + local CAP + FILE="$1" + CAP="$2"Variables in uppercase are meant to be used for global variables.
Same
Quoted 10 lines
comment applies to all the other functions.
tests/btrfs/211 line 47
Quoted 4 lines
tests/btrfs/211 new file +4
-0+ RET=$($GETCAP_PROG "$FILE") + if [ -z "$RET" ]; then + echo "$RET" + _fail "missing capability in file $FILE"This is a practice generally discouraged, we should avoid "
_fail" unless absolutely necessary.
The right approach here is just to "echo" the message. That'senough
Quoted 27 lines
to make the test fail as that message is not part of the golden output.
Furthermore, not using_failallows the test to proceed and potentially find other problems.tests/btrfs/211 line 52
Quoted 5 lines
tests/btrfs/211 new file +5
-0+ fi + if [[ "$RET" != *$CAP* ]]; then + echo "$RET" + echo "$CAP" + _fail "Capability do not match. Output: $RET"Capability -> Capabilities
tests/btrfs/211 line 62
Quoted 10 lines
tests/btrfs/211 new file +10
-0+ fi +} + +_setup() +{ + _scratch_mkfs >/dev/null + _scratch_mount + + FS1="$SCRATCH_MNT/fs1" + FS2="$SCRATCH_MNT/fs2"To make it easier to follow, perhaps declare this outside this function, as they are used by the other functions.
Quoted 12 lines
tests/btrfs/211
Quoted 12 lines
tests/btrfs/211 new file +12
-0+ + $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null + $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null +} + +_full_nocap_inc_withcap_send() +{ + _setup + + # Test full send containing a file with no capability + touch "$FS1/foo.bar" + $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1""$FS1/snap_init" >/dev/null
Quoted 1 line
tests/btrfs/211 line 75
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG send "$FS1/snap_init" -q |$BTRFS_UTIL_PROG receive "$FS2" -q
Quoted 7 lines
tests/btrfs/211 line 77
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ # ensure that we don't have caps set + RET=$($GETCAP_PROG "$FS2/snap_init/foo.bar")Should be declared local (and lower case name).
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ if [ -n "$RET" ]; then + _fail "File contain capabilities when itshouldn't"
Quoted 6 lines
echo and contain -> contains
Quoted 3 lines
tests/btrfs/211 new file +3
-0+ fi + + # Test if incremental send bring the newly addedcapability
Quoted 1 line
tests/btrfs/211 line 83
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep""$FS1/foo.bar"
Quoted 1 line
tests/btrfs/211 line 84
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1""$FS1/snap_inc" >/dev/null
Quoted 1 line
tests/btrfs/211 line 85
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc"-q | \
Quoted 1 line
tests/btrfs/211 line 86
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG receive"$FS2" -q
Quoted 1 line
tests/btrfs/211 line 87
Quoted 1 line
tests/btrfs/211 new file +1
-0+ _check_xattr "$FS2/snap_inc/foo.bar""cap_sys_ptrace,cap_sys_nice+ep"
Quoted 14 lines
tests/btrfs/211 line 96
Quoted 9 lines
tests/btrfs/211 new file +9
-0+ + _scratch_unmount +} + +_roundtrip_send() +{ + local FILES + local FS1 + local FS2So FS1 and FS2 are declared local but never set. And they were previously set as global by "
_setup".
So those two declarations should be removed here.Quoted 12 lines
tests/btrfs/211
Quoted 12 lines
tests/btrfs/211 new file +12
-0+ + # FILES should include foo.bar + FILES="$1" + + _setup + + # create files on fs1, must contain foo.bar + for f in $FILES; do + touch "$FS1/$f" + done + + # Test full send, checking if the receiving side keepsthe capability
Quoted 4 lines
capability -> capabilities (as the test sets 2)
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep""$FS1/foo.bar"
Quoted 1 line
tests/btrfs/211 line 110
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1""$FS1/snap_init" >/dev/null
Quoted 1 line
tests/btrfs/211 line 111
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG send "$FS1/snap_init" -q |$BTRFS_UTIL_PROG receive "$FS2" -q
Quoted 1 line
tests/btrfs/211 line 112
Quoted 1 line
tests/btrfs/211 new file +1
-0+ _check_xattr "$FS2/snap_init/foo.bar""cap_sys_ptrace,cap_sys_nice+ep"
Quoted 2 lines
tests/btrfs/211 line 114
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ + # Test incremental send with different owner/group butsame capability
Quoted 5 lines
capability -> capabilities (as the test sets 2)
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ chgrp 100 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep""$FS1/foo.bar"
Quoted 1 line
tests/btrfs/211 line 117
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1""$FS1/snap_inc" >/dev/null
Quoted 1 line
tests/btrfs/211 line 118
Quoted 1 line
tests/btrfs/211 new file +1
-0+ _check_xattr "$FS1/snap_inc/foo.bar""cap_sys_ptrace,cap_sys_nice+ep"
Quoted 1 line
tests/btrfs/211 line 119
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc"-q | \
Quoted 1 line
tests/btrfs/211 line 120
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG receive "$FS2"-q
Quoted 1 line
tests/btrfs/211 line 121
Quoted 1 line
tests/btrfs/211 new file +1
-0+ _check_xattr "$FS2/snap_inc/foo.bar""cap_sys_ptrace,cap_sys_nice+ep"
Quoted 2 lines
tests/btrfs/211 line 123
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ + # Test capability after incremental send with differentcapability and group
Quoted 5 lines
capability -> capabilities (as the test sets 2)
Quoted 2 lines
tests/btrfs/211 new file +2
-0+ chgrp 0 "$FS1/foo.bar" + $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep""$FS1/foo.bar"
Quoted 1 line
tests/btrfs/211 line 126
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1""$FS1/snap_inc2" >/dev/null
Quoted 1 line
tests/btrfs/211 line 127
Quoted 1 line
tests/btrfs/211 new file +1
-0+ _check_xattr "$FS1/snap_inc2/foo.bar""cap_sys_time,cap_syslog+ep"
Quoted 1 line
tests/btrfs/211 line 128
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2"-q | \
Quoted 1 line
tests/btrfs/211 line 129
Quoted 1 line
tests/btrfs/211 new file +1
-0+ $BTRFS_UTIL_PROG receive"$FS2" -q
Quoted 1 line
tests/btrfs/211 line 130
Quoted 1 line
tests/btrfs/211 new file +1
-0+ _check_xattr "$FS2/snap_inc2/foo.bar""cap_sys_time,cap_syslog+ep"
Quoted 7 lines
tests/btrfs/211
Quoted 7 lines
tests/btrfs/211 new file +7
-0+ + _scratch_unmount +} + +# real QA test starts here + +echo "Test full send + file without caps, then inc send bringinga new cap"
Quoted 27 lines
inc -> incremental
Also, the abbreviation "caps" is used but in other messages (below) the non-abbreviated name "capabilities" is used.
We should be consistent and use only one form.tests/btrfs/211 line 140
Quoted 3 lines
tests/btrfs/211 new file +3
-0+_full_nocap_inc_withcap_send + +echo "Testing if foo.bar alone can keep it's capability"it's -> its
capability -> capabilities (as the test sets 2)Quoted 13 lines
tests/btrfs/211 new file +13
-0+_roundtrip_send "foo.bar" + +echo "Test foo.bar being the first item among other files" +_roundtrip_send "foo.bar foo.bax foo.baz" + +echo "Test foo.bar with objectid between two other files" +_roundtrip_send "foo1 foo.bar foo3" + +echo "Test foo.bar being the last item among other files" +_roundtrip_send "foo1 foo2 foo.bar" + +status=0 +exitQuoted 8 lines
tests/btrfs/211.out line 2
Quoted 8 lines
tests/btrfs/211.out new file +2
-0@@ -0,0 +1,6 @@ +QA output created by 211 +Test full send + file without caps, then inc send bringing a newcap
Quoted 16 lines
tests/btrfs/group line 216
Quoted 13 lines
tests/btrfs/211.out new file +4
-0+Testing if foo.bar alone can keep it's capability +Test foo.bar being the first item among other files +Test foo.bar with objectid between two other files +Test foo.bar being the last item among other filestests/btrfs/group +1
-0@@ -213,3 +213,4 @@ 208 auto quick subvol 209 auto quick log 210 auto quick qgroup snapshot +211 auto quick snapshotMissing the 'send' group.
Quoted 5 lines
Quoted 3 lines
Other that is looks good and it works as expected (with patched and unpatched btrfs)
Thanks.Marcos, ping. Anything I can help with?
Sorry, the test was in my radar but somehow I forgot about it. I hope to send a new version later today, addressing all your comments.
Quoted 1 line
We should really have this test case in fstests.
Sure, I agree.
Quoted 18 lines
Thanks.
Quoted 10 lines
Quoted 4 lines
--
2.25.1--
Filipe David Manana,“Whether you think you can, or you think you can't — you're right.”