Skip to content

Commit 0b9fe0c

Browse files
committed
Read interpreter slots as raw Object pointers
On a Checked build the OBJECTREF copy constructor and operator-> validate the address they read from against Thread::dangerousObjRefs. Interpreter stack slots are reported to the GC through the interpreter's GC info and are written and reused without the checked OBJECTREF lifecycle, so an entry the table holds for one of those addresses (here left by GCFrame::Remove after CreateCustomAttributeInstance unregistered its argument storage, then marked at a possible GC point) is tripped by a later, unrelated read: Thread::IsObjRefValid(this) asserts in OBJECTREF::operator-> at an interpreted virtual call. Read and write object references in interpreter stack slots as raw Object pointers (LOCAL_VAR_OBJREF / SET_LOCAL_VAR_OBJREF), converting to and from native OBJECTREF locals, which keep the usual checking; do the same in InterpreterCodeManager::GetInstance and in the debugger's function-evaluation argument read, whose address can be an interpreter slot. The two paths that passed a slot's address as an OBJECTREF* to GetMethodDescOfVirtualizedCode (the CALLVIRT dispatch-cache miss and the open virtual delegate resolution) pass a GC-protected native local instead. The slot-access conversions preserve Release behavior; virtual call target resolution now protects a native receiver local in all runtime builds. Restore GCFrame::Remove, which an earlier revision of this change had altered, and update the regression test's explanation. Fix #135535
1 parent 6918cfe commit 0b9fe0c

6 files changed

Lines changed: 112 additions & 87 deletions

File tree

‎src/coreclr/debug/ee/funceval.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,9 @@ static void GCProtectAllPassedArgs(DebuggerEval *pDE,
15351535
}
15361536
else
15371537
{
1538-
pObjectRefArray[currArgIndex] = *((OBJECTREF *)CORDB_ADDRESS_TO_PTR(pFEAD->argAddr));
1538+
// The address can be an interpreter stack slot, which is not viewed through a checked OBJECTREF
1539+
// (see LOCAL_VAR_OBJREF in interpexec.cpp): read it as a raw pointer.
1540+
pObjectRefArray[currArgIndex] = ObjectToOBJECTREF(*((Object **)CORDB_ADDRESS_TO_PTR(pFEAD->argAddr)));
15391541

15401542
INDEBUG(pDataLocationArray[currArgIndex] |= DL_ObjectRefArray);
15411543
}

‎src/coreclr/vm/eetwain.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,9 @@ OBJECTREF InterpreterCodeManager::GetInstance(PREGDISPLAY pContext,
23112311
{
23122312
PTR_InterpMethodContextFrame frame = dac_cast<PTR_InterpMethodContextFrame>(GetSP(pContext->pCurrentContext));
23132313
TADDR baseStackSlot = dac_cast<TADDR>((uintptr_t)frame->pStack);
2314-
return *dac_cast<PTR_OBJECTREF>(baseStackSlot);
2314+
// Read the slot as a raw pointer: interpreter stack slots are not viewed through checked
2315+
// OBJECTREFs (see LOCAL_VAR_OBJREF in interpexec.cpp).
2316+
return ObjectToOBJECTREF(*dac_cast<PTR_PTR_Object>(baseStackSlot));
23152317
}
23162318

23172319
PTR_VOID InterpreterCodeManager::GetParamTypeArg(PREGDISPLAY pContext,

‎src/coreclr/vm/frames.cpp‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,11 +1293,8 @@ void GCFrame::Remove()
12931293

12941294
#ifdef _DEBUG
12951295
m_pCurThread->EnableStressHeap();
1296-
// Unlike Pop, do not record the slots as unprotected OBJECTREFs. Remove is used by
1297-
// GCReporting::Unregister for storage supplied by managed code, which does not follow
1298-
// the checked OBJECTREF lifetime and assignment rules. Recording its addresses can
1299-
// cause false IsObjRefValid assertions when the storage is reused later and read
1300-
// through a checked OBJECTREF, as the interpreter does for a call's 'this' argument.
1296+
for(UINT i = 0; i < m_numObjRefs; i++)
1297+
Thread::ObjectRefNew(&m_pObjRefs[i]); // Unprotect them
13011298
#endif
13021299
break;
13031300
}

‎src/coreclr/vm/frames.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,7 @@ class GCFrame
17211721
// Push and pop this frame from the thread's stack.
17221722
void Push(Thread* pThread);
17231723
void Pop();
1724-
// Remove this frame from any position in the thread's stack. Used by GCReporting::Unregister
1725-
// for frames that managed code registered through GCReporting::Register.
1724+
// Remove this frame from any position in the thread's stack
17261725
void Remove();
17271726

17281727
#endif // DACCESS_COMPILE

0 commit comments

Comments
 (0)