Skip to contentSkip to conversation

selftests/landlock: skip ptrace_test when YAMA is enabled

PATCH In review Jeff Xu 3 participants 17 messages Jun 28, 2022 – Jul 18, 2022 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Jeff Xu

author
#0 lore raw

PATCH 1/1 selftests/landlock: skip ptrace_test when YAMA is enabled

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f
---
 .../testing/selftests/landlock/ptrace_test.c  | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
tools/testing/selftests/landlock/ptrace_test.c +49 -0
index c28ef98ff3ac..ef2d36f56764 100644
@@ -226,6 +226,44 @@ FIXTURE_TEARDOWN(hierarchy)
 {
 }
 
+int open_sysfs(const char *path, int flags, int *fd)
+{
+	*fd = open(path, flags);
+
+	if (fd < 0)
+		return -1;
+
+	return 0;
+}
+
+int read_sysfs_int_fd(int fd, int *val)
+{
+	char buf[2];
+
+	if (read(fd, buf, sizeof(buf)) < 0)
+		return -1;
+
+	buf[sizeof(buf) - 1] = '\0';
+	*val = atoi(buf);
+	return 0;
+}
+
+int read_sysfs_int(const char *path, int *val)
+{
+	int fd;
+
+	if (open_sysfs(path, O_RDONLY, &fd) != 0)
+		return -1;
+
+	if (read_sysfs_int_fd(fd, val) != 0) {
+		close(fd);
+		return -1;
+	}
+
+	close(fd);
+	return 0;
+}
+
 /* Test PTRACE_TRACEME and PTRACE_ATTACH for parent and child. */
 TEST_F(hierarchy, trace)
 {
@@ -235,6 +273,17 @@ TEST_F(hierarchy, trace)
 	char buf_parent;
 	long ret;
 
+	int ptrace_val;
+
+	ASSERT_EQ(0, read_sysfs_int("/proc/sys/kernel/yama/ptrace_scope",
+				    &ptrace_val));
+	if (ptrace_val != 0) {
+		/*
+		 * Yama's scoped ptrace is presumed disabled.  If enabled, skip.
+		 */
+		SKIP(return, "yama is enabled, skip current test");
+	}
+
 	/*
 	 * Removes all effective and permitted capabilities to not interfere
 	 * with cap_ptrace_access_check() in case of PTRACE_MODE_FSCREDS.
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
maintainer
#1 lore raw

Hi Jeff,

Thanks for this patch. Here are some comments:

Quoted 18 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f
---
  .../testing/selftests/landlock/ptrace_test.c  | 49 +++++++++++++++++++
  1 file changed, 49 insertions(+)
tools/testing/selftests/landlock/ptrace_test.c +0 -0
index c28ef98ff3ac..ef2d36f56764 100644

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 228

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +0 -0
@@ -226,6 +226,44 @@ FIXTURE_TEARDOWN(hierarchy)
  {
  }
 

Please move these new helpers after test_ptrace_read() and make them static.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 237

Quoted 9 lines
tools/testing/selftests/landlock/ptrace_test.c +9 -0
+int open_sysfs(const char *path, int flags, int *fd)
+{
+	*fd = open(path, flags);
+
+	if (fd < 0)
+		return -1;
+
+	return 0;
+}

open_sysfs() can be replaced with a call to open(). This makes the code simpler.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 243

Quoted 6 lines
tools/testing/selftests/landlock/ptrace_test.c +6 -0
+
+int read_sysfs_int_fd(int fd, int *val)
+{
+	char buf[2];
+
+	if (read(fd, buf, sizeof(buf)) < 0)

I guess read(fd, buf, 1) should be enough and it enables keeping the final '\0'. A comment should state that this helper only read the first digit (which is enough for Yama).

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 246

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+		return -1;
+
+	buf[sizeof(buf) - 1] = '\0';

Use char buf[2] = {}; instead.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 249

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+	*val = atoi(buf);
+	return 0;
+}

Same for read_sysfs_int_fd(), you can inline the code in read_sysfs_int().

Quoted 21 lines
tools/testing/selftests/landlock/ptrace_test.c +17 -0
+
+int read_sysfs_int(const char *path, int *val)
+{
+	int fd;
+
+	if (open_sysfs(path, O_RDONLY, &fd) != 0)
+		return -1;
+
+	if (read_sysfs_int_fd(fd, val) != 0) {
+		close(fd);
+		return -1;
+	}
+
+	close(fd);
+	return 0;
+}
+
  /* Test PTRACE_TRACEME and PTRACE_ATTACH for parent and child. */
  TEST_F(hierarchy, trace)
  {

tools/testing/selftests/landlock/ptrace_test.c TEST_F(hierarchy, trace) · line 279

Quoted 7 lines
tools/testing/selftests/landlock/ptrace_test.c +4 -0
@@ -235,6 +273,17 @@ TEST_F(hierarchy, trace)
  	char buf_parent;
  	long ret;
 
+	int ptrace_val;
+
+	ASSERT_EQ(0, read_sysfs_int("/proc/sys/kernel/yama/ptrace_scope",
+				    &ptrace_val));

This is a good test but it fail if Yama is not built in the kernel.

For now, I think you can create two helpers named something like is_yama_restricting() and is_yama_denying() (for admin-only attach).

tools/testing/selftests/landlock/ptrace_test.c TEST_F(hierarchy, trace) · line 280

Quoted 1 line
tools/testing/selftests/landlock/ptrace_test.c +1 -0
+	if (ptrace_val != 0) {

Some tests should work even if ptrace_val == 1. SKIP() should only be called when the test would fail. Can you please check all tests with all Yama values?

Quoted 9 lines
tools/testing/selftests/landlock/ptrace_test.c +6 -0
+		/*
+		 * Yama's scoped ptrace is presumed disabled.  If enabled, skip.
+		 */
+		SKIP(return, "yama is enabled, skip current test");
+	}
+
  	/*
  	 * Removes all effective and permitted capabilities to not interfere
  	 * with cap_ptrace_access_check() in case of PTRACE_MODE_FSCREDS.
maintainer
#2 lore raw
In reply to Jeff Xu
Quoted 7 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>

I guess we assume that Signed-off-by implies Tested-by, so you can remove this Tested-by.

Quoted 2 lines
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f

Please remove this Change-Id too.

author
#3 lore raw

Hi Mickaël

Thank you for your review, please see my response below.

Quoted 53 lines

Hi Jeff,

Thanks for this patch. Here are some comments:

Quoted 18 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f
---
  .../testing/selftests/landlock/ptrace_test.c  | 49 +++++++++++++++++++
  1 file changed, 49 insertions(+)
tools/testing/selftests/landlock/ptrace_test.c +0 -0
index c28ef98ff3ac..ef2d36f56764 100644

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 228

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +0 -0
@@ -226,6 +226,44 @@ FIXTURE_TEARDOWN(hierarchy)
  {
  }
 

Please move these new helpers after test_ptrace_read() and make them static.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 237

Quoted 9 lines
tools/testing/selftests/landlock/ptrace_test.c +9 -0
+int open_sysfs(const char *path, int flags, int *fd)
+{
+     *fd = open(path, flags);
+
+     if (fd < 0)
+             return -1;
+
+     return 0;
+}

open_sysfs() can be replaced with a call to open(). This makes the code simpler.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 243

Quoted 6 lines
tools/testing/selftests/landlock/ptrace_test.c +6 -0
+
+int read_sysfs_int_fd(int fd, int *val)
+{
+     char buf[2];
+
+     if (read(fd, buf, sizeof(buf)) < 0)

I guess read(fd, buf, 1) should be enough and it enables keeping the final '\0'. A comment should state that this helper only read the first digit (which is enough for Yama).

Quoted 10 lines

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 246

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+             return -1;
+
+     buf[sizeof(buf) - 1] = '\0';

Use char buf[2] = {}; instead.

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+     *val = atoi(buf);
+     return 0;
+}

Thanks, I will revise the code, my original thought is to extend it as a common utility function to parse an int, let me finish it in the next iteration of patch.

Quoted 3 lines

Same for read_sysfs_int_fd(), you can inline the code in read_sysfs_int(). This is a good test but it fail if Yama is not built in the kernel.

I don't have a kernel built without yama, so my original thought is to fail it and whoever has the need can fix it. What is your thought on this ?

Quoted 3 lines

For now, I think you can create two helpers named something like is_yama_restricting() and is_yama_denying() (for admin-only attach).

Can you please clarify on the difference/implementation on those 2 ?

Quoted 5 lines

tools/testing/selftests/landlock/ptrace_test.c TEST_F(hierarchy, trace) · line 280

Quoted 1 line
tools/testing/selftests/landlock/ptrace_test.c +1 -0
+     if (ptrace_val != 0) {

Some tests should work even if ptrace_val == 1. SKIP() should only be called when the test would fail. Can you please check all tests with all Yama values?

Sure, below are yama cases with testing result:
=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing
======================================
Case 1 - restricted ptrace: a process must have a predefined relationship
with the inferior it wants to call PTRACE_ATTACH on. By default, this relationship is that of only its descendants when the above classic criteria is also met. To change the relationship, an inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare an allowed debugger PID to call PTRACE_ATTACH on the inferior. Using PTRACE_TRACEME is unchanged.

Test:
// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace_test 4/8 pass

// #          FAIL  hierarchy.allow_without_domain.trace
// #          FAIL  hierarchy.deny_with_parent_domain.trace
// #          FAIL  hierarchy.allow_sibling_domain.trace
// #          FAIL  hierarchy.deny_with_nested_and_parent_domain.trace

====================================================
Case 2 - admin-only attach: only processes with CAP_SYS_PTRACE may use ptrace
with PTRACE_ATTACH, or through children calling PTRACE_TRACEME.
Case 3 - no attach: no processes may use ptrace with PTRACE_ATTACH nor via
PTRACE_TRACEME. Once set, this sysctl value cannot be changed.
Test: *case2 and case3 have the same results:
// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 2/8 pass
//. ok 4 hierarchy.deny_with_sibling_domain.trace
//. ok 8 hierarchy.deny_with_forked_domain.trace
// the other 6 tests failed with timeout.
===============================================

Do you know why fs_test (47,48) is failing when yama value = 1,2,3 ?

FOR SKIP, it might be messy to add SKIP after checking variant names in TEST_F(), (too many if/else , which make it less readable), ideally this should be when or before FIXTURE_VARIANT_ADD() is called. or somehow refactor the code to remove the variant check in TEST_F()

Is there a better way ?

Thanks
Best Regards,
Jeff

Quoted 18 lines · Mickaël Salaün
Quoted 7 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>

I guess we assume that Signed-off-by implies Tested-by, so you can remove this Tested-by.

Quoted 2 lines
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f

Please remove this Change-Id too.

author
#4 lore raw

A correction (resend with plain text)

Quoted 6 lines

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Note: 47,48 of fs_test are failing for all YAMA config values (0-3)

Quoted 167 lines · Jeff Xu

Hi Mickaël

Thank you for your review, please see my response below.

Quoted 53 lines

Hi Jeff,

Thanks for this patch. Here are some comments:

Quoted 18 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f
---
  .../testing/selftests/landlock/ptrace_test.c  | 49 +++++++++++++++++++
  1 file changed, 49 insertions(+)
tools/testing/selftests/landlock/ptrace_test.c +0 -0
index c28ef98ff3ac..ef2d36f56764 100644

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 228

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +0 -0
@@ -226,6 +226,44 @@ FIXTURE_TEARDOWN(hierarchy)
  {
  }
 

Please move these new helpers after test_ptrace_read() and make them static.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 237

Quoted 9 lines
tools/testing/selftests/landlock/ptrace_test.c +9 -0
+int open_sysfs(const char *path, int flags, int *fd)
+{
+     *fd = open(path, flags);
+
+     if (fd < 0)
+             return -1;
+
+     return 0;
+}

open_sysfs() can be replaced with a call to open(). This makes the code simpler.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 243

Quoted 6 lines
tools/testing/selftests/landlock/ptrace_test.c +6 -0
+
+int read_sysfs_int_fd(int fd, int *val)
+{
+     char buf[2];
+
+     if (read(fd, buf, sizeof(buf)) < 0)

I guess read(fd, buf, 1) should be enough and it enables keeping the final '\0'. A comment should state that this helper only read the first digit (which is enough for Yama).

Quoted 10 lines

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 246

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+             return -1;
+
+     buf[sizeof(buf) - 1] = '\0';

Use char buf[2] = {}; instead.

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+     *val = atoi(buf);
+     return 0;
+}

Thanks, I will revise the code, my original thought is to extend it as a common utility function to parse an int, let me finish it in the next iteration of patch.

Quoted 3 lines

Same for read_sysfs_int_fd(), you can inline the code in read_sysfs_int(). This is a good test but it fail if Yama is not built in the kernel.

I don't have a kernel built without yama, so my original thought is to fail it and whoever has the need can fix it. What is your thought on this ?

Quoted 3 lines

For now, I think you can create two helpers named something like is_yama_restricting() and is_yama_denying() (for admin-only attach).

Can you please clarify on the difference/implementation on those 2 ?

Quoted 5 lines

tools/testing/selftests/landlock/ptrace_test.c TEST_F(hierarchy, trace) · line 280

Quoted 1 line
tools/testing/selftests/landlock/ptrace_test.c +1 -0
+     if (ptrace_val != 0) {

Some tests should work even if ptrace_val == 1. SKIP() should only be called when the test would fail. Can you please check all tests with all Yama values?

Sure, below are yama cases with testing result:
=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing
======================================
Case 1 - restricted ptrace: a process must have a predefined relationship
with the inferior it wants to call PTRACE_ATTACH on. By default, this relationship is that of only its descendants when the above classic criteria is also met. To change the relationship, an inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare an allowed debugger PID to call PTRACE_ATTACH on the inferior. Using PTRACE_TRACEME is unchanged.

Test:
// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace_test 4/8 pass

// #          FAIL  hierarchy.allow_without_domain.trace
// #          FAIL  hierarchy.deny_with_parent_domain.trace
// #          FAIL  hierarchy.allow_sibling_domain.trace
// #          FAIL  hierarchy.deny_with_nested_and_parent_domain.trace

====================================================
Case 2 - admin-only attach: only processes with CAP_SYS_PTRACE may use ptrace
with PTRACE_ATTACH, or through children calling PTRACE_TRACEME.
Case 3 - no attach: no processes may use ptrace with PTRACE_ATTACH nor via
PTRACE_TRACEME. Once set, this sysctl value cannot be changed.
Test: *case2 and case3 have the same results:
// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 2/8 pass
//. ok 4 hierarchy.deny_with_sibling_domain.trace
//. ok 8 hierarchy.deny_with_forked_domain.trace
// the other 6 tests failed with timeout.
===============================================

Do you know why fs_test (47,48) is failing when yama value = 1,2,3 ?

FOR SKIP, it might be messy to add SKIP after checking variant names in TEST_F(), (too many if/else , which make it less readable), ideally this should be when or before FIXTURE_VARIANT_ADD() is called. or somehow refactor the code to remove the variant check in TEST_F()

Is there a better way ?

Thanks
Best Regards,
Jeff

Quoted 18 lines · Mickaël Salaün
Quoted 7 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>

I guess we assume that Signed-off-by implies Tested-by, so you can remove this Tested-by.

Quoted 2 lines
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f

Please remove this Change-Id too.

maintainer
#5 lore raw
In reply to Jeff Xu
Quoted 72 lines · Jeff Xu

Hi Mickaël

Thank you for your review, please see my response below.

Quoted 53 lines

Hi Jeff,

Thanks for this patch. Here are some comments:

Quoted 18 lines · Jeff Xu

ptrace_test assumes YAMA is disabled, skip it if YAMA is enabled.

Cc Jorge Lucangeli Obes <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mickaël Salaün <[email protected]>
Change-Id I623742ca9f20ec706a38c92f6c0bab755f73578f
---
   .../testing/selftests/landlock/ptrace_test.c  | 49 +++++++++++++++++++
   1 file changed, 49 insertions(+)
tools/testing/selftests/landlock/ptrace_test.c +0 -0
index c28ef98ff3ac..ef2d36f56764 100644

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 228

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +0 -0
@@ -226,6 +226,44 @@ FIXTURE_TEARDOWN(hierarchy)
   {
   }
 

Please move these new helpers after test_ptrace_read() and make them static.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 237

Quoted 9 lines
tools/testing/selftests/landlock/ptrace_test.c +9 -0
+int open_sysfs(const char *path, int flags, int *fd)
+{
+     *fd = open(path, flags);
+
+     if (fd < 0)
+             return -1;
+
+     return 0;
+}

open_sysfs() can be replaced with a call to open(). This makes the code simpler.

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 243

Quoted 6 lines
tools/testing/selftests/landlock/ptrace_test.c +6 -0
+
+int read_sysfs_int_fd(int fd, int *val)
+{
+     char buf[2];
+
+     if (read(fd, buf, sizeof(buf)) < 0)

I guess read(fd, buf, 1) should be enough and it enables keeping the final '\0'. A comment should state that this helper only read the first digit (which is enough for Yama).

Quoted 10 lines

tools/testing/selftests/landlock/ptrace_test.c FIXTURE_TEARDOWN(hierarchy) · line 246

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+             return -1;
+
+     buf[sizeof(buf) - 1] = '\0';

Use char buf[2] = {}; instead.

Quoted 3 lines
tools/testing/selftests/landlock/ptrace_test.c +3 -0
+     *val = atoi(buf);
+     return 0;
+}

Thanks, I will revise the code, my original thought is to extend it as a common utility function to parse an int, let me finish it in the next iteration of patch.

Quoted 5 lines
Quoted 3 lines

Same for read_sysfs_int_fd(), you can inline the code in read_sysfs_int(). This is a good test but it fail if Yama is not built in the kernel.

I don't have a kernel built without yama, so my original thought is to fail it and whoever has the need can fix it. What is your thought on this ?

The current status is that all tests should pass with a minimal kernel configuration (cf. the test config file). Yama is an exception for these tests, not the norm, so you also need to test against a kernel without Yama.

Quoted 5 lines
Quoted 4 lines

For now, I think you can create two helpers named something like is_yama_restricting() and is_yama_denying() (for admin-only attach).

Can you please clarify on the difference/implementation on those 2 ?

They should check for the different values of ptrace_scope: https://docs.kernel.org/admin-guide/LSM/Yama.html
- is_yama_restricting() should return true if ptrace_scope == 1
- is_yama_denying() should return true if ptrace_scope >= 2

Restricted ptrace only forbids a child process to ptrace its parents. There is no specific restriction for a parent to ptrace its children.

Ptracing is always denied if ptrace_scope >= 2 (without specific capabilties, which is the case for these tests).

Quoted 50 lines
Quoted 6 lines

tools/testing/selftests/landlock/ptrace_test.c TEST_F(hierarchy, trace) · line 280

Quoted 2 lines
tools/testing/selftests/landlock/ptrace_test.c +1 -0
+     if (ptrace_val != 0) {

Some tests should work even if ptrace_val == 1. SKIP() should only be called when the test would fail. Can you please check all tests with all Yama values?

Sure, below are yama cases with testing result:
=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing
======================================
Case 1 - restricted ptrace: a process must have a predefined relationship
with the inferior it wants to call PTRACE_ATTACH on. By default, this relationship is that of only its descendants when the above classic criteria is also met. To change the relationship, an inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare an allowed debugger PID to call PTRACE_ATTACH on the inferior. Using PTRACE_TRACEME is unchanged.

Test:
// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace_test 4/8 pass

// #          FAIL  hierarchy.allow_without_domain.trace
// #          FAIL  hierarchy.deny_with_parent_domain.trace
// #          FAIL  hierarchy.allow_sibling_domain.trace
// #          FAIL  hierarchy.deny_with_nested_and_parent_domain.trace

====================================================
Case 2 - admin-only attach: only processes with CAP_SYS_PTRACE may use ptrace
with PTRACE_ATTACH, or through children calling PTRACE_TRACEME.
Case 3 - no attach: no processes may use ptrace with PTRACE_ATTACH nor via
PTRACE_TRACEME. Once set, this sysctl value cannot be changed.
Test: *case2 and case3 have the same results:
// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 2/8 pass
//. ok 4 hierarchy.deny_with_sibling_domain.trace
//. ok 8 hierarchy.deny_with_forked_domain.trace
// the other 6 tests failed with timeout.
===============================================

Quoted 1 line

Do you know why fs_test (47,48) is failing when yama value = 1,2,3 ?

These are all the overlayfs tests but I don't know why they are failing with Yama. Could you please pinpoint the exact(s) failing ASSERT? (Whatever my following comments, this would be valuable to know the issue.)

Quoted 7 lines

FOR SKIP, it might be messy to add SKIP after checking variant names in TEST_F(), (too many if/else , which make it less readable), ideally this should be when or before FIXTURE_VARIANT_ADD() is called. or somehow refactor the code to remove the variant check in TEST_F()

Is there a better way ?

OK, let's follow another approach.

The first alternative would be to disable Yama for all the Landlock ptrace tests. You'll first need to save the current Yama settings and restore it after each test, even if they failed. I think this alternative makes sense because Landlock tests should not be about Yama.

The second alternative would be to test with and without Yama, with different Yama settings. That would also require to disable Yama for 1/3 or 1/4 of tests. The downside of this alternative is that it requires 3 or 4 times variants, and it actually test Yama, which is not the goal of the Landlock tests.

Anyway, you also need to update the comment about Yama in the current tests.

A message that is not in the archive (sent off-list or not yet received): CALmYWFvcSn_wks0bXo3_DUyYGtVW_MHrrO1dRoYcxY4uiB1KEA@mail.gmail.com

maintainer
#7 lore raw
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
    process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//.   not ok 47 layout2_overlay.no_restriction
//.   not ok 48 layout2_overlay.same_content_different_file //  Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

author
#8 lore raw
Quoted 19 lines
Quoted 10 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

#9 lore raw
Quoted 20 lines · Jeff Xu
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

author
#10 lore raw
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Quoted 67 lines · Guenter Roeck
Quoted 20 lines · Jeff Xu
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

#11 lore raw
Quoted 11 lines · Jeff Xu
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Guenter

Quoted 69 lines · Guenter Roeck
Quoted 67 lines · Jeff Xu
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

author
#12 lore raw
Quoted 14 lines · Jeff Xu
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 8 lines
Quoted 3 lines

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Thanks
Jeff

Quoted 94 lines · Guenter Roeck
Quoted 11 lines · Jeff Xu
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Guenter

Quoted 69 lines · Guenter Roeck
Quoted 67 lines · Jeff Xu
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

author
#13 lore raw

Jeff Xu <[email protected]>

Quoted 27 lines

Jul 14, 2022, 5:35 PM (20 hours ago)
to Guenter, Mickaël, linux-security-module, Jorge, Guenter, Kees

Quoted 20 lines · Jeff Xu
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Quoted 3 lines

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Quoted 5 lines

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

I built a kernel with overlayfs on chromeos, and lsmod didn't give me what I wanted.
/sys/fs and /proc/fs also doesn't show anything about overlayfs

@Mickaël Salaün
Are you OK with SKIP the overlay test when mount("overlay",...) fails in FIXTURE_SETUP() ? Mount failure can be used as an indication.

Jeff

Quoted 130 lines · Jeff Xu
Quoted 15 lines · Jeff Xu
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 8 lines
Quoted 3 lines

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Thanks
Jeff

Quoted 94 lines · Guenter Roeck
Quoted 11 lines · Jeff Xu
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Guenter

Quoted 69 lines · Guenter Roeck
Quoted 67 lines · Jeff Xu
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

#14 lore raw
Quoted 37 lines · Jeff Xu

Jeff Xu <[email protected]>

Quoted 27 lines

Jul 14, 2022, 5:35 PM (20 hours ago)
to Guenter, Mickaël, linux-security-module, Jorge, Guenter, Kees

Quoted 20 lines · Jeff Xu
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Quoted 3 lines

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Quoted 5 lines

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Quoted 8 lines

I built a kernel with overlayfs on chromeos, and lsmod didn't give me what I wanted.
/sys/fs and /proc/fs also doesn't show anything about overlayfs

@Mickaël Salaün
Are you OK with SKIP the overlay test when mount("overlay",...) fails in FIXTURE_SETUP() ? Mount failure can be used as an indication.

Maybe the error code returned from mount gives a hint. Also, how about /proc/filesystems ?

Guenter

Quoted 137 lines

Jeff

Quoted 130 lines · Jeff Xu
Quoted 15 lines · Jeff Xu
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 8 lines
Quoted 3 lines

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Thanks
Jeff

Quoted 94 lines · Guenter Roeck
Quoted 11 lines · Jeff Xu
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Guenter

Quoted 69 lines · Guenter Roeck
Quoted 67 lines · Jeff Xu
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

author
#15 lore raw
Quoted 1 line

Maybe the error code returned from mount gives a hint.

It returns -1

Quoted 3 lines

Also, how about
/proc/filesystems ?

Yes. it has what I want:
nodev overlay

Thanks for your help! I can use this at runtime check.

Jeff

Quoted 190 lines · Guenter Roeck
Quoted 37 lines · Jeff Xu

Jeff Xu <[email protected]>

Quoted 27 lines

Jul 14, 2022, 5:35 PM (20 hours ago)
to Guenter, Mickaël, linux-security-module, Jorge, Guenter, Kees

Quoted 20 lines · Jeff Xu
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Quoted 3 lines

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Quoted 5 lines

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Quoted 8 lines

I built a kernel with overlayfs on chromeos, and lsmod didn't give me what I wanted.
/sys/fs and /proc/fs also doesn't show anything about overlayfs

@Mickaël Salaün
Are you OK with SKIP the overlay test when mount("overlay",...) fails in FIXTURE_SETUP() ? Mount failure can be used as an indication.

Maybe the error code returned from mount gives a hint. Also, how about /proc/filesystems ?

Guenter

Quoted 137 lines

Jeff

Quoted 130 lines · Jeff Xu
Quoted 15 lines · Jeff Xu
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 8 lines
Quoted 3 lines

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Thanks
Jeff

Quoted 94 lines · Guenter Roeck
Quoted 11 lines · Jeff Xu
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Guenter

Quoted 69 lines · Guenter Roeck
Quoted 67 lines · Jeff Xu
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

#16 lore raw
Quoted 5 lines · Jeff Xu
Quoted 2 lines

Maybe the error code returned from mount gives a hint.

It returns -1

Sorry, I meant errno, not the return value.

Quoted 7 lines
Quoted 3 lines

Also, how about
/proc/filesystems ?

Yes. it has what I want:
nodev overlay

Excellent.

Guenter

Quoted 196 lines

Thanks for your help! I can use this at runtime check.

Jeff

Quoted 190 lines · Guenter Roeck
Quoted 37 lines · Jeff Xu

Jeff Xu <[email protected]>

Quoted 27 lines

Jul 14, 2022, 5:35 PM (20 hours ago)
to Guenter, Mickaël, linux-security-module, Jorge, Guenter, Kees

Quoted 20 lines · Jeff Xu
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Quoted 3 lines

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Quoted 5 lines

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Quoted 8 lines

I built a kernel with overlayfs on chromeos, and lsmod didn't give me what I wanted.
/sys/fs and /proc/fs also doesn't show anything about overlayfs

@Mickaël Salaün
Are you OK with SKIP the overlay test when mount("overlay",...) fails in FIXTURE_SETUP() ? Mount failure can be used as an indication.

Maybe the error code returned from mount gives a hint. Also, how about /proc/filesystems ?

Guenter

Quoted 137 lines

Jeff

Quoted 130 lines · Jeff Xu
Quoted 15 lines · Jeff Xu
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 8 lines
Quoted 3 lines

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

Thanks
Jeff

Quoted 94 lines · Guenter Roeck
Quoted 11 lines · Jeff Xu
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Guenter

Quoted 69 lines · Guenter Roeck
Quoted 67 lines · Jeff Xu
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Quoted 9 lines
Quoted 2 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Quoted 33 lines

Overall, all the failure of landlock selftest seen in chromeOS are expected, we just need to modify the test.

Thanks
Best Regards
Jeff

Quoted 23 lines · Mickaël Salaün
Quoted 10 lines · Jeff Xu

a correction:

=====================================
case 0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
process running under the same uid, as long as it is dumpable (i.e. did not transition uids, start privileged, or have called prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is unchanged.

Quoted 7 lines

Test: All passing

// Base_test: 7/7 pass.
// Fs_test 46/48 pass
//. not ok 47 layout2_overlay.no_restriction
//. not ok 48 layout2_overlay.same_content_different_file
// Ptrace 8/8 pass

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

maintainer
#17 lore raw
Quoted 12 lines · Guenter Roeck
Quoted 5 lines · Jeff Xu
Quoted 2 lines

Maybe the error code returned from mount gives a hint.

It returns -1

Sorry, I meant errno, not the return value.

Quoted 4 lines
Quoted 3 lines

Also, how about
/proc/filesystems ?

Quoted 59 lines
Quoted 3 lines

Yes. it has what I want:
nodev overlay

Excellent.

Guenter

Quoted 52 lines

Thanks for your help! I can use this at runtime check.

Jeff

Quoted 46 lines · Guenter Roeck
Quoted 44 lines · Jeff Xu

Jeff Xu <[email protected]>

Quoted 27 lines

Jul 14, 2022, 5:35 PM (20 hours ago)
to Guenter, Mickaël, linux-security-module, Jorge, Guenter, Kees

Quoted 20 lines · Jeff Xu
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hmm, well, it is not related to Yama then. Could it be linked to other Chromium OS non-upstream patches?

fs_test.c 47 and 48 are failing in chromeOS because OVERLAYFS is not enabled in chromeOS.
If there is a reliable way of detecting OVERLAYFS (checking mount overlayfs is successful ? ), this is a good candidate to add SKIP.

Quoted 5 lines
Quoted 1 line

IS_ENABLED(CONFIG_OVERLAY_FS) ?

Could be. Landlock selftest currently is a user space program though, IS_ENABLED will depend on the kernel header during compile time.

Quoted 3 lines

Ah, sorry, I thought it was an in-kernel test. Userspace should be able to determine if overlayfs is supported by checking /sys/fs/ or possibly /proc/fs/.

Quoted 5 lines

Thanks for clarifying.

lsmod might be the one, such as:
lsmod | grep overlayfs

I built a kernel with overlayfs on chromeos, and lsmod didn't give me what I wanted.
/sys/fs and /proc/fs also doesn't show anything about overlayfs

@Mickaël Salaün
Are you OK with SKIP the overlay test when mount("overlay",...) fails in FIXTURE_SETUP() ? Mount failure can be used as an indication.

In a normal scenario, all configurations in tools/testing/selftests/landlock/config should be enabled, but I think it makes sense for some use cases like chromeOS to be able to not fail if overlayfs is not supported. Please patch FIXTURE_SETUP(layout2_overlay) to skip these tests if the related filesystem string is present (with or without "nodev") in /proc/filesystems . You can create a is_filesystem_supported(const char *filesystem) helper before prepare_layout() for this check, we'll need it for future tests.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Maybe the error code returned from mount gives a hint. Also, how about /proc/filesystems ?

Guenter