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

Andrea Cervesato andrea.cervesato@suse.com
Thu Jul 31 08:44:40 CEST 2025


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



More information about the ltp mailing list