summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/socket/unix/transport
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-02-20 01:43:42 +0000
committergVisor bot <gvisor-bot@google.com>2021-02-20 01:43:42 +0000
commit28599de5147ae22d1f4364baa2eb2463a1e1f892 (patch)
tree0a0140edd430b834278a495e053b4d8f33c2152d /pkg/sentry/socket/unix/transport
parent3f8ff37f4c3486668ace6906e4035d08c7148db3 (diff)
parent93fc09248a2fa8b840d8ce47800414980d74bdb0 (diff)
Merge release-20210208.0-78-g93fc09248 (automated)
Diffstat (limited to 'pkg/sentry/socket/unix/transport')
-rw-r--r--pkg/sentry/socket/unix/transport/unix.go47
1 files changed, 28 insertions, 19 deletions
diff --git a/pkg/sentry/socket/unix/transport/unix.go b/pkg/sentry/socket/unix/transport/unix.go
index ceada54a8..359a5995b 100644
--- a/pkg/sentry/socket/unix/transport/unix.go
+++ b/pkg/sentry/socket/unix/transport/unix.go
@@ -742,8 +742,8 @@ func (e *connectedEndpoint) SetSendBufferSize(v int64) (newSz int64) {
return v
}
-// baseEndpoint is an embeddable unix endpoint base used in both the connected and connectionless
-// unix domain socket Endpoint implementations.
+// baseEndpoint is an embeddable unix endpoint base used in both the connected
+// and connectionless unix domain socket Endpoint implementations.
//
// Not to be used on its own.
//
@@ -753,6 +753,9 @@ type baseEndpoint struct {
tcpip.DefaultSocketOptionsHandler
// Mutex protects the below fields.
+ //
+ // See the lock ordering comment in package kernel/epoll regarding when
+ // this lock can safely be held.
sync.Mutex `state:"nosave"`
// receiver allows Messages to be received.
@@ -774,20 +777,22 @@ type baseEndpoint struct {
func (e *baseEndpoint) EventRegister(we *waiter.Entry, mask waiter.EventMask) {
e.Queue.EventRegister(we, mask)
e.Lock()
- if e.connected != nil {
- e.connected.EventUpdate()
- }
+ c := e.connected
e.Unlock()
+ if c != nil {
+ c.EventUpdate()
+ }
}
// EventUnregister implements waiter.Waitable.EventUnregister.
func (e *baseEndpoint) EventUnregister(we *waiter.Entry) {
e.Queue.EventUnregister(we)
e.Lock()
- if e.connected != nil {
- e.connected.EventUpdate()
- }
+ c := e.connected
e.Unlock()
+ if c != nil {
+ c.EventUpdate()
+ }
}
// Passcred implements Credentialer.Passcred.
@@ -942,22 +947,26 @@ func (e *baseEndpoint) Shutdown(flags tcpip.ShutdownFlags) *syserr.Error {
return syserr.ErrNotConnected
}
- if flags&tcpip.ShutdownRead != 0 {
- e.receiver.CloseRecv()
+ var (
+ r = e.receiver
+ c = e.connected
+ shutdownRead = flags&tcpip.ShutdownRead != 0
+ shutdownWrite = flags&tcpip.ShutdownWrite != 0
+ )
+ if shutdownRead {
+ r.CloseRecv()
}
-
- if flags&tcpip.ShutdownWrite != 0 {
- e.connected.CloseSend()
+ if shutdownWrite {
+ c.CloseSend()
}
-
e.Unlock()
- if flags&tcpip.ShutdownRead != 0 {
- e.receiver.CloseNotify()
+ // Don't hold e.Mutex while calling CloseNotify.
+ if shutdownRead {
+ r.CloseNotify()
}
-
- if flags&tcpip.ShutdownWrite != 0 {
- e.connected.CloseNotify()
+ if shutdownWrite {
+ c.CloseNotify()
}
return nil