Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Apr 2026 13:27:23 +0000
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 8a5601cff1ea - main - openat(2): check that userspace pass known and allowed flags
Message-ID:  <69e0e3bb.43678.8e3a03e@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=8a5601cff1ea32ab63df1377f61620e4f91999b3

commit 8a5601cff1ea32ab63df1377f61620e4f91999b3
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-04-12 10:48:47 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-04-16 13:26:53 +0000

    openat(2): check that userspace pass known and allowed flags
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D56365
---
 sys/kern/vfs_syscalls.c | 5 ++++-
 sys/sys/fcntl.h         | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 06500909589e..0c4eeb584d41 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1168,12 +1168,15 @@ openflags(int *flagsp)
 {
 	int flags;
 
+	flags = *flagsp;
+	if ((flags & ~FUSERALLOWED) != 0)
+		return (EINVAL);
+
 	/*
 	 * Only one of the O_EXEC, O_RDONLY, O_WRONLY and O_RDWR flags
 	 * may be specified.  On the other hand, for O_PATH any mode
 	 * except O_EXEC is ignored.
 	 */
-	flags = *flagsp;
 	if ((flags & O_PATH) != 0) {
 		flags &= ~O_ACCMODE;
 	} else if ((flags & O_EXEC) != 0) {
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
index 8f2fc1e2debb..0b13241f0ee3 100644
--- a/sys/sys/fcntl.h
+++ b/sys/sys/fcntl.h
@@ -171,6 +171,12 @@ typedef	__pid_t		pid_t;
 #define	FOPENFAILED	O_TTY_INIT
 /* Only for O_PATH files which passed ACCESS FREAD check on open */
 #define	FKQALLOWED	O_RESOLVE_BENEATH
+/* Flags userspace is allowed to pass to openat() */
+#define	FUSERALLOWED	(O_ACCMODE | O_NONBLOCK | O_APPEND | O_SHLOCK | \
+    O_EXLOCK | O_ASYNC | O_SYNC | O_NOFOLLOW | O_CREAT | O_TRUNC | \
+    O_EXCL | O_NOCTTY | O_DIRECT | O_DIRECTORY | O_EXEC | O_TTY_INIT | \
+    O_CLOEXEC | O_VERIFY | O_PATH | O_RESOLVE_BENEATH | O_DSYNC | \
+    O_EMPTY_PATH | O_NAMEDATTR | O_CLOFORK)
 
 /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
 #define	FFLAGS(oflags)	((oflags) & O_EXEC ? (oflags) : (oflags) + 1)


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e0e3bb.43678.8e3a03e>