Skip to contentSkip to conversation

rename & split tests

PATCH Superseded Christian Brauner 3 participants 15 messages Apr 28, 2022 – May 7, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover rename & split tests

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

As announced multiple times already we need to rename and split the idmapped mount testsuite into separate source files and also give it a better name to reflect the fact that it covers a lot more than just idmapped mounts.

I have decided against compiling different binaries for now. Instead we compile a single vfstest binary that can be called with various command line switches to run the various test suites. This is not different than what we did for the idmapped-mounts binary. Of course, nothing prevents us from using multiple binaries in the future.

Note that this will have a conflict with Jan's series at:
https://lore.kernel.org/fstests/20220425131809.qzjrah7cw67mzzcw@zlang-mailbox/T/#m47d8da68ef1aff250918398e8d2228729a6acf97

If this patch series here is acceptable I'd pick up Jan's patch and apply it on top of mine as rebasing will introduce too many conflicts.

Thanks!
Christian

Christian Brauner (11):
src: rename idmapped-mounts folder
src/vfs: rename idmapped-mounts.c file
vfstest: rename struct t_idmapped_mounts
utils: add missing global.h include
utils: add struct vfstest_info
utils: move helpers into utils
missing: move sys_execveat() to missing.h
utils: add struct test_suite
vfstests: split idmapped mount tests into separate suite
vfstest: split out btrfs idmapped mounts test
vfstest: split out remaining idmapped mount tests

 .gitignore                                    |     4 +-
 common/rc                                     |    32 +-
 src/Makefile                                  |     2 +-
 src/detached_mounts_propagation.c             |     2 +-
 src/feature.c                                 |     2 +-
 src/idmapped-mounts/utils.c                   |   425 -
 src/idmapped-mounts/utils.h                   |   130 -
 src/{idmapped-mounts => vfs}/Makefile         |    14 +-
 src/vfs/btrfs-idmapped-mounts.c               |  3854 +++++
 src/vfs/btrfs-idmapped-mounts.h               |    15 +
 .../idmapped-mounts.c                         | 11865 ++++------------
 src/vfs/idmapped-mounts.h                     |    17 +
 src/{idmapped-mounts => vfs}/missing.h        |    11 +
 src/{idmapped-mounts => vfs}/mount-idmapped.c |     0
 src/vfs/utils.c                               |  1003 ++
 src/vfs/utils.h                               |   364 +
 src/vfs/vfstest.c                             |  1952 +++
 tests/btrfs/245                               |     2 +-
 tests/generic/633                             |     2 +-
 tests/generic/644                             |     2 +-
 tests/generic/645                             |     2 +-
 tests/generic/656                             |     2 +-
 tests/xfs/152                                 |     4 +-
 tests/xfs/153                                 |     2 +-
 24 files changed, 9952 insertions(+), 9756 deletions(-)
 delete mode 100644 src/idmapped-mounts/utils.c
 delete mode 100644 src/idmapped-mounts/utils.h
 rename src/{idmapped-mounts => vfs}/Makefile (59%)
 create mode 100644 src/vfs/btrfs-idmapped-mounts.c
 create mode 100644 src/vfs/btrfs-idmapped-mounts.h
 rename src/{idmapped-mounts => vfs}/idmapped-mounts.c (50%)
 create mode 100644 src/vfs/idmapped-mounts.h
 rename src/{idmapped-mounts => vfs}/missing.h (93%)
 rename src/{idmapped-mounts => vfs}/mount-idmapped.c (100%)
 create mode 100644 src/vfs/utils.c
 create mode 100644 src/vfs/utils.h
 create mode 100644 src/vfs/vfstest.c
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/11 src: rename idmapped-mounts folder

The idmapped mounts test suite has grown to cover a lot of generic vfs functionality that is not concerned with idmapped mounts at all.

As was discussed upstream it's time to rename it to something that reflects its generic nature. So rename it from idmapped-mounts to vfs.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 .gitignore                                    |  4 +--
 common/rc                                     | 28 +++++++++----------
 src/Makefile                                  |  2 +-
 src/detached_mounts_propagation.c             |  2 +-
 src/feature.c                                 |  2 +-
 src/{idmapped-mounts => vfs}/Makefile         |  4 +--
 .../idmapped-mounts.c                         |  0
 src/{idmapped-mounts => vfs}/missing.h        |  0
 src/{idmapped-mounts => vfs}/mount-idmapped.c |  0
 src/{idmapped-mounts => vfs}/utils.c          |  0
 src/{idmapped-mounts => vfs}/utils.h          |  0
 tests/btrfs/245                               |  2 +-
 tests/generic/633                             |  2 +-
 tests/generic/644                             |  2 +-
 tests/generic/645                             |  2 +-
 tests/generic/656                             |  2 +-
 tests/xfs/152                                 |  2 +-
 tests/xfs/153                                 |  2 +-
 18 files changed, 28 insertions(+), 28 deletions(-)
 rename src/{idmapped-mounts => vfs}/Makefile (86%)
 rename src/{idmapped-mounts => vfs}/idmapped-mounts.c (100%)
 rename src/{idmapped-mounts => vfs}/missing.h (100%)
 rename src/{idmapped-mounts => vfs}/mount-idmapped.c (100%)
 rename src/{idmapped-mounts => vfs}/utils.c (100%)
 rename src/{idmapped-mounts => vfs}/utils.h (100%)
.gitignore +2 -2
index 5f24909e..b9e42635 100644
@@ -192,8 +192,8 @@ tags
 /src/aio-dio-regress/aio-last-ref-held-by-io
 /src/aio-dio-regress/aiocp
 /src/aio-dio-regress/aiodio_sparse2
-/src/idmapped-mounts/idmapped-mounts
-/src/idmapped-mounts/mount-idmapped
+/src/vfs/idmapped-mounts
+/src/vfs/mount-idmapped
 /src/log-writes/replay-log
 /src/perf/*.pyc
 
common/rc +14 -14
index 553ae350..b0940872 100644
@@ -355,23 +355,23 @@ _scratch_mount_idmapped()
 	if [ "$type" = "u" ]; then
 		# This means root will be able to create files as uid %id in
 		# the underlying filesystem by going through the idmapped mount.
-		$here/src/idmapped-mounts/mount-idmapped --map-mount u:0:$id:1 \
-							 --map-mount u:$id:0:1 \
-							 --map-mount g:0:0:1 \
-							 "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
+		$here/src/vfs/mount-idmapped --map-mount u:0:$id:1 \
+					     --map-mount u:$id:0:1 \
+					     --map-mount g:0:0:1 \
+					     "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
 	elif [ "$type" = "g" ]; then
 		# This means root will be able to create files as gid %id in
 		# the underlying filesystem by going through the idmapped mount.
-		$here/src/idmapped-mounts/mount-idmapped --map-mount g:0:$id:1 \
-							 --map-mount g:$id:0:1 \
-							 --map-mount u:0:0:1 \
-							 "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
+		$here/src/vfs/mount-idmapped --map-mount g:0:$id:1 \
+					     --map-mount g:$id:0:1 \
+					     --map-mount u:0:0:1 \
+					     "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
 	elif [ "$type" = "b" ]; then
 		# This means root will be able to create files as uid and gid
 		# %id in the underlying filesystem by going through the idmapped mount.
-		$here/src/idmapped-mounts/mount-idmapped --map-mount b:0:$id:1 \
-							 --map-mount b:$id:0:1 \
-							 "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
+		$here/src/vfs/mount-idmapped --map-mount b:0:$id:1 \
+					     --map-mount b:$id:0:1 \
+					     "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
 	else
 		_fail "usage: either \"u\" (uid), \"g\" (gid), or \"b\" (uid and gid) must be specified "
 	fi
@@ -480,7 +480,7 @@ _idmapped_mount()
 	# {g,u}id 10000000 and $(id -u fsgqa) + 10000000. We change ownership
         # of $mnt so {g,u} id 0 can actually create objects in there.
 	chown 10000000:10000000 $mnt || return 1
-	$here/src/idmapped-mounts/mount-idmapped \
+	$here/src/vfs/mount-idmapped \
 		--map-mount b:10000000:0:100000000000 \
 		$mnt $tmp
 	if [ $? -ne 0 ]; then
@@ -2287,12 +2287,12 @@ _require_mount_setattr()
 # test whether idmapped mounts are supported
 _require_idmapped_mounts()
 {
-        IDMAPPED_MOUNTS_TEST=$here/src/idmapped-mounts/idmapped-mounts
+        IDMAPPED_MOUNTS_TEST=$here/src/vfs/idmapped-mounts
         [ -x $IDMAPPED_MOUNTS_TEST ] || _notrun "idmapped-mounts utilities required"
 
 	_require_mount_setattr
 
-	$here/src/idmapped-mounts/idmapped-mounts --supported \
+	$here/src/vfs/idmapped-mounts --supported \
 		--device "$TEST_DEV" \
 		--mount "$TEST_DIR" \
 		--fstype "$FSTYP"
src/Makefile +1 -1
index 24aef09b..7eeb08ef 100644
@@ -76,7 +76,7 @@ TARGETS += uring_read_fault
 LLDLIBS += -luring
 endif
 
-SUBDIRS += idmapped-mounts
+SUBDIRS += vfs
 ifeq ($(HAVE_LIBCAP), true)
 LLDLIBS += -lcap
 endif
src/detached_mounts_propagation.c +1 -1
index d4bc87f9..17db2c02 100644
@@ -26,7 +26,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "idmapped-mounts/missing.h"
+#include "vfs/missing.h"
 
 static bool is_shared_mountpoint(const char *path)
 {
src/feature.c +1 -1
index bc0b0b30..941f96fb 100644
@@ -46,7 +46,7 @@
 #include <liburing.h>
 #endif
 
-#include "idmapped-mounts/missing.h"
+#include "vfs/missing.h"
 
 #ifndef USRQUOTA
 #define USRQUOTA  0
src/vfs/Makefile renamed from src/idmapped-mounts/Makefile +2 -2
similarity index 86%
rename from src/idmapped-mounts/Makefile
rename to src/vfs/Makefile
index ad4ddc99..2df3daf8 100644
@@ -34,7 +34,7 @@ mount-idmapped: $(CFILES_MOUNT_IDMAPPED)
 	$(Q)$(LTLINK) $(CFILES_MOUNT_IDMAPPED) -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS)
 
 install:
-	$(INSTALL) -m 755 -d $(PKG_LIB_DIR)/src/idmapped-mounts
-	$(INSTALL) -m 755 $(TARGETS) $(PKG_LIB_DIR)/src/idmapped-mounts
+	$(INSTALL) -m 755 -d $(PKG_LIB_DIR)/src/vfs
+	$(INSTALL) -m 755 $(TARGETS) $(PKG_LIB_DIR)/src/vfs
 
 -include .dep
src/vfs/idmapped-mounts.c renamed from src/idmapped-mounts/idmapped-mounts.c +0 -0
similarity index 100%
rename from src/idmapped-mounts/idmapped-mounts.c
rename to src/vfs/idmapped-mounts.c
src/vfs/missing.h renamed from src/idmapped-mounts/missing.h +0 -0
similarity index 100%
rename from src/idmapped-mounts/missing.h
rename to src/vfs/missing.h
src/vfs/mount-idmapped.c renamed from src/idmapped-mounts/mount-idmapped.c +0 -0
similarity index 100%
rename from src/idmapped-mounts/mount-idmapped.c
rename to src/vfs/mount-idmapped.c
src/vfs/utils.c renamed from src/idmapped-mounts/utils.c +0 -0
similarity index 100%
rename from src/idmapped-mounts/utils.c
rename to src/vfs/utils.c
src/vfs/utils.h renamed from src/idmapped-mounts/utils.h +0 -0
similarity index 100%
rename from src/idmapped-mounts/utils.h
rename to src/vfs/utils.h
tests/btrfs/245 +1 -1
index f3380ac2..6403f878 100755
@@ -26,7 +26,7 @@ _scratch_mount "-o user_subvol_rm_allowed" >> $seqres.full
 
 echo "Silence is golden"
 
-$here/src/idmapped-mounts/idmapped-mounts --test-btrfs --device "$TEST_DEV" \
+$here/src/vfs/idmapped-mounts --test-btrfs --device "$TEST_DEV" \
 	--mountpoint "$TEST_DIR" --scratch-device "$SCRATCH_DEV" \
 	--scratch-mountpoint "$SCRATCH_MNT" --fstype "$FSTYP"
 
tests/generic/633 +1 -1
index 38280647..2054b646 100755
@@ -19,7 +19,7 @@ _require_test
 
 echo "Silence is golden"
 
-$here/src/idmapped-mounts/idmapped-mounts --test-core --device "$TEST_DEV" \
+$here/src/vfs/idmapped-mounts --test-core --device "$TEST_DEV" \
 	--mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/generic/644 +1 -1
index 9ed5a511..17fc0539 100755
@@ -21,7 +21,7 @@ _require_test
 
 echo "Silence is golden"
 
-$here/src/idmapped-mounts/idmapped-mounts --test-fscaps-regression \
+$here/src/vfs/idmapped-mounts --test-fscaps-regression \
 	--device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/generic/645 +1 -1
index ffe30bb4..f1209ad0 100755
@@ -21,7 +21,7 @@ _require_test
 
 echo "Silence is golden"
 
-$here/src/idmapped-mounts/idmapped-mounts --test-nested-userns \
+$here/src/vfs/idmapped-mounts --test-nested-userns \
 	--device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/generic/656 +1 -1
index 1231de31..9e95ac96 100755
@@ -26,7 +26,7 @@ _require_group fsgqa2
 
 echo "Silence is golden"
 
-$here/src/idmapped-mounts/idmapped-mounts --test-setattr-fix-968219708108 \
+$here/src/vfs/idmapped-mounts --test-setattr-fix-968219708108 \
 	--device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/xfs/152 +1 -1
index 129d9c06..de9b8fc6 100755
@@ -34,7 +34,7 @@ _cleanup()
 # real QA test starts here
 _supported_fs xfs
 _require_idmapped_mounts
-_require_test_program "idmapped-mounts/mount-idmapped"
+_require_test_program "vfs/mount-idmapped"
 _require_scratch
 _require_xfs_quota
 _require_user fsgqa
tests/xfs/153 +1 -1
index 37303701..8e1430c0 100755
@@ -34,7 +34,7 @@ _require_scratch
 _require_xfs_quota
 _require_user fsgqa
 _require_idmapped_mounts
-_require_test_program "idmapped-mounts/mount-idmapped"
+_require_test_program "vfs/mount-idmapped"
 
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/11 src/vfs: rename idmapped-mounts.c file

In reply to Christian Brauner

The idmapped mounts test suite has grown to cover a lot of generic vfs functionality that is not concerned with idmapped mounts at all.

As was discussed upstream it's time to rename it to something that reflects its generic nature. So rename the source file from idmapped-mounts.c to vfstest.c before we split it into multiple source files in the next patches.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 .gitignore                               |  2 +-
 common/rc                                |  8 ++++----
 src/vfs/Makefile                         |  8 ++++----
 src/vfs/{idmapped-mounts.c => vfstest.c} | 14 +++++++-------
 tests/btrfs/245                          |  2 +-
 tests/generic/633                        |  2 +-
 tests/generic/644                        |  2 +-
 tests/generic/645                        |  2 +-
 tests/generic/656                        |  2 +-
 tests/xfs/152                            |  2 +-
 10 files changed, 22 insertions(+), 22 deletions(-)
 rename src/vfs/{idmapped-mounts.c => vfstest.c} (99%)
.gitignore +1 -1
index b9e42635..88c79412 100644
@@ -192,7 +192,7 @@ tags
 /src/aio-dio-regress/aio-last-ref-held-by-io
 /src/aio-dio-regress/aiocp
 /src/aio-dio-regress/aiodio_sparse2
-/src/vfs/idmapped-mounts
+/src/vfs/vfstest
 /src/vfs/mount-idmapped
 /src/log-writes/replay-log
 /src/perf/*.pyc
common/rc +4 -4
index b0940872..dec6a715 100644
@@ -2287,18 +2287,18 @@ _require_mount_setattr()
 # test whether idmapped mounts are supported
 _require_idmapped_mounts()
 {
-        IDMAPPED_MOUNTS_TEST=$here/src/vfs/idmapped-mounts
-        [ -x $IDMAPPED_MOUNTS_TEST ] || _notrun "idmapped-mounts utilities required"
+        IDMAPPED_MOUNTS_TEST=$here/src/vfs/vfstest
+        [ -x $IDMAPPED_MOUNTS_TEST ] || _notrun "vfstest utilities required"
 
 	_require_mount_setattr
 
-	$here/src/vfs/idmapped-mounts --supported \
+	$here/src/vfs/vfstest --idmapped-mounts-supported \
 		--device "$TEST_DEV" \
 		--mount "$TEST_DIR" \
 		--fstype "$FSTYP"
 
 	if [ $? -ne 0 ]; then
-		_notrun "idmapped-mounts not support by $FSTYP"
+		_notrun "vfstest not support by $FSTYP"
 	fi
 }
 
src/vfs/Makefile +4 -4
index 2df3daf8..adef9ff3 100644
@@ -3,8 +3,8 @@
 TOPDIR = ../..
 include $(TOPDIR)/include/builddefs
 
-TARGETS = idmapped-mounts mount-idmapped
-CFILES_IDMAPPED_MOUNTS = idmapped-mounts.c utils.c
+TARGETS = vfstest mount-idmapped
+CFILES_VFSTEST = vfstest.c utils.c
 CFILES_MOUNT_IDMAPPED = mount-idmapped.c utils.c
 
 HFILES = missing.h utils.h
@@ -25,9 +25,9 @@ depend: .dep
 
 include $(BUILDRULES)
 
-idmapped-mounts: $(CFILES_IDMAPPED_MOUNTS)
+vfstest: $(CFILES_VFSTEST)
 	@echo "    [CC]    $@"
-	$(Q)$(LTLINK) $(CFILES_IDMAPPED_MOUNTS) -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS)
+	$(Q)$(LTLINK) $(CFILES_VFSTEST) -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS)
 
 mount-idmapped: $(CFILES_MOUNT_IDMAPPED)
 	@echo "    [CC]    $@"
src/vfs/vfstest.c renamed from src/vfs/idmapped-mounts.c +7 -7
similarity index 99%
rename from src/vfs/idmapped-mounts.c
rename to src/vfs/vfstest.c
index 4cf6c3bb..66768175 100644
@@ -13801,7 +13801,7 @@ static void usage(void)
 	fprintf(stderr, "--fstype                            Filesystem type used in the tests\n");
 	fprintf(stderr, "--help                              Print help\n");
 	fprintf(stderr, "--mountpoint                        Mountpoint of device\n");
-	fprintf(stderr, "--supported                         Test whether idmapped mounts are supported on this filesystem\n");
+	fprintf(stderr, "--idmapped-mounts-supported	     Test whether idmapped mounts are supported on this filesystem\n");
 	fprintf(stderr, "--scratch-mountpoint                Mountpoint of scratch device used in the tests\n");
 	fprintf(stderr, "--scratch-device                    Scratch device used in the tests\n");
 	fprintf(stderr, "--test-core                         Run core idmapped mount testsuite\n");
@@ -13819,7 +13819,7 @@ static const struct option longopts[] = {
 	{"mountpoint",				required_argument,	0,	'm'},
 	{"scratch-mountpoint",			required_argument,	0,	'a'},
 	{"scratch-device",			required_argument,	0,	'e'},
-	{"supported",				no_argument,		0,	's'},
+	{"idmapped-mounts-supported",		no_argument,		0,	's'},
 	{"help",				no_argument,		0,	'h'},
 	{"test-core",				no_argument,		0,	'c'},
 	{"test-fscaps-regression",		no_argument,		0,	'g'},
@@ -13998,9 +13998,9 @@ int main(int argc, char *argv[])
 {
 	int fret, ret;
 	int index = 0;
-	bool supported = false, test_btrfs = false, test_core = false,
-	     test_fscaps_regression = false, test_nested_userns = false,
-	     test_setattr_fix_968219708108 = false;
+	bool idmapped_mounts_supported = false, test_btrfs = false,
+	     test_core = false, test_fscaps_regression = false,
+	     test_nested_userns = false, test_setattr_fix_968219708108 = false;
 
 	while ((ret = getopt_long_only(argc, argv, "", longopts, &index)) != -1) {
 		switch (ret) {
@@ -14014,7 +14014,7 @@ int main(int argc, char *argv[])
 			t_mountpoint = optarg;
 			break;
 		case 's':
-			supported = true;
+			idmapped_mounts_supported = true;
 			break;
 		case 'c':
 			test_core = true;
@@ -14070,7 +14070,7 @@ int main(int argc, char *argv[])
 		die("failed to open %s", t_mountpoint_scratch);
 
 	t_fs_allow_idmap = fs_allow_idmap();
-	if (supported) {
+	if (idmapped_mounts_supported) {
 		/*
 		 * Caller just wants to know whether the filesystem we're on
 		 * supports idmapped mounts.
tests/btrfs/245 +1 -1
index 6403f878..dadc8492 100755
@@ -26,7 +26,7 @@ _scratch_mount "-o user_subvol_rm_allowed" >> $seqres.full
 
 echo "Silence is golden"
 
-$here/src/vfs/idmapped-mounts --test-btrfs --device "$TEST_DEV" \
+$here/src/vfs/vfstest --test-btrfs --device "$TEST_DEV" \
 	--mountpoint "$TEST_DIR" --scratch-device "$SCRATCH_DEV" \
 	--scratch-mountpoint "$SCRATCH_MNT" --fstype "$FSTYP"
 
tests/generic/633 +1 -1
index 2054b646..9b29dbf1 100755
@@ -19,7 +19,7 @@ _require_test
 
 echo "Silence is golden"
 
-$here/src/vfs/idmapped-mounts --test-core --device "$TEST_DEV" \
+$here/src/vfs/vfstest --test-core --device "$TEST_DEV" \
 	--mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/generic/644 +1 -1
index 17fc0539..edf9b03e 100755
@@ -21,7 +21,7 @@ _require_test
 
 echo "Silence is golden"
 
-$here/src/vfs/idmapped-mounts --test-fscaps-regression \
+$here/src/vfs/vfstest --test-fscaps-regression \
 	--device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/generic/645 +1 -1
index f1209ad0..74e0f589 100755
@@ -21,7 +21,7 @@ _require_test
 
 echo "Silence is golden"
 
-$here/src/vfs/idmapped-mounts --test-nested-userns \
+$here/src/vfs/vfstest --test-nested-userns \
 	--device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/generic/656 +1 -1
index 9e95ac96..5c090cfa 100755
@@ -26,7 +26,7 @@ _require_group fsgqa2
 
 echo "Silence is golden"
 
-$here/src/vfs/idmapped-mounts --test-setattr-fix-968219708108 \
+$here/src/vfs/vfstest --test-setattr-fix-968219708108 \
 	--device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
tests/xfs/152 +1 -1
index de9b8fc6..12b77f91 100755
@@ -246,7 +246,7 @@ qmount_idmapped()
 	mkdir -p "${SCRATCH_MNT}/unmapped"
 	mkdir -p "${SCRATCH_MNT}/idmapped"
 
-	$here/src/idmapped-mounts/mount-idmapped \
+	$here/src/vfstest/mount-idmapped \
 		--map-mount b:$id:$id2:1 \
 		--map-mount b:0:0:1 \
 		"$SCRATCH_MNT/unmapped" "$SCRATCH_MNT/idmapped" || _fail "mount-idmapped failed"
Signature · 1 line
2.32.0
#3 lore raw

PATCH 3/11 vfstest: rename struct t_idmapped_mounts

In reply to Christian Brauner

The idmapped mounts test suite has grown to cover a lot of generic vfs functionality that is not concerned with idmapped mounts at all.

As was discussed upstream it's time to rename it to something that reflects its generic nature.

Rename the basic structure used for the tests from struct t_idmapped_mounts to struct test_struct.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 src/vfs/utils.h   |  6 ++++++
 src/vfs/vfstest.c | 18 +++++++-----------
 2 files changed, 13 insertions(+), 11 deletions(-)
src/vfs/utils.h +6 -0
index afb3c228..06247ec7 100644
@@ -49,6 +49,12 @@
 		__internal_ret__;                             \
 	})
 
+struct test_struct {
+	int (*test)(void);
+	bool require_fs_allow_idmap;
+	const char *description;
+};
+
 typedef enum idmap_type_t {
 	ID_TYPE_UID,
 	ID_TYPE_GID
src/vfs/vfstest.c +7 -11
index 66768175..4d2fc93e 100644
@@ -13829,11 +13829,7 @@ static const struct option longopts[] = {
 	{NULL,					0,			0,	  0},
 };
 
-struct t_idmapped_mounts {
-	int (*test)(void);
-	bool require_fs_allow_idmap;
-	const char *description;
-} basic_suite[] = {
+struct test_struct basic_suite[] = {
 	{ acls,								true,	"posix acls on regular mounts",									},
 	{ create_in_userns,						true,	"create operations in user namespace",								},
 	{ device_node_in_userns,					true,	"device node in user namespace",								},
@@ -13885,15 +13881,15 @@ struct t_idmapped_mounts {
 	{ threaded_idmapped_mount_interactions,				true,	"threaded operations on idmapped mounts",							},
 };
 
-struct t_idmapped_mounts fscaps_in_ancestor_userns[] = {
+struct test_struct fscaps_in_ancestor_userns[] = {
 	{ fscaps_idmapped_mounts_in_userns_valid_in_ancestor_userns,	true,	"fscaps on idmapped mounts in user namespace writing fscap valid in ancestor userns",		},
 };
 
-struct t_idmapped_mounts t_nested_userns[] = {
+struct test_struct t_nested_userns[] = {
 	{ nested_userns,						true,	"test that nested user namespaces behave correctly when attached to idmapped mounts",		},
 };
 
-struct t_idmapped_mounts t_btrfs[] = {
+struct test_struct t_btrfs[] = {
 	{ btrfs_subvolumes_fsids_mapped,				true,	"test subvolumes with mapped fsids",								},
 	{ btrfs_subvolumes_fsids_mapped_userns,				true, 	"test subvolumes with mapped fsids inside user namespace",					},
 	{ btrfs_subvolumes_fsids_mapped_user_subvol_rm_allowed,		true, 	"test subvolume deletion with user_subvol_rm_allowed mount option",				},
@@ -13919,16 +13915,16 @@ struct t_idmapped_mounts t_btrfs[] = {
 };
 
 /* Test for commit 968219708108 ("fs: handle circular mappings correctly"). */
-struct t_idmapped_mounts t_setattr_fix_968219708108[] = {
+struct test_struct t_setattr_fix_968219708108[] = {
 	{ setattr_fix_968219708108,					true,	"test that setattr works correctly",								},
 };
 
-static bool run_test(struct t_idmapped_mounts suite[], size_t suite_size)
+static bool run_test(struct test_struct suite[], size_t suite_size)
 {
 	int i;
 
 	for (i = 0; i < suite_size; i++) {
-		struct t_idmapped_mounts *t = &suite[i];
+		struct test_struct *t = &suite[i];
 		int ret;
 		pid_t pid;
 
Signature · 1 line
2.32.0
#4 lore raw

PATCH 4/11 utils: add missing global.h include

In reply to Christian Brauner

Make sure that utils.{c,h} have access to the necessary defines created during the configure stage when building xfstests.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 src/vfs/utils.h | 2 ++
 1 file changed, 2 insertions(+)
src/vfs/utils.h +2 -0
index 06247ec7..ccf2cefb 100644
@@ -3,6 +3,8 @@
 #ifndef __IDMAP_UTILS_H
 #define __IDMAP_UTILS_H
 
+#include "../global.h"
+
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif
Signature · 1 line
2.32.0
#5 lore raw

PATCH 6/11 utils: move helpers into utils

In reply to Christian Brauner

In order to split the test suite into multiple source files we need to be able to access generic helpers in all source files not just one. So move all generic helpers into utils.{c,h}.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 src/vfs/utils.c   | 448 +++++++++++++++++++++++++++++++++
 src/vfs/utils.h   | 193 +++++++++++++++
 src/vfs/vfstest.c | 611 ----------------------------------------------
 3 files changed, 641 insertions(+), 611 deletions(-)
src/vfs/utils.c +448 -0
index faf06fcd..28944b70 100644
@@ -9,12 +9,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/eventfd.h>
+#include <sys/fsuid.h>
 #include <sys/mount.h>
 #include <sys/prctl.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/xattr.h>
 
 #include "utils.h"
 
@@ -423,3 +425,449 @@ int add_map_entry(struct list *head,
 	list_add_tail(head, new_list);
 	return 0;
 }
+
+/* __expected_uid_gid - check whether file is owned by the provided uid and gid */
+bool __expected_uid_gid(int dfd, const char *path, int flags,
+			uid_t expected_uid, gid_t expected_gid, bool log)
+{
+	int ret;
+	struct stat st;
+
+	ret = fstatat(dfd, path, &st, flags);
+	if (ret < 0)
+		return log_errno(false, "failure: fstatat");
+
+	if (log && st.st_uid != expected_uid)
+		log_stderr("failure: uid(%d) != expected_uid(%d)", st.st_uid, expected_uid);
+
+	if (log && st.st_gid != expected_gid)
+		log_stderr("failure: gid(%d) != expected_gid(%d)", st.st_gid, expected_gid);
+
+	errno = 0; /* Don't report misleading errno. */
+	return st.st_uid == expected_uid && st.st_gid == expected_gid;
+}
+
+/* caps_down - lower all effective caps */
+int caps_down(void)
+{
+	bool fret = false;
+#ifdef HAVE_SYS_CAPABILITY_H
+	cap_t caps = NULL;
+	int ret = -1;
+
+	caps = cap_get_proc();
+	if (!caps)
+		goto out;
+
+	ret = cap_clear_flag(caps, CAP_EFFECTIVE);
+	if (ret)
+		goto out;
+
+	ret = cap_set_proc(caps);
+	if (ret)
+		goto out;
+
+	fret = true;
+
+out:
+	cap_free(caps);
+#endif
+	return fret;
+}
+
+#ifdef HAVE_LIBURING_H
+int io_uring_openat_with_creds(struct io_uring *ring, int dfd, const char *path,
+			       int cred_id, bool with_link, int *ret_cqe)
+{
+	struct io_uring_cqe *cqe;
+	struct io_uring_sqe *sqe;
+	int ret, i, to_submit = 1;
+
+	if (with_link) {
+		sqe = io_uring_get_sqe(ring);
+		if (!sqe)
+			return log_error_errno(-EINVAL, EINVAL, "failure: io_uring_sqe");
+		io_uring_prep_nop(sqe);
+		sqe->flags |= IOSQE_IO_LINK;
+		sqe->user_data = 1;
+		to_submit++;
+	}
+
+	sqe = io_uring_get_sqe(ring);
+	if (!sqe)
+		return log_error_errno(-EINVAL, EINVAL, "failure: io_uring_sqe");
+	io_uring_prep_openat(sqe, dfd, path, O_RDONLY | O_CLOEXEC, 0);
+	sqe->user_data = 2;
+
+	if (cred_id != -1)
+		sqe->personality = cred_id;
+
+	ret = io_uring_submit(ring);
+	if (ret != to_submit) {
+		log_stderr("failure: io_uring_submit");
+		goto out;
+	}
+
+	for (i = 0; i < to_submit; i++) {
+		ret = io_uring_wait_cqe(ring, &cqe);
+		if (ret < 0) {
+			log_stderr("failure: io_uring_wait_cqe");
+			goto out;
+		}
+
+		ret = cqe->res;
+		/*
+		 * Make sure caller can identify that this is a proper io_uring
+		 * failure and not some earlier error.
+		 */
+		if (ret_cqe)
+			*ret_cqe = ret;
+		io_uring_cqe_seen(ring, cqe);
+	}
+	log_debug("Ran test");
+out:
+	return ret;
+}
+#endif /* HAVE_LIBURING_H */
+
+/* caps_up - raise all permitted caps */
+int caps_up(void)
+{
+	bool fret = false;
+#ifdef HAVE_SYS_CAPABILITY_H
+	cap_t caps = NULL;
+	cap_value_t cap;
+	int ret = -1;
+
+	caps = cap_get_proc();
+	if (!caps)
+		goto out;
+
+	for (cap = 0; cap <= CAP_LAST_CAP; cap++) {
+		cap_flag_value_t flag;
+
+		ret = cap_get_flag(caps, cap, CAP_PERMITTED, &flag);
+		if (ret) {
+			if (errno == EINVAL)
+				break;
+			else
+				goto out;
+		}
+
+		ret = cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap, flag);
+		if (ret)
+			goto out;
+	}
+
+	ret = cap_set_proc(caps);
+	if (ret)
+		goto out;
+
+	fret = true;
+out:
+	cap_free(caps);
+#endif
+	return fret;
+}
+
+/* chown_r - recursively change ownership of all files */
+int chown_r(int fd, const char *path, uid_t uid, gid_t gid)
+{
+	int dfd, ret;
+	DIR *dir;
+	struct dirent *direntp;
+
+	dfd = openat(fd, path, O_CLOEXEC | O_DIRECTORY);
+	if (dfd < 0)
+		return -1;
+
+	dir = fdopendir(dfd);
+	if (!dir) {
+		close(dfd);
+		return -1;
+	}
+
+	while ((direntp = readdir(dir))) {
+		struct stat st;
+
+		if (!strcmp(direntp->d_name, ".") ||
+		    !strcmp(direntp->d_name, ".."))
+			continue;
+
+		ret = fstatat(dfd, direntp->d_name, &st, AT_SYMLINK_NOFOLLOW);
+		if (ret < 0 && errno != ENOENT)
+			break;
+
+		if (S_ISDIR(st.st_mode))
+			ret = chown_r(dfd, direntp->d_name, uid, gid);
+		else
+			ret = fchownat(dfd, direntp->d_name, uid, gid, AT_SYMLINK_NOFOLLOW);
+		if (ret < 0 && errno != ENOENT)
+			break;
+	}
+
+	ret = fchownat(fd, path, uid, gid, AT_SYMLINK_NOFOLLOW);
+	closedir(dir);
+	return ret;
+}
+
+/* expected_dummy_vfs_caps_uid - check vfs caps are stored with the provided uid */
+bool expected_dummy_vfs_caps_uid(int fd, uid_t expected_uid)
+{
+#define __cap_raised_permitted(x, ns_cap_data)                                 \
+	((ns_cap_data.data[(x) >> 5].permitted) & (1 << ((x)&31)))
+	struct vfs_ns_cap_data ns_xattr = {};
+	ssize_t ret;
+
+	ret = fgetxattr(fd, "security.capability", &ns_xattr, sizeof(ns_xattr));
+	if (ret < 0 || ret == 0)
+		return false;
+
+	if (ns_xattr.magic_etc & VFS_CAP_REVISION_3) {
+
+		if (le32_to_cpu(ns_xattr.rootid) != expected_uid) {
+			errno = EINVAL;
+			log_stderr("failure: rootid(%d) != expected_rootid(%d)", le32_to_cpu(ns_xattr.rootid), expected_uid);
+		}
+
+		return (le32_to_cpu(ns_xattr.rootid) == expected_uid) &&
+		       (__cap_raised_permitted(CAP_NET_RAW, ns_xattr) > 0);
+	} else {
+		log_stderr("failure: fscaps version");
+	}
+
+	return false;
+}
+
+/* set_dummy_vfs_caps - set dummy vfs caps for the provided uid */
+int set_dummy_vfs_caps(int fd, int flags, int rootuid)
+{
+#define __raise_cap_permitted(x, ns_cap_data)                                  \
+	ns_cap_data.data[(x) >> 5].permitted |= (1 << ((x)&31))
+
+	struct vfs_ns_cap_data ns_xattr;
+
+	memset(&ns_xattr, 0, sizeof(ns_xattr));
+	__raise_cap_permitted(CAP_NET_RAW, ns_xattr);
+	ns_xattr.magic_etc |= VFS_CAP_REVISION_3 | VFS_CAP_FLAGS_EFFECTIVE;
+	ns_xattr.rootid = cpu_to_le32(rootuid);
+
+	return fsetxattr(fd, "security.capability",
+			 &ns_xattr, sizeof(ns_xattr), flags);
+}
+
+bool protected_symlinks_enabled(void)
+{
+	static int enabled = -1;
+
+	if (enabled == -1) {
+		int fd;
+		ssize_t ret;
+		char buf[256];
+
+		enabled = 0;
+
+		fd = open("/proc/sys/fs/protected_symlinks", O_RDONLY | O_CLOEXEC);
+		if (fd < 0)
+			return false;
+
+		ret = read(fd, buf, sizeof(buf));
+		close(fd);
+		if (ret < 0)
+			return false;
+
+		if (atoi(buf) >= 1)
+			enabled = 1;
+        }
+
+	return enabled == 1;
+}
+
+static bool is_xfs(const char *fstype)
+{
+	static int enabled = -1;
+
+	if (enabled == -1)
+		enabled = !strcmp(fstype, "xfs");
+
+	return enabled;
+}
+
+bool xfs_irix_sgid_inherit_enabled(const char *fstype)
+{
+	static int enabled = -1;
+
+	if (enabled == -1) {
+		int fd;
+		ssize_t ret;
+		char buf[256];
+
+		enabled = 0;
+
+		if (is_xfs(fstype)) {
+			fd = open("/proc/sys/fs/xfs/irix_sgid_inherit", O_RDONLY | O_CLOEXEC);
+			if (fd < 0)
+				return false;
+
+			ret = read(fd, buf, sizeof(buf));
+			close(fd);
+			if (ret < 0)
+				return false;
+
+			if (atoi(buf) >= 1)
+				enabled = 1;
+		}
+        }
+
+	return enabled == 1;
+}
+
+bool expected_file_size(int dfd, const char *path, int flags, off_t expected_size)
+{
+	int ret;
+	struct stat st;
+
+	ret = fstatat(dfd, path, &st, flags);
+	if (ret < 0)
+		return log_errno(false, "failure: fstatat");
+
+	if (st.st_size != expected_size)
+		return log_errno(false, "failure: st_size(%zu) != expected_size(%zu)",
+				 (size_t)st.st_size, (size_t)expected_size);
+
+	return true;
+}
+
+/* is_setid - check whether file is S_ISUID and S_ISGID */
+bool is_setid(int dfd, const char *path, int flags)
+{
+	int ret;
+	struct stat st;
+
+	ret = fstatat(dfd, path, &st, flags);
+	if (ret < 0)
+		return false;
+
+	errno = 0; /* Don't report misleading errno. */
+	return (st.st_mode & S_ISUID) || (st.st_mode & S_ISGID);
+}
+
+/* is_setgid - check whether file or directory is S_ISGID */
+bool is_setgid(int dfd, const char *path, int flags)
+{
+	int ret;
+	struct stat st;
+
+	ret = fstatat(dfd, path, &st, flags);
+	if (ret < 0)
+		return false;
+
+	errno = 0; /* Don't report misleading errno. */
+	return (st.st_mode & S_ISGID);
+}
+
+/* is_sticky - check whether file is S_ISVTX */
+bool is_sticky(int dfd, const char *path, int flags)
+{
+	int ret;
+	struct stat st;
+
+	ret = fstatat(dfd, path, &st, flags);
+	if (ret < 0)
+		return false;
+
+	errno = 0; /* Don't report misleading errno. */
+	return (st.st_mode & S_ISVTX) > 0;
+}
+
+bool switch_resids(uid_t uid, gid_t gid)
+{
+	if (setresgid(gid, gid, gid))
+		return log_errno(false, "failure: setregid");
+
+	if (setresuid(uid, uid, uid))
+		return log_errno(false, "failure: setresuid");
+
+	if (setfsgid(-1) != gid)
+		return log_errno(false, "failure: setfsgid(-1)");
+
+	if (setfsuid(-1) != uid)
+		return log_errno(false, "failure: setfsuid(-1)");
+
+	return true;
+}
+
+/* rm_r - recursively remove all files */
+int rm_r(int fd, const char *path)
+{
+	int dfd, ret;
+	DIR *dir;
+	struct dirent *direntp;
+
+	if (!path || strcmp(path, "") == 0)
+		return -1;
+
+	dfd = openat(fd, path, O_CLOEXEC | O_DIRECTORY);
+	if (dfd < 0)
+		return -1;
+
+	dir = fdopendir(dfd);
+	if (!dir) {
+		close(dfd);
+		return -1;
+	}
+
+	while ((direntp = readdir(dir))) {
+		struct stat st;
+
+		if (!strcmp(direntp->d_name, ".") ||
+		    !strcmp(direntp->d_name, ".."))
+			continue;
+
+		ret = fstatat(dfd, direntp->d_name, &st, AT_SYMLINK_NOFOLLOW);
+		if (ret < 0 && errno != ENOENT)
+			break;
+
+		if (S_ISDIR(st.st_mode))
+			ret = rm_r(dfd, direntp->d_name);
+		else
+			ret = unlinkat(dfd, direntp->d_name, 0);
+		if (ret < 0 && errno != ENOENT)
+			break;
+	}
+
+	ret = unlinkat(fd, path, AT_REMOVEDIR);
+	closedir(dir);
+	return ret;
+}
+
+/* fd_to_fd - transfer data from one fd to another */
+int fd_to_fd(int from, int to)
+{
+	for (;;) {
+		uint8_t buf[PATH_MAX];
+		uint8_t *p = buf;
+		ssize_t bytes_to_write;
+		ssize_t bytes_read;
+
+		bytes_read = read_nointr(from, buf, sizeof buf);
+		if (bytes_read < 0)
+			return -1;
+		if (bytes_read == 0)
+			break;
+
+		bytes_to_write = (size_t)bytes_read;
+		do {
+			ssize_t bytes_written;
+
+			bytes_written = write_nointr(to, p, bytes_to_write);
+			if (bytes_written < 0)
+				return -1;
+
+			bytes_to_write -= bytes_written;
+			p += bytes_written;
+		} while (bytes_to_write > 0);
+	}
+
+	return 0;
+}
src/vfs/utils.h +193 -0

225 lines not on this page · raw message

src/vfs/vfstest.c +0 -611

644 lines not on this page · raw message

Signature · 1 line
2.32.0
#6 lore raw

PATCH 7/11 missing: move sys_execveat() to missing.h

In reply to Christian Brauner

The missing.h header provides syscalls potentially missing from the used libc. Move the sys_execveat() definition into it. It doesn't belong into vfstest.c.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 src/vfs/missing.h | 11 +++++++++++
 src/vfs/vfstest.c | 11 -----------
 2 files changed, 11 insertions(+), 11 deletions(-)
src/vfs/missing.h +11 -0
index c4f4cc32..059e742d 100644
@@ -148,4 +148,15 @@ static inline int sys_umount2(const char *path, int flags)
 	return syscall(__NR_umount2, path, flags);
 }
 
+static inline int sys_execveat(int fd, const char *path, char **argv,
+			       char **envp, int flags)
+{
+#ifdef __NR_execveat
+	return syscall(__NR_execveat, fd, path, argv, envp, flags);
+#else
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+
 #endif /* __IDMAP_MISSING_H */
src/vfs/vfstest.c +0 -11
index c3eb5ae4..f6c8c194 100644
@@ -226,17 +226,6 @@ __attribute__((unused)) static int print_r(int fd, const char *path)
 }
 #endif
 
-static int sys_execveat(int fd, const char *path, char **argv, char **envp,
-			int flags)
-{
-#ifdef __NR_execveat
-	return syscall(__NR_execveat, fd, path, argv, envp, flags);
-#else
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
 static void test_setup(struct vfstest_info *info)
 {
 	if (mkdirat(info->t_mnt_fd, T_DIR1, 0777))
Signature · 1 line
2.32.0
#7 lore raw

PATCH 8/11 utils: add struct test_suite

In reply to Christian Brauner

Provide a convenient wrapper struct which provides the tests and the number of tests. The struct can be kept local to each source file so we are sure that the tests and number of tests is correct.

In vfstest.c we provide a run_suite() function which expects a struct test_suite and runs the tests provided by that suite.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 src/vfs/utils.h   |  5 +++++
 src/vfs/vfstest.c | 54 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 46 insertions(+), 13 deletions(-)
src/vfs/utils.h +5 -0
index 3f7cf911..a13efabb 100644
@@ -198,6 +198,11 @@ struct test_struct {
 	const char *description;
 };
 
+struct test_suite {
+	size_t nr_tests;
+	const struct test_struct *tests;
+};
+
 typedef enum idmap_type_t {
 	ID_TYPE_UID,
 	ID_TYPE_GID
src/vfs/vfstest.c +41 -13

104 lines not on this page · raw message

Signature · 1 line
2.32.0
#8 lore raw

PATCH 11/11 vfstest: split out remaining idmapped mount tests

In reply to Christian Brauner

Split out all the remaining idmapped mount tests into the idmapped mounts source file.

Cc Dave Chinner <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Eryu Guan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Zorro Lang <[email protected]>
Cc "Darrick J. Wong" <[email protected]>
Cc fstests <[email protected]>
---
 src/vfs/idmapped-mounts.c | 1123 +++++++++++++++++++++++++++++++++
 src/vfs/idmapped-mounts.h |    2 +
 src/vfs/utils.c           |  130 ++++
 src/vfs/utils.h           |    5 +
 src/vfs/vfstest.c         | 1260 +------------------------------------
 5 files changed, 1261 insertions(+), 1259 deletions(-)
src/vfs/idmapped-mounts.c +1123 -0
index d935e4c8..8c9b03da 100644
@@ -6470,6 +6470,1110 @@ out:
 	return fret;
 }
 
+static int nested_userns(const struct vfstest_info *info)
+{
+	int fret = -1;
+	int ret;
+	pid_t pid;
+	unsigned int id;
+	struct list *it, *next;
+	struct userns_hierarchy hierarchy[] = {
+		{ .level = 1, .fd_userns = -EBADF, },
+		{ .level = 2, .fd_userns = -EBADF, },
+		{ .level = 3, .fd_userns = -EBADF, },
+		{ .level = 4, .fd_userns = -EBADF, },
+		/* Dummy entry that marks the end. */
+		{ .level = MAX_USERNS_LEVEL, .fd_userns = -EBADF, },
+	};
+	struct mount_attr attr_level1 = {
+		.attr_set	= MOUNT_ATTR_IDMAP,
+		.userns_fd	= -EBADF,
+	};
+	struct mount_attr attr_level2 = {
+		.attr_set	= MOUNT_ATTR_IDMAP,
+		.userns_fd	= -EBADF,
+	};
+	struct mount_attr attr_level3 = {
+		.attr_set	= MOUNT_ATTR_IDMAP,
+		.userns_fd	= -EBADF,
+	};
+	struct mount_attr attr_level4 = {
+		.attr_set	= MOUNT_ATTR_IDMAP,
+		.userns_fd	= -EBADF,
+	};
+	int fd_dir1 = -EBADF,
+	    fd_open_tree_level1 = -EBADF,
+	    fd_open_tree_level2 = -EBADF,
+	    fd_open_tree_level3 = -EBADF,
+	    fd_open_tree_level4 = -EBADF;
+	const unsigned int id_file_range = 10000;
+
+	list_init(&hierarchy[0].id_map);
+	list_init(&hierarchy[1].id_map);
+	list_init(&hierarchy[2].id_map);
+	list_init(&hierarchy[3].id_map);
+
+	/*
+	 * Give a large map to the outermost user namespace so we can create
+	 * comfortable nested maps.
+	 */
+	ret = add_map_entry(&hierarchy[0].id_map, 1000000, 0, 1000000000, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: adding uidmap for userns at level 1");
+		goto out;
+	}
+
+	ret = add_map_entry(&hierarchy[0].id_map, 1000000, 0, 1000000000, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: adding gidmap for userns at level 1");
+		goto out;
+	}
+
+	/* This is uid:0->2000000:100000000 in init userns. */
+	ret = add_map_entry(&hierarchy[1].id_map, 1000000, 0, 100000000, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: adding uidmap for userns at level 2");
+		goto out;
+	}
+
+	/* This is gid:0->2000000:100000000 in init userns. */
+	ret = add_map_entry(&hierarchy[1].id_map, 1000000, 0, 100000000, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: adding gidmap for userns at level 2");
+		goto out;
+	}
+
+	/* This is uid:0->3000000:999 in init userns. */
+	ret = add_map_entry(&hierarchy[2].id_map, 1000000, 0, 999, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: adding uidmap for userns at level 3");
+		goto out;
+	}
+
+	/* This is gid:0->3000000:999 in the init userns. */
+	ret = add_map_entry(&hierarchy[2].id_map, 1000000, 0, 999, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: adding gidmap for userns at level 3");
+		goto out;
+	}
+
+	/* id 999 will remain unmapped. */
+
+	/* This is uid:1000->2001000:1 in init userns. */
+	ret = add_map_entry(&hierarchy[2].id_map, 1000, 1000, 1, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: adding uidmap for userns at level 3");
+		goto out;
+	}
+
+	/* This is gid:1000->2001000:1 in init userns. */
+	ret = add_map_entry(&hierarchy[2].id_map, 1000, 1000, 1, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: adding gidmap for userns at level 3");
+		goto out;
+	}
+
+	/* This is uid:1001->3001001:10000 in init userns. */
+	ret = add_map_entry(&hierarchy[2].id_map, 1001001, 1001, 10000000, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: adding uidmap for userns at level 3");
+		goto out;
+	}
+
+	/* This is gid:1001->3001001:10000 in init userns. */
+	ret = add_map_entry(&hierarchy[2].id_map, 1001001, 1001, 10000000, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: adding gidmap for userns at level 3");
+		goto out;
+	}
+
+	/* Don't write a mapping in the 4th userns. */
+	list_empty(&hierarchy[4].id_map);
+
+	/* Create the actual userns hierarchy. */
+	ret = create_userns_hierarchy(hierarchy);
+	if (ret) {
+		log_stderr("failure: create userns hierarchy");
+		goto out;
+	}
+
+	attr_level1.userns_fd = hierarchy[0].fd_userns;
+	attr_level2.userns_fd = hierarchy[1].fd_userns;
+	attr_level3.userns_fd = hierarchy[2].fd_userns;
+	attr_level4.userns_fd = hierarchy[3].fd_userns;
+
+	/*
+	 * Create one directory where we create files for each uid/gid within
+	 * the first userns.
+	 */
+	if (mkdirat(info->t_dir1_fd, DIR1, 0777)) {
+		log_stderr("failure: mkdirat");
+		goto out;
+	}
+
+	fd_dir1 = openat(info->t_dir1_fd, DIR1, O_DIRECTORY | O_CLOEXEC);
+	if (fd_dir1 < 0) {
+		log_stderr("failure: openat");
+		goto out;
+	}
+
+	for (id = 0; id <= id_file_range; id++) {
+		char file[256];
+
+		snprintf(file, sizeof(file), DIR1 "/" FILE1 "_%u", id);
+
+		if (mknodat(info->t_dir1_fd, file, S_IFREG | 0644, 0)) {
+			log_stderr("failure: create %s", file);
+			goto out;
+		}
+
+		if (fchownat(info->t_dir1_fd, file, id, id, AT_SYMLINK_NOFOLLOW)) {
+			log_stderr("failure: fchownat %s", file);
+			goto out;
+		}
+
+		if (!expected_uid_gid(info->t_dir1_fd, file, 0, id, id)) {
+			log_stderr("failure: check ownership %s", file);
+			goto out;
+		}
+	}
+
+	/* Create detached mounts for all the user namespaces. */
+	fd_open_tree_level1 = sys_open_tree(info->t_dir1_fd, DIR1,
+					    AT_NO_AUTOMOUNT |
+					    AT_SYMLINK_NOFOLLOW |
+					    OPEN_TREE_CLOEXEC |
+					    OPEN_TREE_CLONE);
+	if (fd_open_tree_level1 < 0) {
+		log_stderr("failure: sys_open_tree");
+		goto out;
+	}
+
+	fd_open_tree_level2 = sys_open_tree(info->t_dir1_fd, DIR1,
+					    AT_NO_AUTOMOUNT |
+					    AT_SYMLINK_NOFOLLOW |
+					    OPEN_TREE_CLOEXEC |
+					    OPEN_TREE_CLONE);
+	if (fd_open_tree_level2 < 0) {
+		log_stderr("failure: sys_open_tree");
+		goto out;
+	}
+
+	fd_open_tree_level3 = sys_open_tree(info->t_dir1_fd, DIR1,
+					    AT_NO_AUTOMOUNT |
+					    AT_SYMLINK_NOFOLLOW |
+					    OPEN_TREE_CLOEXEC |
+					    OPEN_TREE_CLONE);
+	if (fd_open_tree_level3 < 0) {
+		log_stderr("failure: sys_open_tree");
+		goto out;
+	}
+
+	fd_open_tree_level4 = sys_open_tree(info->t_dir1_fd, DIR1,
+					    AT_NO_AUTOMOUNT |
+					    AT_SYMLINK_NOFOLLOW |
+					    OPEN_TREE_CLOEXEC |
+					    OPEN_TREE_CLONE);
+	if (fd_open_tree_level4 < 0) {
+		log_stderr("failure: sys_open_tree");
+		goto out;
+	}
+
+	/* Turn detached mounts into detached idmapped mounts. */
+	if (sys_mount_setattr(fd_open_tree_level1, "", AT_EMPTY_PATH,
+			      &attr_level1, sizeof(attr_level1))) {
+		log_stderr("failure: sys_mount_setattr");
+		goto out;
+	}
+
+	if (sys_mount_setattr(fd_open_tree_level2, "", AT_EMPTY_PATH,
+			      &attr_level2, sizeof(attr_level2))) {
+		log_stderr("failure: sys_mount_setattr");
+		goto out;
+	}
+
+	if (sys_mount_setattr(fd_open_tree_level3, "", AT_EMPTY_PATH,
+			      &attr_level3, sizeof(attr_level3))) {
+		log_stderr("failure: sys_mount_setattr");
+		goto out;
+	}
+
+	if (sys_mount_setattr(fd_open_tree_level4, "", AT_EMPTY_PATH,
+			      &attr_level4, sizeof(attr_level4))) {
+		log_stderr("failure: sys_mount_setattr");
+		goto out;
+	}
+
+	/* Verify that ownership looks correct for callers in the init userns. */
+	for (id = 0; id <= id_file_range; id++) {
+		bool bret;
+		unsigned int id_level1, id_level2, id_level3;
+		char file[256];
+
+		snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+		id_level1 = id + 1000000;
+		if (!expected_uid_gid(fd_open_tree_level1, file, 0, id_level1, id_level1)) {
+			log_stderr("failure: check ownership %s", file);
+			goto out;
+		}
+
+		id_level2 = id + 2000000;
+		if (!expected_uid_gid(fd_open_tree_level2, file, 0, id_level2, id_level2)) {
+			log_stderr("failure: check ownership %s", file);
+			goto out;
+		}
+
+		if (id == 999) {
+			/* This id is unmapped. */
+			bret = expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid);
+		} else if (id == 1000) {
+			id_level3 = id + 2000000; /* We punched a hole in the map at 1000. */
+			bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+		} else {
+			id_level3 = id + 3000000; /* Rest is business as usual. */
+			bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+		}
+		if (!bret) {
+			log_stderr("failure: check ownership %s", file);
+			goto out;
+		}
+
+		if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid)) {
+			log_stderr("failure: check ownership %s", file);
+			goto out;
+		}
+	}
+
+	/* Verify that ownership looks correct for callers in the first userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr_level1.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			bool bret;
+			unsigned int id_level1, id_level2, id_level3;
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			id_level1 = id;
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, id_level1, id_level1))
+				die("failure: check ownership %s", file);
+
+			id_level2 = id + 1000000;
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, id_level2, id_level2))
+				die("failure: check ownership %s", file);
+
+			if (id == 999) {
+				/* This id is unmapped. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid);
+			} else if (id == 1000) {
+				id_level3 = id + 1000000; /* We punched a hole in the map at 1000. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			} else {
+				id_level3 = id + 2000000; /* Rest is business as usual. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			}
+			if (!bret)
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that ownership looks correct for callers in the second userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr_level2.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			bool bret;
+			unsigned int id_level2, id_level3;
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			id_level2 = id;
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, id_level2, id_level2))
+				die("failure: check ownership %s", file);
+
+			if (id == 999) {
+				/* This id is unmapped. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid);
+			} else if (id == 1000) {
+				id_level3 = id; /* We punched a hole in the map at 1000. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			} else {
+				id_level3 = id + 1000000; /* Rest is business as usual. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			}
+			if (!bret)
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that ownership looks correct for callers in the third userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr_level3.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			bool bret;
+			unsigned int id_level2, id_level3;
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (id == 1000) {
+				/*
+				 * The idmapping of the third userns has a hole
+				 * at uid/gid 1000. That means:
+				 * - 1000->userns_0(2000000) // init userns
+				 * - 1000->userns_1(2000000) // level 1
+				 * - 1000->userns_2(1000000) // level 2
+				 * - 1000->userns_3(1000)    // level 3 (because level 3 has a hole)
+				 */
+				id_level2 = id;
+				bret = expected_uid_gid(fd_open_tree_level2, file, 0, id_level2, id_level2);
+			} else {
+				bret = expected_uid_gid(fd_open_tree_level2, file, 0, info->t_overflowuid, info->t_overflowgid);
+			}
+			if (!bret)
+				die("failure: check ownership %s", file);
+
+
+			if (id == 999) {
+				/* This id is unmapped. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid);
+			} else {
+				id_level3 = id; /* Rest is business as usual. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			}
+			if (!bret)
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that ownership looks correct for callers in the fourth userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (setns(attr_level4.userns_fd, CLONE_NEWUSER))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that chown works correctly for callers in the first userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr_level1.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			bool bret;
+			unsigned int id_level1, id_level2, id_level3, id_new;
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			id_new = id + 1;
+			if (fchownat(fd_open_tree_level1, file, id_new, id_new, AT_SYMLINK_NOFOLLOW))
+				die("failure: fchownat %s", file);
+
+			id_level1 = id_new;
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, id_level1, id_level1))
+				die("failure: check ownership %s", file);
+
+			id_level2 = id_new + 1000000;
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, id_level2, id_level2))
+				die("failure: check ownership %s", file);
+
+			if (id_new == 999) {
+				/* This id is unmapped. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid);
+			} else if (id_new == 1000) {
+				id_level3 = id_new + 1000000; /* We punched a hole in the map at 1000. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			} else {
+				id_level3 = id_new + 2000000; /* Rest is business as usual. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			}
+			if (!bret)
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			/* Revert ownership. */
+			if (fchownat(fd_open_tree_level1, file, id, id, AT_SYMLINK_NOFOLLOW))
+				die("failure: fchownat %s", file);
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that chown works correctly for callers in the second userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr_level2.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			bool bret;
+			unsigned int id_level2, id_level3, id_new;
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			id_new = id + 1;
+			if (fchownat(fd_open_tree_level2, file, id_new, id_new, AT_SYMLINK_NOFOLLOW))
+				die("failure: fchownat %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			id_level2 = id_new;
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, id_level2, id_level2))
+				die("failure: check ownership %s", file);
+
+			if (id_new == 999) {
+				/* This id is unmapped. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid);
+			} else if (id_new == 1000) {
+				id_level3 = id_new; /* We punched a hole in the map at 1000. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			} else {
+				id_level3 = id_new + 1000000; /* Rest is business as usual. */
+				bret = expected_uid_gid(fd_open_tree_level3, file, 0, id_level3, id_level3);
+			}
+			if (!bret)
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			/* Revert ownership. */
+			if (fchownat(fd_open_tree_level2, file, id, id, AT_SYMLINK_NOFOLLOW))
+				die("failure: fchownat %s", file);
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that chown works correctly for callers in the third userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr_level3.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			unsigned int id_new;
+			char file[256];
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			id_new = id + 1;
+			if (id_new == 999 || id_new == 1000) {
+				/*
+				 * We can't change ownership as we can't
+				 * chown from or to an unmapped id.
+				 */
+				if (!fchownat(fd_open_tree_level3, file, id_new, id_new, AT_SYMLINK_NOFOLLOW))
+					die("failure: fchownat %s", file);
+			} else {
+				if (fchownat(fd_open_tree_level3, file, id_new, id_new, AT_SYMLINK_NOFOLLOW))
+					die("failure: fchownat %s", file);
+			}
+
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			/* There's no id 1000 anymore as we changed ownership for id 1000 to 1001 above. */
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (id_new == 999) {
+				/*
+				 * We did not change ownership as we can't
+				 * chown to an unmapped id.
+				 */
+				if (!expected_uid_gid(fd_open_tree_level3, file, 0, id, id))
+					die("failure: check ownership %s", file);
+			} else if (id_new == 1000) {
+				/*
+				 * We did not change ownership as we can't
+				 * chown from an unmapped id.
+				 */
+				if (!expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid))
+					die("failure: check ownership %s", file);
+			} else {
+				if (!expected_uid_gid(fd_open_tree_level3, file, 0, id_new, id_new))
+					die("failure: check ownership %s", file);
+			}
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			/* Revert ownership. */
+			if (id_new != 999 && id_new != 1000) {
+				if (fchownat(fd_open_tree_level3, file, id, id, AT_SYMLINK_NOFOLLOW))
+					die("failure: fchownat %s", file);
+			}
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	/* Verify that chown works correctly for callers in the fourth userns. */
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (setns(attr_level4.userns_fd, CLONE_NEWUSER))
+			die("failure: switch_userns");
+
+		for (id = 0; id <= id_file_range; id++) {
+			char file[256];
+			unsigned long id_new;
+
+			snprintf(file, sizeof(file), FILE1 "_%u", id);
+
+			id_new = id + 1;
+			if (!fchownat(fd_open_tree_level4, file, id_new, id_new, AT_SYMLINK_NOFOLLOW))
+				die("failure: fchownat %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level1, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level2, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level3, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+			if (!expected_uid_gid(fd_open_tree_level4, file, 0, info->t_overflowuid, info->t_overflowgid))
+				die("failure: check ownership %s", file);
+
+		}
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	fret = 0;
+	log_debug("Ran test");
+
+out:
+	list_for_each_safe(it, &hierarchy[0].id_map, next) {
+		list_del(it);
+		free(it->elem);
+		free(it);
+	}
+
+	list_for_each_safe(it, &hierarchy[1].id_map, next) {
+		list_del(it);
+		free(it->elem);
+		free(it);
+	}
+
+	list_for_each_safe(it, &hierarchy[2].id_map, next) {
+		list_del(it);
+		free(it->elem);
+		free(it);
+	}
+
+	safe_close(hierarchy[0].fd_userns);
+	safe_close(hierarchy[1].fd_userns);
+	safe_close(hierarchy[2].fd_userns);
+	safe_close(fd_dir1);
+	safe_close(fd_open_tree_level1);
+	safe_close(fd_open_tree_level2);
+	safe_close(fd_open_tree_level3);
+	safe_close(fd_open_tree_level4);
+	return fret;
+}
+
+#define USER1 "fsgqa"
+#define USER2 "fsgqa2"
+
+/**
+ * lookup_ids - lookup uid and gid for a username
+ * @name: [in]  name of the user
+ * @uid:  [out] pointer to the user-ID
+ * @gid:  [out] pointer to the group-ID
+ *
+ * Lookup the uid and gid of a user.
+ *
+ * Return: On success, true is returned.
+ *         On error, false is returned.
+ */
+static bool lookup_ids(const char *name, uid_t *uid, gid_t *gid)
+{
+	bool bret = false;
+	struct passwd *pwentp = NULL;
+	struct passwd pwent;
+	char *buf;
+	ssize_t bufsize;
+	int ret;
+
+	bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+	if (bufsize < 0)
+		bufsize = 1024;
+
+	buf = malloc(bufsize);
+	if (!buf)
+		return bret;
+
+	ret = getpwnam_r(name, &pwent, buf, bufsize, &pwentp);
+	if (!ret && pwentp) {
+		*uid = pwent.pw_uid;
+		*gid = pwent.pw_gid;
+		bret = true;
+	}
+
+	free(buf);
+	return bret;
+}
+
+/**
+ * setattr_fix_968219708108 - test for commit 968219708108 ("fs: handle circular mappings correctly")
+ *
+ * Test that ->setattr() works correctly for idmapped mounts with circular
+ * idmappings such as:
+ *
+ * b:1000:1001:1
+ * b:1001:1000:1
+ *
+ * Assume a directory /source with two files:
+ *
+ * /source/file1 | 1000:1000
+ * /source/file2 | 1001:1001
+ *
+ * and we create an idmapped mount of /source at /target with an idmapped of:
+ *
+ * mnt_userns:        1000:1001:1
+ *                    1001:1000:1
+ *
+ * In the idmapped mount file1 will be owned by uid 1001 and file2 by uid 1000:
+ *
+ * /target/file1 | 1001:1001
+ * /target/file2 | 1000:1000
+ *
+ * Because in essence the idmapped mount switches ownership for {g,u}id 1000
+ * and {g,u}id 1001.
+ *
+ * 1. A user with fs{g,u}id 1000 must be allowed to setattr /target/file2 from
+ *    {g,u}id 1000 in the idmapped mount to {g,u}id 1000.
+ * 2. A user with fs{g,u}id 1001 must be allowed to setattr /target/file1 from
+ *    {g,u}id 1001 in the idmapped mount to {g,u}id 1001.
+ * 3. A user with fs{g,u}id 1000 must fail to setattr /target/file1 from
+ *    {g,u}id 1001 in the idmapped mount to {g,u}id 1000.
+ *    This must fail with EPERM. The caller's fs{g,u}id doesn't match the
+ *    {g,u}id of the file.
+ * 4. A user with fs{g,u}id 1001 must fail to setattr /target/file2 from
+ *    {g,u}id 1000 in the idmapped mount to {g,u}id 1000.
+ *    This must fail with EPERM. The caller's fs{g,u}id doesn't match the
+ *    {g,u}id of the file.
+ * 5. Both, a user with fs{g,u}id 1000 and a user with fs{g,u}id 1001, must
+ *    fail to setattr /target/file1 owned by {g,u}id 1001 in the idmapped mount
+ *    and /target/file2 owned by {g,u}id 1000 in the idmapped mount to any
+ *    {g,u}id apart from {g,u}id 1000 or 1001 with EINVAL.
+ *    Only {g,u}id 1000 and 1001 have a mapping in the idmapped mount. Other
+ *    {g,u}id are unmapped.
+ */
+static int setattr_fix_968219708108(const struct vfstest_info *info)
+{
+	int fret = -1;
+	int open_tree_fd = -EBADF;
+	struct mount_attr attr = {
+		.attr_set	= MOUNT_ATTR_IDMAP,
+		.userns_fd	= -EBADF,
+	};
+	int ret;
+	uid_t user1_uid, user2_uid;
+	gid_t user1_gid, user2_gid;
+	pid_t pid;
+	struct list idmap;
+	struct list *it_cur, *it_next;
+
+	if (!caps_supported())
+		return 0;
+
+	list_init(&idmap);
+
+	if (!lookup_ids(USER1, &user1_uid, &user1_gid)) {
+		log_stderr("failure: lookup_user");
+		goto out;
+	}
+
+	if (!lookup_ids(USER2, &user2_uid, &user2_gid)) {
+		log_stderr("failure: lookup_user");
+		goto out;
+	}
+
+	log_debug("Found " USER1 " with uid(%d) and gid(%d) and " USER2 " with uid(%d) and gid(%d)",
+		  user1_uid, user1_gid, user2_uid, user2_gid);
+
+	if (mkdirat(info->t_dir1_fd, DIR1, 0777)) {
+		log_stderr("failure: mkdirat");
+		goto out;
+	}
+
+	if (mknodat(info->t_dir1_fd, DIR1 "/" FILE1, S_IFREG | 0644, 0)) {
+		log_stderr("failure: mknodat");
+		goto out;
+	}
+
+	if (chown_r(info->t_mnt_fd, T_DIR1, user1_uid, user1_gid)) {
+		log_stderr("failure: chown_r");
+		goto out;
+	}
+
+	if (mknodat(info->t_dir1_fd, DIR1 "/" FILE2, S_IFREG | 0644, 0)) {
+		log_stderr("failure: mknodat");
+		goto out;
+	}
+
+	if (fchownat(info->t_dir1_fd, DIR1 "/" FILE2, user2_uid, user2_gid, AT_SYMLINK_NOFOLLOW)) {
+		log_stderr("failure: fchownat");
+		goto out;
+	}
+
+	print_r(info->t_mnt_fd, T_DIR1);
+
+	/* u:1000:1001:1 */
+	ret = add_map_entry(&idmap, user1_uid, user2_uid, 1, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: add_map_entry");
+		goto out;
+	}
+
+	/* u:1001:1000:1 */
+	ret = add_map_entry(&idmap, user2_uid, user1_uid, 1, ID_TYPE_UID);
+	if (ret) {
+		log_stderr("failure: add_map_entry");
+		goto out;
+	}
+
+	/* g:1000:1001:1 */
+	ret = add_map_entry(&idmap, user1_gid, user2_gid, 1, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: add_map_entry");
+		goto out;
+	}
+
+	/* g:1001:1000:1 */
+	ret = add_map_entry(&idmap, user2_gid, user1_gid, 1, ID_TYPE_GID);
+	if (ret) {
+		log_stderr("failure: add_map_entry");
+		goto out;
+	}
+
+	attr.userns_fd = get_userns_fd_from_idmap(&idmap);
+	if (attr.userns_fd < 0) {
+		log_stderr("failure: get_userns_fd");
+		goto out;
+	}
+
+	open_tree_fd = sys_open_tree(info->t_dir1_fd, DIR1,
+				     AT_NO_AUTOMOUNT |
+				     AT_SYMLINK_NOFOLLOW |
+				     OPEN_TREE_CLOEXEC |
+				     OPEN_TREE_CLONE |
+				     AT_RECURSIVE);
+	if (open_tree_fd < 0) {
+		log_stderr("failure: sys_open_tree");
+		goto out;
+	}
+
+	if (sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr, sizeof(attr))) {
+		log_stderr("failure: sys_mount_setattr");
+		goto out;
+	}
+
+	print_r(open_tree_fd, "");
+
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		/* switch to {g,u}id 1001 */
+		if (!switch_resids(user2_uid, user2_gid))
+			die("failure: switch_resids");
+
+		/* drop all capabilities */
+		if (!caps_down())
+			die("failure: caps_down");
+
+		/*
+		 * The {g,u}id 0 is not mapped in this idmapped mount so this
+		 * needs to fail with EINVAL.
+		 */
+		if (!fchownat(open_tree_fd, FILE1, 0, 0, AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EINVAL)
+			die("failure: errno");
+
+		/*
+		 * A user with fs{g,u}id 1001 must be allowed to change
+		 * ownership of /target/file1 owned by {g,u}id 1001 in this
+		 * idmapped mount to {g,u}id 1001.
+		 */
+		if (fchownat(open_tree_fd, FILE1, user2_uid, user2_gid,
+			     AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+
+		/* Verify that the ownership is still {g,u}id 1001. */
+		if (!expected_uid_gid(open_tree_fd, FILE1, AT_SYMLINK_NOFOLLOW,
+				      user2_uid, user2_gid))
+			die("failure: check ownership");
+
+		/*
+		 * A user with fs{g,u}id 1001 must not be allowed to change
+		 * ownership of /target/file1 owned by {g,u}id 1001 in this
+		 * idmapped mount to {g,u}id 1000.
+		 */
+		if (!fchownat(open_tree_fd, FILE1, user1_uid, user1_gid,
+			      AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EPERM)
+			die("failure: errno");
+
+		/* Verify that the ownership is still {g,u}id 1001. */
+		if (!expected_uid_gid(open_tree_fd, FILE1, AT_SYMLINK_NOFOLLOW,
+				      user2_uid, user2_gid))
+			die("failure: check ownership");
+
+		/*
+		 * A user with fs{g,u}id 1001 must not be allowed to change
+		 * ownership of /target/file2 owned by {g,u}id 1000 in this
+		 * idmapped mount to {g,u}id 1000.
+		 */
+		if (!fchownat(open_tree_fd, FILE2, user1_uid, user1_gid,
+			      AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EPERM)
+			die("failure: errno");
+
+		/* Verify that the ownership is still {g,u}id 1000. */
+		if (!expected_uid_gid(open_tree_fd, FILE2, AT_SYMLINK_NOFOLLOW,
+				      user1_uid, user1_gid))
+			die("failure: check ownership");
+
+		/*
+		 * A user with fs{g,u}id 1001 must not be allowed to change
+		 * ownership of /target/file2 owned by {g,u}id 1000 in this
+		 * idmapped mount to {g,u}id 1001.
+		 */
+		if (!fchownat(open_tree_fd, FILE2, user2_uid, user2_gid,
+			      AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EPERM)
+			die("failure: errno");
+
+		/* Verify that the ownership is still {g,u}id 1000. */
+		if (!expected_uid_gid(open_tree_fd, FILE2, AT_SYMLINK_NOFOLLOW,
+				      user1_uid, user1_gid))
+			die("failure: check ownership");
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		/* switch to {g,u}id 1000 */
+		if (!switch_resids(user1_uid, user1_gid))
+			die("failure: switch_resids");
+
+		/* drop all capabilities */
+		if (!caps_down())
+			die("failure: caps_down");
+
+		/*
+		 * The {g,u}id 0 is not mapped in this idmapped mount so this
+		 * needs to fail with EINVAL.
+		 */
+		if (!fchownat(open_tree_fd, FILE1, 0, 0, AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EINVAL)
+			die("failure: errno");
+
+		/*
+		 * A user with fs{g,u}id 1000 must be allowed to change
+		 * ownership of /target/file2 owned by {g,u}id 1000 in this
+		 * idmapped mount to {g,u}id 1000.
+		 */
+		if (fchownat(open_tree_fd, FILE2, user1_uid, user1_gid,
+			     AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+
+		/* Verify that the ownership is still {g,u}id 1000. */
+		if (!expected_uid_gid(open_tree_fd, FILE2, AT_SYMLINK_NOFOLLOW,
+				      user1_uid, user1_gid))
+			die("failure: check ownership");
+
+		/*
+		 * A user with fs{g,u}id 1000 must not be allowed to change
+		 * ownership of /target/file2 owned by {g,u}id 1000 in this
+		 * idmapped mount to {g,u}id 1001.
+		 */
+		if (!fchownat(open_tree_fd, FILE2, user2_uid, user2_gid,
+			      AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EPERM)
+			die("failure: errno");
+
+		/* Verify that the ownership is still {g,u}id 1000. */
+		if (!expected_uid_gid(open_tree_fd, FILE2, AT_SYMLINK_NOFOLLOW,
+				      user1_uid, user1_gid))
+			die("failure: check ownership");
+
+		/*
+		 * A user with fs{g,u}id 1000 must not be allowed to change
+		 * ownership of /target/file1 owned by {g,u}id 1001 in this
+		 * idmapped mount to {g,u}id 1000.
+		 */
+		if (!fchownat(open_tree_fd, FILE1, user1_uid, user1_gid,
+			     AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EPERM)
+			die("failure: errno");
+
+		/* Verify that the ownership is still {g,u}id 1001. */
+		if (!expected_uid_gid(open_tree_fd, FILE1, AT_SYMLINK_NOFOLLOW,
+				      user2_uid, user2_gid))
+			die("failure: check ownership");
+
+		/*
+		 * A user with fs{g,u}id 1000 must not be allowed to change
+		 * ownership of /target/file1 owned by {g,u}id 1001 in this
+		 * idmapped mount to {g,u}id 1001.
+		 */
+		if (!fchownat(open_tree_fd, FILE1, user2_uid, user2_gid,
+			      AT_SYMLINK_NOFOLLOW))
+			die("failure: change ownership");
+		if (errno != EPERM)
+			die("failure: errno");
+
+		/* Verify that the ownership is still {g,u}id 1001. */
+		if (!expected_uid_gid(open_tree_fd, FILE1, AT_SYMLINK_NOFOLLOW,
+				      user2_uid, user2_gid))
+			die("failure: check ownership");
+
+		exit(EXIT_SUCCESS);
+	}
+	if (wait_for_pid(pid))
+		goto out;
+
+	fret = 0;
+	log_debug("Ran test");
+out:
+	safe_close(attr.userns_fd);
+	safe_close(open_tree_fd);
+
+	list_for_each_safe(it_cur, &idmap, it_next) {
+		list_del(it_cur);
+		free(it_cur->elem);
+		free(it_cur);
+	}
+
+	return fret;
+}
+
 static const struct test_struct t_idmapped_mounts[] = {
 	{ acls,                                                         true,   "posix acls on regular mounts",                                                                 },
 	{ create_in_userns,                                             true,   "create operations in user namespace",                                                          },
@@ -6523,3 +7627,22 @@ const struct test_suite s_fscaps_in_ancestor_userns = {
 	.tests		= t_fscaps_in_ancestor_userns,
 	.nr_tests	= ARRAY_SIZE(t_fscaps_in_ancestor_userns),
 };
+
+static const struct test_struct t_nested_userns[] = {
+	{ nested_userns,						true,	"test that nested user namespaces behave correctly when attached to idmapped mounts",		},
+};
+
+const struct test_suite s_nested_userns = {
+	.tests = t_nested_userns,
+	.nr_tests = ARRAY_SIZE(t_nested_userns),
+};
+
+/* Test for commit 968219708108 ("fs: handle circular mappings correctly"). */
+static const struct test_struct t_setattr_fix_968219708108[] = {
+	{ setattr_fix_968219708108,					true,	"test that setattr works correctly",								},
+};
+
+const struct test_suite s_setattr_fix_968219708108 = {
+	.tests = t_setattr_fix_968219708108,
+	.nr_tests = ARRAY_SIZE(t_setattr_fix_968219708108),
+};
src/vfs/idmapped-mounts.h +2 -0
index 37c8886d..9febecd3 100644
@@ -11,5 +11,7 @@
 
 extern const struct test_suite s_idmapped_mounts;
 extern const struct test_suite s_fscaps_in_ancestor_userns;
+extern const struct test_suite s_nested_userns;
+extern const struct test_suite s_setattr_fix_968219708108;
 
 #endif /* __IDMAPPED_MOUNTS_H */
src/vfs/utils.c +130 -0

133 lines not on this page · raw message

src/vfs/utils.h +5 -0
index a13efabb..07aae675 100644
@@ -347,6 +347,11 @@ extern int io_uring_openat_with_creds(struct io_uring *ring, int dfd,
 
 extern int chown_r(int fd, const char *path, uid_t uid, gid_t gid);
 extern int rm_r(int fd, const char *path);
+#ifdef DEBUG_TRACE
+extern int print_r(int fd, const char *path);
+#else
+static inline int print_r(int fd, const char *path) { return 0; }
+#endif
 extern int fd_to_fd(int from, int to);
 extern bool protected_symlinks_enabled(void);
 extern bool xfs_irix_sgid_inherit_enabled(const char *fstype);
src/vfs/vfstest.c +1 -1259

1,284 lines not on this page · raw message

Signature · 1 line
2.32.0
#10 lore raw
In reply to Christian Brauner
Quoted 9 lines · Christian Brauner

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

As announced multiple times already we need to rename and split the idmapped mount testsuite into separate source files and also give it a better name to reflect the fact that it covers a lot more than just idmapped mounts.

Quoted 8 lines

I have decided against compiling different binaries for now. Instead we compile a single vfstest binary that can be called with various command line switches to run the various test suites. This is not different than what we did for the idmapped-mounts binary. Of course, nothing prevents us from using multiple binaries in the future.

Note that this will have a conflict with Jan's series at:
https://lore.kernel.org/fstests/20220425131809.qzjrah7cw67mzzcw@zlang-mailbox/T/#m47d8da68ef1aff250918398e8d2228729a6acf97

Hi Christian,

Thanks for your patches! But even without above conflict patches, I still can't merge your patchset, failures as below [1].
May you rebase your patches on latest fstests for-next branch, and send out again? As Christoph Hellwig has Acked your patchset, we'd better to make it work with current fstests at least, for others might want to give it a try.

Thanks,
Zorro

[1]

$ git reset --hard fbc6486b
HEAD is now at fbc6486b generic: test that renaming into a directory fails with EDQUOT
$ git am -s ./20220428_brauner_rename_split_tests.mbx
Applying: src: rename idmapped-mounts folder
Applying: src/vfs: rename idmapped-mounts.c file
Applying: vfstest: rename struct t_idmapped_mounts
Applying: utils: add missing global.h include
Applying: utils: move helpers into utils
error: patch failed: src/vfs/utils.h:51
error: src/vfs/utils.h: patch does not apply
error: patch failed: src/vfs/vfstest.c:35
error: src/vfs/vfstest.c: patch does not apply
Patch failed at 0005 utils: move helpers into utils
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Quoted 61 lines

If this patch series here is acceptable I'd pick up Jan's patch and apply it on top of mine as rebasing will introduce too many conflicts.

Thanks!
Christian

Christian Brauner (11):
src: rename idmapped-mounts folder
src/vfs: rename idmapped-mounts.c file
vfstest: rename struct t_idmapped_mounts
utils: add missing global.h include
utils: add struct vfstest_info
utils: move helpers into utils
missing: move sys_execveat() to missing.h
utils: add struct test_suite
vfstests: split idmapped mount tests into separate suite
vfstest: split out btrfs idmapped mounts test
vfstest: split out remaining idmapped mount tests

 .gitignore                                    |     4 +-
 common/rc                                     |    32 +-
 src/Makefile                                  |     2 +-
 src/detached_mounts_propagation.c             |     2 +-
 src/feature.c                                 |     2 +-
 src/idmapped-mounts/utils.c                   |   425 -
 src/idmapped-mounts/utils.h                   |   130 -
 src/{idmapped-mounts => vfs}/Makefile         |    14 +-
 src/vfs/btrfs-idmapped-mounts.c               |  3854 +++++
 src/vfs/btrfs-idmapped-mounts.h               |    15 +
 .../idmapped-mounts.c                         | 11865 ++++------------
 src/vfs/idmapped-mounts.h                     |    17 +
 src/{idmapped-mounts => vfs}/missing.h        |    11 +
 src/{idmapped-mounts => vfs}/mount-idmapped.c |     0
 src/vfs/utils.c                               |  1003 ++
 src/vfs/utils.h                               |   364 +
 src/vfs/vfstest.c                             |  1952 +++
 tests/btrfs/245                               |     2 +-
 tests/generic/633                             |     2 +-
 tests/generic/644                             |     2 +-
 tests/generic/645                             |     2 +-
 tests/generic/656                             |     2 +-
 tests/xfs/152                                 |     4 +-
 tests/xfs/153                                 |     2 +-
 24 files changed, 9952 insertions(+), 9756 deletions(-)
 delete mode 100644 src/idmapped-mounts/utils.c
 delete mode 100644 src/idmapped-mounts/utils.h
 rename src/{idmapped-mounts => vfs}/Makefile (59%)
 create mode 100644 src/vfs/btrfs-idmapped-mounts.c
 create mode 100644 src/vfs/btrfs-idmapped-mounts.h
 rename src/{idmapped-mounts => vfs}/idmapped-mounts.c (50%)
 create mode 100644 src/vfs/idmapped-mounts.h
 rename src/{idmapped-mounts => vfs}/missing.h (93%)
 rename src/{idmapped-mounts => vfs}/mount-idmapped.c (100%)
 create mode 100644 src/vfs/utils.c
 create mode 100644 src/vfs/utils.h
 create mode 100644 src/vfs/vfstest.c
Signature · 1 line
2.32.0
#11 lore raw
Quoted 16 lines · Zorro Lang
Quoted 15 lines · Christian Brauner

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

As announced multiple times already we need to rename and split the idmapped mount testsuite into separate source files and also give it a better name to reflect the fact that it covers a lot more than just idmapped mounts.

I have decided against compiling different binaries for now. Instead we compile a single vfstest binary that can be called with various command line switches to run the various test suites. This is not different than what we did for the idmapped-mounts binary. Of course, nothing prevents us from using multiple binaries in the future.

Quoted 7 lines
Quoted 2 lines

Note that this will have a conflict with Jan's series at:
https://lore.kernel.org/fstests/20220425131809.qzjrah7cw67mzzcw@zlang-mailbox/T/#m47d8da68ef1aff250918398e8d2228729a6acf97

Hi Christian,

Thanks for your patches! But even without above conflict patches, I still can't merge your patchset, failures as below [1].

Hi Zorro!

The fstests list has a limit on how large a single patch can be in terms of number of lines (10.000, I believe). Since this patchset contains patches that change about 10.000 lines the fstests list drops those patches. I ran into this issue before when we added the testsuite in the first place but it has never been fixed.

The consequence of this is that b4 is missing patches since they are on no list. This becomes more obvious if you use b4's quilt option which creates a folder with individual patches:

0001_src_rename_idmapped_mounts_folder.patch 0002_src_vfs_rename_idmapped_mounts_c_file.patch 0003_vfstest_rename_struct_t_idmapped_mounts.patch 0004_utils_add_missing_global_h_include.patch 0006_utils_move_helpers_into_utils.patch 0007_missing_move_sys_execveat_to_missing_h.patch 0008_utils_add_struct_test_suite.patch 0011_vfstest_split_out_remaining_idmapped_mount_tests.patch series

so this is missing patches 9 and 10...

Quoted 2 lines

May you rebase your patches on latest fstests for-next branch, and send out again? As Christoph Hellwig has Acked your patchset, we'd better to make it

I think we will have the same problem, i.e., patches will not be on the list since they are too large and so b4 won't work. To work around this I'll give you a signed tag to pull from in the cover letter.

Christian

#12 lore raw
In reply to Zorro Lang
Quoted 16 lines · Zorro Lang
Quoted 15 lines · Christian Brauner

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

As announced multiple times already we need to rename and split the idmapped mount testsuite into separate source files and also give it a better name to reflect the fact that it covers a lot more than just idmapped mounts.

I have decided against compiling different binaries for now. Instead we compile a single vfstest binary that can be called with various command line switches to run the various test suites. This is not different than what we did for the idmapped-mounts binary. Of course, nothing prevents us from using multiple binaries in the future.

Quoted 7 lines
Quoted 2 lines

Note that this will have a conflict with Jan's series at:
https://lore.kernel.org/fstests/20220425131809.qzjrah7cw67mzzcw@zlang-mailbox/T/#m47d8da68ef1aff250918398e8d2228729a6acf97

Hi Christian,

Thanks for your patches! But even without above conflict patches, I still can't merge your patchset, failures as below [1].

Hi Zorro!
(Resending, since my last message had a messed-up To: line.)

The fstests list has a limit on how large a single patch can be in terms of number of lines (10.000, I believe). Since this patchset contains patches that change about 10.000 lines the fstests list drops those patches. I ran into this issue before when we added the testsuite in the first place but it has never been fixed.

The consequence of this is that b4 is missing patches since they are on no list. This becomes more obvious if you use b4's quilt option which creates a folder with individual patches:

0001_src_rename_idmapped_mounts_folder.patch 0002_src_vfs_rename_idmapped_mounts_c_file.patch 0003_vfstest_rename_struct_t_idmapped_mounts.patch 0004_utils_add_missing_global_h_include.patch 0006_utils_move_helpers_into_utils.patch 0007_missing_move_sys_execveat_to_missing_h.patch 0008_utils_add_struct_test_suite.patch 0011_vfstest_split_out_remaining_idmapped_mount_tests.patch series

so this is missing patches 9 and 10...

Quoted 2 lines

May you rebase your patches on latest fstests for-next branch, and send out again? As Christoph Hellwig has Acked your patchset, we'd better to make it

I think we will have the same problem, i.e., patches will not be on the list since they are too large and so b4 won't work. To work around this I'll give you a signed tag to pull from in the cover letter.

Christian

#13 lore raw
Quoted 48 lines · Christian Brauner
Quoted 16 lines · Zorro Lang
Quoted 15 lines · Christian Brauner

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

As announced multiple times already we need to rename and split the idmapped mount testsuite into separate source files and also give it a better name to reflect the fact that it covers a lot more than just idmapped mounts.

I have decided against compiling different binaries for now. Instead we compile a single vfstest binary that can be called with various command line switches to run the various test suites. This is not different than what we did for the idmapped-mounts binary. Of course, nothing prevents us from using multiple binaries in the future.

Quoted 7 lines
Quoted 2 lines

Note that this will have a conflict with Jan's series at:
https://lore.kernel.org/fstests/20220425131809.qzjrah7cw67mzzcw@zlang-mailbox/T/#m47d8da68ef1aff250918398e8d2228729a6acf97

Hi Christian,

Thanks for your patches! But even without above conflict patches, I still can't merge your patchset, failures as below [1].

Hi Zorro!
(Resending, since my last message had a messed-up To: line.)

The fstests list has a limit on how large a single patch can be in terms of number of lines (10.000, I believe). Since this patchset contains patches that change about 10.000 lines the fstests list drops those patches. I ran into this issue before when we added the testsuite in the first place but it has never been fixed.

The consequence of this is that b4 is missing patches since they are on no list. This becomes more obvious if you use b4's quilt option which creates a folder with individual patches:

0001_src_rename_idmapped_mounts_folder.patch 0002_src_vfs_rename_idmapped_mounts_c_file.patch 0003_vfstest_rename_struct_t_idmapped_mounts.patch 0004_utils_add_missing_global_h_include.patch 0006_utils_move_helpers_into_utils.patch 0007_missing_move_sys_execveat_to_missing_h.patch 0008_utils_add_struct_test_suite.patch 0011_vfstest_split_out_remaining_idmapped_mount_tests.patch series

Quoted 1 line

so this is missing patches 9 and 10...

Oh, I didn't notice that. Let me check ...

Quoted 7 lines
Quoted 3 lines

May you rebase your patches on latest fstests for-next branch, and send out again? As Christoph Hellwig has Acked your patchset, we'd better to make it

I think we will have the same problem, i.e., patches will not be on the list since they are too large and so b4 won't work. To work around this I'll give you a signed tag to pull from in the cover letter.

Hmm...I just used another method(avoid b4) to merge your 11 patches, I think it works:

# git log --oneline
14714a1b (HEAD -> for-brauner) vfstest: split out remaining idmapped mount tests
ed027078 vfstest: split out btrfs idmapped mounts test
fd026c1a vfstests: split idmapped mount tests into separate suite
1cec19ec utils: add struct test_suite
3dadfe72 missing: move sys_execveat() to missing.h
ba0370e4 utils: move helpers into utils
781f86e1 utils: add struct vfstest_info
e1ffed6b utils: add missing global.h include
4f68af21 vfstest: rename struct t_idmapped_mounts
8fcd0f72 src/vfs: rename idmapped-mounts.c file
0b03254e src: rename idmapped-mounts folder
fbc6486b (redhat/master, origin/master, origin/HEAD, rh-master, master) generic: test that renaming into a directory fails with EDQUOT
...
...

And yes, patch 9 and 10 are really huge:

$ git show ed027078 | wc -l
8223
$ git show fd026c1a | wc -l
15641

But I still can't merge it into for-next branch, so you have to do once rebase at least. As we have 3 more idmapped patches to from XuYang to be merged, you'd better to wait the fstests release this week, then do once rebase on for-next branch. Hope that can save a little of your time.

Thanks,
Zorro

Quoted 3 lines

Christian

#14 lore raw
Quoted 80 lines · Zorro Lang
Quoted 48 lines · Christian Brauner
Quoted 16 lines · Zorro Lang
Quoted 15 lines · Christian Brauner

From: "Christian Brauner (Microsoft)" <[email protected]>

Hey everyone,

As announced multiple times already we need to rename and split the idmapped mount testsuite into separate source files and also give it a better name to reflect the fact that it covers a lot more than just idmapped mounts.

I have decided against compiling different binaries for now. Instead we compile a single vfstest binary that can be called with various command line switches to run the various test suites. This is not different than what we did for the idmapped-mounts binary. Of course, nothing prevents us from using multiple binaries in the future.

Quoted 7 lines
Quoted 2 lines

Note that this will have a conflict with Jan's series at:
https://lore.kernel.org/fstests/20220425131809.qzjrah7cw67mzzcw@zlang-mailbox/T/#m47d8da68ef1aff250918398e8d2228729a6acf97

Hi Christian,

Thanks for your patches! But even without above conflict patches, I still can't merge your patchset, failures as below [1].

Hi Zorro!
(Resending, since my last message had a messed-up To: line.)

The fstests list has a limit on how large a single patch can be in terms of number of lines (10.000, I believe). Since this patchset contains patches that change about 10.000 lines the fstests list drops those patches. I ran into this issue before when we added the testsuite in the first place but it has never been fixed.

The consequence of this is that b4 is missing patches since they are on no list. This becomes more obvious if you use b4's quilt option which creates a folder with individual patches:

0001_src_rename_idmapped_mounts_folder.patch 0002_src_vfs_rename_idmapped_mounts_c_file.patch 0003_vfstest_rename_struct_t_idmapped_mounts.patch 0004_utils_add_missing_global_h_include.patch 0006_utils_move_helpers_into_utils.patch 0007_missing_move_sys_execveat_to_missing_h.patch 0008_utils_add_struct_test_suite.patch 0011_vfstest_split_out_remaining_idmapped_mount_tests.patch series

Quoted 1 line

so this is missing patches 9 and 10...

Oh, I didn't notice that. Let me check ...

Quoted 7 lines
Quoted 3 lines

May you rebase your patches on latest fstests for-next branch, and send out again? As Christoph Hellwig has Acked your patchset, we'd better to make it

I think we will have the same problem, i.e., patches will not be on the list since they are too large and so b4 won't work. To work around this I'll give you a signed tag to pull from in the cover letter.

Hmm...I just used another method(avoid b4) to merge your 11 patches, I think it works:

# git log --oneline
14714a1b (HEAD -> for-brauner) vfstest: split out remaining idmapped mount tests
ed027078 vfstest: split out btrfs idmapped mounts test
fd026c1a vfstests: split idmapped mount tests into separate suite
1cec19ec utils: add struct test_suite
3dadfe72 missing: move sys_execveat() to missing.h
ba0370e4 utils: move helpers into utils
781f86e1 utils: add struct vfstest_info
e1ffed6b utils: add missing global.h include
4f68af21 vfstest: rename struct t_idmapped_mounts
8fcd0f72 src/vfs: rename idmapped-mounts.c file
0b03254e src: rename idmapped-mounts folder
fbc6486b (redhat/master, origin/master, origin/HEAD, rh-master, master) generic: test that renaming into a directory fails with EDQUOT
...
...

And yes, patch 9 and 10 are really huge:

Quoted 8 lines
$ git show ed027078 | wc -l
8223
$ git show fd026c1a | wc -l
15641

But I still can't merge it into for-next branch, so you have to do once rebase at least. As we have 3 more idmapped patches to from XuYang to be merged, you'd better to wait the fstests release this week, then do once rebase

Yeah, sounds good!

Christian