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

Wei Gao wegao@suse.com
Fri Aug 1 02:28:57 CEST 2025


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

Signed-off-by: Wei Gao <wegao@suse.com>
---
 testcases/kernel/syscalls/mount/mount08.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/mount/mount08.c b/testcases/kernel/syscalls/mount/mount08.c
index e2824ac55..fb2b28736 100644
--- a/testcases/kernel/syscalls/mount/mount08.c
+++ b/testcases/kernel/syscalls/mount/mount08.c
@@ -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);
 }
-- 
2.49.0



More information about the ltp mailing list