mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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).
This commit is contained in:
parent
5b3980b040
commit
5f38f5500e
Notes:
sideshowbarker
2024-07-17 05:13:00 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/5f38f5500e Pull-request: https://github.com/SerenityOS/serenity/pull/15752
1 changed files with 1 additions and 4 deletions
|
@ -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 {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue