mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user