All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Lautrbach <lautrbach@redhat.com>
To: Stephen Smalley <stephen.smalley.work@gmail.com>,
	selinux@vger.kernel.org
Cc: omosnace@redhat.com, jwcart2@gmail.com,
	Stephen Smalley <stephen.smalley.work@gmail.com>
Subject: Re: [PATCH] libselinux: Do not fall back to /selinux on a sysfs mount failure
Date: Thu, 23 Apr 2026 13:43:13 +0200	[thread overview]
Message-ID: <87o6j952cu.fsf@redhat.com> (raw)
In-Reply-To: <20260304200238.26493-2-stephen.smalley.work@gmail.com>

Stephen Smalley <stephen.smalley.work@gmail.com> writes:

> Even if we cannot mount sysfs ourselves (e.g. in a user namespace),
> we can still try to mount on /sys/fs/selinux first prior to falling
> back to /selinux.
>
> Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>

Acked-by: Petr Lautrbach <lautrbach@redhat.com>


> ---
>  libselinux/src/load_policy.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/libselinux/src/load_policy.c b/libselinux/src/load_policy.c
> index 8e737a23..bb7f2dd0 100644
> --- a/libselinux/src/load_policy.c
> +++ b/libselinux/src/load_policy.c
> @@ -290,16 +290,11 @@ int selinux_init_load_policy(int *enforce)
>  	 */
>  	const char *mntpoint = NULL;
>  	/* First make sure /sys is mounted */
> -	if (mount("sysfs", "/sys", "sysfs", 0, 0) == 0 || errno == EBUSY) {
> -		/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */
> -		if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, MS_NOEXEC | MS_NOSUID, 0) == 0 || errno == EBUSY) {
> -			mntpoint = SELINUXMNT;
> -		} else {
> -			/* check old mountpoint */
> -			if (mount(SELINUXFS, OLDSELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
> -				mntpoint = OLDSELINUXMNT;
> -			}
> -		}
> +	(void) mount("sysfs", "/sys", "sysfs", 0, 0);
> +
> +	/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */
> +	if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, MS_NOEXEC | MS_NOSUID, 0) == 0 || errno == EBUSY) {
> +		mntpoint = SELINUXMNT;
>  	} else {
>  		/* check old mountpoint */
>  		if (mount(SELINUXFS, OLDSELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
> -- 
> 2.52.0


  reply	other threads:[~2026-04-23 11:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 20:02 [PATCH] libselinux: Do not fall back to /selinux on a sysfs mount failure Stephen Smalley
2026-04-23 11:43 ` Petr Lautrbach [this message]
2026-05-11 16:44   ` Stephen Smalley

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=87o6j952cu.fsf@redhat.com \
    --to=lautrbach@redhat.com \
    --cc=jwcart2@gmail.com \
    --cc=omosnace@redhat.com \
    --cc=selinux@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.