summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2022-10-22 19:52:53 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-22 19:59:36 +0200
commit5f38f5500e082f1afa2ddae14409f16815b49198 (patch)
tree8767ee59b9df57292ed252967f9630dd82b1d7f2
parent5b3980b04067ccc2b795ec407822757a82396157 (diff)
downloadserenity-5f38f5500e082f1afa2ddae14409f16815b49198.zip
SystemServer: Fix race condition in Service::determine_account()
In theory our peer process could die between the call to getsockopt() and Core::system::stat() and another process could end up with the same PID which would result in us incorrectly launching the service as another user (e.g. root).
-rw-r--r--Userland/Services/SystemServer/Service.cpp5
1 files changed, 1 insertions, 4 deletions
diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp
index f82e29428e..20bcb83a2c 100644
--- a/Userland/Services/SystemServer/Service.cpp
+++ b/Userland/Services/SystemServer/Service.cpp
@@ -419,10 +419,7 @@ ErrorOr<void> Service::determine_account(int fd)
socklen_t creds_size = sizeof(creds);
TRY(Core::System::getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &creds_size));
- auto const directory_name = String::formatted("/proc/{}/", creds.pid);
- auto const stat = TRY(Core::System::stat(directory_name));
-
- m_account = TRY(Core::Account::from_uid(stat.st_uid, Core::Account::Read::PasswdOnly));
+ m_account = TRY(Core::Account::from_uid(creds.uid, Core::Account::Read::PasswdOnly));
return {};
}