Linux Test Project
 help / color / mirror / Atom feed
* Re: [LTP] [PATCH v1] mount08.c: SKIP test if selinux is running
  2025-07-28 21:27 [LTP] [PATCH v1] mount08.c: SKIP test if selinux is running Wei Gao via ltp
@ 2025-07-28 10:04 ` Cyril Hrubis
  2025-07-28 10:31   ` Petr Vorel
  2025-07-31 14:33 ` [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode Wei Gao via ltp
  1 sibling, 1 reply; 10+ messages in thread
From: Cyril Hrubis @ 2025-07-28 10:04 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

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

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  testcases/kernel/syscalls/mount/mount08.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/testcases/kernel/syscalls/mount/mount08.c b/testcases/kernel/syscalls/mount/mount08.c
> index e2824ac55..1f97de182 100644
> --- a/testcases/kernel/syscalls/mount/mount08.c
> +++ b/testcases/kernel/syscalls/mount/mount08.c
> @@ -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);
>  }
> -- 
> 2.49.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v1] mount08.c: SKIP test if selinux is running
  2025-07-28 10:04 ` Cyril Hrubis
@ 2025-07-28 10:31   ` Petr Vorel
  0 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2025-07-28 10:31 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi,

> 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;

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

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH v1] mount08.c: SKIP test if selinux is running
@ 2025-07-28 21:27 Wei Gao via ltp
  2025-07-28 10:04 ` Cyril Hrubis
  2025-07-31 14:33 ` [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode Wei Gao via ltp
  0 siblings, 2 replies; 10+ messages in thread
From: Wei Gao via ltp @ 2025-07-28 21:27 UTC (permalink / raw)
  To: ltp

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

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


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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-07-31 14:33 ` [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode Wei Gao via ltp
@ 2025-07-31  4:39   ` Petr Vorel
  2025-07-31  6:44   ` Andrea Cervesato via ltp
  2025-08-01  0:28   ` [LTP] [PATCH v3] " Wei Gao via ltp
  2 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2025-07-31  4:39 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

Hi Wei,

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

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Thanks!

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-07-31 14:33 ` [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode Wei Gao via ltp
  2025-07-31  4:39   ` Petr Vorel
@ 2025-07-31  6:44   ` Andrea Cervesato via ltp
  2025-07-31 10:54     ` Petr Vorel
  2025-08-01  0:28   ` [LTP] [PATCH v3] " Wei Gao via ltp
  2 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2025-07-31  6:44 UTC (permalink / raw)
  To: Wei Gao, ltp

Hi!

On 7/31/25 4:33 PM, Wei Gao via ltp wrote:
> 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 | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/mount/mount08.c b/testcases/kernel/syscalls/mount/mount08.c
> index e2824ac55..d965094a1 100644
> --- a/testcases/kernel/syscalls/mount/mount08.c
> +++ b/testcases/kernel/syscalls/mount/mount08.c
> @@ -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);
>   }

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


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-07-31  6:44   ` Andrea Cervesato via ltp
@ 2025-07-31 10:54     ` Petr Vorel
  0 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2025-07-31 10:54 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi Andrea, Wei,

> 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

> - Andrea

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-07-28 21:27 [LTP] [PATCH v1] mount08.c: SKIP test if selinux is running Wei Gao via ltp
  2025-07-28 10:04 ` Cyril Hrubis
@ 2025-07-31 14:33 ` Wei Gao via ltp
  2025-07-31  4:39   ` Petr Vorel
                     ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: Wei Gao via ltp @ 2025-07-31 14:33 UTC (permalink / raw)
  To: ltp

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 | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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


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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v3] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-08-01  0:28   ` [LTP] [PATCH v3] " Wei Gao via ltp
@ 2025-07-31 17:09     ` Andrea Cervesato via ltp
  2025-07-31 17:13     ` Andrea Cervesato via ltp
  1 sibling, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2025-07-31 17:09 UTC (permalink / raw)
  To: Wei Gao, ltp

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v3] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-08-01  0:28   ` [LTP] [PATCH v3] " Wei Gao via ltp
  2025-07-31 17:09     ` Andrea Cervesato via ltp
@ 2025-07-31 17:13     ` Andrea Cervesato via ltp
  1 sibling, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2025-07-31 17:13 UTC (permalink / raw)
  To: Wei Gao, ltp

Merged, thanks!

- Andrea


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [LTP] [PATCH v3] mount08.c: Check EACCES error when test under selinux enabled in enforce mode
  2025-07-31 14:33 ` [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode Wei Gao via ltp
  2025-07-31  4:39   ` Petr Vorel
  2025-07-31  6:44   ` Andrea Cervesato via ltp
@ 2025-08-01  0:28   ` Wei Gao via ltp
  2025-07-31 17:09     ` Andrea Cervesato via ltp
  2025-07-31 17:13     ` Andrea Cervesato via ltp
  2 siblings, 2 replies; 10+ messages in thread
From: Wei Gao via ltp @ 2025-08-01  0:28 UTC (permalink / raw)
  To: ltp

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


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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-07-31 17:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28 21:27 [LTP] [PATCH v1] mount08.c: SKIP test if selinux is running Wei Gao via ltp
2025-07-28 10:04 ` Cyril Hrubis
2025-07-28 10:31   ` Petr Vorel
2025-07-31 14:33 ` [LTP] [PATCH v2] mount08.c: Check EACCES error when test under selinux enabled in enforce mode Wei Gao via ltp
2025-07-31  4:39   ` Petr Vorel
2025-07-31  6:44   ` Andrea Cervesato via ltp
2025-07-31 10:54     ` Petr Vorel
2025-08-01  0:28   ` [LTP] [PATCH v3] " Wei Gao via ltp
2025-07-31 17:09     ` Andrea Cervesato via ltp
2025-07-31 17:13     ` Andrea Cervesato via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox