diff options
author | Josh Bleecher Snyder <josh@tailscale.com> | 2020-12-15 15:02:13 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-07 14:49:44 +0100 |
commit | 70861686d3005de91b45d38e5b16fd3132a4a872 (patch) | |
tree | c235b16ab7aae0907f4276feef66239eb820a29b /device/peer.go | |
parent | c8faa34cdee37d9bcb588675e2385024bef86c18 (diff) |
device: fix races from changing private_key
Access keypair.sendNonce atomically.
Eliminate one unnecessary initialization to zero.
Mutate handshake.lastSentHandshake with the mutex held.
Co-authored-by: David Anderson <danderson@tailscale.com>
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/peer.go')
-rw-r--r-- | device/peer.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/device/peer.go b/device/peer.go index c094160..fe6de33 100644 --- a/device/peer.go +++ b/device/peer.go @@ -249,16 +249,17 @@ func (peer *Peer) ExpireCurrentKeypairs() { handshake.mutex.Lock() peer.device.indexTable.Delete(handshake.localIndex) handshake.Clear() - handshake.mutex.Unlock() peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second)) + handshake.mutex.Unlock() keypairs := &peer.keypairs keypairs.Lock() if keypairs.current != nil { - keypairs.current.sendNonce = RejectAfterMessages + atomic.StoreUint64(&keypairs.current.sendNonce, RejectAfterMessages) } if keypairs.next != nil { - keypairs.loadNext().sendNonce = RejectAfterMessages + next := keypairs.loadNext() + atomic.StoreUint64(&next.sendNonce, RejectAfterMessages) } keypairs.Unlock() } |