1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

Kernel: Make sys$getsid not require the big lock

Reorganize the code slightly to avoid creating a TOCTOU bug, then mark
the syscall as not needing the big lock anymore.
This commit is contained in:
Andreas Kling 2023-04-03 13:39:11 +02:00
parent 1382439267
commit 41f5598516
2 changed files with 8 additions and 7 deletions

View file

@ -12,16 +12,17 @@ namespace Kernel {
ErrorOr<FlatPtr> Process::sys$getsid(pid_t pid)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
VERIFY_NO_PROCESS_BIG_LOCK(this);
TRY(require_promise(Pledge::stdio));
if (pid == 0)
if (pid == 0 || pid == this->pid())
return sid().value();
auto process = Process::from_pid_in_same_jail(pid);
if (!process)
auto peer = Process::from_pid_in_same_jail(pid);
if (!peer)
return ESRCH;
if (sid() != process->sid())
auto peer_sid = peer->sid();
if (sid() != peer_sid)
return EPERM;
return process->sid().value();
return peer_sid.value();
}
ErrorOr<FlatPtr> Process::sys$setsid()