Skip to contentSkip to conversation

mount08.c: SKIP test if selinux is running

PATCH In review Wei Gao via ltp 3 participants 10 messages Jul 28, 2025 – Jul 31, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mount08.c: SKIP test if selinux is running

---
 testcases/kernel/syscalls/mount/mount08.c | 3 +++
 1 file changed, 3 insertions(+)
testcases/kernel/syscalls/mount/mount08.c +3 -0
index e2824ac55..1f97de182 100644
@@ -41,6 +41,9 @@ static void run(void)
 
 static void setup(void)
 {
+	if (tst_selinux_enforcing())
+		tst_brk(TCONF, "SKIP test since selinux is running");
+
 	SAFE_TOUCH(FOO, 0777, NULL);
 	SAFE_TOUCH(BAR, 0777, NULL);
 }
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

The commit is missing why this has to be done. Please be more verbose and explain the reasons in the commit message.

Quoted 25 lines
---
 testcases/kernel/syscalls/mount/mount08.c | 3 +++
 1 file changed, 3 insertions(+)
testcases/kernel/syscalls/mount/mount08.c +3 -0
index e2824ac55..1f97de182 100644
@@ -41,6 +41,9 @@ static void run(void)
 
 static void setup(void)
 {
+	if (tst_selinux_enforcing())
+		tst_brk(TCONF, "SKIP test since selinux is running");
+
 	SAFE_TOUCH(FOO, 0777, NULL);
 	SAFE_TOUCH(BAR, 0777, NULL);
 }
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi,

Quoted 2 lines

The commit is missing why this has to be done. Please be more verbose and explain the reasons in the commit message.

+1, I was going to write the same (remember: often more useful commit message is not *what* you change, but *why* your did the change).

Also, test under SELinux returns EACCES instead of ENOENT:

mount08.c:32: TFAIL: mount(/proc/130541/fd/4) expected ENOENT: EACCES (13)

Why not keep the test just update errno for SELinux?

In setup:
static int exp_errno = ENOENT;

	if (tst_selinux_enforcing())
		exp_errno = EACCES;
Quoted 11 lines
Quoted 10 lines
---
 testcases/kernel/syscalls/mount/mount08.c | 3 +++
 1 file changed, 3 insertions(+)
testcases/kernel/syscalls/mount/mount08.c +0 -0
index e2824ac55..1f97de182 100644
@@ -41,6 +41,9 @@ static void run(void)
Quoted 4 lines

testcases/kernel/syscalls/mount/mount08.c static void run(void) · line 45

