diff options
author | Andrei Vagin <avagin@google.com> | 2020-06-02 19:17:53 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-06-02 19:19:15 -0700 |
commit | e6334e81ca8d951e56f03d8ea0629e3c85556cf1 (patch) | |
tree | 3dc40f5413d9e3ababbe0b46bb43f99ab5c7d580 /pkg/sentry | |
parent | c615faaee42ab6c30f21a19a90f865548156ae97 (diff) |
Check that two sockets with different types can't be connected to each other
PiperOrigin-RevId: 314450191
Diffstat (limited to 'pkg/sentry')
-rw-r--r-- | pkg/sentry/socket/unix/transport/connectioned.go | 2 | ||||
-rw-r--r-- | pkg/sentry/socket/unix/unix.go | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/pkg/sentry/socket/unix/transport/connectioned.go b/pkg/sentry/socket/unix/transport/connectioned.go index ce5b94ee7..09c6d3b27 100644 --- a/pkg/sentry/socket/unix/transport/connectioned.go +++ b/pkg/sentry/socket/unix/transport/connectioned.go @@ -252,7 +252,7 @@ func (e *connectionedEndpoint) Close() { // BidirectionalConnect implements BoundEndpoint.BidirectionalConnect. func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint)) *syserr.Error { if ce.Type() != e.stype { - return syserr.ErrConnectionRefused + return syserr.ErrWrongProtocolForSocket } // Check if ce is e to avoid a deadlock. diff --git a/pkg/sentry/socket/unix/unix.go b/pkg/sentry/socket/unix/unix.go index 5b29e9d7f..c4c9db81b 100644 --- a/pkg/sentry/socket/unix/unix.go +++ b/pkg/sentry/socket/unix/unix.go @@ -417,7 +417,18 @@ func (s *socketOpsCommon) Connect(t *kernel.Task, sockaddr []byte, blocking bool defer ep.Release() // Connect the server endpoint. - return s.ep.Connect(t, ep) + err = s.ep.Connect(t, ep) + + if err == syserr.ErrWrongProtocolForSocket { + // Linux for abstract sockets returns ErrConnectionRefused + // instead of ErrWrongProtocolForSocket. + path, _ := extractPath(sockaddr) + if len(path) > 0 && path[0] == 0 { + err = syserr.ErrConnectionRefused + } + } + + return err } // Write implements fs.FileOperations.Write. |