From b1ceabc884c048a3794b0d036728abfcf245d0ef Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Fri, 4 Mar 2022 12:23:49 -0800 Subject: [PATCH] Hold baseEndpoint.mu when calling baseEndpoint.Connected() Connected must be called with baseEndpoint.mu locked. Updated method comment to include this precondition. Reported-by: syzbot+3ee57917033a3a23c8e0@syzkaller.appspotmail.com PiperOrigin-RevId: 432506434 --- pkg/sentry/socket/unix/transport/connectioned.go | 2 ++ pkg/sentry/socket/unix/transport/connectionless.go | 2 ++ pkg/sentry/socket/unix/transport/unix.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/pkg/sentry/socket/unix/transport/connectioned.go b/pkg/sentry/socket/unix/transport/connectioned.go index d0c336617..0d299dbb8 100644 --- a/pkg/sentry/socket/unix/transport/connectioned.go +++ b/pkg/sentry/socket/unix/transport/connectioned.go @@ -519,6 +519,8 @@ func (e *connectionedEndpoint) State() uint32 { // OnSetSendBufferSize implements tcpip.SocketOptionsHandler.OnSetSendBufferSize. func (e *connectionedEndpoint) OnSetSendBufferSize(v int64) (newSz int64) { + e.Lock() + defer e.Unlock() if e.Connected() { return e.baseEndpoint.connected.SetSendBufferSize(v) } diff --git a/pkg/sentry/socket/unix/transport/connectionless.go b/pkg/sentry/socket/unix/transport/connectionless.go index 7a0373756..09c9b334b 100644 --- a/pkg/sentry/socket/unix/transport/connectionless.go +++ b/pkg/sentry/socket/unix/transport/connectionless.go @@ -222,6 +222,8 @@ func (e *connectionlessEndpoint) State() uint32 { // OnSetSendBufferSize implements tcpip.SocketOptionsHandler.OnSetSendBufferSize. func (e *connectionlessEndpoint) OnSetSendBufferSize(v int64) (newSz int64) { + e.Lock() + defer e.Unlock() if e.Connected() { return e.baseEndpoint.connected.SetSendBufferSize(v) } diff --git a/pkg/sentry/socket/unix/transport/unix.go b/pkg/sentry/socket/unix/transport/unix.go index 387fd1596..361514a78 100644 --- a/pkg/sentry/socket/unix/transport/unix.go +++ b/pkg/sentry/socket/unix/transport/unix.go @@ -813,6 +813,8 @@ func (e *baseEndpoint) ConnectedPasscred() bool { } // Connected implements ConnectingEndpoint.Connected. +// +// Preconditions: e.mu must be held. func (e *baseEndpoint) Connected() bool { return e.receiver != nil && e.connected != nil }