Skip to content

Commit

Permalink
Make DacValidateMethodTable more bullet proof by DAC'ifing the Method…
Browse files Browse the repository at this point in the history
…Table pointer (using PTR_MethodTable). On Windows,

SEH can catch the native AV exceptions but on Linux/MacOS this can crash lldb/SOS on invalid MT addresses.

This will also help with eestack/dumpstack crashing lldb also.
  • Loading branch information
mikem8361 committed Jul 22, 2022
1 parent a7aefe4 commit 75b8f0d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ BOOL DacValidateEEClass(EEClass *pEEClass)

}

BOOL DacValidateMethodTable(MethodTable *pMT, BOOL &bIsFree)
BOOL DacValidateMethodTable(PTR_MethodTable pMT, BOOL &bIsFree)
{
// Verify things are right.
BOOL retval = FALSE;
Expand Down Expand Up @@ -440,7 +440,7 @@ ClrDataAccess::GetMethodTableSlot(CLRDATA_ADDRESS mt, unsigned int slot, CLRDATA

SOSDacEnter();

MethodTable* mTable = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable mTable = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(mTable, bIsFree))
{
Expand Down Expand Up @@ -1465,7 +1465,7 @@ ClrDataAccess::GetObjectStringData(CLRDATA_ADDRESS obj, unsigned int count, _Ino
SOSDacEnter();

TADDR mtTADDR = DACGetMethodTableFromObjectPointer(TO_TADDR(obj), m_pTarget);
MethodTable *mt = PTR_MethodTable(mtTADDR);
PTR_MethodTable mt = PTR_MethodTable(mtTADDR);

// Object must be a string
BOOL bFree = FALSE;
Expand Down Expand Up @@ -1515,7 +1515,7 @@ ClrDataAccess::GetObjectClassName(CLRDATA_ADDRESS obj, unsigned int count, _Inou

// Don't turn the Object into a pointer, it is too costly on
// scans of the gc heap.
MethodTable *mt = NULL;
PTR_MethodTable mt = NULL;
TADDR mtTADDR = DACGetMethodTableFromObjectPointer(CLRDATA_ADDRESS_TO_TADDR(obj), m_pTarget);
if (mtTADDR != NULL)
mt = PTR_MethodTable(mtTADDR);
Expand Down Expand Up @@ -1732,7 +1732,7 @@ ClrDataAccess::GetMethodTableData(CLRDATA_ADDRESS mt, struct DacpMethodTableData

SOSDacEnter();

MethodTable* pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(pMT, bIsFree))
{
Expand Down Expand Up @@ -1775,7 +1775,7 @@ ClrDataAccess::GetMethodTableName(CLRDATA_ADDRESS mt, unsigned int count, _Inout

SOSDacEnter();

MethodTable *pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL free = FALSE;

if (mt == HOST_CDADDR(g_pFreeObjectMethodTable))
Expand Down Expand Up @@ -1936,7 +1936,7 @@ ClrDataAccess::GetMethodTableFieldData(CLRDATA_ADDRESS mt, struct DacpMethodTabl

SOSDacEnter();

MethodTable* pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!pMT || !DacValidateMethodTable(pMT, bIsFree))
{
Expand Down Expand Up @@ -1966,7 +1966,7 @@ ClrDataAccess::GetMethodTableCollectibleData(CLRDATA_ADDRESS mt, struct DacpMeth

SOSDacEnter();

MethodTable* pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!pMT || !DacValidateMethodTable(pMT, bIsFree))
{
Expand All @@ -1993,7 +1993,7 @@ ClrDataAccess::GetMethodTableTransparencyData(CLRDATA_ADDRESS mt, struct DacpMet

SOSDacEnter();

MethodTable *pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(pMT, bIsFree))
{
Expand Down Expand Up @@ -2177,7 +2177,7 @@ ClrDataAccess::GetObjectData(CLRDATA_ADDRESS addr, struct DacpObjectData *object
hr = E_INVALIDARG;

BOOL bFree = FALSE;
MethodTable *mt = NULL;
PTR_MethodTable mt = NULL;
if (SUCCEEDED(hr))
{
mt = PTR_MethodTable(mtTADDR);
Expand Down Expand Up @@ -5125,7 +5125,7 @@ HRESULT ClrDataAccess::IsTrackedType(
hr = E_INVALIDARG;

BOOL bFree = FALSE;
MethodTable *mt = NULL;
PTR_MethodTable mt = NULL;
if (SUCCEEDED(hr))
{
mt = PTR_MethodTable(mtTADDR);
Expand Down

0 comments on commit 75b8f0d

Please sign in to comment.