Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 1/2] core: add tst_selinux_enabled() utility
Date: Wed, 23 Jul 2025 14:41:27 +0200	[thread overview]
Message-ID: <20250723124127.GA154226@pevik> (raw)
In-Reply-To: <a911cbc1-ad7e-4b0e-97f0-4e2c594c7084@suse.com>

Hi all,

> On 7/22/25 2:06 PM, Petr Vorel wrote:
> > +++ lib/tst_security.c
> > @@ -107,7 +107,7 @@ int tst_selinux_enabled(void)
> >   {
> >   	int res = 0;
> > -	if (tst_is_mounted(SELINUX_PATH))
> > +	if (access(SELINUX_STATUS_PATH, F_OK) == 0)
> >   		res = 1;
> >   	tst_res(TINFO, "SELinux enabled: %s", res ? "yes" : "no");

> This is more or less what I was doing at the beginning, but Cyril suggested
> this approach which is more similar to libselinux. Please, check v3.

Sure :). FYI I did check v3 before replying to v4 (I always try to get to the
context looking into older versions, I also noted v3 in one of my replies :)).

And yes, I think you were right, that's why I raised my concern again.

But ok, to quote it here Cyril's reply in v3:
https://lore.kernel.org/ltp/aG5v6enhdqFGgiBj@yuki.lan/

	> +	if (access(SELINUX_PATH, F_OK) == 0 && !tst_dir_is_empty(SELINUX_PATH, 0))
	> +		res = 1;

	Maybe we we can do tst_is_mounted(SELINUX_PATH) here instead. At least
	that seems to be what is_selinux_enabled() seems to be doing.
---

Enabled SELinux means both /sys/fs/selinux/enforce and mounted /sys/fs/selinux/.
I even checked to boot kernel with SELinux compiled in but disabled in the
command line via 'security=selinux selinux=0 enforcing=0' and the result is
expected: no /sys/fs/selinux directory.

Both ways of checking are OK, just "access(SELINUX_STATUS_PATH, F_OK) == 0" is
the quickest way (given test requires just SELinux enabled, not enforcing mode).

This can be changed before merge. Or, feel free to keep the original version as
it also works.

Kind regards,
Petr

> - Andrea


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

  reply	other threads:[~2025-07-23 12:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22  6:55 [LTP] [PATCH v4 0/2] Add listxattr04 test reproducer Andrea Cervesato
2025-07-22  6:55 ` [LTP] [PATCH v4 1/2] core: add tst_selinux_enabled() utility Andrea Cervesato
2025-07-22 10:51   ` Petr Vorel
2025-07-22 12:06   ` Petr Vorel
2025-07-22 13:18     ` Stephen Smalley
2025-07-22 13:20       ` Stephen Smalley
2025-07-22 13:42         ` Petr Vorel
2025-07-22 13:48           ` Stephen Smalley
2025-07-23 11:17             ` Andrea Cervesato via ltp
2025-07-23 12:51               ` Petr Vorel
2025-07-23 11:19     ` Andrea Cervesato via ltp
2025-07-23 12:41       ` Petr Vorel [this message]
2025-07-23 12:43         ` Andrea Cervesato via ltp
2025-07-23 12:46           ` Stephen Smalley
2025-07-23 13:13             ` Stephen Smalley
2025-07-23 13:15               ` Andrea Cervesato via ltp
2025-07-23 19:50                 ` Petr Vorel
2025-07-22 19:12   ` Wei Gao via ltp
2025-07-22  6:55 ` [LTP] [PATCH v4 2/2] Add listxattr04 reproducer Andrea Cervesato
2025-07-22 14:11   ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250723124127.GA154226@pevik \
    --to=pvorel@suse.cz \
    --cc=andrea.cervesato@suse.com \
    --cc=ltp@lists.linux.it \
    --cc=stephen.smalley.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox