aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 04:02:18 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 04:02:18 +0100
commit7d38571580548238040e08f9ebf5ef4d245b4011 (patch)
treec5a0c093bb85db534172729f76c9575db151f519
parentFix lock bug in wg_peer clean (diff)
downloadwireguard-openbsd-7d38571580548238040e08f9ebf5ef4d245b4011.tar.xz
wireguard-openbsd-7d38571580548238040e08f9ebf5ef4d245b4011.zip
Fix lock ordering in tx_initiation, not perfect though.
-rw-r--r--src/wireguard.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/wireguard.c b/src/wireguard.c
index 4131b00..502bbde 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -609,8 +609,7 @@ wg_device_tx_initiation(struct wg_device *dev, struct wg_msg_initiation *init,
if ((peer = wg_device_ref_peerid(dev, id)) == NULL)
return WG_ID;
- rw_enter_read(&peer->p_lock);
-
+ /* TODO better locking */
if (!wg_timespec_timedout(&peer->p_last_initiation, WG_REKEY_TIMEOUT))
ret_error(WG_HS_RATE);
@@ -620,6 +619,9 @@ wg_device_tx_initiation(struct wg_device *dev, struct wg_msg_initiation *init,
session = wg_device_new_session(dev);
hs = &session->s_handshake;
+ rw_enter_read(&dev->d_lock);
+ rw_enter_read(&peer->p_lock);
+
wg_keypair_generate(&hs->h_local);
init->type = WG_MSG_INITIATION;
@@ -659,6 +661,7 @@ wg_device_tx_initiation(struct wg_device *dev, struct wg_msg_initiation *init,
sizeof(peer->p_cookie.cookie));
rw_exit_read(&peer->p_lock);
+ rw_exit_read(&dev->d_lock);
/* TODO lock? */
getnanotime(&peer->p_last_initiation);
@@ -674,7 +677,6 @@ wg_device_tx_initiation(struct wg_device *dev, struct wg_msg_initiation *init,
wg_peer_put(peer);
return WG_OK;
leave:
- rw_exit_read(&peer->p_lock);
wg_peer_put(peer);
return ret;
}