Skip to content

Commit 2f7f776

Browse files
AnilAltinaygvisor-bot
authored andcommitted
Automated rollback of changelist 798788535
PiperOrigin-RevId: 803481970
1 parent 16e9064 commit 2f7f776

File tree

15 files changed

+9
-384
lines changed

15 files changed

+9
-384
lines changed

pkg/sentry/socket/hostinet/socket.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"gvisor.dev/gvisor/pkg/errors/linuxerr"
2525
"gvisor.dev/gvisor/pkg/fdnotifier"
2626
"gvisor.dev/gvisor/pkg/log"
27-
"gvisor.dev/gvisor/pkg/marshal"
2827
"gvisor.dev/gvisor/pkg/marshal/primitive"
2928
"gvisor.dev/gvisor/pkg/safemem"
3029
"gvisor.dev/gvisor/pkg/sentry/arch"
@@ -829,8 +828,3 @@ func init() {
829828
registered[fam] = struct{}{}
830829
}
831830
}
832-
833-
// GetPeerCreds implements socket.Socket.GetPeerCreds
834-
func (s *Socket) GetPeerCreds(t *kernel.Task) (marshal.Marshallable, *syserr.Error) {
835-
return nil, syserr.ErrNotSupported
836-
}

pkg/sentry/socket/netlink/socket.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,6 @@ func (s *Socket) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Er
568568
return sa, uint32(sa.SizeBytes()), nil
569569
}
570570

