[release/11.0] Align CoreCLR GS cookie protection with NativeAOT - #132976
Merged
Conversation
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: 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. |
Member
|
@jkotas I think this is important to land in 11 to get better SOS mac arm64 support. |
Contributor
|
Tagging subscribers to this area: @agocke |
Member
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. |
jkotas
approved these changes
Aug 31, 2026
Member
|
/ba-g Helix monitor doing its thing... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #132925 to release/11.0
/cc @steveisok
Customer Impact
[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
[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:
release/X.0-staging, notrelease/X.0.release/X.0(no-stagingsuffix).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.