wg(4): fix race between tx/rx handshakes, from Matt Dunwoodie, ok mpi@
authorsthen <sthen@openbsd.org>
Sun, 21 Mar 2021 18:13:59 +0000 (18:13 +0000)
committersthen <sthen@openbsd.org>
Sun, 21 Mar 2021 18:13:59 +0000 (18:13 +0000)
commit1507f9071270bfba00c7a3f5c192590e1442b199
tree43ac034874e64776b8211ecf3cf0687bddce6978
parent4d9bef631e28aca545cb80bd24b2650b6f3b34aa
wg(4): fix race between tx/rx handshakes, from Matt Dunwoodie, ok mpi@

"There is a race between sending/receiving handshake packets. This
occurs if we consume an initiation, then send an initiation prior to
replying to the consumed initiation.

In particular, when consuming an initiation, we don't generate the
index until creating the response (which is incorrect). If we attempt
to create an initiation between these processes, we drop any
outstanding handshake which in this case has index 0 as set when
consuming the initiation.

The fix attached is to generate the index when consuming the initiation
so that any spurious initiation creation can drop a valid index. The
patch also consolidates setting fields on the handshake."
sys/net/wg_noise.c