Quoted 4 lines
testcases/kernel/syscalls/mount/mount08.c +2 -0
 static void setup(void)
 {
+	if (tst_selinux_enforcing())
+		tst_brk(TCONF, "SKIP test since selinux is running");

Please don't use upper case. Also SELinux is not "running" but enabled in enforce mode. If test should be really skip I would use:

	tst_brk(TCONF, "skip test due SELinux enforce");

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v2 1/1 mount08.c: Check EACCES error when test under selinux enabled in enforce mode

In reply to Wei Gao via ltp

Test case expected ENOENT but get EACCES when selinux enabled in enforce mode. This patch add check errno under selinux.

---
 testcases/kernel/syscalls/mount/mount08.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/mount/mount08.c +6 -1
index e2824ac55..d965094a1 100644
@@ -16,6 +16,8 @@
 #define FOO MNTPOINT "/foo"
 #define BAR MNTPOINT "/bar"
 
+static int exp_errno = ENOENT;
+
 static void run(void)
 {
 	char path[PATH_MAX];
@@ -31,7 +33,7 @@ static void run(void)
 
 	TST_EXP_FAIL(
 		mount(BAR, path, "", MS_BIND, 0),
-		ENOENT,
+		exp_errno,
 		"mount(%s)", path
 	);
 
@@ -41,6 +43,9 @@ static void run(void)
 
 static void setup(void)
 {
+	if (tst_selinux_enforcing())
+		exp_errno = EACCES;
+
 	SAFE_TOUCH(FOO, 0777, NULL);
 	SAFE_TOUCH(BAR, 0777, NULL);
 }
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/1
#4 lore raw

Re: [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode

Hi Wei,

Quoted 2 lines

Test case expected ENOENT but get EACCES when selinux enabled in enforce mode. This patch add check errno under selinux.

Thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode

In reply to Wei Gao via ltp

Hi!

Quoted 31 lines · Wei Gao via ltp

Test case expected ENOENT but get EACCES when selinux enabled in enforce mode. This patch add check errno under selinux.

---
  testcases/kernel/syscalls/mount/mount08.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/mount/mount08.c +3 -1
index e2824ac55..d965094a1 100644
@@ -16,6 +16,8 @@
  #define FOO MNTPOINT "/foo"
  #define BAR MNTPOINT "/bar"
 
+static int exp_errno = ENOENT;
+
  static void run(void)
  {
  	char path[PATH_MAX];
@@ -31,7 +33,7 @@ static void run(void)
 
  	TST_EXP_FAIL(
  		mount(BAR, path, "", MS_BIND, 0),
-		ENOENT,
+		exp_errno,
  		"mount(%s)", path
  	);
 

testcases/kernel/syscalls/mount/mount08.c static void run(void) · line 51

Quoted 9 lines
testcases/kernel/syscalls/mount/mount08.c +3 -0
@@ -41,6 +43,9 @@ static void run(void)
 
  static void setup(void)
  {
+	if (tst_selinux_enforcing())
+		exp_errno = EACCES;
+
  	SAFE_TOUCH(FOO, 0777, NULL);
  	SAFE_TOUCH(BAR, 0777, NULL);
  }

We are not 100% sure that SELinux will be configured to block the access to mount. We should probably consider both of them only when SELinux is enabled, otherwise ENOENT only.

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode

Hi Andrea, Wei,

Quoted 3 lines

We are not 100% sure that SELinux will be configured to block the access to mount. We should probably consider both of them only when SELinux is enabled, otherwise ENOENT only.

Good point. Lets' use TST_EXP_FAIL_ARR with ENOENT or ENOENT and EACCES. Wei, please make a comment in source code, why EACCES is not enough for SELinux. Thanks!

Kind regards,
Petr

Quoted 1 line

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 1/1 mount08.c: Check EACCES error when test under selinux enabled in enforce mode

In reply to Wei Gao via ltp

Test case expected ENOENT but get EACCES when selinux enabled in enforce mode. This patch add check errno under selinux.

---
 testcases/kernel/syscalls/mount/mount08.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/mount/mount08.c +15 -2
index e2824ac55..fb2b28736 100644
@@ -6,6 +6,8 @@
 /*\
  * Verify that mount will raise ENOENT if we try to mount on magic links
  * under /proc/<pid>/fd/<nr>.
+ * If SELinux is enabled, the expected error also can be EACCES since
+ * SElinux plicy could be configured to block the operation.
  */
 
 #include "tst_test.h"
@@ -16,6 +18,12 @@
 #define FOO MNTPOINT "/foo"
 #define BAR MNTPOINT "/bar"
 
+static int exp_errnos_num;
+static int exp_errnos[] = {
+	ENOENT,
+	EACCES,
+};
+
 static void run(void)
 {
 	char path[PATH_MAX];
@@ -29,9 +37,9 @@ static void run(void)
 
 	sprintf(path, "/proc/%d/fd/%d", getpid(), proc_fd);
 
-	TST_EXP_FAIL(
+	TST_EXP_FAIL_ARR(
 		mount(BAR, path, "", MS_BIND, 0),
-		ENOENT,
+		exp_errnos, exp_errnos_num,
 		"mount(%s)", path
 	);
 
@@ -41,6 +49,11 @@ static void run(void)
 
 static void setup(void)
 {
+	exp_errnos_num = ARRAY_SIZE(exp_errnos) - 1;
+
+	if (tst_selinux_enforcing())
+		exp_errnos_num++;
+
 	SAFE_TOUCH(FOO, 0777, NULL);
 	SAFE_TOUCH(BAR, 0777, NULL);
 }
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp