Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use holding thread id in AwareLock to avoid orphaned lock crash #107168

Merged
merged 8 commits into from
Dec 10, 2024

Conversation

eduardo-vp
Copy link
Member

In GetThreadOwningMonitorLock, in case there's a sync block, the method only checks for pThread to be equal to NULL to return false, otherwise it assumes pThread actually points to a thread. However, it can be the case that pThread is -1 for orphaned locks and should return false as well (the calling thread doesn't own the lock).

Fixes #44071.

src/coreclr/vm/syncblk.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/syncblk.cpp Show resolved Hide resolved
@@ -436,6 +436,7 @@ class AwareLock

ULONG m_Recursion;
PTR_Thread m_HoldingThread;
DWORD m_HoldingThreadId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to remove m_HoldingThread altogether. It would probably need a change to get the Thread pointer from the thread ID in the DAC. Maybe this could be cleaned up in a separate PR, for now at least the field shouldn't be dereferenced.

src/coreclr/vm/syncblk.cpp Show resolved Hide resolved
@eduardo-vp eduardo-vp force-pushed the fix-orphaned-lock-crash branch from 76fc67d to 9de4e06 Compare November 28, 2024 22:50
src/coreclr/vm/syncblk.inl Outdated Show resolved Hide resolved
Copy link
Member

@kouvel kouvel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment, otherwise LGTM, thanks!

src/coreclr/vm/syncblk.inl Outdated Show resolved Hide resolved
@eduardo-vp eduardo-vp changed the title Check if lock is orphaned in GetThreadOwningMonitorLock Use holding thread id in AwareLock to avoid orphaned lock crash Dec 10, 2024
@eduardo-vp eduardo-vp merged commit 938f057 into dotnet:main Dec 10, 2024
81 of 90 checks passed
@eduardo-vp eduardo-vp deleted the fix-orphaned-lock-crash branch December 11, 2024 00:02
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.

Crash caused by orphaned locks
3 participants