diff options
author | Matt Dunwoodie <ncon@noconroy.net> | 2021-04-20 10:46:55 +1000 |
---|---|---|
committer | Matt Dunwoodie <ncon@noconroy.net> | 2021-04-20 10:52:36 +1000 |
commit | 204142fa426a0102fc359aa0aa3c8ce423410ce0 (patch) | |
tree | 04aaeb865f2c7ff82720184e13c089938cdb8fba | |
parent | wg_noise: remove duplicate peer check (diff) | |
download | wireguard-freebsd-204142fa426a0102fc359aa0aa3c8ce423410ce0.tar.xz wireguard-freebsd-204142fa426a0102fc359aa0aa3c8ce423410ce0.zip |
wg_noise: assign index without lock then check
Signed-off-by: Matt Dunwoodie <ncon@noconroy.net>
-rw-r--r-- | src/wg_noise.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/wg_noise.c b/src/wg_noise.c index 435c56d..c92e44a 100644 --- a/src/wg_noise.c +++ b/src/wg_noise.c @@ -351,11 +351,12 @@ static void noise_remote_index_insert(struct noise_local *l, struct noise_remote *r) { struct noise_index *i, *r_i = &r->r_index; + struct epoch_tracker et; uint32_t idx; noise_remote_index_remove(l, r); - rw_wlock(&l->l_index_lock); + NET_EPOCH_ENTER(et); assign_id: r_i->i_local_index = arc4random(); idx = r_i->i_local_index & HT_INDEX_MASK; @@ -363,9 +364,18 @@ assign_id: if (i->i_local_index == r_i->i_local_index) goto assign_id; + rw_wlock(&l->l_index_lock); + CK_LIST_FOREACH(i, &l->l_index_hash[idx], i_entry) { + if (i->i_local_index == r_i->i_local_index) { + rw_wunlock(&l->l_index_lock); + goto assign_id; + } + } CK_LIST_INSERT_HEAD(&l->l_index_hash[idx], r_i, i_entry); rw_wunlock(&l->l_index_lock); + NET_EPOCH_EXIT(et); + r->r_handshake_alive = 1; } |