From ad645f31d0af61c5edb7a2b18e6e294c9f27e53d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 11 Aug 2024 00:58:12 +0300 Subject: [PATCH] Kernel/LibC: Add setsid() --- kernel/include/kernel/Process.h | 1 + kernel/kernel/Process.cpp | 14 ++++++++++++++ userspace/libraries/LibC/include/sys/syscall.h | 1 + userspace/libraries/LibC/unistd.cpp | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index f65ba0c1..029bc5ce 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -85,6 +85,7 @@ namespace Kernel BAN::ErrorOr sys_setuid(uid_t); BAN::ErrorOr sys_setgid(gid_t); + BAN::ErrorOr sys_setsid(); BAN::ErrorOr sys_seteuid(uid_t); BAN::ErrorOr sys_setegid(gid_t); BAN::ErrorOr sys_setreuid(uid_t, uid_t); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 911750f3..8689ef80 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -2001,6 +2001,20 @@ namespace Kernel return BAN::Error::from_errno(EPERM); } + BAN::ErrorOr Process::sys_setsid() + { + LockGuard _(m_process_lock); + + if (is_session_leader() || m_pid == m_pgrp) + return BAN::Error::from_errno(EPERM); + + m_sid = m_pid; + m_pgrp = m_pid; + m_controlling_terminal.clear(); + + return 0; + } + BAN::ErrorOr Process::sys_seteuid(uid_t uid) { if (uid < 0 || uid >= 1'000'000'000) diff --git a/userspace/libraries/LibC/include/sys/syscall.h b/userspace/libraries/LibC/include/sys/syscall.h index 8b695c13..1d947e7a 100644 --- a/userspace/libraries/LibC/include/sys/syscall.h +++ b/userspace/libraries/LibC/include/sys/syscall.h @@ -25,6 +25,7 @@ __BEGIN_DECLS O(SYS_READ_DIR, readdir) \ O(SYS_SET_UID, setuid) \ O(SYS_SET_GID, setgid) \ + O(SYS_SET_SID, setsid) \ O(SYS_SET_EUID, seteuid) \ O(SYS_SET_EGID, setegid) \ O(SYS_SET_REUID, setreuid) \ diff --git a/userspace/libraries/LibC/unistd.cpp b/userspace/libraries/LibC/unistd.cpp index 3ae50e08..262b66b8 100644 --- a/userspace/libraries/LibC/unistd.cpp +++ b/userspace/libraries/LibC/unistd.cpp @@ -475,6 +475,11 @@ int setgid(gid_t gid) return syscall(SYS_SET_GID, gid); } +int setsid(void) +{ + return syscall(SYS_SET_SID); +} + int setreuid(uid_t ruid, uid_t euid) { return syscall(SYS_SET_REUID, ruid, euid);