Repository navigation
JIT: reject method entry inside handlers or filters - #135602
Conversation
IL offset 0 must not lie inside a handler or filter. Entry into these regions is controlled by the exception-handling mechanism (ECMA-335 I.12.4.2.8.1). The tested EntryInFinally, EntryInFault and EntryInCatch methods compile and return on the main Release JIT on linux-x64, while the main Checked JIT asserts 'block->bbRefs == blockRefs' in fgDebugCheckBBlist. On the shipped .NET 10.0.12 runtime on linux-x64, those methods compile and invocation overflows the stack. The tested filter beginning with pop is already rejected by the importer. Reject method entry inside a handler or filter in fgFindBasicBlocks while reading the EH clauses. A handler beginning at offset 0, or a filter beginning at offset 0, contains the method entry. The IL regression test uses RuntimeHelpers.PrepareMethod and requires InvalidProgramException for all four cases without invoking them. Fixes dotnet#135593
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Mono's RuntimeHelpers.PrepareMethod compiles nothing, so this test cannot observe a rejection on Mono: every scenario reports "compiled" and the test returns 101. Mono's handling of these methods is tracked in dotnet#135639: its JIT rejects only EntryInFilter, and its LLVM AOT compiler asserts on EntryInFinally (mini-llvm.c, `handler_bb`), which fails the "AOT compile CoreCLR tests" step of the llvmaot leg. Mark the test ActiveIssue on Mono and MonoAotIncompatible, the same pair that jit64/localloc/ehverify/eh07_large uses for its invalid IL.
… header The project file's MonoAotIncompatible and the ActiveIssue attribute already say why the test is disabled on Mono, so the header comment repeated them.
The Mono runtime-test legs build and run only Priority 0 tests, so the attribute has had no effect since the test became Priority 1. The project file keeps MonoAotIncompatible and the dotnet#135639 link.
|
Also removed the Note This reply was prepared with AI assistance (Anthropic Claude, checked by OpenAI Codex) at my request. I reviewed it before posting. |
|
Following the review on #135827, where the invalid-IL test was dropped: I'm happy to do the same here and keep only the Note This comment was prepared with AI assistance (Anthropic Claude, checked by OpenAI Codex) at my request. I reviewed it before posting. |
|
I think it is ok to take this (for consistency with what's there already), without the tests. |
Drop Runtime_135593 as requested in review. The PR now contains only the new check in fgFindBasicBlocks.
|
Done in 20a08e2. |
|
Thank you for the review and merge! |
IL offset 0 must not lie inside a handler or filter: entry into these regions is controlled by the exception-handling mechanism (ECMA-335 I.12.4.2.8.1). The JIT had no explicit check for this. On linux-x64, the tested
EntryInFinally,EntryInFaultandEntryInCatchmethods compile and return on the main Release JIT, while the main Checked JIT assertsblock->bbRefs == blockRefsinfgDebugCheckBBlist. On the shipped .NET 10.0.12 runtime on linux-x64, those methods compile and invocation overflows the stack. The tested catch and filter variants beginning withpopare already rejected by the importer's stack-underflow check.Change
fgFindBasicBlocksnow rejects the method while reading the EH clauses: a handler that starts at offset 0, or a filter that starts at offset 0, contains the method entry. The check sits next to the existing "end of try/handler beyond end of method" checks and reportsInvalidProgramExceptionthroughBADCODE3like they do.Test
There is no test: it was dropped in review, as on #135827.
Validation
Checked JIT at main 8630d89, baseline vs this change, under
corerun. The measurement used an IL program, since dropped from the PR, with four methods whose first instruction is inside afinally, afault, acatch(one that does not pop, so the entry point is the only defect) and afilter. The program attempted to compile each method throughRuntimeHelpers.PrepareMethod, never calling it, and returned 100 only if all four were rejected. The last column is the test from the PR for #135592:8630d89)Runtime_135592(PR for #135592)block->bbRefs == blockRefs(fgdiagnostic.cpp) onEntryInFinallyblock->bbRefs == blockRefs(fgdiagnostic.cpp) onEntryInFinallyblock->bbRefs == blockRefs(fgdiagnostic.cpp) onEntryInFinallyblock->bbRefs == blockRefs(fgdiagnostic.cpp) onEntryInFinallyblock->bbRefs == blockRefs(fgdiagnostic.cpp) onEntryInFinallyBehaviour of the standalone
EntryInFinally,EntryInFaultandEntryInCatchNoPoprepros from #135593, usingRuntimeHelpers.PrepareMethodfollowed by a call if compilation succeeds, one method per process, on an explicitly selected shipped runtime:EntryInFinallyEntryInFaultEntryInCatchNoPopInvalidProgramExceptionInvalidProgramExceptionInvalidProgramExceptionInvalidProgramExceptionInvalidProgramExceptionInvalidProgramExceptionOn windows-arm64, 11.0.0-preview.5.26302.115 fails all three with
OutOfMemoryExceptionfromPrepareMethod.With the fix, every lane's checked JIT rejects all four methods with
InvalidProgramException, and the release JIT on linux-x64 does too.Resolves #135593
Note
This PR was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.