Skip to content

Add null check in LCGMethodResolver::GetManagedResolver#124457

Merged
leculver merged 3 commits intodotnet:mainfrom
leculver:issue_1837
Feb 17, 2026
Merged

Add null check in LCGMethodResolver::GetManagedResolver#124457
leculver merged 3 commits intodotnet:mainfrom
leculver:issue_1837

Conversation

@leculver
Copy link
Contributor

SOS's dumplog hits a crash when calling GetManagedResolver, because it can see a null m_managedResolver handle in diagnostic code that we wouldn't normally run into in the runtime. This avoids the crash while writing out the stresslog.

I took a look at the callsites of the function, some of them do not check that the return value isn't null...but this change is safe simply because we would have been crashing on return ObjectFromHandle(m_managedResolver); anyway if this were a problem. I don't think we need an assert at those callsites, but happy to add them if requested.

@jkotas fixes the issue you filed here: dotnet/diagnostics#1837

@leculver leculver requested review from Copilot and jkotas February 16, 2026 09:30
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 16, 2026
Copy link
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

Prevents SOS dumplog from crashing when it encounters an LCGMethodResolver instance with a null m_managedResolver handle during diagnostic/stresslog processing, by making GetManagedResolver() safely return NULL in that case.

Changes:

  • Add a null-handle guard in LCGMethodResolver::GetManagedResolver() before calling ObjectFromHandle(m_managedResolver).

@jkotas
Copy link
Member

jkotas commented Feb 16, 2026

fixes the issue you filed here

Is this fixing the issue or just making it less likely for a crash like that to happen? I think it is the later.

Copilot AI review requested due to automatic review settings February 16, 2026 15:13
Copy link
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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@github-actions github-actions bot added area-VM-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 16, 2026
@leculver
Copy link
Contributor Author

leculver commented Feb 16, 2026

My understanding is:

  1. These objects are allocated on the LoaderHeap, so we generally won't free this chunk of memory.
  2. Freeing one of these adds it to a free list and zeros it. In that case, we'll see a null value here.
  3. It's possible it could be reused, at which point it will either be null (as it's being initialized) or some different method, which is misleading but not crashing. (Reused the object I believe, I don't think this goes into a general memory buffer pool so we'd read a different field/different type. We'd still be operating on the same m_managedResolver field but maybe on a different iteration.)
  4. DacValidateMD is not foolproof, but in addition to the above, the md pointer we pass in needs to round trip from md -> mt -> md slot -> md, and all of that has to be valid memory (iirc).

So, we either fail DacValidateMD, or we make it to where this change is made and either get a nullptr or the wrong methoddesc from something eating that slot.

As best I can tell, that's preventing the crash, though it wouldn't prevent us from reporting the wrong lcg if the slot is reused. (Or if there's a window in here we might crash it's being greatly reduced to nearly never.)

Assuming I got all of the above right, I can't think of anything that would be a more complete fix without a much bigger lift here. (And that's a big assumption. :)) This all relies on a lot of implementation detail that could change at any time, but that's true of a lot of what SOS/Dac does...

I'm happy to take this in a different direction if you have a different idea of what a fix might look like?

Thanks for the feedback on this and other issues! I'm trying to ramp back up on doing actual runtime work after a long break, and I'm definitely a bit rusty.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Feb 16, 2026

These objects are allocated on the LoaderHeap, so we generally won't free this chunk of memory.

Nit: We would free this memory if the dynamic method was attached to collectible module.

DacValidateMD is not foolproof

Right. Also, DAC APIs are wrapped in SEH handlers on Windows that allows us to swallow crashes like this one. SEH is not a thing on non-Windows, we depend on a combination of luck and workarounds like the one added in this PR to avoid crashes.

Hopefully, we will be able to get rid of these problems by switching to cDAC in not-too-distant future.

@leculver leculver enabled auto-merge (squash) February 17, 2026 01:06
leculver and others added 3 commits February 17, 2026 12:59
…GSEGV

When running 'dumplog' on a crash dump containing dynamic/LCG methods with
a null m_managedResolver handle, ObjectFromHandle(0) dereferences a null
pointer. On Windows, SEH catches this; on Linux/lldb, it causes a SIGSEGV
that crashes the debugger.

Fixes dotnet/diagnostics#1837

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@leculver leculver merged commit 3fbc6d0 into dotnet:main Feb 17, 2026
100 of 102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments