Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 7ec87b0

Browse files
hoyosjsJohn Salem
authored andcommitted
Fix use after free AV in EventPipe (#24924)
* Reenable tests turned off in #24772 * Disable event pipe tests for investigation * Fix logic for deletion * In case of error - we need to take the lock because disabling the event pipe session * Intentionally leaking the EventPipeSession to mitigate a known race condition for now * Fix for EventListener lock order and throwing * Fix purposeful leak to still close the session
1 parent 877efe9 commit 7ec87b0

File tree

7 files changed

+33
-19
lines changed

7 files changed

+33
-19
lines changed

src/vm/eventpipe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void EventPipe::DisableInternal(EventPipeSessionID id, EventPipeProviderCallback
457457
EventPipeSession *EventPipe::GetSession(EventPipeSessionID id)
458458
{
459459
LIMITED_METHOD_CONTRACT;
460-
_ASSERTE(IsLockOwnedByCurrentThread());
460+
CrstHolder _crst(GetLock());
461461

462462
if (s_pSessions == nullptr)
463463
return nullptr;

src/vm/eventpipebuffermanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ EventPipeEventInstance* EventPipeBufferManager::GetNextEvent()
616616
{
617617
CONTRACTL
618618
{
619-
NOTHROW;
619+
THROWS;
620620
GC_NOTRIGGER;
621621
MODE_ANY;
622622
PRECONDITION(!EventPipe::IsLockOwnedByCurrentThread());

src/vm/eventpipeconfiguration.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ void EventPipeConfiguration::DeleteSession(EventPipeSession *pSession)
335335
{
336336
// Reset the mask of active sessions.
337337
m_activeSessions &= ~pSession->GetId();
338-
delete pSession;
338+
pSession->Close();
339+
// TODO: Re-enable this after fixing the underlying race condition
340+
// delete pSession;
339341
}
340342
}
341343

src/vm/eventpipesession.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ EventPipeSession::EventPipeSession(
6262
QueryPerformanceCounter(&m_sessionStartTimeStamp);
6363
}
6464

65+
void EventPipeSession::Close()
66+
{
67+
CONTRACTL
68+
{
69+
NOTHROW;
70+
GC_TRIGGERS;
71+
MODE_PREEMPTIVE;
72+
}
73+
CONTRACTL_END;
74+
75+
// FIXME: **ONLY** closes the stream. This explicitly **LEAKS** the
76+
// provider list and buffer manager.
77+
delete m_pFile;
78+
}
79+
6580
EventPipeSession::~EventPipeSession()
6681
{
6782
CONTRACTL
@@ -182,7 +197,9 @@ DWORD WINAPI EventPipeSession::ThreadProc(void *args)
182197
pEventPipeSession->SetThreadShutdownEvent();
183198

184199
if (!fSuccess)
185-
pEventPipeSession->Disable();
200+
{
201+
EventPipe::RunWithCallbackPostponed([pEventPipeSession](EventPipeProviderCallbackDataQueue *pEventPipeProviderCallbackDataQueue){pEventPipeSession->Disable();});
202+
}
186203
}
187204
EX_CATCH
188205
{

src/vm/eventpipesession.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class EventPipeSession
8989
uint32_t numProviders,
9090
bool rundownEnabled = false);
9191
~EventPipeSession();
92+
void Close();
9293

9394
EventPipeSessionID GetId() const
9495
{

src/vm/eventpipesessionprovider.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,12 @@ void EventPipeSessionProviderList::Clear()
188188
{
189189
if (m_pProviders != NULL)
190190
{
191-
SListElem<EventPipeSessionProvider *> *pElem = m_pProviders->GetHead();
192-
while (pElem != NULL)
191+
while (!m_pProviders->IsEmpty())
193192
{
193+
SListElem<EventPipeSessionProvider*> *pElem = m_pProviders->RemoveHead();
194194
EventPipeSessionProvider *pProvider = pElem->GetValue();
195195
delete pProvider;
196-
197-
SListElem<EventPipeSessionProvider *> *pCurElem = pElem;
198-
pElem = m_pProviders->GetNext(pElem);
199-
delete pCurElem;
200-
201-
// Remove deleted node.
202-
m_pProviders->RemoveHead();
196+
delete pElem;
203197
}
204198
}
205199

tests/issues.targets

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<Project DefaultTargets = "GetListOfTestCmds" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<!-- All OS/Arch common excludes -->
44
<ItemGroup Condition="'$(XunitTestBinBase)' != ''">
5+
<ExcludeList Include="$(XunitTestBinBase)/tracing/eventsource/**/*">
6+
<Issue>24839</Issue>
7+
</ExcludeList>
8+
<ExcludeList Include="$(XunitTestBinBase)/tracing/tracevalidation/**/*">
9+
<Issue>24839</Issue>
10+
</ExcludeList>
511
<ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/generics/threadstart/GThread23/*">
612
<Issue>19339</Issue>
713
</ExcludeList>
@@ -518,12 +524,6 @@
518524
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/GitHub_19601/Github_19601/*">
519525
<Issue>Needs Triage</Issue>
520526
</ExcludeList>
521-
<ExcludeList Include="$(XunitTestBinBase)/tracing/eventsource/**/*">
522-
<Issue>Failing on alpine, being tracked by #24772</Issue>
523-
</ExcludeList>
524-
<ExcludeList Include="$(XunitTestBinBase)/tracing/tracevalidation/**/*">
525-
<Issue>Failing on alpine, being tracked by #24772</Issue>
526-
</ExcludeList>
527527
</ItemGroup>
528528

529529
<!-- Unix arm64 specific -->

0 commit comments

Comments
 (0)