Skip to content

[release/11.0] Fix usage of stale GC reference in the InterpreterStub on apple - #136643

Merged
akoeplinger merged 1 commit into
release/11.0from
backport/pr-136518-to-release/11.0
Nov 16, 2026
Merged

akoeplinger merged 1 commit into
release/11.0from
backport/pr-136518-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #136518 to release/11.0

/cc @BrzVlad

Customer Impact

  • Customer reported
  • Found internally

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 this pointer, if the object is moved by the GC.

Regression

  • Yes
  • No

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.

)

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

Copy link
Copy Markdown
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.

@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.

@BrzVlad BrzVlad added the Servicing-consider Issue for next servicing release review label Oct 29, 2026
@BrzVlad BrzVlad added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 29, 2026
@ViveliDuCh

Copy link
Copy Markdown
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!

@BrzVlad

BrzVlad commented Nov 16, 2026

Copy link
Copy Markdown
Member

@ViveliDuCh This change was approved with tactics, failures are unrelated. Please merge.

@akoeplinger

Copy link
Copy Markdown
Member

/ba-g unrelated failure

@akoeplinger
akoeplinger merged commit 31ebcd7 into release/11.0 Nov 16, 2026
123 of 129 checks passed
@akoeplinger
akoeplinger deleted the backport/pr-136518-to-release/11.0 branch November 16, 2026 14:56
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.

3 participants