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: switch seunshare_mount_file() to use open()
Date: Thu, 14 May 2026 14:44:25 +0200	[thread overview]
Message-ID: <871pfe88k6.fsf@redhat.com> (raw)
In-Reply-To: <20260512192631.751908-1-stephen.smalley.work@gmail.com>

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

> seunshare_mount_file() currently uses fopen() to create the dst
> if it doesn't already exist. Switch to using open() with
> explicitly specified flags including O_NOFOLLOW and an explicitly
> specified mode for the new file.
>
> Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>

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

> ---
>  sandbox/seunshare.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/sandbox/seunshare.c b/sandbox/seunshare.c
> index a1900eaa..17a727e7 100644
> --- a/sandbox/seunshare.c
> +++ b/sandbox/seunshare.c
> @@ -304,18 +304,20 @@ static int seunshare_mount(const char *src, const char *dst, struct stat *src_st
>   */
>  static int seunshare_mount_file(const char *src, const char *dst)
>  {
> -	int flags = 0;
> -
>  	if (verbose)
>  		printf(_("Mounting %s on %s\n"), src, dst);
>  
>  	if (access(dst, F_OK) == -1) {
> -		 FILE *fptr;
> -         fptr = fopen(dst, "w");
> -		 fclose(fptr);
> +		int fd = open(dst, O_WRONLY | O_CREAT | O_NOFOLLOW | O_CLOEXEC, 0600);
> +		if (fd < 0) {
> +			fprintf(stderr, _("Failed to create mount point %s: %m\n"), dst);
> +			return -1;
> +		}
> +		close(fd);
>  	}
> +
>  	/* mount file */
> -	if (mount(src, dst, NULL, MS_BIND | flags, NULL) < 0) {
> +	if (mount(src, dst, NULL, MS_BIND, NULL) < 0) {
>  		fprintf(stderr, _("Failed to mount %s on %s: %s\n"), src, dst, strerror(errno));
>  		return -1;
>  	}
> -- 
> 2.54.0


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 19:26 [PATCH] sandbox/seunshare: switch seunshare_mount_file() to use open() Stephen Smalley
2026-05-14 12:44 ` Petr Lautrbach [this message]
2026-05-14 15:16   ` Stephen Smalley
2026-05-15 14:08   ` 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=871pfe88k6.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.