From 9bc250e28d3bb4293c39a283807b67b6e82dda1d Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 7 Dec 2022 17:56:27 -0500 Subject: [PATCH] kernel/vfs: Validate that only one of O_RDWR or O_WRONLY is used, if any. Otherwise we will have open modes that could have both and lead to confusion in code that presumes only one will be set. This catches the cause of some ported software (e.g. Wayland layer) misbehaving with ramfs mounted in /var/shared_memory: the ramfs does not properly handle both flags set, and due to another bug, they are for shm_open'ed files. --- src/system/kernel/fs/vfs.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 46166801ca..2469c6cb19 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -2831,6 +2831,9 @@ get_new_fd(int type, struct fs_mount* mount, struct vnode* vnode, && (type == FDTYPE_FILE || type == FDTYPE_DIR)) return B_BUSY; + if ((openMode & O_RDWR) != 0 && (openMode & O_WRONLY) != 0) + return B_BAD_VALUE; + descriptor = alloc_fd(); if (!descriptor) return B_NO_MEMORY;