Repository navigation
Description
Description
A long-running desktop app (Avalonia 12, Win32 windowing backend) reliably fail-fasts with a runtime-raised System.ExecutionEngineException (HRESULT 0x80131506, faulting module coreclr.dll) every ~8–80 minutes of idle/normal use. The exception is raised by the runtime itself from Debugger::HandleFatalError → RaiseFailFastException, so it bypasses AppDomain.UnhandledException and cannot be caught.
Using DOTNET_StressLog=1 + a full minidump (DOTNET_DbgEnableMiniDump=1, DbgMiniDumpType=4) I captured the runtime's own fatal-event trail across three independent crashes. All three show the same mechanism: the GC's thread-suspension / return-address-hijack machinery raises the fatal error while suspending a thread stopped at a non-fully-interruptible JIT point (fullyInt=0), while the main UI thread is being GC-root-scanned inside the Win32 message pump's DispatchMessage(MSG) P/Invoke frame, during a routine (not pressure-driven) GC.
Disabling CET (<CetCompat>false</CetCompat>) stops the crash completely (confirmed by a 2+ hour soak — see below), which strongly implicates CET hardware shadow-stack enforcement colliding with the GC's return-address hijack.
Frequency / Severity
- Reproduces every ~8–80 minutes of runtime. Fatal (process dies); no managed handler can intercept.
- Reproduced across two different builds of the app and two render modes (GPU/ANGLE and CPU/software) — 3 captured dumps total.
StressLog — the fatal sequence (representative; identical shape in all 3 dumps)
<tid> <ts> : SYNC Stopped in Jitted code at pc=... sp=... fullyInt=0
<tid> <ts> : SYNC Hijacking return address ... for thread ...
<tid> <ts> : CORDB D::HFE: About to call LogFatalError <-- FATAL
<tid> <ts> : EH SetLastThrownObject: obj=... (ExecutionEngineException)
<tid> <ts> : CORDB D::RFFE: About to call RaiseFailFastException <-- FAIL-FAST
<tid> <ts> : SYNC Thread::SuspendAllThreads() - Success
- Exactly one fatal event per crash. Thrown object is the
System.ExecutionEngineExceptionsingleton (same MethodTable across all 3 crashes),_message=null,HResult=0x80131506, exception code0xE0434352→ runtime-raised, not a managedthrow. - At every
SuspendAllThreads(including the fatal one), the main UI thread showsScanning Frameless method IL_STUB_PInvoke(MSG ByRef)— i.e. it is parked in the Win32GetMessage/DispatchMessage(MSG)P/Invoke and being root-scanned. - The thread being hijacked at the fatal moment varies by crash and is doing ordinary work:
- Crash A: main UI thread mid-
Measure(layout). - Crash B: a non-main thread.
- Crash C: a thread inside
System.DateTimeOffset.ValidateOffset/..ctor— pure CoreLib, no app/render frames (a periodic timer's timestamp path).
- Crash A: main UI thread mid-
- The GC at the fatal point is routine: e.g. Crash C was
BEGINGC ... requested generation = 1— an ordinary periodic gen-1, ~1 GC / 4 s, ~35 MB heap.
Minimal characterization of the invariant
During a routine GC, while the main UI thread is suspended inside the Win32
DispatchMessage(MSG)P/Invoke frame being root-scanned, the runtime hijacks the return address of another thread stopped at afullyInt=0JIT point and immediately entersDebugger::HandleFatalError→ raisesExecutionEngineException→RaiseFailFastException.
The hijack-victim thread's work is incidental (layout in one crash, DateTimeOffset ctor in another) — the constant is the suspend/hijack step itself faulting, with the pump P/Invoke frame present in the root scan.
Disabling CET stops it — confirmed
- Building the app with
<CetCompat>false</CetCompat>(opts the exe out of CET shadow stacks; apphost PECET_COMPATbit verified flipped 1→0 viadumpbin /headers) eliminates the crash: the CET-off build ran 125+ minutes with zero EEE and was still healthy, versus an 8–80 minute crash baseline on every CET-on build (3 dumps, 2 binaries, GPU and software render). - This points at CET hardware shadow-stack enforcement as the trigger: a GC return-address hijack sets a thread's return address to a stub that is not on the shadow stack, which CET treats as a control-flow violation and terminates the process. The runtime has a CET-safe suspension path using special user-mode APCs (
QueueUserAPC2); this looks like a case where the hijack path is taken while shadow stacks are active. <CetCompat>false>is a usable mitigation but disables a security feature for the whole process — an in-runtime fix (always take the CET-safe suspension path when shadow stacks are enabled) would be preferable.
Ruled out (with evidence)
- GPU / Skia / ANGLE render path — exonerated. Forced CPU software rendering (no
av_libGLESv2.dll/av_libEGL.dll/nvwgf2umx.dll/d3d11.dll/dxgi.dll/opengl32.dll/vulkan-1.dllloaded — verified by module-list diff vs the GPU-mode dumps) still crashed with the identical mechanism in ~8 min, on a thread doingDateTimeOffsetconstruction with zero render frames. - Allocation pressure — exonerated. Fatal GCs are routine periodic gen-0/gen-1 at ~1/4 s with a ~35 MB heap; a low-allocation run crashed faster than a high-allocation one. No GC heap corruption (
verifyheapclean). - Application exception storm — exonerated. An earlier high-rate
InvalidDataExceptionstorm (an app-side deserialization bug, unrelated to the runtime) was fixed; with it gone (InvalidDataException= 0 across a 273 MB StressLog) the EEE still reproduced. Background exception rate at crash is ~1/8 s, not a storm.
Environment
- .NET: 10.0.8 (DAC 10.0.826.23019)
- OS: Windows 11, build 26200 (x64)
- UI framework: Avalonia 12, Win32 windowing backend, classic desktop lifetime, single-threaded WPF-style UI message pump
TieredCompilationalready disabled; reproduces with and without tiering knobs.- App is mostly idle at crash time (periodic timers + UI message pump + routine GC).
Possibly related
- WinForms Desktop application (.NET 8 & .NET 9) crashes randomly with corclr.dll errors #112598 — WinForms + WebView2 (Win32 message pump + native interop), random
0x80131506/coreclr.dll/0xc0000005, 1–10 min after launch, worse with more RAM, escalated after Windows 11 24H2. Open,tracking-external-issue, no working workaround. Closest match; the 24H2 correlation implicates the OS CET/shadow-stack/APC change. - .net8 ver8.0.8 Desktop Crash 0x80131506 #108118 — ElementHost / WinForms sibling crash (same family).
- Intermittent
!AreCetShadowStacksEnabled() || UseSpecialUserModeApc()assertion when embedding CoreCLR #83437 — the runtime assertion!AreCetShadowStacksEnabled() || UseSpecialUserModeApc()(encodes "shadow stacks on ⇒ must be on the special-APC suspension path"). - dotnet/core AssemblyLoadContext.Unloading is not called when TERM signal sent to application #6733 —
QueueUserAPC2faults on older CPUs (the CET-safe APC path's own failure mode).
Repro assets available on request
- 3 full minidumps (Type=4) with armed StressLog (
DOTNET_StressLog=1, 128 MB/thread ring); the two storm-free dumps are cleanest (~273 MB each, can be trimmed to the fatal window). clrstack/clrthreads/threads/ module-list captures per dump.
Questions for the runtime team
- Is this a known issue in the return-address hijack /
EEPolicy::HandleFatalErrorpath on Windows when a thread is suspended at afullyInt=0point while another thread'sIL_STUB_PInvoke(MSG ByRef)frame is being root-scanned? - CET: when shadow stacks are enabled, under what conditions can the GC take the hijack suspension path (return-address overwrite) instead of the CET-safe
QueueUserAPC2path? We've confirmed<CetCompat>false>stops the crash — is that the recommended mitigation on 10.0.8, or is an in-runtime fix planned? - Do any suspension-timing knobs change time-to-crash as a race corroborator:
DOTNET_gcServer=1,DOTNET_GCgen0size=<larger>,DOTNET_TieredPGO=0,DOTNET_JITMinOpts=1? (DOTNET_ThreadSuspendInjectionis Unix-only and does not apply on Windows.) - Is there a recommended mitigation for desktop apps on 10.0.8 short of pinning an earlier runtime, other than opting out of CET?
Suggested areas: area-VM-coreclr, area-GC-coreclr.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
jkotas commentedon Jun 6, 2026
It is not a known issue.
Return-address overwrite is CET safe thanks to
RtlGetReturnAddressHijackTargetWindows API.We cannot tell without understanding the root cause. While opting out of CET makes your test work, it does not mean that it is reliable workaround.
It would be great if you can open an issue at http://developercommunity.visualstudio.com/, attach the crash dumps to it as private attachments, and share the link here.
dotnet-policy-service commentedon Jun 8, 2026
Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jun 8, 2026
This issue has been marked
needs-author-actionand may be missing some important information.janvorli commentedon Jun 8, 2026
The return address hijacking (via the CET safe mechanism exposed by Windows as @jkotas mentioned above) is used when the user APC handler finds that the location where the APC interrupted the thread is in managed code and it is not a GC safe (interruptible) point and it is not in a method epilog. See the HandleSuspensionForInterruptedThread.
dotnet-policy-service commentedon Oct 14, 2026
This issue has been automatically marked
no-recent-activitybecause it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will removeno-recent-activity.epurdy-ss commentedon Oct 14, 2026
We hit what may be the same failure family (
0x80131506, access violations, around return-address hijacking) and traced ours to a root cause, with a small repro and a workaround. Posting it here in case it explains this issue; glad to open a separate issue instead if you prefer.Summary
On x64 Windows, a GC return-address hijack can be written into the caller's frame instead of the return-address slot. It happens when the thread is stopped inside a JIT'd epilog that ends in
jmp qword ptr [abs32](FF 24 25 disp32, no REX.W). The unwinder does not recognise that encoding as an epilog, treats the IP as method body, and returns a return-address slot that is too high by whatever the epilog had already popped. The runtime then writes the hijack stub address (OnHijackTripThread) over a live slot in the caller. Depending on what that slot held, we saw a corrupted local (the stub's low 16 bits,0x3720, read back as data),Internal CLR error (0x80131506), and access violations during marking.Two defects that meet
src/coreclr/jit/emitxarch.cpp, theIF_METHPTRpath emits a tail call through a call cell whose address fits in 32 bits asFF 24 25 disp32with no REX.W. The otherINS_tail_i_jmpforms getAddRexWPrefix("Tailcall with addressing mode/register needs to be rex.w prefixed to be recognized as part of epilog by unwinder"); this path does not (still the case onmaintoday). A native harness that callsRtlVirtualUnwindon a frame stopped at each instruction of each epilog form the JIT emits:ret,E9,FF 25,48 FF 25,48 FF E0,48 FF 60 18,49 FF 23and48 FF 24 25all unwind to the right caller; forFF 24 25, after theadd rsp, 56and each of the four pops, the caller's SP comes back 56, 64, 72, 80 and 88 bytes too high.coreclr.dlland reached RIP-relative (FF 25, which unwinds fine). With W^X enabled, the scan inReserveDoubleMappedMemory(src/coreclr/minipal/Windows/doublemapping.cpp) can step over a DLL image to the image's end, which is page-aligned but rarely 64 KB-aligned, so the followingMapViewOfFileExattempts at those addresses fail even through free space.ExecutableAllocator::Reservethen drops its hint and reserves bottom-up, below 2 GB, where a cell's address fits in 32 bits and the JIT picksFF 24 25. In our test hosts this happened about 1.3 s after start (around the load ofSystem.Text.RegularExpressions.dll).Evidence
DOTNET_StressLog=1, suspension and hijack records), checked against its full dump: 2,211 hijacks. 2,189 replaced a value preceded by a call instruction (a real return address); 22 replaced something else (zeros, GC heap pointers). All 22, and none of the 2,189, were taken with the thread stopped in an epilog ending inFF 24 25.DOTNET_FastTailCalls=0: 1,845 hijacks, none misplaced, and no such epilog anywhere.Repro
152 lines of safe C# (the two P/Invokes only query and reserve address space), in a
dotnet new consoleproject targetingnet10.0.Squeeze()reserves (never commits) the free address space within 2 GB ofcoreclr.dll, so the allocator falls back at once;Burn(2000)compiles 2,000 emitted methods so the next code and precode reservations happen after that; then one thread keeps 256 bytes of known values in its own frame and, in a tight loop, calls a method whose epilog pops every callee-saved register and tail-calls through its callee's precode slot, while another thread allocates so the GC keeps suspending it. The squeeze is only a shortcut: our crashing processes had nothing like it and reached the below-2 GB layout on their own (about 1.3 s after start, as above), and in a run of our real application path on 8 threads, 2 of 4 processes got there within seconds.On .NET 10.0.12 (SDK 10.0.401), Windows 11 Pro 24H2 (build 26100), x64, workstation GC, 10 s per run:
dotnet run -c Release(three runs)0x00007FFBB03E3720=coreclr.dll+ 0x183720, the hijack stubDOTNET_FastTailCalls=0-- --no-squeeze(cells stay nearcoreclr.dll,FF 25)A longer probe of ours also reproduces it under server GC.
Program.cs
Workaround
DOTNET_FastTailCalls=0: the JIT emits no fast tail calls, so no JIT'd epilog ends in a jump. No measurable cost in our workloads, and our application's output is byte-identical with it.Relation to this issue
Your trail (
Stopped in Jitted code ... fullyInt=0, thenHijacking return address, then the fatal error) has the same shape. We have not checked which suspension path our repro took, or whether CET was active. @janvorli's note says the hijack is used when the interrupted IP "is not in a method epilog"; if that check relies on the same epilog recognition as the unwinder, anFF 24 25epilog would pass it. Two cheap checks on your side: whether thepcof the fatalStopped in Jitted coderecord lies in an epilog ending inFF 24 25 <disp32>, and whetherDOTNET_FastTailCalls=0stops the crash with CET left on.6 remaining items
dotnet-policy-service commentedon Nov 2, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jkotas commentedon Nov 2, 2026
This is invalid x64 epilog emitted by the JIT.
https://learn.microsoft.com/cpp/build/prolog-and-epilog says "Only a subset of jmp statements are allowable in the epilog. The subset is exclusively the class of jmp statements with ModRM memory references where ModRM mod field value is 00" though I do not think that's quite right. The unwinder implementation looks for REX prefix:
runtime/src/coreclr/unwinder/amd64/unwinder.cpp
Lines 1400 to 1413 in 7f4a969
epurdy-ss commentedon Nov 2, 2026
By the way, I didn't mean to hijack the issue. When I was first looking into it, it seemed likely that it could be related to the OP. Following the ASLR finding, our case is probably separate from the original crash here: ours reproduces with CET on or off, while the original report is cured by false.
I don't know if you want to split this now or something.
jkotas commentedon Nov 2, 2026
We can use this issue to track fixing the invalid epilog. OP did not have enough information to root cause the problem.
[-]ExecutionEngineException fail-fast in GC thread-suspension / return-address hijack while root-scanning a Win32 message-pump P/Invoke frame (.NET 10.0.8, Windows, Avalonia desktop)[/-][+]ExecutionEngineException fail-fast in GC thread-suspension / return-address hijack (invalid tailcall epilog)[/+]