Skip to content

[release/11.0] Align CoreCLR GS cookie protection with NativeAOT - #132976

Merged
steveisok merged 1 commit into
release/11.0from
backport/pr-132925-to-release/11.0
Aug 31, 2026
Merged

[release/11.0] Align CoreCLR GS cookie protection with NativeAOT#132976
steveisok merged 1 commit into
release/11.0from
backport/pr-132925-to-release/11.0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Backport of #132925 to release/11.0

/cc @steveisok

Customer Impact

  • Customer reported
  • Found internally

[Select one or both of the boxes. Describe how this issue impacts customers, citing the expected and actual behaviors and scope of the issue. If customer-reported, provide the issue number.]

Regression

  • Yes
  • No

[If yes, specify when the regression was introduced. Provide the PR or commit if known.]

Testing

[How was the fix verified? How was the issue missed previously? What tests were added?]

Risk

[High/Medium/Low. Justify the indication by mentioning how risks were measured and addressed.]

IMPORTANT: If this backport is for a servicing release, please verify that:

  • For .NET 8 and .NET 9: The PR target branch is release/X.0-staging, not release/X.0.
  • For .NET 10+: The PR target branch is release/X.0 (no -staging suffix).

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Fixes #99977

Hosting CoreCLR inside Apple's stock `/usr/bin/lldb` on macOS arm64 fails: `coreclr_initialize`
returns `HRESULT 0x8007000C`. `InitGSCookie()` temporarily calls `ClrVirtualProtect(PAGE_READWRITE)`
on `s_gsCookie`, which lives in Apple's `__DATA_CONST` segment (via `const`/`READONLY_ATTR`).
Apple marks that segment immutable once a Mach exception port owns the process — which happens
when CoreCLR is hosted inside LLDB with `PAL_MachExceptionMode` set to avoid Apple's guarded Mach
exception-port operations — so the underlying `mprotect` call fails.

NativeAOT hit and fixed the identical Apple problem in #99173. Its read-only GS cookie feature is
also disabled on WebAssembly, where changing page protections is unnecessary overhead, and on
OpenBSD, where `ld.so` marks read-only segments immutable at load time. This PR aligns CoreCLR with
that existing NativeAOT platform policy:

- Define `FEATURE_READONLY_GS_COOKIE` on all targets except Apple, WebAssembly, and OpenBSD.
- `vars.hpp`/`vars.cpp`: `s_gsCookie` keeps its read-only `const`/`READONLY_ATTR` declaration
  when the feature is enabled; otherwise it is plain writable data.
- `ceemain.cpp`: `InitGSCookie()` skips both `ClrVirtualProtect` calls when the feature is
  disabled. Cookie generation and the write itself are unchanged on every platform.

On Apple and OpenBSD, this trades a narrow defense-in-depth mitigation for compatibility with the
platform's immutable read-only segments. On WebAssembly, it avoids page-protection overhead that
provides no benefit. Other platforms retain the existing read-only cookie behavior.

> [!NOTE]
> This description was drafted with the assistance of an AI coding agent (GitHub Copilot).
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@steveisok
steveisok requested review from a team and jkotas August 31, 2026 17:48
@steveisok

Copy link
Copy Markdown
Member

@jkotas I think this is important to land in 11 to get better SOS mac arm64 support.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@jkotas

jkotas commented Aug 31, 2026

Copy link
Copy Markdown
Member

this is important to land in 11 to get better SOS mac arm64 support.

It would be better to land the changes to get SOS AOT compiled that avoids this and number of other problems on all platforms.

Still, I am ok with backporting.

@steveisok steveisok added the Servicing-approved Approved for servicing release label Aug 31, 2026
@steveisok

Copy link
Copy Markdown
Member

/ba-g Helix monitor doing its thing...

@steveisok
steveisok merged commit 7d3bd9b into release/11.0 Aug 31, 2026
108 of 110 checks passed
@steveisok
steveisok deleted the backport/pr-132925-to-release/11.0 branch August 31, 2026 21:04
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants