Skip to contentSkip to conversation

generic: extend fscaps test

PATCH Superseded Christian Brauner 3 participants 3 messages Apr 23, 2021 – Apr 26, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 generic: extend fscaps test

From: Christian Brauner <[email protected]>

Add a test to verify that setting a v3 fscap that is valid in an ancestor user namespace works.

---
 src/idmapped-mounts/idmapped-mounts.c | 56 +++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
src/idmapped-mounts/idmapped-mounts.c +56 -0
index 870a8fe7..4e3252ca 100644
@@ -3193,6 +3193,62 @@ static int fscaps_idmapped_mounts_in_userns(void)
 		goto out;
 	}
 
+	/*
+	 * Verify we can set an v3 fscap for real root this was regressed at
+	 * some point. Make sure this doesn't happen again!
+	 */
+	if (fremovexattr(file1_fd, "security.capability")) {
+		log_stderr("failure: fremovexattr");
+		goto out;
+	}
+	if (expected_dummy_vfs_caps_uid(file1_fd, -1)) {
+		log_stderr("failure: expected_dummy_vfs_caps_uid");
+		goto out;
+	}
+	if (errno != ENODATA) {
+		log_stderr("failure: errno");
+		goto out;
+	}
+
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		if (expected_dummy_vfs_caps_uid(file1_fd2, -1))
+			die("failure: expected_dummy_vfs_caps_uid");
+		if (errno != ENODATA)
+			die("failure: errno");
+
+		if (set_dummy_vfs_caps(file1_fd2, 0, 0))
+			die("failure: set_dummy_vfs_caps");
+
+		if (!expected_dummy_vfs_caps_uid(file1_fd2, 0))
+			die("failure: expected_dummy_vfs_caps_uid");
+
+		if (!expected_dummy_vfs_caps_uid(file1_fd, 0) && errno != EOVERFLOW)
+			die("failure: expected_dummy_vfs_caps_uid");
+
+		exit(EXIT_SUCCESS);
+	}
+
+	if (wait_for_pid(pid))
+		goto out;
+
+	if (!expected_dummy_vfs_caps_uid(file1_fd2, 10000)) {
+		log_stderr("failure: expected_dummy_vfs_caps_uid");
+		goto out;
+	}
+
+	if (!expected_dummy_vfs_caps_uid(file1_fd, 0)) {
+		log_stderr("failure: expected_dummy_vfs_caps_uid");
+		goto out;
+	}
+
 	fret = 0;
 	log_debug("Ran test");
 out:

base-commit: 15510d3a208187e234333f7974580786d54d52dc

Signature · 1 line
2.27.0
#1 lore raw
Quoted 4 lines · Christian Brauner

From: Christian Brauner <[email protected]>

Add a test to verify that setting a v3 fscap that is valid in an ancestor user namespace works.

The subject is not clear which test it updates, I can only know it's generic/633 that calls idmapped-mounts binary to do the test.

Quoted 13 lines
---
 src/idmapped-mounts/idmapped-mounts.c | 56 +++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
src/idmapped-mounts/idmapped-mounts.c +0 -0
index 870a8fe7..4e3252ca 100644

src/idmapped-mounts/idmapped-mounts.c static int fscaps_idmapped_mounts_in_userns(void) · line 3199

Quoted 7 lines
src/idmapped-mounts/idmapped-mounts.c +4 -0
@@ -3193,6 +3193,62 @@ static int fscaps_idmapped_mounts_in_userns(void)
 		goto out;
 	}
 
+	/*
+	 * Verify we can set an v3 fscap for real root this was regressed at
+	 * some point. Make sure this doesn't happen again!
+	 */

We usually don't add new test cases to existing tests, as that may introduce new failures and let people think there's a regression, then find out it's the new case introduced the failure.

But this test was just merged last week, and the test is closely related to existing cases and could re-use the test framework/setups, so I think it's fine to add this case.

But as above comment said, this new cases is targeted to a regression happened previously, I think it'd be better to put it in a seperate test function, not folded into an existing test function.

And is there a commit that fixed the mentioned regression? Reference it in the comments would help people find the correct fix, if there's any.

Thanks,
Eryu

Quoted 59 lines
src/idmapped-mounts/idmapped-mounts.c +52 -0
+	if (fremovexattr(file1_fd, "security.capability")) {
+		log_stderr("failure: fremovexattr");
+		goto out;
+	}
+	if (expected_dummy_vfs_caps_uid(file1_fd, -1)) {
+		log_stderr("failure: expected_dummy_vfs_caps_uid");
+		goto out;
+	}
+	if (errno != ENODATA) {
+		log_stderr("failure: errno");
+		goto out;
+	}
+
+	pid = fork();
+	if (pid < 0) {
+		log_stderr("failure: fork");
+		goto out;
+	}
+	if (pid == 0) {
+		if (!switch_userns(attr.userns_fd, 0, 0, false))
+			die("failure: switch_userns");
+
+		if (expected_dummy_vfs_caps_uid(file1_fd2, -1))
+			die("failure: expected_dummy_vfs_caps_uid");
+		if (errno != ENODATA)
+			die("failure: errno");
+
+		if (set_dummy_vfs_caps(file1_fd2, 0, 0))
+			die("failure: set_dummy_vfs_caps");
+
+		if (!expected_dummy_vfs_caps_uid(file1_fd2, 0))
+			die("failure: expected_dummy_vfs_caps_uid");
+
+		if (!expected_dummy_vfs_caps_uid(file1_fd, 0) && errno != EOVERFLOW)
+			die("failure: expected_dummy_vfs_caps_uid");
+
+		exit(EXIT_SUCCESS);
+	}
+
+	if (wait_for_pid(pid))
+		goto out;
+
+	if (!expected_dummy_vfs_caps_uid(file1_fd2, 10000)) {
+		log_stderr("failure: expected_dummy_vfs_caps_uid");
+		goto out;
+	}
+
+	if (!expected_dummy_vfs_caps_uid(file1_fd, 0)) {
+		log_stderr("failure: expected_dummy_vfs_caps_uid");
+		goto out;
+	}
+
 	fret = 0;
 	log_debug("Ran test");
 out:

base-commit: 15510d3a208187e234333f7974580786d54d52dc

Signature · 1 line
2.27.0
#2 lore raw
Quoted 8 lines · Eryu Guan
Quoted 4 lines · Christian Brauner

From: Christian Brauner <[email protected]>

Add a test to verify that setting a v3 fscap that is valid in an ancestor user namespace works.

The subject is not clear which test it updates, I can only know it's generic/633 that calls idmapped-mounts binary to do the test.

Right, sorry. Will add that.

Quoted 17 lines
Quoted 17 lines
---
 src/idmapped-mounts/idmapped-mounts.c | 56 +++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
src/idmapped-mounts/idmapped-mounts.c +0 -0
index 870a8fe7..4e3252ca 100644
@@ -3193,6 +3193,62 @@ static int fscaps_idmapped_mounts_in_userns(void)
 		goto out;
 	}
 
Quoted 8 lines

src/idmapped-mounts/idmapped-mounts.c static int fscaps_idmapped_mounts_in_userns(void) · line 3199

Quoted 4 lines
src/idmapped-mounts/idmapped-mounts.c +4 -0
+	/*
+	 * Verify we can set an v3 fscap for real root this was regressed at
+	 * some point. Make sure this doesn't happen again!
+	 */

We usually don't add new test cases to existing tests, as that may introduce new failures and let people think there's a regression, then find out it's the new case introduced the failure.

Hm, okay. I'm pretty sure that I'll grow the idmapped mount test-suite quite a bit more so I need to think about how to make this easily extensible. I want the ability to use the binary itself to run all tests. So I may just introduce flags to allow for running specific tests or subsets of tests such as:

idmapped-mounts --fscaps --acl

Quoted 11 lines

But this test was just merged last week, and the test is closely related to existing cases and could re-use the test framework/setups, so I think it's fine to add this case.

But as above comment said, this new cases is targeted to a regression happened previously, I think it'd be better to put it in a seperate test function, not folded into an existing test function.

And is there a commit that fixed the mentioned regression? Reference it in the comments would help people find the correct fix, if there's any.

That is an annoyingly convoluted story involving a buggy "fix" a revert and then a proper fix. But I'll sure add details. Thank you!

Christian