Skip to content

Commit c0bf129

Browse files
nybidarigvisor-bot
authored andcommitted
Remove usage of net-disconnect-ok flag.
The net-disconnect-ok flag was previously used only to cause a panic in the beforeSave() method of TCP and unix connections if it was set to false. Since this flag is now set to true by default, and this default setting causes TCP and unix connections to always be aborted during the save operation, the flag no longer serves its original purpose of conditionally preventing connection termination. So, the flag's usage is removed. PiperOrigin-RevId: 840433518
1 parent 385d295 commit c0bf129

File tree

19 files changed

+30
-99
lines changed

19 files changed

+30
-99
lines changed

pkg/sentry/fsimpl/gofer/socket.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type endpoint struct {
5454
}
5555

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

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

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

8686
// UnidirectionalConnect implements
8787
// transport.BoundEndpoint.UnidirectionalConnect.
88-
func (e *endpoint) UnidirectionalConnect(ctx context.Context, opts transport.UnixSocketOpts) (transport.ConnectedEndpoint, *syserr.Error) {
89-
c, err := e.newConnectedEndpoint(ctx, linux.SOCK_DGRAM, &waiter.Queue{}, opts)
88+
func (e *endpoint) UnidirectionalConnect(ctx context.Context) (transport.ConnectedEndpoint, *syserr.Error) {
89+
c, err := e.newConnectedEndpoint(ctx, linux.SOCK_DGRAM, &waiter.Queue{})
9090
if err != nil {
9191
return nil, err
9292
}
@@ -102,15 +102,15 @@ func (e *endpoint) UnidirectionalConnect(ctx context.Context, opts transport.Uni
102102
return c, nil
103103
}
104104

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

113-
c, serr := transport.NewSCMEndpoint(hostSockFD, queue, e.path, opts)
113+
c, serr := transport.NewSCMEndpoint(hostSockFD, queue, e.path)
114114
if serr != nil {
115115
unix.Close(hostSockFD)
116116
log.Warningf("NewSCMEndpoint failed: path=%q, err=%v", e.path, serr)

pkg/sentry/fsimpl/testutil/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ go_library(
3131
"//pkg/sentry/platform/kvm",
3232
"//pkg/sentry/platform/ptrace",
3333
"//pkg/sentry/seccheck",
34-
"//pkg/sentry/socket/unix/transport",
3534
"//pkg/sentry/time",
3635
"//pkg/sentry/usage",
3736
"//pkg/sentry/vfs",

pkg/sentry/fsimpl/testutil/kernel.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"gvisor.dev/gvisor/pkg/sentry/pgalloc"
3636
"gvisor.dev/gvisor/pkg/sentry/platform"
3737
"gvisor.dev/gvisor/pkg/sentry/seccheck"
38-
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
3938
"gvisor.dev/gvisor/pkg/sentry/time"
4039
"gvisor.dev/gvisor/pkg/sentry/usage"
4140
"gvisor.dev/gvisor/pkg/sentry/vfs"
@@ -107,7 +106,6 @@ func Boot() (*kernel.Kernel, error) {
107106
RootUTSNamespace: kernel.NewUTSNamespace("hostname", "domain", creds.UserNamespace),
108107
RootIPCNamespace: kernel.NewIPCNamespace(creds.UserNamespace),
109108
RootPIDNamespace: kernel.NewRootPIDNamespace(creds.UserNamespace),
110-
UnixSocketOpts: transport.UnixSocketOpts{},
111109
}); err != nil {
112110
return nil, fmt.Errorf("initializing kernel: %v", err)
113111
}

pkg/sentry/kernel/kernel.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import (
7272
"gvisor.dev/gvisor/pkg/sentry/pgalloc"
7373
"gvisor.dev/gvisor/pkg/sentry/platform"
7474
"gvisor.dev/gvisor/pkg/sentry/socket/netlink/port"
75-
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
7675
"gvisor.dev/gvisor/pkg/sentry/state/stateio"
7776
sentrytime "gvisor.dev/gvisor/pkg/sentry/time"
7877
"gvisor.dev/gvisor/pkg/sentry/unimpl"
@@ -388,9 +387,6 @@ type Kernel struct {
388387
// when checkpoint/restore are done. It's protected by checkpointMu.
389388
checkpointGen CheckpointGeneration
390389

391-
// UnixSocketOpts stores configuration options for management of unix sockets.
392-
UnixSocketOpts transport.UnixSocketOpts
393-
394390
// SaveRestoreExecConfig stores configuration options for the save/restore
395391
// exec binary.
396392
SaveRestoreExecConfig *SaveRestoreExecConfig
@@ -456,9 +452,6 @@ type InitKernelArgs struct {
456452
// used by processes. If it is zero, the limit will be set to
457453
// unlimited.
458454
MaxFDLimit int32
459-
460-
// UnixSocketOpts contains configuration options for unix sockets.
461-
UnixSocketOpts transport.UnixSocketOpts
462455
}
463456

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

585578
k.cgroupRegistry = newCgroupRegistry()
586-
k.UnixSocketOpts = args.UnixSocketOpts
587579
k.MaxKeySetSize = atomicbitops.FromInt32(auth.MaxSetSize)
588580
return nil
589581
}

pkg/sentry/socket/netlink/socket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func New(t *kernel.Task, skType linux.SockType, protocol Protocol) (*Socket, *sy
146146
}
147147

148148
// Create a connection from which the kernel can write messages.
149-
connection, err := ep.(transport.BoundEndpoint).UnidirectionalConnect(t, t.Kernel().UnixSocketOpts)
149+
connection, err := ep.(transport.BoundEndpoint).UnidirectionalConnect(t)
150150
if err != nil {
151151
ep.Close(t)
152152
return nil, err

pkg/sentry/socket/unix/transport/connectioned.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (e *connectionedEndpoint) swapPeerCredsLocked(ctx context.Context, cend Con
293293
}
294294

295295
// BidirectionalConnect implements BoundEndpoint.BidirectionalConnect.
296-
func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint), opts UnixSocketOpts) *syserr.Error {
296+
func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint)) *syserr.Error {
297297
if ce.Type() != e.stype {
298298
return syserr.ErrWrongProtocolForSocket
299299
}
@@ -400,13 +400,13 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
400400
}
401401

402402
// UnidirectionalConnect implements BoundEndpoint.UnidirectionalConnect.
403-
func (e *connectionedEndpoint) UnidirectionalConnect(ctx context.Context, opts UnixSocketOpts) (ConnectedEndpoint, *syserr.Error) {
403+
func (e *connectionedEndpoint) UnidirectionalConnect(ctx context.Context) (ConnectedEndpoint, *syserr.Error) {
404404
return nil, syserr.ErrConnectionRefused
405405
}
406406

407407
// Connect attempts to directly connect to another Endpoint.
408408
// Implements Endpoint.Connect.
409-
func (e *connectionedEndpoint) Connect(ctx context.Context, server BoundEndpoint, opts UnixSocketOpts) *syserr.Error {
409+
func (e *connectionedEndpoint) Connect(ctx context.Context, server BoundEndpoint) *syserr.Error {
410410
returnConnect := func(r Receiver, ce ConnectedEndpoint) {
411411
e.receiver = r
412412
e.connected = ce
@@ -418,7 +418,7 @@ func (e *connectionedEndpoint) Connect(ctx context.Context, server BoundEndpoint
418418
}
419419
}
420420

421-
return server.BidirectionalConnect(ctx, e, returnConnect, opts)
421+
return server.BidirectionalConnect(ctx, e, returnConnect)
422422
}
423423

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

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

466466
if !e.ListeningLocked() {
467467
e.Unlock()
468468
return nil, syserr.ErrInvalidEndpointState
469469
}
470470

471-
ne, err := e.getAcceptedEndpointLocked(ctx, opts)
471+
ne, err := e.getAcceptedEndpointLocked(ctx)
472472
e.Unlock()
473473
if err != nil {
474474
return nil, err
@@ -492,7 +492,7 @@ func (e *connectionedEndpoint) Accept(ctx context.Context, peerAddr *Address, op
492492
// Preconditions:
493493
// - e.Listening()
494494
// - e is locked.
495-
func (e *connectionedEndpoint) getAcceptedEndpointLocked(ctx context.Context, opts UnixSocketOpts) (*connectionedEndpoint, *syserr.Error) {
495+
func (e *connectionedEndpoint) getAcceptedEndpointLocked(ctx context.Context) (*connectionedEndpoint, *syserr.Error) {
496496
// Accept connections from within the sentry first, since this avoids
497497
// an RPC to the gofer on the common path.
498498
select {
@@ -515,7 +515,7 @@ func (e *connectionedEndpoint) getAcceptedEndpointLocked(ctx context.Context, op
515515
return nil, syserr.FromError(err)
516516
}
517517
q := &waiter.Queue{}
518-
scme, serr := NewSCMEndpoint(nfd, q, e.path, opts)
518+
scme, serr := NewSCMEndpoint(nfd, q, e.path)
519519
if serr != nil {
520520
unix.Close(nfd)
521521
return nil, serr

pkg/sentry/socket/unix/transport/connectionless.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ func (e *connectionlessEndpoint) Close(ctx context.Context) {
8585
}
8686

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

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

117-
opts := UnixSocketOpts{}
118-
connected, err := to.UnidirectionalConnect(ctx, opts)
117+
connected, err := to.UnidirectionalConnect(ctx)
119118
if err != nil {
120119
return 0, nil, syserr.ErrInvalidEndpointState
121120
}
@@ -139,8 +138,8 @@ func (e *connectionlessEndpoint) Type() linux.SockType {
139138
}
140139

141140
// Connect attempts to connect directly to server.
142-
func (e *connectionlessEndpoint) Connect(ctx context.Context, server BoundEndpoint, opts UnixSocketOpts) *syserr.Error {
143-
connected, err := server.UnidirectionalConnect(ctx, opts)
141+
func (e *connectionlessEndpoint) Connect(ctx context.Context, server BoundEndpoint) *syserr.Error {
142+
connected, err := server.UnidirectionalConnect(ctx)
144143
if err != nil {
145144
return err
146145
}
@@ -161,7 +160,7 @@ func (*connectionlessEndpoint) Listen(context.Context, int) *syserr.Error {
161160
}
162161

163162
// Accept accepts a new connection.
164-
func (*connectionlessEndpoint) Accept(context.Context, *Address, UnixSocketOpts) (Endpoint, *syserr.Error) {
163+
func (*connectionlessEndpoint) Accept(context.Context, *Address) (Endpoint, *syserr.Error) {
165164
return nil, syserr.ErrNotSupported
166165
}
167166

pkg/sentry/socket/unix/transport/host.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,10 @@ type SCMConnectedEndpoint struct {
421421
HostConnectedEndpoint
422422

423423
queue *waiter.Queue
424-
opts UnixSocketOpts
425424
}
426425

427426
// beforeSave is invoked by stateify.
428427
func (e *SCMConnectedEndpoint) beforeSave() {
429-
if !e.opts.DisconnectOnSave {
430-
panic("socket cannot be saved in a connected state")
431-
}
432-
433428
e.mu.Lock()
434429
defer e.mu.Unlock()
435430
fdnotifier.RemoveFD(int32(e.fd))
@@ -470,14 +465,13 @@ func (e *SCMConnectedEndpoint) Release(ctx context.Context) {
470465
// The caller is responsible for calling Init(). Additionally, Release needs to
471466
// be called twice because ConnectedEndpoint is both a Receiver and
472467
// ConnectedEndpoint.
473-
func NewSCMEndpoint(hostFD int, queue *waiter.Queue, addr string, opts UnixSocketOpts) (*SCMConnectedEndpoint, *syserr.Error) {
468+
func NewSCMEndpoint(hostFD int, queue *waiter.Queue, addr string) (*SCMConnectedEndpoint, *syserr.Error) {
474469
e := SCMConnectedEndpoint{
475470
HostConnectedEndpoint: HostConnectedEndpoint{
476471
fd: hostFD,
477472
addr: addr,
478473
},
479474
queue: queue,
480-
opts: opts,
481475
}
482476

483477
if err := e.init(); err != nil {

pkg/sentry/socket/unix/transport/unix.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,6 @@ type RecvOutput struct {
147147
UnusedRights []RightsControlMessage
148148
}
149149

150-
// UnixSocketOpts is a container for configuration options for gvisor's management of
151-
// unix sockets.
152-
// +stateify savable
153-
type UnixSocketOpts struct {
154-
// If true, the endpoint will be put in a closed state before save; if false, an attempt to save
155-
// will throw.
156-
DisconnectOnSave bool
157-
}
158-
159150
// Endpoint is the interface implemented by Unix transport protocol
160151
// implementations that expose functionality like sendmsg, recvmsg, connect,
161152
// etc. to Unix socket implementations.
@@ -189,7 +180,7 @@ type Endpoint interface {
189180
// endpoint passed in as a parameter.
190181
//
191182
// The error codes are the same as Connect.
192-
Connect(ctx context.Context, server BoundEndpoint, opts UnixSocketOpts) *syserr.Error
183+
Connect(ctx context.Context, server BoundEndpoint) *syserr.Error
193184

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

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

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

297288
// Passcred returns whether or not the SO_PASSCRED socket option is
298289
// enabled on this end.

pkg/sentry/socket/unix/unix.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (s *Socket) blockingAccept(t *kernel.Task, peerAddr *transport.Address) (tr
150150
// Try to accept the connection; if it fails, then wait until we get a
151151
// notification.
152152
for {
153-
if ep, err := s.ep.Accept(t, peerAddr, t.Kernel().UnixSocketOpts); err != syserr.ErrWouldBlock {
153+
if ep, err := s.ep.Accept(t, peerAddr); err != syserr.ErrWouldBlock {
154154
return ep, err
155155
}
156156

@@ -167,7 +167,7 @@ func (s *Socket) Accept(t *kernel.Task, peerRequested bool, flags int, blocking
167167
if peerRequested {
168168
peerAddr = &transport.Address{}
169169
}
170-
ep, err := s.ep.Accept(t, peerAddr, t.Kernel().UnixSocketOpts)
170+
ep, err := s.ep.Accept(t, peerAddr)
171171
if err != nil {
172172
if err != syserr.ErrWouldBlock || !blocking {
173173
return 0, nil, 0, err
@@ -618,7 +618,7 @@ func (s *Socket) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr
618618
s.ep.SetPeerCreds(control.MakeCreds(t))
619619

620620
// Connect the server endpoint.
621-
err = s.ep.Connect(t, ep, t.Kernel().UnixSocketOpts)
621+
err = s.ep.Connect(t, ep)
622622

623623
if err == syserr.ErrWrongProtocolForSocket {
624624
// Linux for abstract sockets returns ErrConnectionRefused

0 commit comments

Comments
 (0)