From dd53e070c5199d54392316f1398296442b578f9d Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 17 Jun 2020 14:08:14 -0400 Subject: [PATCH] Kernel+LibC: Remove setreuid() / setregid() again It looks like they're considered a bad idea, so let's not add them before we need them. I figured it's good to have them in git history if we ever do need them though, hence the add/remove dance. --- Kernel/Process.cpp | 42 --------------------------------------- Kernel/Process.h | 2 -- Kernel/Syscall.h | 2 -- Libraries/LibC/unistd.cpp | 12 ----------- Libraries/LibC/unistd.h | 2 -- 5 files changed, 60 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index c0a308df4c..f902679548 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2187,48 +2187,6 @@ int Process::sys$setgid(gid_t gid) return 0; } -int Process::sys$setreuid(uid_t ruid, uid_t euid) -{ - REQUIRE_PROMISE(id); - - // This has FreeBSD semantics. - // Linux and Solaris also allow id == m_suid. - auto ok = [this](uid_t id) { return id == (uid_t)-1 || id == m_uid || id == m_euid; }; - if ((!ok(ruid) || !ok(euid)) && !is_superuser()) - return -EPERM; - - if (ruid != (uid_t)-1) - m_uid = ruid; - if (euid != (uid_t)-1) - m_euid = euid; - - if (ruid != (uid_t)-1 || m_euid != m_uid) - m_suid = m_euid; - - return 0; -} - -int Process::sys$setregid(gid_t rgid, gid_t egid) -{ - REQUIRE_PROMISE(id); - - // This has FreeBSD semantics. - // Linux and Solaris also allow id == m_sgid. - auto ok = [this](gid_t id) { return id == (gid_t)-1 || id == m_gid || id == m_egid; }; - if ((!ok(rgid) || !ok(egid)) && !is_superuser()) - return -EPERM; - - if (rgid != (gid_t)-1) - m_gid = rgid; - if (egid != (gid_t)-1) - m_egid = egid; - - if (rgid != (gid_t)-1 || m_egid != m_gid) - m_sgid = m_egid; - - return 0; -} - int Process::sys$setresuid(uid_t ruid, uid_t euid, uid_t suid) { REQUIRE_PROMISE(id); diff --git a/Kernel/Process.h b/Kernel/Process.h index ffa533d66e..ec9aeb3201 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -249,8 +249,6 @@ public: int sys$setegid(gid_t); int sys$setuid(uid_t); int sys$setgid(gid_t); - int sys$setreuid(uid_t, uid_t); - int sys$setregid(gid_t, gid_t); int sys$setresuid(uid_t, uid_t, uid_t); int sys$setresgid(gid_t, gid_t, gid_t); unsigned sys$alarm(unsigned seconds); diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index e6585879ca..e593aa985c 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -98,8 +98,6 @@ namespace Kernel { __ENUMERATE_SYSCALL(setegid) \ __ENUMERATE_SYSCALL(setuid) \ __ENUMERATE_SYSCALL(setgid) \ - __ENUMERATE_SYSCALL(setreuid) \ - __ENUMERATE_SYSCALL(setregid) \ __ENUMERATE_SYSCALL(setresuid) \ __ENUMERATE_SYSCALL(setresgid) \ __ENUMERATE_SYSCALL(alarm) \ diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index a9ed5e7e69..c33b1fe7d2 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -491,18 +491,6 @@ int setgid(gid_t gid) __RETURN_WITH_ERRNO(rc, rc, -1); } -int setreuid(uid_t ruid, uid_t euid) -{ - int rc = syscall(SC_setreuid, ruid, euid); - __RETURN_WITH_ERRNO(rc, rc, -1); -} - -int setregid(gid_t rgid, gid_t egid) -{ - int rc = syscall(SC_setregid, rgid, egid); - __RETURN_WITH_ERRNO(rc, rc, -1); -} - int setresuid(uid_t ruid, uid_t euid, uid_t suid) { int rc = syscall(SC_setresuid, ruid, euid, suid); diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index 12d1e2c057..af72d4fc82 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -92,8 +92,6 @@ int seteuid(uid_t); int setegid(gid_t); int setuid(uid_t); int setgid(gid_t); -int setreuid(uid_t, uid_t); -int setregid(gid_t, gid_t); int setresuid(uid_t, uid_t, uid_t); int setresgid(gid_t, gid_t, gid_t); pid_t tcgetpgrp(int fd);