aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-11 09:36:57 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-11 12:34:54 +0200
commit4716f858ff2a2d92a3ee772de1fcd357fa0c0acc (patch)
treef753e01c90831049355a65962c19780dacfa2164
parentnetlink: allow preventing creation of new peers when updating (diff)
downloadWireGuard-4716f858ff2a2d92a3ee772de1fcd357fa0c0acc.tar.xz
WireGuard-4716f858ff2a2d92a3ee772de1fcd357fa0c0acc.zip
noise: recompare stamps after taking write lock
-rw-r--r--src/noise.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/noise.c b/src/noise.c
index 57f749c..269b69f 100644
--- a/src/noise.c
+++ b/src/noise.c
@@ -566,6 +566,7 @@ wg_noise_handshake_consume_initiation(struct message_handshake_initiation *src,
u8 s[NOISE_PUBLIC_KEY_LEN];
u8 e[NOISE_PUBLIC_KEY_LEN];
u8 t[NOISE_TIMESTAMP_LEN];
+ u64 initiation_consumption;
down_read(&wg->static_identity.lock);
if (unlikely(!wg->static_identity.has_identity))
@@ -614,11 +615,14 @@ wg_noise_handshake_consume_initiation(struct message_handshake_initiation *src,
/* Success! Copy everything to peer */
down_write(&handshake->lock);
memcpy(handshake->remote_ephemeral, e, NOISE_PUBLIC_KEY_LEN);
- memcpy(handshake->latest_timestamp, t, NOISE_TIMESTAMP_LEN);
+ if (memcmp(t, handshake->latest_timestamp, NOISE_TIMESTAMP_LEN) > 0)
+ memcpy(handshake->latest_timestamp, t, NOISE_TIMESTAMP_LEN);
memcpy(handshake->hash, hash, NOISE_HASH_LEN);
memcpy(handshake->chaining_key, chaining_key, NOISE_HASH_LEN);
handshake->remote_index = src->sender_index;
- handshake->last_initiation_consumption = ktime_get_coarse_boottime_ns();
+ if ((s64)(handshake->last_initiation_consumption -
+ (initiation_consumption = ktime_get_coarse_boottime_ns())) < 0)
+ handshake->last_initiation_consumption = initiation_consumption;
handshake->state = HANDSHAKE_CONSUMED_INITIATION;
up_write(&handshake->lock);
ret_peer = peer;