diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-25 18:27:42 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-25 19:35:55 +0100 |
commit | 82f86e35d6e0aa521df632fdba43fe7a37a5db4c (patch) | |
tree | 7f96f91c8467598a8419498576a7da9c06baeaa4 /Kernel/Syscalls/setuid.cpp | |
parent | 3c9bd911b8b90e8034c9b61633a6985e752eb417 (diff) | |
download | serenity-82f86e35d6e0aa521df632fdba43fe7a37a5db4c.zip |
Kernel+LibC: Introduce a "dumpable" flag for processes
This new flag controls two things:
- Whether the kernel will generate core dumps for the process
- Whether the EUID:EGID should own the process's files in /proc
Processes are automatically made non-dumpable when their EUID or EGID is
changed, either via syscalls that specifically modify those ID's, or via
sys$execve(), when a set-uid or set-gid program is executed.
A process can change its own dumpable flag at any time by calling the
new sys$prctl(PR_SET_DUMPABLE) syscall.
Fixes #4504.
Diffstat (limited to 'Kernel/Syscalls/setuid.cpp')
-rw-r--r-- | Kernel/Syscalls/setuid.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Kernel/Syscalls/setuid.cpp b/Kernel/Syscalls/setuid.cpp index 8ea014039d..ee01f4e325 100644 --- a/Kernel/Syscalls/setuid.cpp +++ b/Kernel/Syscalls/setuid.cpp @@ -35,6 +35,8 @@ int Process::sys$seteuid(uid_t euid) if (euid != m_uid && euid != m_suid && !is_superuser()) return -EPERM; + if (m_euid != euid) + set_dumpable(false); m_euid = euid; return 0; } @@ -46,6 +48,9 @@ int Process::sys$setegid(gid_t egid) if (egid != m_gid && egid != m_sgid && !is_superuser()) return -EPERM; + if (m_egid != egid) + set_dumpable(false); + m_egid = egid; return 0; } @@ -57,6 +62,9 @@ int Process::sys$setuid(uid_t uid) if (uid != m_uid && uid != m_euid && !is_superuser()) return -EPERM; + if (m_euid != uid) + set_dumpable(false); + m_uid = uid; m_euid = uid; m_suid = uid; @@ -70,6 +78,9 @@ int Process::sys$setgid(gid_t gid) if (gid != m_gid && gid != m_egid && !is_superuser()) return -EPERM; + if (m_egid != gid) + set_dumpable(false); + m_gid = gid; m_egid = gid; m_sgid = gid; @@ -91,6 +102,9 @@ int Process::sys$setresuid(uid_t ruid, uid_t euid, uid_t suid) if ((!ok(ruid) || !ok(euid) || !ok(suid)) && !is_superuser()) return -EPERM; + if (m_euid != euid) + set_dumpable(false); + m_uid = ruid; m_euid = euid; m_suid = suid; @@ -112,6 +126,9 @@ int Process::sys$setresgid(gid_t rgid, gid_t egid, gid_t sgid) if ((!ok(rgid) || !ok(egid) || !ok(sgid)) && !is_superuser()) return -EPERM; + if (m_egid != egid) + set_dumpable(false); + m_gid = rgid; m_egid = egid; m_sgid = sgid; |