From 9eeee24a39298055d9aaae606a55a5fb1c2a186f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 Aug 2022 22:22:58 +0200 Subject: [PATCH] Kernel+LibC: Enforce a limit on the number of supplementary group IDs This patch adds the NGROUPS_MAX constant and enforces it in sys$setgroups() to ensure that no process has more than 32 supplementary group IDs. The number doesn't mean anything in particular, just had to pick a number. Perhaps one day we'll have a reason to change it. --- Kernel/API/POSIX/sys/limits.h | 9 +++++++++ Kernel/Syscalls/setuid.cpp | 4 ++++ Userland/Libraries/LibC/limits.h | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 Kernel/API/POSIX/sys/limits.h diff --git a/Kernel/API/POSIX/sys/limits.h b/Kernel/API/POSIX/sys/limits.h new file mode 100644 index 0000000000..df12d14894 --- /dev/null +++ b/Kernel/API/POSIX/sys/limits.h @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#define NGROUPS_MAX 32 diff --git a/Kernel/Syscalls/setuid.cpp b/Kernel/Syscalls/setuid.cpp index 0f22eabb42..53200d5d19 100644 --- a/Kernel/Syscalls/setuid.cpp +++ b/Kernel/Syscalls/setuid.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include namespace Kernel { @@ -246,6 +247,9 @@ ErrorOr Process::sys$setgroups(size_t count, Userspace VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::id)); + if (count > NGROUPS_MAX) + return EINVAL; + auto credentials = this->credentials(); if (!credentials->is_superuser()) diff --git a/Userland/Libraries/LibC/limits.h b/Userland/Libraries/LibC/limits.h index 4e767b0eca..63e1728415 100644 --- a/Userland/Libraries/LibC/limits.h +++ b/Userland/Libraries/LibC/limits.h @@ -1,11 +1,12 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include #include