diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-04-12 10:48:47 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-04-16 13:26:53 +0000 |
| commit | 8a5601cff1ea32ab63df1377f61620e4f91999b3 (patch) | |
| tree | 98b92bccc64476844ff90e46f3fff0feb8586bcf | |
| parent | e48e9794589993da039a2f4d1c66f8fdd6421155 (diff) | |
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
| -rw-r--r-- | sys/kern/vfs_syscalls.c | 5 | ||||
| -rw-r--r-- | sys/sys/fcntl.h | 6 |
2 files changed, 10 insertions, 1 deletions
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) |
