Skip to content

Commit

Permalink
Kernel: Harden sys$setgroups Vector usage against OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
bgianfo authored and linusg committed May 1, 2021
1 parent f0568bf commit a678851
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Kernel/Syscalls/setuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ KResultOr<int> Process::sys$setgroups(ssize_t count, Userspace<const gid_t*> use
}

Vector<gid_t> 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;

Expand All @@ -174,7 +175,8 @@ KResultOr<int> Process::sys$setgroups(ssize_t count, Userspace<const gid_t*> 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())
Expand Down

0 comments on commit a678851

Please sign in to comment.