Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Apr 2026 00:42:51 +0000
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 65ccf925415f - stable/15 - openat(2): check that userspace pass known and allowed flags
Message-ID:  <69e1820b.42da5.82436e7@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=65ccf925415fd3b88385da018f15e3c999bab003

commit 65ccf925415fd3b88385da018f15e3c999bab003
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-04-12 10:48:47 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-04-17 00:42:39 +0000

    openat(2): check that userspace pass known and allowed flags
    
    (cherry picked from commit 8a5601cff1ea32ab63df1377f61620e4f91999b3)
---
 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 92b43672bae0..dc02e3351fee 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?69e1820b.42da5.82436e7>