summaryrefslogtreecommitdiff
path: root/Servers/SystemServer
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-02 23:28:37 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-02 23:36:21 +0100
commit0958d826d6cb84b9a309846ce44eefa7ea3d9f70 (patch)
treeadfcbdb094a6121f46b1f9c2944268e2ce81594e /Servers/SystemServer
parent0f9800ca57a5e710e61a4bf1274478b194a34e42 (diff)
downloadserenity-0958d826d6cb84b9a309846ce44eefa7ea3d9f70.zip
SystemServer: Call setgid() before setuid() when dropping privileges
Also add error checking and bail out if either call fails. Doing it the wrong way around was causing us to retain GID=0 for all processes (oops!) Thanks to Chris Ball for reporting the bug. :^)
Diffstat (limited to 'Servers/SystemServer')
-rw-r--r--Servers/SystemServer/Service.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Servers/SystemServer/Service.cpp b/Servers/SystemServer/Service.cpp
index 907588d7a5..cc17353638 100644
--- a/Servers/SystemServer/Service.cpp
+++ b/Servers/SystemServer/Service.cpp
@@ -167,8 +167,10 @@ void Service::spawn()
}
if (!m_user.is_null()) {
- setuid(m_uid);
- setgid(m_gid);
+ if (setgid(m_gid) < 0 || setuid(m_uid) < 0) {
+ fprintf(stderr, "Failed to drop privileges (GID=%u, UID=%u)\n", m_gid, m_uid);
+ exit(1);
+ }
}
char* argv[m_extra_arguments.size() + 2];