Skip to content

Fix iOS arm64 CoreCLR crash from shared MethodDesc::CalliCookie slot#127876

Open
kotlarmilos wants to merge 3 commits intodotnet:mainfrom
kotlarmilos:fix/interp-calli-cookie-conflict
Open

Fix iOS arm64 CoreCLR crash from shared MethodDesc::CalliCookie slot#127876
kotlarmilos wants to merge 3 commits intodotnet:mainfrom
kotlarmilos:fix/interp-calli-cookie-conflict

Conversation

@kotlarmilos
Copy link
Copy Markdown
Member

@kotlarmilos kotlarmilos commented May 6, 2026

Problem

PR #127016 updated MethodDescCodeData::CallStub added a new writer in CInterpreterJitInfo::GetCookieForInterpreterCalliSig that caches a calli signature CallStubHeader* on the P/Invoke target MethodDesc.

PR #127016 added a small "calli cookie" cache. Each managed method has one slot where this cookie is stored. The problem is that two different parts of the runtime now write to that one slot:

  • The interpreter-to-native call path stores a helper that's set up for the method's own signature
  • The new code in [wasm][coreclr] Cache calli cookies #127016 stores a helper that's set up for the signature of a calli instruction inside an IL stub.

On iOS, when an app tries to execute address 0 the kernel does not give us a normal crash. It assumes the page is unsigned/tampered and kills the process with SIGKILL and a CODESIGNING / Invalid Page reason.

Proposed fix

Drop the new pContextMD->{Set,Get}CalliCookie cache reads/writes in CInterpreterJitInfo::GetCookieForInterpreterCalliSig. The function now always computes the cookie via GetCookieForCalliSig(sig, pContextMD), matching pre-#127016 behavior.

Fixes #127869 #127863 #127867

PR dotnet#127016 added a new writer to MethodDescCodeData::CalliCookie in
CInterpreterJitInfo::GetCookieForInterpreterCalliSig that caches a
per-calli-signature CallStubHeader* on the P/Invoke target MethodDesc.

The same slot already has writers/readers that key on different
signatures (UpdateCallStubForMethod for InvokeManagedMethod /
InvokeDelegateInvokeMethod, and the FEATURE_PORTABLE_ENTRYPOINTS
INTOP_CALLI path / wasm/helpers.cpp using MetaSig(targetMethod)).
First-writer-wins meant later readers dispatched through an
incompatible Routines array and CallJittedMethodRetI8 jumped to a
PCODE 0 entry. On iOS arm64 device this surfaces as
EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE at 0x0 → CODESIGNING /
Invalid Page → SIGKILL (CS_KILL on app-bundle processes).

Drop the pContextMD->{Set,Get}CalliCookie reads/writes in
GetCookieForInterpreterCalliSig. The function now always computes the
cookie via GetCookieForCalliSig(sig, pContextMD), matching pre-dotnet#127016
behavior. pContextMD is still passed so Swift calling-convention
detection is preserved.

Fixes dotnet#127869 (and the duplicates dotnet#127863 / dotnet#127867).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

@kotlarmilos kotlarmilos marked this pull request as ready for review May 6, 2026 17:14
@kotlarmilos kotlarmilos added this to the 11.0.0 milestone May 6, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 6, 2026

Github does not allow me to comment on this PR inline for some reason (hitting internal github errors).

A better wording of the comment:

    // Do not cache the cookie on pContextMD: MethodDesc::CalliCookie is for
    // calling the target via managed calling convention. The stub we are about
    // to generate calls the target via unmanaged calling convention.

Comment thread src/coreclr/vm/jitinterface.cpp Outdated
@kotlarmilos kotlarmilos enabled auto-merge (squash) May 6, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS][interp] Null calli target in MethodBaseInvoker.InvokeWithOneArg

2 participants