diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-02-26 19:23:18 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-26 19:23:18 +0000 |
commit | 796fd943e2c8210dd0837feeac21b7483d62be49 (patch) | |
tree | 780d0a73303a7d758aa321c95794e9055072256f /pkg/tcpip/stack/transport_demuxer.go | |
parent | 2cd2e6fb8893e28432ea14c450c1c265d2989bd3 (diff) | |
parent | da2505df94770301e7907cfaff5e5c7fdd531b75 (diff) |
Merge release-20210208.0-101-gda2505df9 (automated)
Diffstat (limited to 'pkg/tcpip/stack/transport_demuxer.go')
-rw-r--r-- | pkg/tcpip/stack/transport_demuxer.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pkg/tcpip/stack/transport_demuxer.go b/pkg/tcpip/stack/transport_demuxer.go index 61cbaf688..e799f9290 100644 --- a/pkg/tcpip/stack/transport_demuxer.go +++ b/pkg/tcpip/stack/transport_demuxer.go @@ -583,9 +583,14 @@ func (d *transportDemuxer) deliverRawPacket(protocol tcpip.TransportProtocolNumb // raw endpoint first. If there are multiple raw endpoints, they all // receive the packet. eps.mu.RLock() - // Copy the list of raw endpoints so we can release eps.mu earlier. - rawEPs := make([]RawTransportEndpoint, len(eps.rawEndpoints)) - copy(rawEPs, eps.rawEndpoints) + // Copy the list of raw endpoints to avoid packet handling under lock. + var rawEPs []RawTransportEndpoint + if n := len(eps.rawEndpoints); n != 0 { + rawEPs = make([]RawTransportEndpoint, n) + if m := copy(rawEPs, eps.rawEndpoints); m != n { + panic(fmt.Sprintf("unexpected copy = %d, want %d", m, n)) + } + } eps.mu.RUnlock() for _, rawEP := range rawEPs { // Each endpoint gets its own copy of the packet for the sake @@ -593,7 +598,7 @@ func (d *transportDemuxer) deliverRawPacket(protocol tcpip.TransportProtocolNumb rawEP.HandlePacket(pkt.Clone()) } - return len(rawEPs) > 0 + return len(rawEPs) != 0 } // deliverError attempts to deliver the given error to the appropriate transport |