From a678851b41b4cc940ff0bc7016a05dc5b8b04e2f Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Fri, 30 Apr 2021 03:10:55 -0700 Subject: [PATCH] Kernel: Harden sys$setgroups Vector usage against OOM --- Kernel/Syscalls/setuid.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/Syscalls/setuid.cpp b/Kernel/Syscalls/setuid.cpp index e5453287c1e..729a9f2196a 100644 --- a/Kernel/Syscalls/setuid.cpp +++ b/Kernel/Syscalls/setuid.cpp @@ -163,7 +163,8 @@ KResultOr Process::sys$setgroups(ssize_t count, Userspace use } Vector new_extra_gids; - new_extra_gids.resize(count); + if (!new_extra_gids.try_resize(count)) + return ENOMEM; if (!copy_n_from_user(new_extra_gids.data(), user_gids, count)) return EFAULT; @@ -174,7 +175,8 @@ KResultOr Process::sys$setgroups(ssize_t count, Userspace use } ProtectedDataMutationScope scope { *this }; - m_extra_gids.resize(unique_extra_gids.size()); + if (!m_extra_gids.try_resize(unique_extra_gids.size())) + return ENOMEM; size_t i = 0; for (auto& extra_gid : unique_extra_gids) { if (extra_gid == gid())