Skip to content

[Interpreter] ResumeAfterCatchException escapes ThrowControlForThread when compiled code raises a thread abort again and an interpreted frame catches it #135532

Closed

Description

@pcshrosbree

TL;DR: With DOTNET_InterpMode=1, a ControlledExecution action that cancels itself crashes the process: ResumeAfterCatchException terminates it on linux-x64 and osx-arm64, and an assert fails on windows-x64. ThrowControlForThread lacks the resume-after-catch handler that IL_Throw and HandleManagedFault install; with that handler added, the windows-x64 shadow-stack search then goes one slot too far. This is separate from #135463.

Description

With DOTNET_InterpMode=1 (user code interpreted, CoreLib compiled), a ControlledExecution action that cancels itself crashes the process:

  • linux-x64 and osx-arm64 (Checked): terminate called after throwing an instance of 'ResumeAfterCatchException'
  • windows-x64 (Checked): an assert in exception handling

The failing case is ControlledExecutionTests.CancelItselfOutsideOfTryCatchFinally, which has been disabled since #122308. This failure is separate from #135463 (fixed by #135520): the case still fails with that fix, and #135520's test does not cover it. I have a fix and will open it as a draft PR stacked on #135520.

var cts = new CancellationTokenSource();
ControlledExecution.Run(() => cts.Cancel(), cts.Token); // expected: OperationCanceledException

Analysis

CancellationTokenSource.Cancel (compiled) catches the ThreadAbortException, and at the end of that catch EECodeManager::ResumeAfterCatch raises it again through ThrowControlForThread. An interpreted frame further up then catches the abort: either ControlledExecution.Run, which translates it, or the user's catch. Resuming in an interpreted frame unwinds the native frames with a C++ ResumeAfterCatchException.

Other places that start a dispatch on top of managed frames (IL_Throw, HandleManagedFault) use INSTALL_RESUME_AFTER_CATCH_HANDLER_WITH_CONTEXT to catch that exception and rethrow it past those frames. ThrowControlForThread does not, so the exception runs into the managed frames the thread was redirected from.

Adding that handler fixes linux-x64 and osx-arm64. On windows-x64 with shadow stacks, the case then hits the assertion *(ULONG64*)targetSSP == pContext->Rip in ExecuteFunctionBelowContext. RethrowResumeAfterCatchExceptionSkipManagedFrames searches for a "precise" SSP on the assumption that the slot below the SSP holds a return address in the context's frame. The SSP that RedirectForThrowControl records belongs to a frame that was interrupted, not stopped at a call, so that slot is stale and the search moves one slot too far. The same mismatch is behind #135530.

Fix

My fix adds the handler and tells it that the context was interrupted, so it uses the SSP as it is. With it and #135520, the case above passes under DOTNET_InterpMode 1, 2 and 3 on linux-x64, osx-arm64 and windows-x64 (Checked, CET enabled on Windows).

Note

This issue was prepared with AI assistance (Anthropic Claude).

Activity

  1. added
    untriaged
    on Oct 9, 2026
  2. dotnet-policy-service commented on Oct 9, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke
    See info in area-owners.md if you want to be subscribed.

  3. dotnet-policy-service commented on Oct 9, 2026

    @dotnet-policy-service
    Contributor

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

  4. added 2 commits that reference this issue on Oct 16, 2026
    bc3b55a
    3b7297c
  5. added a commit that references this issue on Oct 29, 2026
    c6c65e7
  6. removed
    untriaged
    on Nov 2, 2026
  7. added a commit that references this issue on Nov 2, 2026
    f950f7a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions