All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sandbox/seunshare: switch seunshare_mount_file() to use open()
@ 2026-05-12 19:26 Stephen Smalley
  2026-05-14 12:44 ` Petr Lautrbach
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Smalley @ 2026-05-12 19:26 UTC (permalink / raw)
  To: selinux; +Cc: jwcart2, plautrba, omosnace, paul, perfinion, Stephen Smalley

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>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-15 14:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 19:26 [PATCH] sandbox/seunshare: switch seunshare_mount_file() to use open() Stephen Smalley
2026-05-14 12:44 ` Petr Lautrbach
2026-05-14 15:16   ` Stephen Smalley
2026-05-15 14:08   ` Petr Lautrbach

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.