Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further prevent ability to access memory on Windows #10618

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/core/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ namespace Bootstrap
DWORD cbBufferSize = 0;
PSID pLocalSystemSid = nullptr;
DWORD pLocalSystemSidSize = SECURITY_MAX_SID_SIZE;
PSID pOwnerRightsSid = nullptr;
DWORD pOwnerRightsSidSize = SECURITY_MAX_SID_SIZE;

// Access control list
PACL pACL = nullptr;
Expand Down Expand Up @@ -165,9 +167,20 @@ namespace Bootstrap
goto Cleanup;
}

// Retrieve CreaterOwnerRights SID
pOwnerRightsSid = static_cast<PSID>(HeapAlloc(GetProcessHeap(), 0, pOwnerRightsSidSize));
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
if (pOwnerRightsSid == nullptr) {
goto Cleanup;
}

if (!CreateWellKnownSid(WinCreatorOwnerRightsSid, nullptr, pOwnerRightsSid, &pOwnerRightsSidSize)) {
auto error = GetLastError();
goto Cleanup;
}

// Calculate the amount of memory that must be allocated for the DACL
cbACL = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(pTokenUser->User.Sid)
+ sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(pLocalSystemSid);
+ sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(pLocalSystemSid) + GetLengthSid(pOwnerRightsSid);

// Create and initialize an ACL
pACL = static_cast<PACL>(HeapAlloc(GetProcessHeap(), 0, cbACL));
Expand All @@ -189,6 +202,11 @@ namespace Bootstrap
goto Cleanup;
}

// Explicitly set "Process Owner" rights to Read Only. The default is Full Control.
if (!AddAccessAllowedAce(pACL, ACL_REVISION, READ_CONTROL, pOwnerRightsSid)) {
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
goto Cleanup;
}

#ifdef WITH_XC_SSHAGENT
// OpenSSH for Windows ssh-agent service is running as LocalSystem
if (!AddAccessAllowedAce(pACL,
Expand All @@ -213,16 +231,19 @@ namespace Bootstrap

Cleanup:

if (pACL != nullptr) {
if (pACL) {
HeapFree(GetProcessHeap(), 0, pACL);
}
if (pLocalSystemSid != nullptr) {
if (pLocalSystemSid) {
HeapFree(GetProcessHeap(), 0, pLocalSystemSid);
}
if (pTokenUser != nullptr) {
if (pOwnerRightsSid) {
HeapFree(GetProcessHeap(), 0, pOwnerRightsSid);
}
if (pTokenUser) {
HeapFree(GetProcessHeap(), 0, pTokenUser);
}
if (hToken != nullptr) {
if (hToken) {
CloseHandle(hToken);
}
#endif
Expand Down