All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Lautrbach <plautrba@redhat.com>
To: Stephen Smalley <stephen.smalley.work@gmail.com>,
	selinux@vger.kernel.org
Cc: jwcart2@gmail.com, omosnace@redhat.com, paul@paul-moore.com,
	perfinion@gentoo.org,
	Stephen Smalley <stephen.smalley.work@gmail.com>
Subject: Re: [PATCH] sandbox/seunshare: remount /tmp and /var/tmp with the proper flags
Date: Thu, 14 May 2026 14:45:18 +0200	[thread overview]
Message-ID: <87v7cq6ty9.fsf@redhat.com> (raw)
In-Reply-To: <20260512200605.753172-1-stephen.smalley.work@gmail.com>

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

> mount(2) with MS_BIND ignores any nosuid/nodev/noexec flags, so
> seunshare_mount() was never setting those on the /tmp and
> /var/tmp mounts. Fix seunshare_mount() to remount them
> with those flags after the bind mount, which does
> set them properly.
>
> Test:
> mkdir tmp
> seunshare -t tmp /bin/bash
> cp /bin/bash /tmp
> /tmp/bash
>
> Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>

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

> ---
>  sandbox/seunshare.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/sandbox/seunshare.c b/sandbox/seunshare.c
> index b9c85bf2..985e0cfb 100644
> --- a/sandbox/seunshare.c
> +++ b/sandbox/seunshare.c
> @@ -260,26 +260,32 @@ static int verify_shell(const char *shell_name)
>   */
>  static int seunshare_mount(const char *src, const char *dst, struct stat *src_st)
>  {
> -	int flags = 0;
> +	int bind_flags = MS_BIND;
> +	int sec_flags = 0;
>  	int is_tmp = 0;
>  
>  	if (verbose)
>  		printf(_("Mounting %s on %s\n"), src, dst);
>  
>  	if (strcmp("/tmp", dst) == 0) {
> -		flags = flags | MS_NODEV | MS_NOSUID | MS_NOEXEC;
> +		sec_flags = MS_NODEV | MS_NOSUID | MS_NOEXEC;
>  		is_tmp = 1;
>  	}
>  
>  	if (strncmp("/run/user", dst, 9) == 0) {
> -		flags = flags | MS_REC;
> +		bind_flags |= MS_REC;
>  	}
>  
>  	/* mount directory */
> -	if (mount(src, dst, NULL, MS_BIND | flags, NULL) < 0) {
> +	if (mount(src, dst, NULL, bind_flags, NULL) < 0) {
>  		fprintf(stderr, _("Failed to mount %s on %s: %s\n"), src, dst, strerror(errno));
>  		return -1;
>  	}
> +	/* remount with security flags, ignored on original bind mount */
> +	if (sec_flags && mount(NULL, dst, NULL, MS_BIND | MS_REMOUNT | sec_flags, NULL) < 0) {
> +		fprintf(stderr, _("Failed to remount %s: %m\n"), dst);
> +		return -1;
> +	}
>  
>  	/* verify whether we mounted what we expected to mount */
>  	if (verify_directory(dst, src_st, NULL) < 0) return -1;
> @@ -289,10 +295,15 @@ static int seunshare_mount(const char *src, const char *dst, struct stat *src_st
>  		if (verbose)
>  			printf(_("Mounting /tmp on /var/tmp\n"));
>  
> -		if (mount("/tmp", "/var/tmp",  NULL, MS_BIND | flags, NULL) < 0) {
> +		if (mount("/tmp", "/var/tmp",  NULL, MS_BIND, NULL) < 0) {
>  			fprintf(stderr, _("Failed to mount /tmp on /var/tmp: %s\n"), strerror(errno));
>  			return -1;
>  		}
> +		/* remount with security flags, ignored on original bind mount */
> +		if (mount(NULL, "/var/tmp", NULL, MS_BIND | MS_REMOUNT | sec_flags, NULL) < 0) {
> +			fprintf(stderr, _("Failed to remount /var/tmp: %m\n"));
> +			return -1;
> +		}
>  	}
>  
>  	return 0;
> -- 
> 2.54.0


  reply	other threads:[~2026-05-14 12:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 20:06 [PATCH] sandbox/seunshare: remount /tmp and /var/tmp with the proper flags Stephen Smalley
2026-05-14 12:45 ` Petr Lautrbach [this message]
2026-05-15 14:11   ` Petr Lautrbach

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=87v7cq6ty9.fsf@redhat.com \
    --to=plautrba@redhat.com \
    --cc=jwcart2@gmail.com \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=perfinion@gentoo.org \
    --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.