Kernel: open() now validates file access mode

This commit is contained in:
Bananymous 2023-08-11 11:53:38 +03:00
parent 38c0bc7bae
commit 8f3348cf2b
1 changed files with 4 additions and 0 deletions

View File

@ -59,6 +59,10 @@ namespace Kernel
if (flags & ~(O_RDONLY | O_WRONLY | O_NOFOLLOW | O_SEARCH | O_APPEND | O_TRUNC | O_CLOEXEC)) if (flags & ~(O_RDONLY | O_WRONLY | O_NOFOLLOW | O_SEARCH | O_APPEND | O_TRUNC | O_CLOEXEC))
return BAN::Error::from_errno(ENOTSUP); 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)); auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, flags));
if (flags & O_TRUNC) if (flags & O_TRUNC)