Skip to content

Commit 89b65f2

Browse files
parth-opensrcgvisor-bot
authored andcommitted
socket: support checking capability in owner namespace.
PiperOrigin-RevId: 859178339
1 parent 6b63320 commit 89b65f2

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

pkg/sentry/socket/hostinet/socket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ func (s *Socket) Type() (family int, skType linux.SockType, protocol int) {
867867
return s.family, s.stype, s.protocol
868868
}
869869

870+
// HasCapability implements socket.Socket.TaskHasCapability.
871+
func (s *Socket) HasCapability(cp linux.Capability, t *kernel.Task) bool {
872+
// Unimplemented.
873+
return false
874+
}
875+
870876
func init() {
871877
// Register all families in AllowedSocketTypes and AllowedRawSocket
872878
// types. If we don't allow raw sockets, they will be rejected in the

pkg/sentry/socket/netlink/socket.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,3 +1057,10 @@ func (s *Socket) GetPortID() int32 {
10571057
defer s.mu.Unlock()
10581058
return s.portID
10591059
}
1060+
1061+
// HasCapability implements socket.Socket.HasCapability.
1062+
func (s *Socket) HasCapability(cp linux.Capability, t *kernel.Task) bool {
1063+
// Unimplemented, only to satisfy the interface.
1064+
// netlink_net_capable differs from sk_net_capable.
1065+
return false
1066+
}

pkg/sentry/socket/netstack/netstack.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3861,3 +3861,8 @@ func (s *sock) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error {
38613861
}
38623862
return linuxerr.ENODEV
38633863
}
3864+
3865+
// HasCapability implements socket.Socket.TaskHasCapability.
3866+
func (s *sock) HasCapability(cp linux.Capability, t *kernel.Task) bool {
3867+
return t.Credentials().HasCapabilityIn(cp, s.namespace.UserNamespace())
3868+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,3 +855,9 @@ func (s *socketOperations) waitEventT(ctx context.Context, event waiter.EventMas
855855
s.EventUnregister(&e)
856856
return err
857857
}
858+
859+
// HasCapability implements socket.Socket.TaskHasCapability.
860+
func (s *socketOperations) HasCapability(cp linux.Capability, t *kernel.Task) bool {
861+
// Unimplemented.
862+
return false
863+
}

pkg/sentry/socket/socket.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ type Socket interface {
260260
// GetPeerCreds returns the peer credentials of the socket.
261261
GetPeerCreds(t *kernel.Task) (marshal.Marshallable, *syserr.Error)
262262

263+
// HasCapability returns true if the task has the given capability in
264+
// the socket opener's user namespace.
265+
// Similar to `sk_net_capable` in Linux.
266+
HasCapability(cp linux.Capability, t *kernel.Task) bool
267+
263268
// RecvMsg implements the recvmsg(2) linux unix.
264269
//
265270
// senderAddrLen is the address length to be returned to the application,

pkg/sentry/socket/unix/unix.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ func (s *Socket) Type() (family int, skType linux.SockType, protocol int) {
900900
return linux.AF_UNIX, s.stype, 0
901901
}
902902

903+
// HasCapability implements socket.Socket.TaskHasCapability.
904+
func (s *Socket) HasCapability(cp linux.Capability, t *kernel.Task) bool {
905+
// Unimplemented.
906+
return false
907+
}
908+
903909
func convertAddress(addr transport.Address) (linux.SockAddr, uint32) {
904910
var out linux.SockAddrUnix
905911
out.Family = linux.AF_UNIX

0 commit comments

Comments
 (0)