]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: remove racey read in session key rotation.
authorDavid Anderson <danderson@tailscale.com>
Wed, 11 Mar 2020 00:52:50 +0000 (17:52 -0700)
committerDavid Crawshaw <david@zentus.com>
Fri, 3 Apr 2020 00:35:28 +0000 (11:35 +1100)
This code was attempting to use the "compare racily, then lock
and compare again" idiom to try and reduce lock contention.
However, that idiom is not safe to use unless the comparison
uses atomic operations, which this does not.

This change simply deletes the racy read. This makes the code
correct, but potentially increases lock contention.

Signed-off-by: David Anderson <danderson@tailscale.com>
device/noise-protocol.go

index dbb6f93d99d0cc1d8cd53994d5ece1292b359d2f..3ce7839eda2431f3d9bdc9036ec7fd328d8ab31d 100644 (file)
@@ -609,9 +609,6 @@ func (peer *Peer) BeginSymmetricSession() error {
 
 func (peer *Peer) ReceivedWithKeypair(receivedKeypair *Keypair) bool {
        keypairs := &peer.keypairs
-       if keypairs.next != receivedKeypair {
-               return false
-       }
        keypairs.Lock()
        defer keypairs.Unlock()
        if keypairs.next != receivedKeypair {