571-
// GetPeerCreds implements socket.Socket.GetPeerCreds.
572-
func (s *Socket) GetPeerCreds(t *kernel.Task) (marshal.Marshallable, *syserr.Error) {
573-
return nil, syserr.ErrNotSupported
574-
}
575-
576571
// RecvMsg implements socket.Socket.RecvMsg.
577572
func (s *Socket) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, deadline ktime.Time, senderRequested bool, controlDataLen uint64) (int, int, linux.SockAddr, uint32, socket.ControlMessages, *syserr.Error) {
578573
from := &linux.SockAddrNetlink{

pkg/sentry/socket/netstack/netstack.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,14 @@ func getSockOptSocket(t *kernel.Task, s socket.Socket, ep commonEndpoint, family
980980
if family != linux.AF_UNIX || outLen < unix.SizeofUcred {
981981
return nil, syserr.ErrInvalidArgument
982982
}
983-
return s.GetPeerCreds(t)
983+
984+
tcred := t.Credentials()
985+
creds := linux.ControlMessageCredentials{
986+
PID: int32(t.ThreadGroup().ID()),
987+
UID: uint32(tcred.EffectiveKUID.In(tcred.UserNamespace).OrOverflow()),
988+
GID: uint32(tcred.EffectiveKGID.In(tcred.UserNamespace).OrOverflow()),
989+
}
990+
return &creds, nil
984991

985992
case linux.SO_PASSCRED:
986993
if outLen < sizeOfInt32 {
@@ -3019,10 +3026,6 @@ func (s *sock) GetPeerName(*kernel.Task) (linux.SockAddr, uint32, *syserr.Error)
30193026
return a, l, nil
30203027
}
30213028

3022-
func (s *sock) GetPeerCreds(*kernel.Task) (marshal.Marshallable, *syserr.Error) {
3023-
return nil, syserr.ErrNotSupported
3024-
}
3025-
30263029
func (s *sock) fillCmsgInq(cmsg *socket.ControlMessages) {
30273030
if !s.sockOptInq {
30283031
return

pkg/sentry/socket/plugin/stack/socket.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,6 @@ func (s *socketOperations) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32,
569569
return socket.UnmarshalSockAddr(s.family, addr), addrlen, nil
570570
}
571571

572-
// GetPeerCreds implements socket.Socket.GetPeerCreds.
573-
func (s *socketOperations) GetPeerCreds(t *kernel.Task) (marshal.Marshallable, *syserr.Error) {
574-
return nil, syserr.ErrInvalidEndpointState
575-
}
576-
577572
// recv is a helper function for doing non-blocking read once.
578573
// It returns:
579574
// 1. number of bytes received;

pkg/sentry/socket/socket.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ type Socket interface {
257257
// necessarily the actual length of the address.
258258
GetPeerName(t *kernel.Task) (addr linux.SockAddr, addrLen uint32, err *syserr.Error)
259259

260-
// GetPeerCreds returns the peer credentials of the socket.
261-
GetPeerCreds(t *kernel.Task) (marshal.Marshallable, *syserr.Error)
262-
263260
// RecvMsg implements the recvmsg(2) linux unix.
264261
//
265262
// senderAddrLen is the address length to be returned to the application,

pkg/sentry/socket/unix/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ go_library(
4242
"//pkg/sentry/fsutil",
4343
"//pkg/sentry/inet",
4444
"//pkg/sentry/kernel",
45-
"//pkg/sentry/kernel/auth",
4645
"//pkg/sentry/ktime",
4746
"//pkg/sentry/socket",
4847
"//pkg/sentry/socket/control",

pkg/sentry/socket/unix/transport/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ go_library(
9797
"//pkg/log",
9898
"//pkg/refs",
9999
"//pkg/sentry/hostfd",
100-
"//pkg/sentry/kernel/auth",
101100
"//pkg/sentry/uniqueid",
102101
"//pkg/sync",
103102
"//pkg/sync/locking",

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ type connectionedEndpoint struct {
106106
// tcpip.SockStream.
107107
stype linux.SockType
108108

109-
// peerCreds is used to store the peer credentials.
110-
// This will store the socket's own credentials until the connection is
111-
// established with connect(2). Once the connection is established, this
112-
// will store the peer's credentials. The use of this option is possible
113-
// only for connected `AF_UNIX` stream sockets and for `AF_UNIX` stream and
114-
// datagram socket pairs created using socketpair(2)
115-
peerCreds CredentialsControlMessage
116-
117109
// acceptedChan is per the TCP endpoint implementation. Note that the
118110
// sockets in this channel are _already in the connected state_, and
119111
// have another associated connectionedEndpoint.
@@ -282,16 +274,6 @@ func (e *connectionedEndpoint) Close(ctx context.Context) {
282274
}
283275
}
284276

285-
func (e *connectionedEndpoint) swapPeerCreds(ctx context.Context, cend ConnectingEndpoint, ne *connectionedEndpoint) *syserr.Error {
286-
ce, ok := cend.(*connectionedEndpoint)
287-
if !ok {
288-
return syserr.ErrInvalidEndpointState
289-
}
290-
// Swap peer credentials between the two endpoints.
291-
ne.peerCreds, ce.peerCreds = ce.peerCreds, ne.peerCreds
292-
return nil
293-
}
294-
295277
// BidirectionalConnect implements BoundEndpoint.BidirectionalConnect.
296278
func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce ConnectingEndpoint, returnConnect func(Receiver, ConnectedEndpoint), opts UnixSocketOpts) *syserr.Error {
297279
if ce.Type() != e.stype {
@@ -345,7 +327,6 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
345327
ne.ops.SetSendBufferSize(defaultBufferSize, false /* notify */)
346328
ne.ops.SetReceiveBufferSize(defaultBufferSize, false /* notify */)
347329
ne.SocketOptions().SetPassCred(e.SocketOptions().GetPassCred())
348-
ne.peerCreds = e.peerCreds
349330

350331
readQueue := &queue{ReaderQueue: ce.WaiterQueue(), WriterQueue: ne.Queue, limit: defaultBufferSize}
351332
readQueue.InitRefs()
@@ -373,9 +354,6 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
373354
}
374355
readQueue.IncRef()
375356
if e.stype == linux.SOCK_STREAM {
376-
if err := e.swapPeerCreds(ctx, ce, ne); err != nil {
377-
return err
378-
}
379357
returnConnect(&streamQueueReceiver{queueReceiver: queueReceiver{readQueue: readQueue}}, connected)
380358
} else {
381359
returnConnect(&queueReceiver{readQueue: readQueue}, connected)
@@ -677,11 +655,3 @@ func (e *connectionedEndpoint) EventUnregister(we *waiter.Entry) {
677655
func (e *connectionedEndpoint) GetAcceptConn() bool {
678656
return e.Listening()
679657
}
680-
681-
func (e *connectionedEndpoint) PeerCreds() CredentialsControlMessage {
682-
return e.peerCreds
683-
}
684-
685-
func (e *connectionedEndpoint) SetPeerCreds(creds CredentialsControlMessage) {
686-
e.peerCreds = creds
687-
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,6 @@ func (*connectionlessEndpoint) Accept(context.Context, *Address, UnixSocketOpts)
158158
return nil, syserr.ErrNotSupported
159159
}
160160

161-
func (e *connectionlessEndpoint) PeerCreds() CredentialsControlMessage {
162-
return nil
163-
}
164-
165-
func (e *connectionlessEndpoint) SetPeerCreds(creds CredentialsControlMessage) {
166-
// no-op
167-
}
168-
169161
// Bind binds the connection.
170162
//
171163
// For Unix endpoints, this _only sets the address associated with the socket_.

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ type CredentialsControlMessage interface {
5252
Equals(CredentialsControlMessage) bool
5353
}
5454

55-
// A PeerCredentialer is a socket or endpoint that supports the SO_PEERCREDS socket
56-
// option.
57-
type PeerCredentialer interface {
58-
// PeerCreds returns the peer credentials.
59-
PeerCreds() CredentialsControlMessage
60-
61-
// SetPeerCreds sets the peer credentials.
62-
SetPeerCreds(creds CredentialsControlMessage)
63-
}
64-
6555
// A ControlMessages represents a collection of socket control messages.
6656
//
6757
// +stateify savable
@@ -161,7 +151,6 @@ type UnixSocketOpts struct {
161151
// etc. to Unix socket implementations.
162152
type Endpoint interface {
163153
Credentialer
164-
PeerCredentialer
165154
waiter.Waitable
166155

167156
// Close puts the endpoint in a closed state and frees all resources

0 commit comments

Comments
 (0)