-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix AV in IsTailCall by checking for NULL trace address #123640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Modified InitForMulticastDelegateHelper() and InitForExternalMethodFixup() to accept a PCODE addr parameter instead of setting address to NULL. This fixes the invariant that GetAddress() works for non-TRACE_UNJITTED_METHOD types. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a broken invariant in the TraceDestination class where GetAddress() should return a valid PCODE for all trace types except TRACE_UNJITTED_METHOD. PRs #108942 and #108414 introduced two new trace types (TRACE_MULTICAST_DELEGATE_HELPER and TRACE_EXTERNAL_METHOD_FIXUP) that incorrectly set address = NULL, causing null reference exceptions in debugger code.
Changes:
- Updated
InitForMulticastDelegateHelperandInitForExternalMethodFixupto accept a PCODE address parameter - Modified both call sites to pass
stubStartAddressinstead of leaving the address as NULL - Ensures the invariant that all non-
TRACE_UNJITTED_METHODtrace types have valid addresses
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/vm/stubmgr.h | Added PCODE addr parameter to InitForMulticastDelegateHelper and InitForExternalMethodFixup methods, and updated both to assign the address to this->address |
| src/coreclr/vm/stubmgr.cpp | Updated call sites in RangeSectionStubManager::DoTraceStub and ILStubManager::DoTraceStub to pass stubStartAddress to the Init methods |
|
I do not think stubStartAddress is meaningful in the case of InitForExternalMethodFixup. It will fall in here runtime/src/coreclr/vm/codeman.cpp Line 6450 in 061f153
runtime/src/coreclr/vm/codeman.cpp Line 6688 in 061f153
runtime/src/coreclr/vm/jitinterface.cpp Line 15181 in 061f153
|
|
fyi @lateralusX These TraceDestination addresses became NULL by-design as part of Johan's changes to the stubmanager. Although we could potentially put a non-NULL address in that fields I think we'd need to decide what that address is supposed to mean. Right now if you call TraceStub/FollowTrace the TraceDestination you get back has three potential meanings:
Putting the stubStartAddress in the TraceDestination field doesn't line up with how case (3) uses the address and none of the other cases are intended to use the address at all. Checking the address for NULL in IsTailCall() would resolve the immediate AV issue but I suspect we may also have a tailcall stepping issue as well. In particular if ReadyToRun image A has method Foo1() which tailcalls to Foo2() then Foo1() probably has a call to one of the tailcall helpers at the end that might be indirected through an ExternalMethodFixup. The code of IsTailCall() assumes that given the call IP we can immediately determine the destination MethodDesc that will be invoked but that isn't something the StubManager for ExternalMethodFixup figures out immediately. We'd need to redesign something to make that work. I think it would be fine to fix the AV now and file a separate issue about tail-call stepping correctness in ReadyToRun assemblies. |
I was not part of the original design/change, but I have been working on a rewrite of those changes + adding some more stubs, but none of that work has been merged yet (put it on hold in favor for other work): Since putting the tracepoint address to NULL in the stub manager scenario was by design, it is also carried over into my rewrite above, but that includes a change in IsTailCall to detect when we have TRACE_TRACEPOINT, so it would not hit the issue accessing NULL trace.GetAddress in IsTailCall. If that hits other stepping issues is currently unknown, like described above, but that would at least have prevented the crash. I know we discussed fixing the IsTailCall in the past by checking !trace.GetAddress() and return false. I agree that we should implement that fix now and then look at potential stepping issues when continue working on the rewrite of this implementation in the branch above. |
|
@copilot , address the feedback. Revert the current changes adding the stub address to the trace types and fix the AV bug in IsTailCall. Open an issue to track the bug in IsTailCall not respecting certain cross R2R image calls. |
Reverted changes to stubmgr.h and stubmgr.cpp since NULL addresses are by-design for TRACE_MULTICAST_DELEGATE_HELPER and TRACE_EXTERNAL_METHOD_FIXUP. Instead, fixed the AV bug in IsTailCall (controller.cpp) by checking if trace.GetAddress() returns NULL before calling GetNativeCodeMethodDesc. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Reverted the stubmgr changes and fixed the AV in Note: I cannot open GitHub issues from this environment. Please create an issue to track the tail-call stepping correctness bug for cross ReadyToRun image calls. |
|
@copilot , address build failure |
PCODE is unsigned long and cannot be compared directly to NULL (std::nullptr_t). Updated the comparison to use (PCODE)NULL to match existing patterns in the codebase. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
... Fixed the build error by using |
|
/ba-g Test failures are unrelated |
Description
PRs #108942 and #108414 introduced
TRACE_MULTICAST_DELEGATE_HELPERandTRACE_EXTERNAL_METHOD_FIXUPtrace types that setaddress = NULL. This caused null reference exceptions inIsTailCall(controller.cpp) when callingGetNativeCodeMethodDesc()with a NULL address.Per reviewer feedback, the NULL addresses for these trace types are by-design:
TRACE_MULTICAST_DELEGATE_HELPERandTRACE_EXTERNAL_METHOD_FIXUPuse callbacks that pass content toTraceManager()to determine where execution will go nextChanges
IsTailCallinsrc/coreclr/debug/ee/controller.cppto check iftrace.GetAddress()returns NULL before callingGetNativeCodeMethodDesc()Note: There may be a separate tail-call stepping correctness issue for cross ReadyToRun image calls that should be tracked in a separate issue.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.