Kernel: Harden sys$poll Vector usage against OOM.

This commit is contained in:
Brian Gianforcaro 2021-04-29 01:41:30 -07:00 committed by Andreas Kling
parent 119b7be249
commit b3096276bb
Notes: sideshowbarker 2024-07-18 18:54:03 +09:00

View file

@ -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;
}
@ -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();