summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmanda Tait <atait@google.com>2019-02-25 10:01:25 -0800
committerShentubot <shentubot@google.com>2019-02-25 10:02:29 -0800
commitc14a1a161869804af5ae2f1f73fd8eeb135ff043 (patch)
tree1a579653fea54fce3943c5dc4567563a646c05ef
parent317c0324c9c73e1c6d6c9cfa7e9cdbfbf1f63b06 (diff)
Fix race condition in NIC.DeliverNetworkPacket
cl/234850781 introduced a race condition in NIC.DeliverNetworkPacket by failing to hold a lock. This change fixes this regressesion by acquiring a read lock before iterating through n.endpoints, and then releasing the lock once iteration is complete. PiperOrigin-RevId: 235549770 Change-Id: Ib0133288be512d478cf759c3314dc95ec3205d4b
-rw-r--r--pkg/tcpip/stack/nic.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go
index 43d7c2ec4..a6b04faaf 100644
--- a/pkg/tcpip/stack/nic.go
+++ b/pkg/tcpip/stack/nic.go
@@ -403,14 +403,19 @@ func (n *NIC) DeliverNetworkPacket(linkEP LinkEndpoint, remote, _ tcpip.LinkAddr
// route to each IPv4 network endpoint and let each endpoint handle the
// packet.
if dst == header.IPv4Broadcast {
+ // n.endpoints is mutex protected so acquire lock.
+ n.mu.RLock()
for _, ref := range n.endpoints {
+ n.mu.RUnlock()
if ref.protocol == header.IPv4ProtocolNumber && ref.tryIncRef() {
r := makeRoute(protocol, dst, src, linkEP.LinkAddress(), ref)
r.RemoteLinkAddress = remote
ref.ep.HandlePacket(&r, vv)
ref.decRef()
}
+ n.mu.RLock()
}
+ n.mu.RUnlock()
return
}