kernel: fix lock order inversion in ThreadGroup.Release()

PiperOrigin-RevId: 681199251
This commit is contained in:
Jamie Liu
2024-10-01 16:10:15 -07:00
committed by gVisor bot
parent baaaf47fc2
commit b99fd8711f
2 changed files with 20 additions and 12 deletions
+7 -6
View File
@@ -19,12 +19,13 @@
// Lock order (outermost locks must be taken first):
//
// Kernel.extMu
// ThreadGroup.timerMu
// ktime.Timer.mu (for IntervalTimer) and Kernel.cpuClockMu
// TaskSet.mu
// SignalHandlers.mu
// Task.mu
// runningTasksMu
// TTY.mu
// ThreadGroup.timerMu
// ktime.Timer.mu (for IntervalTimer) and Kernel.cpuClockMu
// TaskSet.mu
// SignalHandlers.mu
// Task.mu
// runningTasksMu
//
// Locking SignalHandlers.mu in multiple SignalHandlers requires locking
// TaskSet.mu exclusively first. Locking Task.mu in multiple Tasks at the same
+13 -6
View File
@@ -343,15 +343,22 @@ func (tg *ThreadGroup) Release(ctx context.Context) {
}
clear(tg.timers) // nil maps can't be saved
// Disassociate from the tty if we have one.
var tty *TTY
if tg.tty != nil {
tg.tty.mu.Lock() // FIXME(b/370763686)
if tg.tty.tg == tg {
tg.tty.tg = nil
}
tg.tty.mu.Unlock()
tg.tty = nil
// Can't lock tty.mu due to lock ordering.
tty = tg.tty
}
tg.signalHandlers.mu.Unlock()
if tty != nil {
tty.mu.Lock()
tg.signalHandlers.mu.Lock()
tg.tty = nil
if tty.tg == tg {
tty.tg = nil
}
tg.signalHandlers.mu.Unlock()
tty.mu.Unlock()
}
for _, it := range its {
it.DestroyTimer()
}