Skip to contentSkip to conversation

Fix generic/633 failure on systems without CONFIG_USER_NS

PATCH In review Jan Kara 3 participants 8 messages Mar 31, 2022 – Apr 25, 2022

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

cover Fix generic/633 failure on systems without CONFIG_USER_NS

Hello!

these two patches fix a failure of test generic/633 on a system without CONFIG_USER_NS.

Honza

author
#1 lore raw

PATCH 1/2 idmapped_mounts: Prepare for support for more features

Currently idmapped_mounts tests fail for kernels without CONFIG_USER_NS because some tests are run despite missing support for idmapped mounts and they implicitely require user namespace support. Prepare idmapped_mounts to support more features a test may require to reliably run.

---
 src/idmapped-mounts/idmapped-mounts.c | 102 +++++++++++++-------------
 1 file changed, 53 insertions(+), 49 deletions(-)
src/idmapped-mounts/idmapped-mounts.c +53 -49
index 4cf6c3bb2a25..d3b27da6c085 100644
@@ -13829,60 +13829,63 @@ static const struct option longopts[] = {
 	{NULL,					0,			0,	  0},
 };
 
+/* Flags for which functionality is required by the test */
+#define T_REQUIRE_IDMAPPED_MOUNTS (1U << 0)
+
 struct t_idmapped_mounts {
 	int (*test)(void);
-	bool require_fs_allow_idmap;
+	unsigned int support_flags;
 	const char *description;
 } 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",								},
-	{ expected_uid_gid_idmapped_mounts,				true,	"expected ownership on idmapped mounts",							},
-	{ fscaps,							false,	"fscaps on regular mounts",									},
-	{ fscaps_idmapped_mounts,					true,	"fscaps on idmapped mounts",									},
-	{ fscaps_idmapped_mounts_in_userns,				true,	"fscaps on idmapped mounts in user namespace",							},
-	{ fscaps_idmapped_mounts_in_userns_separate_userns,		true,	"fscaps on idmapped mounts in user namespace with different id mappings",			},
-	{ fsids_mapped,							true,	"mapped fsids",											},
-	{ fsids_unmapped,						true,	"unmapped fsids",										},
-	{ hardlink_crossing_mounts,					false,	"cross mount hardlink",										},
-	{ hardlink_crossing_idmapped_mounts,				true,	"cross idmapped mount hardlink",								},
-	{ hardlink_from_idmapped_mount,					true,	"hardlinks from idmapped mounts",								},
-	{ hardlink_from_idmapped_mount_in_userns,			true,	"hardlinks from idmapped mounts in user namespace",						},
+	{ acls,								T_REQUIRE_IDMAPPED_MOUNTS,	"posix acls on regular mounts",									},
+	{ create_in_userns,						T_REQUIRE_IDMAPPED_MOUNTS,	"create operations in user namespace",								},
+	{ device_node_in_userns,					T_REQUIRE_IDMAPPED_MOUNTS,	"device node in user namespace",								},
+	{ expected_uid_gid_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"expected ownership on idmapped mounts",							},
+	{ fscaps,							0,				"fscaps on regular mounts",									},
+	{ fscaps_idmapped_mounts,					T_REQUIRE_IDMAPPED_MOUNTS,	"fscaps on idmapped mounts",									},
+	{ fscaps_idmapped_mounts_in_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"fscaps on idmapped mounts in user namespace",							},
+	{ fscaps_idmapped_mounts_in_userns_separate_userns,		T_REQUIRE_IDMAPPED_MOUNTS,	"fscaps on idmapped mounts in user namespace with different id mappings",			},
+	{ fsids_mapped,							T_REQUIRE_IDMAPPED_MOUNTS,	"mapped fsids",											},
+	{ fsids_unmapped,						T_REQUIRE_IDMAPPED_MOUNTS,	"unmapped fsids",										},
+	{ hardlink_crossing_mounts,					0,				"cross mount hardlink",										},
+	{ hardlink_crossing_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"cross idmapped mount hardlink",								},
+	{ hardlink_from_idmapped_mount,					T_REQUIRE_IDMAPPED_MOUNTS,	"hardlinks from idmapped mounts",								},
+	{ hardlink_from_idmapped_mount_in_userns,			T_REQUIRE_IDMAPPED_MOUNTS,	"hardlinks from idmapped mounts in user namespace",						},
 #ifdef HAVE_LIBURING_H
