From 8480ffe108c77df518b15bc13b5ebc7bbb410d67 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 11 Aug 2023 11:53:38 +0300 Subject: [PATCH] Kernel: open() now validates file access mode --- kernel/kernel/OpenFileDescriptorSet.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/kernel/OpenFileDescriptorSet.cpp b/kernel/kernel/OpenFileDescriptorSet.cpp index 42cfccb5c8..38e098379c 100644 --- a/kernel/kernel/OpenFileDescriptorSet.cpp +++ b/kernel/kernel/OpenFileDescriptorSet.cpp @@ -59,6 +59,10 @@ namespace Kernel if (flags & ~(O_RDONLY | O_WRONLY | O_NOFOLLOW | O_SEARCH | O_APPEND | O_TRUNC | O_CLOEXEC)) return BAN::Error::from_errno(ENOTSUP); + int access_mask = O_EXEC | O_RDONLY | O_WRONLY | O_SEARCH; + if ((flags & access_mask) != O_RDWR && __builtin_popcount(flags & access_mask) != 1) + return BAN::Error::from_errno(EINVAL); + auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, flags)); if (flags & O_TRUNC)