Skip to content

Downgrade system IL impersonation token to high#40447

Open
Brian-Perkins wants to merge 1 commit intomasterfrom
user/bperkins/downgrade_system_il
Open

Downgrade system IL impersonation token to high#40447
Brian-Perkins wants to merge 1 commit intomasterfrom
user/bperkins/downgrade_system_il

Conversation

@Brian-Perkins
Copy link
Copy Markdown

Summary of the Pull Request

Creating objects while impersonating service accounts with an integrity level of 'system' can cause problems because the VM worker process only runs at 'high' IL. Downgrade 'system' to 'high'.

Validation Steps Performed

Manually ran scenarios under NetworkService account.

Copilot AI review requested due to automatic review settings May 6, 2026 22:31
@Brian-Perkins Brian-Perkins requested a review from a team as a code owner May 6, 2026 22:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adjusts duplicated user tokens so that when a duplicated token has System integrity level, it is downgraded to High integrity level to match the VM worker process and avoid access issues on created objects.

Changes:

  • Adds TOKEN_ADJUST_DEFAULT to the duplicated token’s access rights.
  • Detects System IL on the duplicated token and sets its integrity level to High via SetTokenInformation(TokenIntegrityLevel).

Comment on lines +186 to +198
union
{
SID sid;
BYTE buffer[SECURITY_SID_SIZE(1)];
} sidBuffer;
SID_IDENTIFIER_AUTHORITY micSidAuthority = SECURITY_MANDATORY_LABEL_AUTHORITY;
THROW_IF_NTSTATUS_FAILED(::RtlInitializeSidEx(&sidBuffer.sid, &micSidAuthority, 1, SECURITY_MANDATORY_HIGH_RID));

TOKEN_MANDATORY_LABEL tokenLabel{};
tokenLabel.Label.Attributes = SE_GROUP_INTEGRITY;
tokenLabel.Label.Sid = &sidBuffer.sid;
THROW_IF_WIN32_BOOL_FALSE(::SetTokenInformation(
newToken.get(), TokenIntegrityLevel, &tokenLabel, (sizeof(tokenLabel) + ::GetLengthSid(&sidBuffer.sid))));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is true or not...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

BYTE buffer[SECURITY_SID_SIZE(1)];
} sidBuffer;
SID_IDENTIFIER_AUTHORITY micSidAuthority = SECURITY_MANDATORY_LABEL_AUTHORITY;
THROW_IF_NTSTATUS_FAILED(::RtlInitializeSidEx(&sidBuffer.sid, &micSidAuthority, 1, SECURITY_MANDATORY_HIGH_RID));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could simplify this a bit by using wsl::windows::common::security::CreateSid(SECURITY_MANDATORY_LABEL_AUTHORITY, SECURITY_MANDATORY_HIGH_RID)

Comment on lines +186 to +198
union
{
SID sid;
BYTE buffer[SECURITY_SID_SIZE(1)];
} sidBuffer;
SID_IDENTIFIER_AUTHORITY micSidAuthority = SECURITY_MANDATORY_LABEL_AUTHORITY;
THROW_IF_NTSTATUS_FAILED(::RtlInitializeSidEx(&sidBuffer.sid, &micSidAuthority, 1, SECURITY_MANDATORY_HIGH_RID));

TOKEN_MANDATORY_LABEL tokenLabel{};
tokenLabel.Label.Attributes = SE_GROUP_INTEGRITY;
tokenLabel.Label.Sid = &sidBuffer.sid;
THROW_IF_WIN32_BOOL_FALSE(::SetTokenInformation(
newToken.get(), TokenIntegrityLevel, &tokenLabel, (sizeof(tokenLabel) + ::GetLengthSid(&sidBuffer.sid))));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants