diff options
author | Tamir Duberstein <tamird@google.com> | 2021-01-28 19:58:49 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-28 20:01:08 -0800 |
commit | b81b5883c747dcd019a228e109dbe52514710a88 (patch) | |
tree | a0a810a825fbdb8bee24744edffd7f3f6b5d08a0 /pkg/tcpip/stack | |
parent | 9cc2570ea74c678238ed82d044cfecbfe62c5981 (diff) |
Acquire entry lock with cache lock held
Avoid a race condition in which an entry is acquired while it is being
evicted by overlapping the entry lock with the cache lock.
PiperOrigin-RevId: 354452639
Diffstat (limited to 'pkg/tcpip/stack')
-rw-r--r-- | pkg/tcpip/stack/linkaddrcache.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/pkg/tcpip/stack/linkaddrcache.go b/pkg/tcpip/stack/linkaddrcache.go index 3ce7a57db..930b8f795 100644 --- a/pkg/tcpip/stack/linkaddrcache.go +++ b/pkg/tcpip/stack/linkaddrcache.go @@ -148,10 +148,10 @@ func (c *linkAddrCache) AddLinkAddress(k tcpip.Address, v tcpip.LinkAddress) { c.mu.Lock() entry := c.getOrCreateEntryLocked(k) - c.mu.Unlock() - entry.mu.Lock() defer entry.mu.Unlock() + c.mu.Unlock() + entry.mu.linkAddr = v entry.changeStateLocked(ready, expiration) } @@ -201,10 +201,10 @@ func (c *linkAddrCache) getOrCreateEntryLocked(k tcpip.Address) *linkAddrEntry { // get reports any known link address for k. func (c *linkAddrCache) get(k tcpip.Address, linkRes LinkAddressResolver, localAddr tcpip.Address, nic NetworkInterface, onResolve func(LinkResolutionResult)) (tcpip.LinkAddress, <-chan struct{}, tcpip.Error) { c.mu.Lock() - defer c.mu.Unlock() entry := c.getOrCreateEntryLocked(k) entry.mu.Lock() defer entry.mu.Unlock() + c.mu.Unlock() switch s := entry.mu.s; s { case ready: |