git: 8a5601cff1ea - main - openat(2): check that userspace pass known and allowed flags
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Apr 2026 13:27:23 UTC
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)