Skip to content

Commit

Permalink
Kernel: Harden sys$poll Vector usage against OOM.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgianfo authored and awesomekling committed Apr 29, 2021
1 parent 119b7be commit b309627
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Kernel/Syscalls/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ KResultOr<int> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> user_
nfds_checked *= params.nfds;
if (nfds_checked.has_overflow())
return EFAULT;
fds_copy.resize(params.nfds);
if (!fds_copy.try_resize(params.nfds))
return ENOMEM;
if (!copy_from_user(fds_copy.data(), &params.fds[0], nfds_checked.value()))
return EFAULT;
}
Expand All @@ -174,7 +175,8 @@ KResultOr<int> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> user_
block_flags |= BlockFlags::Write;
if (pfd.events & POLLPRI)
block_flags |= BlockFlags::ReadPriority;
fds_info.append({ description.release_nonnull(), block_flags });
if (!fds_info.try_append({ description.release_nonnull(), block_flags }))
return ENOMEM;
}

auto current_thread = Thread::current();
Expand Down

0 comments on commit b309627

Please sign in to comment.