Repository navigation
Conversation
…net#136265) Fixes dotnet#136201. Initialize the Unix GS cookie before registering the lazy runtime initialization callback, and query the page size independently of GC initialization. Add coverage for a first export call with a stack-allocated buffer. --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]> Copilot-Session: 417e95b3-e5d3-40a0-b723-4f2b70693851 (cherry picked from commit 53ac1a9)
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Author
|
@dotnet-policy-service agree |
Member
|
@LaborJos we need a good justification for backports because they add risk. We don't blanket backport all fixed. The obvious backports are corruptions, reliability issues, regressions, etc. Something that didn't work since at least .NET 8, has a clear failure mode and possible workarounds (do the stackalloc in a method called from the UnmanagedCallersOnly method) is a tough sell. Can you share more about your scenario and why backport is needed? The decision is not on me, we have a council that decides. But I'll not bring forward a weak case for consideration. |
Member
|
Closing per #136343 (comment). |
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 #136265 to
release/10.0.Related customer report: #136201.
Description
Initialize the Unix NativeAOT shared-library GS cookie before publishing the lazy runtime initialization callback. Otherwise the first managed export can save the initial zero cookie in its prologue, initialize the runtime (and change the cookie), then fail the cookie check in its epilogue.
Retain the executable initialization path and the regression test that calls an export with a stack-allocated buffer before any other managed export.
Branch-specific adaptations:
PalGetModuleHandleFromPointersignature andPopulateDebugHeaderscall.sysconf(_SC_PAGE_SIZE)inPalVirtualProtect, following the existing Unix PAL page-size query. This branch does not containminipal/ospagesize.h; page-size lookup must not depend on GC/runtime initialization.new Type[]syntax for export calling conventions.Customer Impact
Customer-reported NativeAOT shared libraries on linux-x64 abort the process (exit 134) when their first export call has a GS-protected frame, such as a
stackallocor a struct containing a fixed buffer. The report reproduces this with .NET 10.0.13, as well as .NET 8 and other versions.Calling a different export first or moving the buffer into a separate non-inlined method can avoid the reported crash, but requires callers or library authors to know about the initialization-order issue.
Regression
No known regression specific to .NET 10. The issue was also reproduced on .NET 8 and .NET 9.
Testing
git diff --checkpassed.Risk
Low-to-moderate. This is a narrow backport of the reviewed mainline fix, but it changes Unix shared-library initialization and memory protection before normal runtime initialization. The page-size query is made independent of GC initialization, and executable cookie initialization remains explicit. The Unix initialization path and shared-library smoke test need CI coverage; Windows behavior should remain unchanged.
Third-party attribution
Submission containing materials of a third party: Michal Strehovský (@MichalStrehovsky), the author of the original fix in #136265 (commit 53ac1a9), and the .NET Foundation and contributors as identified in the source-file notices. The original code is licensed under the MIT License: https://github.com/dotnet/runtime/blob/main/LICENSE.TXT.
This PR backports that existing fix with the branch-specific adaptations described above; it does not claim ownership of the original work. Original source-file license notices, commit authorship, and upstream commit attribution are retained.
/cc @MichalStrehovsky @agocke
Prepared with assistance from GitHub Copilot.