-	{ io_uring,							false,	"io_uring",											},
-	{ io_uring_userns,						false,	"io_uring in user namespace",									},
-	{ io_uring_idmapped,						true,	"io_uring from idmapped mounts",								},
-	{ io_uring_idmapped_userns,					true,	"io_uring from idmapped mounts in user namespace",						},
-	{ io_uring_idmapped_unmapped,					true,	"io_uring from idmapped mounts with unmapped ids",						},
-	{ io_uring_idmapped_unmapped_userns,				true,	"io_uring from idmapped mounts with unmapped ids in user namespace",				},
+	{ io_uring,							0,				"io_uring",											},
+	{ io_uring_userns,						0,				"io_uring in user namespace",									},
+	{ io_uring_idmapped,						T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts",								},
+	{ io_uring_idmapped_userns,					T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts in user namespace",						},
+	{ io_uring_idmapped_unmapped,					T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts with unmapped ids",						},
+	{ io_uring_idmapped_unmapped_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts with unmapped ids in user namespace",				},
 #endif
-	{ protected_symlinks,						false,	"following protected symlinks on regular mounts",						},
-	{ protected_symlinks_idmapped_mounts,				true,	"following protected symlinks on idmapped mounts",						},
-	{ protected_symlinks_idmapped_mounts_in_userns,			true,	"following protected symlinks on idmapped mounts in user namespace",				},
-	{ rename_crossing_mounts,					false,	"cross mount rename",										},
-	{ rename_crossing_idmapped_mounts,				true,	"cross idmapped mount rename",									},
-	{ rename_from_idmapped_mount,					true,	"rename from idmapped mounts",									},
-	{ rename_from_idmapped_mount_in_userns,				true,	"rename from idmapped mounts in user namespace",						},
-	{ setattr_truncate,						false,	"setattr truncate",										},
-	{ setattr_truncate_idmapped,					true,	"setattr truncate on idmapped mounts",								},
-	{ setattr_truncate_idmapped_in_userns,				true,	"setattr truncate on idmapped mounts in user namespace",					},
-	{ setgid_create,						false,	"create operations in directories with setgid bit set",						},
-	{ setgid_create_idmapped,					true,	"create operations in directories with setgid bit set on idmapped mounts",			},
-	{ setgid_create_idmapped_in_userns,				true,	"create operations in directories with setgid bit set on idmapped mounts in user namespace",	},
-	{ setid_binaries,						false,	"setid binaries on regular mounts",								},
-	{ setid_binaries_idmapped_mounts,				true,	"setid binaries on idmapped mounts",								},
-	{ setid_binaries_idmapped_mounts_in_userns,			true,	"setid binaries on idmapped mounts in user namespace",						},
-	{ setid_binaries_idmapped_mounts_in_userns_separate_userns,	true,	"setid binaries on idmapped mounts in user namespace with different id mappings",		},
-	{ sticky_bit_unlink,						false,	"sticky bit unlink operations on regular mounts",						},
-	{ sticky_bit_unlink_idmapped_mounts,				true,	"sticky bit unlink operations on idmapped mounts",						},
-	{ sticky_bit_unlink_idmapped_mounts_in_userns,			true,	"sticky bit unlink operations on idmapped mounts in user namespace",				},
-	{ sticky_bit_rename,						false,	"sticky bit rename operations on regular mounts",						},
-	{ sticky_bit_rename_idmapped_mounts,				true,	"sticky bit rename operations on idmapped mounts",						},
-	{ sticky_bit_rename_idmapped_mounts_in_userns,			true,	"sticky bit rename operations on idmapped mounts in user namespace",				},
-	{ symlink_regular_mounts,					false,	"symlink from regular mounts",									},
-	{ symlink_idmapped_mounts,					true,	"symlink from idmapped mounts",									},
-	{ symlink_idmapped_mounts_in_userns,				true,	"symlink from idmapped mounts in user namespace",						},
-	{ threaded_idmapped_mount_interactions,				true,	"threaded operations on idmapped mounts",							},
+	{ protected_symlinks,						0,				"following protected symlinks on regular mounts",						},
+	{ protected_symlinks_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"following protected symlinks on idmapped mounts",						},
+	{ protected_symlinks_idmapped_mounts_in_userns,			T_REQUIRE_IDMAPPED_MOUNTS,	"following protected symlinks on idmapped mounts in user namespace",				},
+	{ rename_crossing_mounts,					0,				"cross mount rename",										},
+	{ rename_crossing_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"cross idmapped mount rename",									},
+	{ rename_from_idmapped_mount,					T_REQUIRE_IDMAPPED_MOUNTS,	"rename from idmapped mounts",									},
+	{ rename_from_idmapped_mount_in_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"rename from idmapped mounts in user namespace",						},
+	{ setattr_truncate,						0,				"setattr truncate",										},
+	{ setattr_truncate_idmapped,					T_REQUIRE_IDMAPPED_MOUNTS,	"setattr truncate on idmapped mounts",								},
+	{ setattr_truncate_idmapped_in_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"setattr truncate on idmapped mounts in user namespace",					},
+	{ setgid_create,						0,				"create operations in directories with setgid bit set",						},
+	{ setgid_create_idmapped,					T_REQUIRE_IDMAPPED_MOUNTS,	"create operations in directories with setgid bit set on idmapped mounts",			},
+	{ setgid_create_idmapped_in_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"create operations in directories with setgid bit set on idmapped mounts in user namespace",	},
+	{ setid_binaries,						0,				"setid binaries on regular mounts",								},
+	{ setid_binaries_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"setid binaries on idmapped mounts",								},
+	{ setid_binaries_idmapped_mounts_in_userns,			T_REQUIRE_IDMAPPED_MOUNTS,	"setid binaries on idmapped mounts in user namespace",						},
+	{ setid_binaries_idmapped_mounts_in_userns_separate_userns,	T_REQUIRE_IDMAPPED_MOUNTS,	"setid binaries on idmapped mounts in user namespace with different id mappings",		},
+	{ sticky_bit_unlink,						0,				"sticky bit unlink operations on regular mounts",						},
+	{ sticky_bit_unlink_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"sticky bit unlink operations on idmapped mounts",						},
+	{ sticky_bit_unlink_idmapped_mounts_in_userns,			T_REQUIRE_IDMAPPED_MOUNTS,	"sticky bit unlink operations on idmapped mounts in user namespace",				},
+	{ sticky_bit_rename,						0,				"sticky bit rename operations on regular mounts",						},
+	{ sticky_bit_rename_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"sticky bit rename operations on idmapped mounts",						},
+	{ sticky_bit_rename_idmapped_mounts_in_userns,			T_REQUIRE_IDMAPPED_MOUNTS,	"sticky bit rename operations on idmapped mounts in user namespace",				},
+	{ symlink_regular_mounts,					0,				"symlink from regular mounts",									},
+	{ symlink_idmapped_mounts,					T_REQUIRE_IDMAPPED_MOUNTS,	"symlink from idmapped mounts",									},
+	{ symlink_idmapped_mounts_in_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"symlink from idmapped mounts in user namespace",						},
+	{ threaded_idmapped_mount_interactions,				T_REQUIRE_IDMAPPED_MOUNTS,	"threaded operations on idmapped mounts",							},
 };
 
 struct t_idmapped_mounts fscaps_in_ancestor_userns[] = {
@@ -13936,7 +13939,8 @@ static bool run_test(struct t_idmapped_mounts suite[], size_t suite_size)
 		 * If the underlying filesystems does not support idmapped
 		 * mounts only run vfs generic tests.
 		 */
-		if (t->require_fs_allow_idmap && !t_fs_allow_idmap) {
+		if (t->support_flags & T_REQUIRE_IDMAPPED_MOUNTS &&
+		    !t_fs_allow_idmap) {
 			log_debug("Skipping test %s", t->description);
 			continue;
 		}
Signature · 1 line
2.34.1
Tested-by Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] idmapped_mounts: Prepare for support for more features

Quoted 8 lines · Jan Kara

Currently idmapped_mounts tests fail for kernels without CONFIG_USER_NS because some tests are run despite missing support for idmapped mounts and they implicitely require user namespace support. Prepare idmapped_mounts to support more features a test may require to reliably run.

---

Thank you. Looks good,

author
#3 lore raw

PATCH 2/2 generic/633: Avoid failure without CONFIG_USER_NS

In reply to Jan Kara

Some tests in idmapped_mounts fail without CONFIG_USER_NS because they have implicit dependence on user namespaces and these tests are run despite idmapped mount support not being detected. Detect whether at least user namespaces are supported and skip tests needing them when they are not.

---
 src/idmapped-mounts/idmapped-mounts.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
src/idmapped-mounts/idmapped-mounts.c +19 -4
index d3b27da6c085..93c44510348e 100644
@@ -127,6 +127,8 @@ char t_buf[PATH_MAX];
 
 /* whether the underlying filesystem supports idmapped mounts */
 bool t_fs_allow_idmap;
+/* whether the system supports user namespaces */
+bool t_has_userns;
 
 static void stash_overflowuid(void)
 {
@@ -13831,6 +13833,7 @@ static const struct option longopts[] = {
 
 /* Flags for which functionality is required by the test */
 #define T_REQUIRE_IDMAPPED_MOUNTS (1U << 0)
+#define T_REQUIRE_USERNS (1U << 1)
 
 struct t_idmapped_mounts {
 	int (*test)(void);
@@ -13841,7 +13844,7 @@ struct t_idmapped_mounts {
 	{ create_in_userns,						T_REQUIRE_IDMAPPED_MOUNTS,	"create operations in user namespace",								},
 	{ device_node_in_userns,					T_REQUIRE_IDMAPPED_MOUNTS,	"device node in user namespace",								},
 	{ expected_uid_gid_idmapped_mounts,				T_REQUIRE_IDMAPPED_MOUNTS,	"expected ownership on idmapped mounts",							},
-	{ fscaps,							0,				"fscaps on regular mounts",									},
+	{ fscaps,							T_REQUIRE_USERNS,		"fscaps on regular mounts",									},
 	{ fscaps_idmapped_mounts,					T_REQUIRE_IDMAPPED_MOUNTS,	"fscaps on idmapped mounts",									},
 	{ fscaps_idmapped_mounts_in_userns,				T_REQUIRE_IDMAPPED_MOUNTS,	"fscaps on idmapped mounts in user namespace",							},
 	{ fscaps_idmapped_mounts_in_userns_separate_userns,		T_REQUIRE_IDMAPPED_MOUNTS,	"fscaps on idmapped mounts in user namespace with different id mappings",			},
@@ -13853,7 +13856,7 @@ struct t_idmapped_mounts {
 	{ hardlink_from_idmapped_mount_in_userns,			T_REQUIRE_IDMAPPED_MOUNTS,	"hardlinks from idmapped mounts in user namespace",						},
 #ifdef HAVE_LIBURING_H
 	{ io_uring,							0,				"io_uring",											},
-	{ io_uring_userns,						0,				"io_uring in user namespace",									},
+	{ io_uring_userns,						T_REQUIRE_USERNS,		"io_uring in user namespace",									},
 	{ io_uring_idmapped,						T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts",								},
 	{ io_uring_idmapped_userns,					T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts in user namespace",						},
 	{ io_uring_idmapped_unmapped,					T_REQUIRE_IDMAPPED_MOUNTS,	"io_uring from idmapped mounts with unmapped ids",						},
@@ -13939,8 +13942,9 @@ static bool run_test(struct t_idmapped_mounts suite[], size_t suite_size)
 		 * If the underlying filesystems does not support idmapped
 		 * mounts only run vfs generic tests.
 		 */
-		if (t->support_flags & T_REQUIRE_IDMAPPED_MOUNTS &&
-		    !t_fs_allow_idmap) {
+		if ((t->support_flags & T_REQUIRE_IDMAPPED_MOUNTS &&
+		    !t_fs_allow_idmap) ||
+		    (t->support_flags & T_REQUIRE_USERNS && !t_has_userns)) {
 			log_debug("Skipping test %s", t->description);
 			continue;
 		}
@@ -13998,6 +14002,16 @@ static bool fs_allow_idmap(void)
 	return ret == 0;
 }
 
+static bool sys_has_userns(void)
+{
+	int fd = get_userns_fd(0, 1000, 1);
+
+	if (fd < 0)
+		return false;
+	close(fd);
+	return true;
+}
+
 int main(int argc, char *argv[])
 {
 	int fret, ret;
@@ -14084,6 +14098,7 @@ int main(int argc, char *argv[])
 
 		exit(EXIT_SUCCESS);
 	}
+	t_has_userns = sys_has_userns();
 
 	stash_overflowuid();
 	stash_overflowgid();
Signature · 1 line
2.34.1
Tested-by Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] generic/633: Avoid failure without CONFIG_USER_NS

Quoted 8 lines · Jan Kara

Some tests in idmapped_mounts fail without CONFIG_USER_NS because they have implicit dependence on user namespaces and these tests are run despite idmapped mount support not being detected. Detect whether at least user namespaces are supported and skip tests needing them when they are not.

---

Thank you. Looks good,

#5 lore raw
In reply to Jan Kara
Quoted 4 lines · Jan Kara

Hello!

these two patches fix a failure of test generic/633 on a system without CONFIG_USER_NS.

Thank you!
I've pulled and tested the patches.
RVB+TB on the individual patches.

Christian

#6 lore raw
Quoted 9 lines · Christian Brauner
Quoted 4 lines · Jan Kara

Hello!

these two patches fix a failure of test generic/633 on a system without CONFIG_USER_NS.

Thank you!
I've pulled and tested the patches.
RVB+TB on the individual patches.

Hey Eryu,
hey Zorro,

Jan's patches have not shown up in xfstests upstream and I think they got lost on the mailing list.

Hopefully they can be picked up this week.

Thanks!
Christian

#7 lore raw
Quoted 11 lines · Christian Brauner
Quoted 9 lines · Christian Brauner
Quoted 4 lines · Jan Kara

Hello!

these two patches fix a failure of test generic/633 on a system without CONFIG_USER_NS.

Thank you!
I've pulled and tested the patches.
RVB+TB on the individual patches.

Quoted 7 lines

Hey Eryu,
hey Zorro,

Jan's patches have not shown up in xfstests upstream and I think they got lost on the mailing list.

Hopefully they can be picked up this week.

Hi Christian,

This patchset has been merged in my local branch now, I'll give it (and other on-queue commits) a testing this week, then push them this weekend if test pass.

Thanks,
Zorro

Quoted 4 lines

Thanks!
Christian