Skip to content

Commit bc67d37

Browse files
zx2c4davem330
authored andcommitted
wireguard: noise: read preshared key while taking lock
Prior we read the preshared key after dropping the handshake lock, which isn't an actual crypto issue if it races, but it's still not quite correct. So copy that part of the state into a temporary like we do with the rest of the handshake state variables. Then we can release the lock, operate on the temporary, and zero it out at the end of the function. In performance tests, the impact of this was entirely unnoticable, probably because those bytes are coming from the same cacheline as other things that are being copied out in the same manner. Reported-by: Matt Dunwoodie <[email protected]> Fixes: e7096c1 ("net: WireGuard secure network tunnel") Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ee3c1aa commit bc67d37

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/net/wireguard/noise.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src,
715715
u8 e[NOISE_PUBLIC_KEY_LEN];
716716
u8 ephemeral_private[NOISE_PUBLIC_KEY_LEN];
717717
u8 static_private[NOISE_PUBLIC_KEY_LEN];
718+
u8 preshared_key[NOISE_SYMMETRIC_KEY_LEN];
718719

719720
down_read(&wg->static_identity.lock);
720721

@@ -733,6 +734,8 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src,
733734
memcpy(chaining_key, handshake->chaining_key, NOISE_HASH_LEN);
734735
memcpy(ephemeral_private, handshake->ephemeral_private,
735736
NOISE_PUBLIC_KEY_LEN);
737+
memcpy(preshared_key, handshake->preshared_key,
738+
NOISE_SYMMETRIC_KEY_LEN);
736739
up_read(&handshake->lock);
737740

738741
if (state != HANDSHAKE_CREATED_INITIATION)
@@ -750,7 +753,7 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src,
750753
goto fail;
751754

752755
/* psk */
753-
mix_psk(chaining_key, hash, key, handshake->preshared_key);
756+
mix_psk(chaining_key, hash, key, preshared_key);
754757

755758
/* {} */
756759
if (!message_decrypt(NULL, src->encrypted_nothing,
@@ -783,6 +786,7 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src,
783786
memzero_explicit(chaining_key, NOISE_HASH_LEN);
784787
memzero_explicit(ephemeral_private, NOISE_PUBLIC_KEY_LEN);
785788
memzero_explicit(static_private, NOISE_PUBLIC_KEY_LEN);
789+
memzero_explicit(preshared_key, NOISE_SYMMETRIC_KEY_LEN);
786790
up_read(&wg->static_identity.lock);
787791
return ret_peer;
788792
}

0 commit comments

Comments
 (0)