From e161bec8dca37a97f1d05e79c0bd5a4d73912ee5 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Mon, 10 Feb 2025 14:41:50 -0800 Subject: [PATCH] Unlock fdbased.endpoint.mu before fdbased.endpoint.Wait(). This prevents the deadlock described in #11456. Fixes #11456. PiperOrigin-RevId: 725352718 --- pkg/tcpip/link/fdbased/endpoint.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index 8d8cef703..1b6135570 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -422,17 +422,19 @@ func isSocketFD(fd int) (bool, error) { // Attach implements stack.LinkEndpoint.Attach. func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) { e.mu.Lock() - defer e.mu.Unlock() // nil means the NIC is being removed. if dispatcher == nil && e.dispatcher != nil { for _, dispatcher := range e.inboundDispatchers { dispatcher.Stop() } - e.Wait() e.dispatcher = nil + // NOTE(gvisor.dev/issue/11456): Unlock e.mu before e.Wait(). + e.mu.Unlock() + e.Wait() return } + defer e.mu.Unlock() if dispatcher != nil && e.dispatcher == nil { e.dispatcher = dispatcher // Link endpoints are not savable. When transportation endpoints are