Fix AV in ICorProfilerInfo2::GetClassLayout for Runtime Async continuation types#131133
Open
UtkarshBandekar wants to merge 2 commits into
Open
Fix AV in ICorProfilerInfo2::GetClassLayout for Runtime Async continuation types#131133UtkarshBandekar wants to merge 2 commits into
UtkarshBandekar wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@dotnet-policy-service agree |
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ICorProfilerInfo2::GetClassLayout()crashes with an access violation whencalled on a
ClassIDthat refers to a dynamically-generated Runtime AsyncContinuation
MethodTable(introduced in #120411). These types have nobacking metadata (
TypeDef/FieldDeftokens), butGetClassLayoutassumesevery field it encounters can be resolved via
FieldDesc::GetMemberDef().For continuation types,
ApproxFieldDescIterator::Next()can return a nullFieldDesc*, and the existing code callsGetMemberDef()on itunconditionally, causing a null-pointer dereference at
field.h:134(
return TokenFromRid(m_mb, mdtFieldDef)).Fixes/relates to #120800.
Root cause
Confirmed via WinDbg on a local repro (
.NET 11.0.0-preview.6.26359.118):!dumpmt /d <ClassID>resolves toContinuation_24_0_1_16_1, withmdToken: 0000000002000000— RID 0, i.e. no real metadata token.MethodTable::IsContinuationWithoutMetadata()/
TypeHandle::IsContinuationWithoutMetadata(), butGetClassLayoutnevercalls it.
mov ecx, dword ptr [rax+8]withrax == 0, insideFieldDesc::GetMemberDefinlined intoProfToEEInterfaceImpl::GetClassLayout+0x15e.profiler heap-walk (
ForceGC→GetClassLayoutcalled per class), so anyprofiler doing a heap snapshot while a Runtime Async continuation is live
will hit this.
Fix
Add an early check for
typeHandle.IsContinuationWithoutMetadata()inProfToEEInterfaceImpl::GetClassLayout, returningCORPROF_E_DATAINCOMPLETE— consistent with how this file already signals "no data available" in
other entrypoints (
GetModuleInfo2,GetRVAStaticAddress,EnumModuleFrozenObjects, etc.).Repro
Minimal repro: suspend an async method mid-await (object live across the
suspension point), then have a profiler call
GetClassLayouton theresulting continuation's
ClassID— e.g. via a full-heap GC snapshot(
ForceGC+ heap walk), which is what triggers it in practice.Testing
src/tests/profiler/exercisingGetClassLayoutagainst a live Runtime Async continuation object.CORPROF_E_DATAINCOMPLETEis returned rather than crashing.