diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-18 20:26:40 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-18 20:26:40 +0200 |
commit | 2d01527aee1308f4c07652849da569825870ed14 (patch) | |
tree | 5dfdede6008dc96b1512f035f18ebf0f2733e4ea /src/noise.c | |
parent | df53a8ac4a274cd86ee99017b7670c9e0ddaa5c6 (diff) |
noise: take locks for ss precomputation
Usually this is called from handshake_init, where locking doesn't matter
because nothing references it yet, but it's also called when changing
the device private key, so it's probably a good thing to not process a
handshake with a ss precomputation that's part old and part new.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/noise.c')
-rw-r--r-- | src/noise.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/noise.c b/src/noise.c index b346ca9..bab8e7c 100644 --- a/src/noise.c +++ b/src/noise.c @@ -44,10 +44,16 @@ void __init noise_init(void) bool noise_precompute_static_static(struct wireguard_peer *peer) { + bool ret = true; + down_read(&peer->handshake.static_identity->lock); + down_write(&peer->handshake.lock); if (peer->handshake.static_identity->has_identity) - return curve25519(peer->handshake.precomputed_static_static, peer->handshake.static_identity->static_private, peer->handshake.remote_static); - memset(peer->handshake.precomputed_static_static, 0, NOISE_PUBLIC_KEY_LEN); - return true; + ret = curve25519(peer->handshake.precomputed_static_static, peer->handshake.static_identity->static_private, peer->handshake.remote_static); + else + memset(peer->handshake.precomputed_static_static, 0, NOISE_PUBLIC_KEY_LEN); + up_write(&peer->handshake.lock); + up_read(&peer->handshake.static_identity->lock); + return ret; } bool noise_handshake_init(struct noise_handshake *handshake, struct noise_static_identity *static_identity, const u8 peer_public_key[NOISE_PUBLIC_KEY_LEN], const u8 peer_preshared_key[NOISE_SYMMETRIC_KEY_LEN], struct wireguard_peer *peer) |