Skip to content

Commit

Permalink
Lock around packetmmap cooked field and check for PACKET_RESERVE opt …
Browse files Browse the repository at this point in the history
…size.

Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 725302503
  • Loading branch information
manninglucas authored and gvisor-bot committed Feb 10, 2025
1 parent deaf50d commit d6454b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/sentry/socket/netstack/packetmmap/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ type Endpoint struct {

// +checklocks:mu
mode ringBufferMode
// +checklocks:mu
cooked bool

cooked bool
packetEP stack.MappablePacketEndpoint
reserve uint32
nicID tcpip.NICID
Expand Down Expand Up @@ -192,6 +193,7 @@ func (m *Endpoint) HandlePacket(nicID tcpip.NICID, netProto tcpip.NetworkProtoco
)

m.mu.Lock()
cooked := m.cooked
if !m.rxRingBuffer.hasRoom() {
m.mu.Unlock()
m.stack.Stats().DroppedPackets.Increment()
Expand All @@ -208,7 +210,7 @@ func (m *Endpoint) HandlePacket(nicID tcpip.NICID, netProto tcpip.NetworkProtoco
}

pktBuf := pkt.ToBuffer()
if m.cooked {
if cooked {
pktBuf.TrimFront(int64(len(pkt.LinkHeader().Slice()) + len(pkt.VirtioNetHeader().Slice())))
// Cooked packet endpoints don't include the link-headers in received
// packets.
Expand Down

0 comments on commit d6454b4

Please sign in to comment.