Skip to content

JIT: Fix patchpoint info out-of-bounds read for special OSR locals#125378

Merged
jakobbotsch merged 2 commits intodotnet:mainfrom
jakobbotsch:fix-125255
Mar 10, 2026
Merged

JIT: Fix patchpoint info out-of-bounds read for special OSR locals#125378
jakobbotsch merged 2 commits intodotnet:mainfrom
jakobbotsch:fix-125255

Conversation

@jakobbotsch
Copy link
Copy Markdown
Member

genEnregisterOSRArgsAndLocals was not properly handling computing the stack offset for special OSR locals like MonitorAcquired and the async contexts. It meant that if these ended up enregistered we would hit an out-of-bounds when trying to obtain their offset.

Fix #125255

This was a regression introduced by #121672 which started marking these 3 locals as OSR locals. Before that we only had MonitorAcquired, and I suspect that one was never enregistered, so even though it was not handled by genEnregisterOSRArgsAndLocals that was never a problem. However, the async contexts can be enregistered in the OSR function so they do need to be handled here.

Copilot AI review requested due to automatic review settings March 10, 2026 12:14
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 10, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an OSR JIT crash caused by computing tier0 stack offsets for special OSR locals (MonitorAcquired and async context locals) using the normal patchpoint local-offset table, which can lead to out-of-bounds reads when those locals are enregistered.

Changes:

  • Introduced Compiler::lvaOSRLocalTier0FrameOffset to centralize tier0 frame offset lookup for OSR locals, including special-case locals.
  • Updated OSR virtual frame offset assignment and OSR enregistration initialization to use the new helper instead of PatchpointInfo::Offset.
  • Removed duplicated special-local offset logic from lvaAssignVirtualFrameOffsetsToLocals.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/lclvars.cpp Uses the new helper for tier0 frame offset computation (including promoted fields) to avoid OOB reads.
src/coreclr/jit/compiler.h Declares lvaOSRLocalTier0FrameOffset.
src/coreclr/jit/compiler.cpp Implements the helper with explicit handling for special OSR locals and bounds assertions for normal locals.
src/coreclr/jit/codegencommon.cpp Uses the helper when initializing enregistered OSR locals from the tier0 frame.

Comment thread src/coreclr/jit/lclvars.cpp
@jakobbotsch
Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

No diffs.

@jakobbotsch jakobbotsch requested a review from AndyAyersMS March 10, 2026 16:15
Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that this never came up before.

@jakobbotsch jakobbotsch merged commit 2a4ede4 into dotnet:main Mar 10, 2026
131 checks passed
@jakobbotsch jakobbotsch deleted the fix-125255 branch March 10, 2026 16:49
Copilot AI pushed a commit that referenced this pull request Mar 13, 2026
…125378)

`genEnregisterOSRArgsAndLocals` was not properly handling computing the
stack offset for special OSR locals like `MonitorAcquired` and the async
contexts. It meant that if these ended up enregistered we would hit an
out-of-bounds when trying to obtain their offset.

This was a regression introduced by #121672 which started marking these
3 locals as OSR locals. Before that we only had `MonitorAcquired`, and I
suspect that one was never enregistered, so even though it was not
handled by `genEnregisterOSRArgsAndLocals` that was never a problem.
However, the async contexts can be enregistered in the OSR function so
they do need to be handled here.
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test Failure: System.Net.Http.WinHttpHandler.Functional.Tests

3 participants