Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/sentry/fsimpl/gofer/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type endpoint struct {
}

// BidirectionalConnect implements BoundEndpoint.BidirectionalConnect.
func (e *endpoint) BidirectionalConnect(ctx context.Context, ce transport.ConnectingEndpoint, returnConnect func(transport.Receiver, transport.ConnectedEndpoint), opts transport.UnixSocketOpts) *syserr.Error {
func (e *endpoint) BidirectionalConnect(ctx context.Context, ce transport.ConnectingEndpoint, returnConnect func(transport.Receiver, transport.ConnectedEndpoint)) *syserr.Error {
// No lock ordering required as only the ConnectingEndpoint has a mutex.
ce.Lock()

Expand All @@ -68,7 +68,7 @@ func (e *endpoint) BidirectionalConnect(ctx context.Context, ce transport.Connec
return syserr.ErrInvalidEndpointState
}

c, err := e.newConnectedEndpoint(ctx, ce.Type(), ce.WaiterQueue(), opts)
c, err := e.newConnectedEndpoint(ctx, ce.Type(), ce.WaiterQueue())
if err != nil {
ce.Unlock()
return err
Expand All @@ -85,8 +85,8 @@ func (e *endpoint) BidirectionalConnect(ctx context.Context, ce transport.Connec

// UnidirectionalConnect implements
// transport.BoundEndpoint.UnidirectionalConnect.
func (e *endpoint) UnidirectionalConnect(ctx context.Context, opts transport.UnixSocketOpts) (transport.ConnectedEndpoint, *syserr.Error) {
c, err := e.newConnectedEndpoint(ctx, linux.SOCK_DGRAM, &waiter.Queue{}, opts)
func (e *endpoint) UnidirectionalConnect(ctx context.Context) (transport.ConnectedEndpoint, *syserr.Error) {
c, err := e.newConnectedEndpoint(ctx, linux.SOCK_DGRAM, &waiter.Queue{})
if err != nil {
return nil, err
}
Expand All @@ -102,15 +102,15 @@ func (e *endpoint) UnidirectionalConnect(ctx context.Context, opts transport.Uni
return c, nil
}

func (e *endpoint) newConnectedEndpoint(ctx context.Context, sockType linux.SockType, queue *waiter.Queue, opts transport.UnixSocketOpts) (*transport.SCMConnectedEndpoint, *syserr.Error) {
func (e *endpoint) newConnectedEndpoint(ctx context.Context, sockType linux.SockType, queue *waiter.Queue) (*transport.SCMConnectedEndpoint, *syserr.Error) {
e.dentry.inode.fs.renameMu.RLock()
hostSockFD, err := e.dentry.connect(ctx, sockType)
e.dentry.inode.fs.renameMu.RUnlock()
if err != nil {
return nil, syserr.ErrConnectionRefused
}

c, serr := transport.NewSCMEndpoint(hostSockFD, queue, e.path, opts)
c, serr := transport.NewSCMEndpoint(hostSockFD, queue, e.path)
if serr != nil {
unix.Close(hostSockFD)
log.Warningf("NewSCMEndpoint failed: path=%q, err=%v", e.path, serr)
Expand Down
1 change: 0 additions & 1 deletion pkg/sentry/fsimpl/testutil/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ go_library(
"//pkg/sentry/platform/kvm",
"//pkg/sentry/platform/ptrace",
"//pkg/sentry/seccheck",
"//pkg/sentry/socket/unix/transport",
"//pkg/sentry/time",
"//pkg/sentry/usage",
"//pkg/sentry/vfs",
Expand Down
2 changes: 0 additions & 2 deletions pkg/sentry/fsimpl/testutil/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/seccheck"
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
"gvisor.dev/gvisor/pkg/sentry/time"
"gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sentry/vfs"
Expand Down Expand Up @@ -107,7 +106,6 @@ func Boot() (*kernel.Kernel, error) {
RootUTSNamespace: kernel.NewUTSNamespace("hostname", "domain", creds.UserNamespace),
RootIPCNamespace: kernel.NewIPCNamespace(creds.UserNamespace),
RootPIDNamespace: kernel.NewRootPIDNamespace(creds.UserNamespace),
UnixSocketOpts: transport.UnixSocketOpts{},
}); err != nil {
return nil, fmt.Errorf("initializing kernel: %v", err)
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/sentry/kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import (
"gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/socket/netlink/port"
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
"gvisor.dev/gvisor/pkg/sentry/state/stateio"
sentrytime "gvisor.dev/gvisor/pkg/sentry/time"
"gvisor.dev/gvisor/pkg/sentry/unimpl"
Expand Down Expand Up @@ -388,9 +387,6 @@ type Kernel struct {
// when checkpoint/restore are done. It's protected by checkpointMu.
checkpointGen CheckpointGeneration

// UnixSocketOpts stores configuration options for management of unix sockets.
UnixSocketOpts transport.UnixSocketOpts

// SaveRestoreExecConfig stores configuration options for the save/restore
// exec binary.
SaveRestoreExecConfig *SaveRestoreExecConfig
Expand Down Expand Up @@ -456,9 +452,6 @@ type InitKernelArgs struct {
// used by processes. If it is zero, the limit will be set to
// unlimited.
MaxFDLimit int32

// UnixSocketOpts contains configuration options for unix sockets.
UnixSocketOpts transport.UnixSocketOpts
}

// Init initialize the Kernel with no tasks.
Expand Down Expand Up @@ -583,7 +576,6 @@ func (k *Kernel) Init(args InitKernelArgs) error {
k.sockets = make(map[*vfs.FileDescription]*SocketRecord)

k.cgroupRegistry = newCgroupRegistry()
k.UnixSocketOpts = args.UnixSocketOpts
k.MaxKeySetSize = atomicbitops.FromInt32(auth.MaxSetSize)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sentry/socket/netlink/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func New(t *kernel.Task, skType linux.SockType, protocol Protocol) (*Socket, *sy
}

// Create a connection from which the kernel can write messages.
connection, err := ep.(transport.BoundEndpoint).UnidirectionalConnect(t, t.Kernel().UnixSocketOpts)
connection, err := ep.(transport.BoundEndpoint).UnidirectionalConnect(t)
if err != nil {
ep.Close(t)
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions pkg/sentry/socket/unix/transport/connectioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (e *connectionedEndpoint) swapPeerCredsLocked(ctx context.Context, cend Con
}

// BidirectionalConnect implements BoundEndpoint.BidirectionalConnect.
func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint), opts UnixSocketOpts) *syserr.Error {
func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint)) *syserr.Error {
if ce.Type() != e.stype {
return syserr.ErrWrongProtocolForSocket
}
Expand Down Expand Up @@ -400,13 +400,13 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
}

// UnidirectionalConnect implements BoundEndpoint.UnidirectionalConnect.
func (e *connectionedEndpoint) UnidirectionalConnect(ctx context.Context, opts UnixSocketOpts) (ConnectedEndpoint, *syserr.Error) {
func (e *connectionedEndpoint) UnidirectionalConnect(ctx context.Context) (ConnectedEndpoint, *syserr.Error) {
return nil, syserr.ErrConnectionRefused
}

// Connect attempts to directly connect to another Endpoint.
// Implements Endpoint.Connect.
func (e *connectionedEndpoint) Connect(ctx context.Context, server BoundEndpoint, opts UnixSocketOpts) *syserr.Error {
func (e *connectionedEndpoint) Connect(ctx context.Context, server BoundEndpoint) *syserr.Error {
returnConnect := func(r Receiver, ce ConnectedEndpoint) {
e.receiver = r
e.connected = ce
Expand All @@ -418,7 +418,7 @@ func (e *connectionedEndpoint) Connect(ctx context.Context, server BoundEndpoint
}
}

return server.BidirectionalConnect(ctx, e, returnConnect, opts)
return server.BidirectionalConnect(ctx, e, returnConnect)
}

// Listen starts listening on the connection.
Expand Down Expand Up @@ -460,15 +460,15 @@ func (e *connectionedEndpoint) Listen(ctx context.Context, backlog int) *syserr.
}

// Accept accepts a new connection.
func (e *connectionedEndpoint) Accept(ctx context.Context, peerAddr *Address, opts UnixSocketOpts) (Endpoint, *syserr.Error) {
func (e *connectionedEndpoint) Accept(ctx context.Context, peerAddr *Address) (Endpoint, *syserr.Error) {
e.Lock()

if !e.ListeningLocked() {
e.Unlock()
return nil, syserr.ErrInvalidEndpointState
}

ne, err := e.getAcceptedEndpointLocked(ctx, opts)
ne, err := e.getAcceptedEndpointLocked(ctx)
e.Unlock()
if err != nil {
return nil, err
Expand All @@ -492,7 +492,7 @@ func (e *connectionedEndpoint) Accept(ctx context.Context, peerAddr *Address, op
// Preconditions:
// - e.Listening()
// - e is locked.
func (e *connectionedEndpoint) getAcceptedEndpointLocked(ctx context.Context, opts UnixSocketOpts) (*connectionedEndpoint, *syserr.Error) {
func (e *connectionedEndpoint) getAcceptedEndpointLocked(ctx context.Context) (*connectionedEndpoint, *syserr.Error) {
// Accept connections from within the sentry first, since this avoids
// an RPC to the gofer on the common path.
select {
Expand All @@ -515,7 +515,7 @@ func (e *connectionedEndpoint) getAcceptedEndpointLocked(ctx context.Context, op
return nil, syserr.FromError(err)
}
q := &waiter.Queue{}
scme, serr := NewSCMEndpoint(nfd, q, e.path, opts)
scme, serr := NewSCMEndpoint(nfd, q, e.path)
if serr != nil {
unix.Close(nfd)
return nil, serr
Expand Down
13 changes: 6 additions & 7 deletions pkg/sentry/socket/unix/transport/connectionless.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (e *connectionlessEndpoint) Close(ctx context.Context) {
}

// BidirectionalConnect implements BoundEndpoint.BidirectionalConnect.
func (e *connectionlessEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint), opts UnixSocketOpts) *syserr.Error {
func (e *connectionlessEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint)) *syserr.Error {
return syserr.ErrConnectionRefused
}

// UnidirectionalConnect implements BoundEndpoint.UnidirectionalConnect.
func (e *connectionlessEndpoint) UnidirectionalConnect(ctx context.Context, opts UnixSocketOpts) (ConnectedEndpoint, *syserr.Error) {
func (e *connectionlessEndpoint) UnidirectionalConnect(ctx context.Context) (ConnectedEndpoint, *syserr.Error) {
e.Lock()
r := e.receiver
e.Unlock()
Expand All @@ -114,8 +114,7 @@ func (e *connectionlessEndpoint) SendMsg(ctx context.Context, data [][]byte, c C
return e.baseEndpoint.SendMsg(ctx, data, c, nil)
}

opts := UnixSocketOpts{}
connected, err := to.UnidirectionalConnect(ctx, opts)
connected, err := to.UnidirectionalConnect(ctx)
if err != nil {
return 0, nil, syserr.ErrInvalidEndpointState
}
Expand All @@ -139,8 +138,8 @@ func (e *connectionlessEndpoint) Type() linux.SockType {
}

// Connect attempts to connect directly to server.
func (e *connectionlessEndpoint) Connect(ctx context.Context, server BoundEndpoint, opts UnixSocketOpts) *syserr.Error {
connected, err := server.UnidirectionalConnect(ctx, opts)
func (e *connectionlessEndpoint) Connect(ctx context.Context, server BoundEndpoint) *syserr.Error {
connected, err := server.UnidirectionalConnect(ctx)
if err != nil {
return err
}
Expand All @@ -161,7 +160,7 @@ func (*connectionlessEndpoint) Listen(context.Context, int) *syserr.Error {
}

// Accept accepts a new connection.
func (*connectionlessEndpoint) Accept(context.Context, *Address, UnixSocketOpts) (Endpoint, *syserr.Error) {
func (*connectionlessEndpoint) Accept(context.Context, *Address) (Endpoint, *syserr.Error) {
return nil, syserr.ErrNotSupported
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/sentry/socket/unix/transport/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,10 @@ type SCMConnectedEndpoint struct {
HostConnectedEndpoint

queue *waiter.Queue
opts UnixSocketOpts
}

// beforeSave is invoked by stateify.
func (e *SCMConnectedEndpoint) beforeSave() {
if !e.opts.DisconnectOnSave {
panic("socket cannot be saved in a connected state")
}

e.mu.Lock()
defer e.mu.Unlock()
fdnotifier.RemoveFD(int32(e.fd))
Expand Down Expand Up @@ -470,14 +465,13 @@ func (e *SCMConnectedEndpoint) Release(ctx context.Context) {
// The caller is responsible for calling Init(). Additionally, Release needs to
// be called twice because ConnectedEndpoint is both a Receiver and
// ConnectedEndpoint.
func NewSCMEndpoint(hostFD int, queue *waiter.Queue, addr string, opts UnixSocketOpts) (*SCMConnectedEndpoint, *syserr.Error) {
func NewSCMEndpoint(hostFD int, queue *waiter.Queue, addr string) (*SCMConnectedEndpoint, *syserr.Error) {
e := SCMConnectedEndpoint{
HostConnectedEndpoint: HostConnectedEndpoint{
fd: hostFD,
addr: addr,
},
queue: queue,
opts: opts,
}

if err := e.init(); err != nil {
Expand Down
17 changes: 4 additions & 13 deletions pkg/sentry/socket/unix/transport/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ type RecvOutput struct {
UnusedRights []RightsControlMessage
}

// UnixSocketOpts is a container for configuration options for gvisor's management of
// unix sockets.
// +stateify savable
type UnixSocketOpts struct {
// If true, the endpoint will be put in a closed state before save; if false, an attempt to save
// will throw.
DisconnectOnSave bool
}

// Endpoint is the interface implemented by Unix transport protocol
// implementations that expose functionality like sendmsg, recvmsg, connect,
// etc. to Unix socket implementations.
Expand Down Expand Up @@ -189,7 +180,7 @@ type Endpoint interface {
// endpoint passed in as a parameter.
//
// The error codes are the same as Connect.
Connect(ctx context.Context, server BoundEndpoint, opts UnixSocketOpts) *syserr.Error
Connect(ctx context.Context, server BoundEndpoint) *syserr.Error

// Shutdown closes the read and/or write end of the endpoint connection
// to its peer.
Expand All @@ -207,7 +198,7 @@ type Endpoint interface {
//
// peerAddr if not nil will be populated with the address of the connected
// peer on a successful accept.
Accept(ctx context.Context, peerAddr *Address, opts UnixSocketOpts) (Endpoint, *syserr.Error)
Accept(ctx context.Context, peerAddr *Address) (Endpoint, *syserr.Error)

// Bind binds the endpoint to a specific local address and port.
// Specifying a NIC is optional.
Expand Down Expand Up @@ -282,7 +273,7 @@ type BoundEndpoint interface {
//
// This method will return syserr.ErrConnectionRefused on endpoints with a
// type that isn't SockStream or SockSeqpacket.
BidirectionalConnect(ctx context.Context, ep ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint), opts UnixSocketOpts) *syserr.Error
BidirectionalConnect(ctx context.Context, ep ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint)) *syserr.Error

// UnidirectionalConnect establishes a write-only connection to a unix
// endpoint.
Expand All @@ -292,7 +283,7 @@ type BoundEndpoint interface {
//
// This method will return syserr.ErrConnectionRefused on a non-SockDgram
// endpoint.
UnidirectionalConnect(ctx context.Context, opts UnixSocketOpts) (ConnectedEndpoint, *syserr.Error)
UnidirectionalConnect(ctx context.Context) (ConnectedEndpoint, *syserr.Error)

// Passcred returns whether or not the SO_PASSCRED socket option is
// enabled on this end.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sentry/socket/unix/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *Socket) blockingAccept(t *kernel.Task, peerAddr *transport.Address) (tr
// Try to accept the connection; if it fails, then wait until we get a
// notification.
for {
if ep, err := s.ep.Accept(t, peerAddr, t.Kernel().UnixSocketOpts); err != syserr.ErrWouldBlock {
if ep, err := s.ep.Accept(t, peerAddr); err != syserr.ErrWouldBlock {
return ep, err
}

Expand All @@ -167,7 +167,7 @@ func (s *Socket) Accept(t *kernel.Task, peerRequested bool, flags int, blocking
if peerRequested {
peerAddr = &transport.Address{}
}
ep, err := s.ep.Accept(t, peerAddr, t.Kernel().UnixSocketOpts)
ep, err := s.ep.Accept(t, peerAddr)
if err != nil {
if err != syserr.ErrWouldBlock || !blocking {
return 0, nil, 0, err
Expand Down Expand Up @@ -618,7 +618,7 @@ func (s *Socket) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr
s.ep.SetPeerCreds(control.MakeCreds(t))

// Connect the server endpoint.
err = s.ep.Connect(t, ep, t.Kernel().UnixSocketOpts)
err = s.ep.Connect(t, ep)

if err == syserr.ErrWrongProtocolForSocket {
// Linux for abstract sockets returns ErrConnectionRefused
Expand Down
8 changes: 0 additions & 8 deletions pkg/tcpip/link/fdbased/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ type Options struct {
// include CapabilitySaveRestore
SaveRestore bool

// DisconnectOk if true, indicates that this NIC capability set should
// include CapabilityDisconnectOk.
DisconnectOk bool

// GSOMaxSize is the maximum GSO packet size. It is zero if GSO is
// disabled.
GSOMaxSize uint32
Expand Down Expand Up @@ -277,10 +273,6 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
caps |= stack.CapabilitySaveRestore
}

if opts.DisconnectOk {
caps |= stack.CapabilityDisconnectOk
}

if len(opts.FDs) == 0 {
return nil, fmt.Errorf("opts.FD is empty, at least one FD must be specified")
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/tcpip/link/xdp/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ type Options struct {
// include CapabilitySaveRestore
SaveRestore bool

// DisconnectOk if true, indicates that this NIC capability set should
// include CapabilityDisconnectOk.
DisconnectOk bool

// TXChecksumOffload if true, indicates that this endpoints capability
// set should include CapabilityTXChecksumOffload.
TXChecksumOffload bool
Expand Down Expand Up @@ -129,10 +125,6 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
caps |= stack.CapabilitySaveRestore
}

if opts.DisconnectOk {
caps |= stack.CapabilityDisconnectOk
}

if err := unix.SetNonblock(opts.FD, true); err != nil {
return nil, fmt.Errorf("unix.SetNonblock(%v) failed: %v", opts.FD, err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/tcpip/stack/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,6 @@ const (
CapabilityRXChecksumOffload
CapabilityResolutionRequired
CapabilitySaveRestore
CapabilityDisconnectOk
CapabilityLoopback
)

Expand Down
Loading
Loading