Actions
Bug #22598
openA thread that ends holding two mutexes corrupts the next owner's mutex list
Bug #22598:
A thread that ends holding two mutexes corrupts the next owner's mutex list
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [x86_64-linux]
Description
Reproduces on 4.0.9 and master:
m1 = Thread::Mutex.new
m2 = Thread::Mutex.new
Thread.new { m1.lock; m2.lock }.join
Thread.new { m2.synchronize { } }.join
# [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
When a thread exits, rb_threadptr_unlock_all_locking_mutexes pops each mutex off th->keeping_mutexes before unlocking it, so rb_mutex_unlock_th never clears its next_mutex. The next thread to lock m2 inherits m1 in its list and unlocks it when it exits, which crashes if m1 is unlocked, releases it out from under another thread if it's locked, and is a use after free if it's been collected.
No data to display
Actions