Kenrel: Validate inode open mode on read/write syscalls

This commit is contained in:
Bananymous 2024-12-15 20:49:12 +02:00
parent 1815a913c3
commit 46d4e32510
1 changed files with 4 additions and 0 deletions

View File

@ -300,6 +300,8 @@ namespace Kernel
{
TRY(validate_fd(fd));
auto& open_file = m_open_files[fd];
if (!(open_file->flags & O_RDONLY))
return BAN::Error::from_errno(EBADF);
if ((open_file->flags & O_NONBLOCK) && !open_file->inode()->can_read())
return 0;
size_t nread = TRY(open_file->inode()->read(open_file->offset, buffer));
@ -311,6 +313,8 @@ namespace Kernel
{
TRY(validate_fd(fd));
auto& open_file = m_open_files[fd];
if (!(open_file->flags & O_WRONLY))
return BAN::Error::from_errno(EBADF);
if ((open_file->flags & O_NONBLOCK) && !open_file->inode()->can_write())
return 0;
if (open_file->flags & O_APPEND)