Skip to content

Commit

Permalink
Validate PACKET_RX_RING and PACKET_VERSION socket option value size.
Browse files Browse the repository at this point in the history
Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 723999333
  • Loading branch information
ayushr2 authored and gvisor-bot committed Feb 6, 2025
1 parent 902a56c commit d8518f2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sentry/socket/netstack/netstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,9 @@ func setSockOptPacket(t *kernel.Task, s socket.Socket, ep commonEndpoint, name i
switch name {
case linux.PACKET_RX_RING:
var tpacketReq linux.TpacketReq
if len(optVal) < tpacketReq.SizeBytes() {
return syserr.ErrInvalidArgument
}
tpacketReq.UnmarshalBytes(optVal)
req := tcpip.TpacketReq{
TpBlockSize: tpacketReq.TpBlockSize,
Expand Down Expand Up @@ -2751,6 +2754,9 @@ func setSockOptPacket(t *kernel.Task, s socket.Socket, ep commonEndpoint, name i
}
return nil
case linux.PACKET_VERSION:
if len(optVal) < sizeOfInt32 {
return syserr.ErrInvalidArgument
}
v := hostarch.ByteOrder.Uint32(optVal)
return syserr.TranslateNetstackError(ep.SetSockOptInt(tcpip.PacketMMapVersionOption, int(v)))
default:
Expand Down

0 comments on commit d8518f2

Please sign in to comment.