diff options
author | Brian Geffon <bgeffon@google.com> | 2018-05-16 13:06:23 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-16 13:07:12 -0700 |
commit | f295e26b8abe395eaf1d4bee9a792a79b34d156f (patch) | |
tree | 261d23af963fd77ceabf52975f1cdd6b419e5b54 /pkg/sentry/fs/gofer/socket.go | |
parent | 4b7e4f3d3612dde08a37a040d5be92c37cd0ee57 (diff) |
Release mutex in BidirectionalConnect to avoid deadlock.
When doing a BidirectionalConnect we don't need to continue holding
the ConnectingEndpoint's mutex when creating the NewConnectedEndpoint
as it was held during the Connect. Additionally, we're not holding
the baseEndpoint mutex while Unregistering an event.
PiperOrigin-RevId: 196875557
Change-Id: Ied4ceed89de883121c6cba81bc62aa3a8549b1e9
Diffstat (limited to 'pkg/sentry/fs/gofer/socket.go')
-rw-r--r-- | pkg/sentry/fs/gofer/socket.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/pkg/sentry/fs/gofer/socket.go b/pkg/sentry/fs/gofer/socket.go index 954000ef0..406756f5f 100644 --- a/pkg/sentry/fs/gofer/socket.go +++ b/pkg/sentry/fs/gofer/socket.go @@ -79,26 +79,33 @@ func (e *endpoint) BidirectionalConnect(ce unix.ConnectingEndpoint, returnConnec // No lock ordering required as only the ConnectingEndpoint has a mutex. ce.Lock() - defer ce.Unlock() // Check connecting state. if ce.Connected() { + ce.Unlock() return tcpip.ErrAlreadyConnected } if ce.Listening() { + ce.Unlock() return tcpip.ErrInvalidEndpointState } hostFile, err := e.file.Connect(cf) if err != nil { + ce.Unlock() return tcpip.ErrConnectionRefused } - r, c, terr := host.NewConnectedEndpoint(hostFile, ce.WaiterQueue(), e.path) + c, terr := host.NewConnectedEndpoint(hostFile, ce.WaiterQueue(), e.path) if terr != nil { + ce.Unlock() return terr } - returnConnect(r, c) + + returnConnect(c, c) + ce.Unlock() + c.Init() + return nil } @@ -109,14 +116,15 @@ func (e *endpoint) UnidirectionalConnect() (unix.ConnectedEndpoint, *tcpip.Error return nil, tcpip.ErrConnectionRefused } - r, c, terr := host.NewConnectedEndpoint(hostFile, &waiter.Queue{}, e.path) + c, terr := host.NewConnectedEndpoint(hostFile, &waiter.Queue{}, e.path) if terr != nil { return nil, terr } + c.Init() // We don't need the receiver. - r.CloseRecv() - r.Release() + c.CloseRecv() + c.Release() return c, nil } |