Repository navigation
[release/11.0] Fix usage of stale GC reference in the InterpreterStub on apple - #136643
Merged
Merged
Conversation
) InterpreterStub needs to obtain the thread information from thread local storage. If this information is null, it will initialize it, process which could trigger a GC. Transition frames have references precisely scanned from the allocated transition block. After a call which can trigger a GC, the stub will need to reload the argument registers from the transition block preventing usage of potentially stale references. On Apple, this stub has the optimization of pushing the argument regs only on the slowpath. Here is the pseudocode of the stub logic, for the APPLE targets: ``` InterpreterStub() Save regs except the argument regs x22 = x0; x20 = get_thread_from_tls # this dirties x0 if (x20 && x20->m_pInterpThreadContext) goto HaveInterpThreadContext; NoManagedThreadOrCallStub: x0 = x22; # save argument regs to the TransitionBlock # call GetInterpThreadContextWithPossiblyMissingThreadOrCallStub # restore argument regs from TransitionBlock HaveInterpThreadContext: x0 = x22; # continue with calling code ``` x22 was holding the original x0 value. Following the slowpath, x22 should have been updated to hold the new x0 value restored from the TransitionBlock. As a simpler fix, we just do the x22 tmp usage around the tls access, making the code more intuitive. Wasn't able to reproduce the bug with a standalone repro. Forced the repro by compiling `Main` with r2r. `Main` would do some fragmented allocation (so that a moving compaction is triggered), then allocate the object argument passing it to the interpreted method. Forcefully triggering GC inside the runtime on this slowpath reproduced the bug with 100% determinism. (running also under DOTNET_HeapVerify=1, so that the stale reference points to garbage as well). Fixes #136472
|
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 |
BrzVlad
approved these changes
Oct 29, 2026
Member
|
Hi, the code complete date for 11.0.1 (the December 2026 release) is Monday 16 November. Make sure to merge this PR on that date at the latest, or it won't make it into that release. As a reminder, if this is a product change, you also need Tactics approval before merging this PR (test-only or infra-only changes don't require Tactics approval). Happy to help with the merge if needed! |
Member
|
@ViveliDuCh This change was approved with tactics, failures are unrelated. Please merge. |
Member
|
/ba-g unrelated failure |
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 #136518 to release/11.0
/cc @BrzVlad
Customer Impact
When running on iOS, when R2R calls an interpreter method for the first time, there is a chance for the interpreter method to receive a stale
thispointer, if the object is moved by the GC.Regression
This is happens with CoreCLR on iOS which is a new configuration, regressing from mono.
Testing
Reproduced the issue locally by forcing a compacting and clearing GC to happen at the problematic time. Validated that behavior is correct with this fix. User provided a more complex repro, but I was unable to easily reproduce the crash with it.
This appears to fix also some flaky failures on interpreter CI, which I wasn't able to reproduce and confirm until recently.
Risk
Low. Fix is small and targeted. It prevents restoring a register in the interpreter stub with a value from a location that the GC doesn't keep track of.