From a8765fa6737315a07cf426378207a47c88ac52dd Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Thu, 29 Apr 2021 02:27:38 -0700 Subject: [PATCH] Kernel: Harden sys$select Vector usage against OOM. Theoretically the append should never fail as we have in-line storage of FD_SETSIZE, which should always be enough. However I'm planning on removing the non-try variants of AK::Vector when compiling in kernel mode in the future, so this will need to go eventually. I suppose it also protects against some unforeseen bug where we we can append more than FD_SETSIZE items. --- Kernel/Syscalls/select.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/Syscalls/select.cpp b/Kernel/Syscalls/select.cpp index e39c4b6707..f38946f211 100644 --- a/Kernel/Syscalls/select.cpp +++ b/Kernel/Syscalls/select.cpp @@ -78,8 +78,10 @@ KResultOr Process::sys$select(Userspace u dbgln("sys$select: Bad fd number {}", fd); return EBADF; } - fds_info.append({ description.release_nonnull(), block_flags }); - fds.append(fd); + if (!fds_info.try_append({ description.release_nonnull(), block_flags })) + return ENOMEM; + if (!fds.try_append(fd)) + return ENOMEM; } if constexpr (IO_DEBUG || POLL_SELECT_DEBUG)