generic/692: test group ownership change
PATCH 1/1 generic/692: test group ownership change
When group ownership is changed a caller whose fsuid owns the inode can change the group of the inode to any group they are a member of. When searching through the caller's groups we failed to use the gid mapped according to the idmapped mount otherwise we fail to change ownership. Add a test for this.
--- tests/generic/692 | 74 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/692.out | 3 ++ 2 files changed, 77 insertions(+) create mode 100755 tests/generic/692 create mode 100644 tests/generic/692.out
tests/generic/692 new file +74 -0
@@ -0,0 +1,74 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Christian Brauner (Microsoft). All Rights Reserved. +# +# FS QA Test 692 +# +# Test that users can changed group ownership of a file they own to a group +# they are a member of. +# +# Regression test for commit: +# +# 263de29d8397 ("fs: account for group membership") +# +. ./common/preamble +_begin_fstest auto quick perms attr idmapped mount + +# Override the default cleanup function. +_cleanup() +{ + cd / + $UMOUNT_PROG $TEST_DIR/target-mnt + rm -r -f $tmp.* +} + +# Import common functions. +# . ./common/filter + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_test +_require_chown +_require_idmapped_mounts +_require_user fsgqa +_require_group fsgqa +_require_group fsgqa2 + +uqid=`id -u fsgqa` +gqid=`id -g fsgqa` +uqid2=`id -u fsgqa2` +gqid2=`id -g fsgqa2` + +setup_tree() +{ + mkdir -p $TEST_DIR/source-mnt + chmod 0777 $TEST_DIR/source-mnt + touch $TEST_DIR/source-mnt/dir1 + chown 65534:65534 $TEST_DIR/source-mnt + chown 65534:65535 $TEST_DIR/source-mnt/dir1 + + mkdir -p $TEST_DIR/target-mnt + chmod 0777 $TEST_DIR/target-mnt +} + +setup_idmapped_mnt() +{ + $here/src/vfs/mount-idmapped \ + --map-mount=u:65534:$uqid:1 \ + --map-mount=g:65534:$gqid:1 \ + --map-mount=u:65535:$uqid2:1 \ + --map-mount=g:65535:$gqid2:1 \ + $TEST_DIR/source-mnt $TEST_DIR/target-mnt +} + +setup_tree +setup_idmapped_mnt +stat -c '%U:%G' "$TEST_DIR/target-mnt/dir1" +_user_do "chgrp $gqid $TEST_DIR/target-mnt/dir1" +stat -c '%U:%G' "$TEST_DIR/target-mnt/dir1" + +# success, all done +status=0 +exit
tests/generic/692.out new file +3 -0
@@ -0,0 +1,3 @@ +QA output created by 692 +fsgqa:fsgqa2 +fsgqa:fsgqa
base-commit: 568ac9fffeb6afec03e5d6c9936617232fd7fc6d
Signature · 1 line
2.34.1
Quoted 6 lines · Christian Brauner
When group ownership is changed a caller whose fsuid owns the inode can change the group of the inode to any group they are a member of. When searching through the caller's groups we failed to use the gid mapped according to the idmapped mount otherwise we fail to change ownership. Add a test for this.
Quoted 6 lines
Cc Seth Forshee <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Aleksa Sarai <[email protected]>Cc <[email protected]>Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Thanks for this test, a few of small review points as below ...
Quoted 23 lines
tests/generic/692 | 74 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/692.out | 3 ++ 2 files changed, 77 insertions(+) create mode 100755 tests/generic/692 create mode 100644 tests/generic/692.outtests/generic/692 new file +11
-0@@ -0,0 +1,74 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Christian Brauner (Microsoft). All Rights Reserved. +# +# FS QA Test 692 +# +# Test that users can changed group ownership of a file they own to a group +# they are a member of. +# +# Regression test for commit: +#
tests/generic/692 line 21
Quoted 10 lines
tests/generic/692 new file +10
-0+# 263de29d8397 ("fs: account for group membership") +# +. ./common/preamble +_begin_fstest auto quick perms attr idmapped mount + +# Override the default cleanup function. +_cleanup() +{ + cd / + $UMOUNT_PROG $TEST_DIR/target-mnt
Do you need to filter out the errors by "2>/dev/null"?
tests/generic/692 line 26
Quoted 5 lines
tests/generic/692 new file +5
-0+ rm -r -f $tmp.* +} + +# Import common functions. +# . ./common/filter
I think you didn't use any filter, right? If so, this can be removed.
tests/generic/692 line 30
Quoted 4 lines
tests/generic/692 new file +4
-0+ +# real QA test starts here + +# Modify as appropriate.
^^^
This line can be removed too.
Quoted 18 lines
tests/generic/692 new file +18
-0+_supported_fs generic +_require_test +_require_chown +_require_idmapped_mounts +_require_user fsgqa +_require_group fsgqa +_require_group fsgqa2 + +uqid=`id -u fsgqa` +gqid=`id -g fsgqa` +uqid2=`id -u fsgqa2` +gqid2=`id -g fsgqa2` + +setup_tree() +{ + mkdir -p $TEST_DIR/source-mnt + chmod 0777 $TEST_DIR/source-mnt + touch $TEST_DIR/source-mnt/dir1
tests/generic/692 line 58
Quoted 10 lines
tests/generic/692 new file +10
-0+ chown 65534:65534 $TEST_DIR/source-mnt + chown 65534:65535 $TEST_DIR/source-mnt/dir1 + + mkdir -p $TEST_DIR/target-mnt + chmod 0777 $TEST_DIR/target-mnt +} + +setup_idmapped_mnt() +{ + $here/src/vfs/mount-idmapped \
You might need:
_require_test_program "vfs/mount-idmapped"
due to _require_idmapped_mounts doesn't guarantee that.
Thanks,
Zorro
Quoted 30 lines
tests/generic/692 new file +16
-0+ --map-mount=u:65534:$uqid:1 \ + --map-mount=g:65534:$gqid:1 \ + --map-mount=u:65535:$uqid2:1 \ + --map-mount=g:65535:$gqid2:1 \ + $TEST_DIR/source-mnt $TEST_DIR/target-mnt +} + +setup_tree +setup_idmapped_mnt +stat -c '%U:%G' "$TEST_DIR/target-mnt/dir1" +_user_do "chgrp $gqid $TEST_DIR/target-mnt/dir1" +stat -c '%U:%G' "$TEST_DIR/target-mnt/dir1" + +# success, all done +status=0 +exittests/generic/692.out new file +3
-0@@ -0,0 +1,3 @@ +QA output created by 692 +fsgqa:fsgqa2 +fsgqa:fsgqabase-commit:
568ac9fffeb6afec03e5d6c9936617232fd7fc6dSignature · 1 line
2.34.1
Quoted 7 lines · Zorro Lang
Quoted 6 lines · Christian Brauner
When group ownership is changed a caller whose fsuid owns the inode can change the group of the inode to any group they are a member of. When searching through the caller's groups we failed to use the gid mapped according to the idmapped mount otherwise we fail to change ownership. Add a test for this.
Quoted 8 lines
Quoted 6 lines
Cc Seth Forshee <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Aleksa Sarai <[email protected]>Cc <[email protected]>Signed-off-by Christian Brauner (Microsoft) <[email protected]>---
Thanks for this test, a few of small review points as below ...
Thanks for the review!
Quoted 28 lines
Quoted 28 lines
tests/generic/692 | 74 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/692.out | 3 ++ 2 files changed, 77 insertions(+) create mode 100755 tests/generic/692 create mode 100644 tests/generic/692.outtests/generic/692 new file +15
-0@@ -0,0 +1,74 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Christian Brauner (Microsoft). All Rights Reserved. +# +# FS QA Test 692 +# +# Test that users can changed group ownership of a file they own to a group +# they are a member of. +# +# Regression test for commit: +# +# 263de29d8397 ("fs: account for group membership") +# +. ./common/preamble +_begin_fstest auto quick perms attr idmapped mount
Quoted 8 lines
tests/generic/692 line 21
Quoted 6 lines
tests/generic/692 new file +6
-0+ +# Override the default cleanup function. +_cleanup() +{ + cd / + $UMOUNT_PROG $TEST_DIR/target-mntDo you need to filter out the errors by "2>/dev/null"?
Yeah, good idea.
Quoted 8 lines
tests/generic/692 line 26
Quoted 6 lines
tests/generic/692 new file +5
-0+ rm -r -f $tmp.* +} + +# Import common functions. +# . ./common/filterI think you didn't use any filter, right? If so, this can be removed.
Removed.
Quoted 7 lines
tests/generic/692 line 30
Quoted 5 lines
tests/generic/692 new file +4
-0+ +# real QA test starts here + +# Modify as appropriate.^^^This line can be removed too.
Removed.
Quoted 33 lines
Quoted 19 lines
tests/generic/692 new file +18
-0+_supported_fs generic +_require_test +_require_chown +_require_idmapped_mounts +_require_user fsgqa +_require_group fsgqa +_require_group fsgqa2 + +uqid=`id -u fsgqa` +gqid=`id -g fsgqa` +uqid2=`id -u fsgqa2` +gqid2=`id -g fsgqa2` + +setup_tree() +{ + mkdir -p $TEST_DIR/source-mnt + chmod 0777 $TEST_DIR/source-mnt + touch $TEST_DIR/source-mnt/dir1tests/generic/692 line 58
Quoted 10 lines
tests/generic/692 new file +10
-0+ chown 65534:65534 $TEST_DIR/source-mnt + chown 65534:65535 $TEST_DIR/source-mnt/dir1 + + mkdir -p $TEST_DIR/target-mnt + chmod 0777 $TEST_DIR/target-mnt +} + +setup_idmapped_mnt() +{ + $here/src/vfs/mount-idmapped \You might need:
_require_test_program"vfs/mount-idmapped"
Quoted 1 line
due to
_require_idmapped_mountsdoesn't guarantee that.
Yes, good point!
Thanks!
Christian