aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/hashtables.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-06-06 21:49:29 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-06-08 04:24:13 +0200
commit06099be8610d9b1ee8ad34165cf5f24fa0c0ec55 (patch)
tree5e6aa524acc5c127eb7ef5d251c01afd33d352b4 /src/hashtables.c
parentgo test: use x/crypto for blake2s now that we have 128-bit mac (diff)
downloadwireguard-monolithic-historical-06099be8610d9b1ee8ad34165cf5f24fa0c0ec55.tar.xz
wireguard-monolithic-historical-06099be8610d9b1ee8ad34165cf5f24fa0c0ec55.zip
noise: fix race when replacing handshake
Replacing an entry that's already been replaced is something that could happen when processing handshake messages in parallel, when starting up multiple instances on the same machine. Reported-by: Hubert Goisern <zweizweizwoelf@gmail.com>
Diffstat (limited to 'src/hashtables.c')
-rw-r--r--src/hashtables.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/hashtables.c b/src/hashtables.c
index db97f7e..a01a899 100644
--- a/src/hashtables.c
+++ b/src/hashtables.c
@@ -97,13 +97,16 @@ search_unused_slot:
return entry->index;
}
-void index_hashtable_replace(struct index_hashtable *table, struct index_hashtable_entry *old, struct index_hashtable_entry *new)
+bool index_hashtable_replace(struct index_hashtable *table, struct index_hashtable_entry *old, struct index_hashtable_entry *new)
{
+ if (unlikely(hlist_unhashed(&old->index_hash)))
+ return false;
spin_lock_bh(&table->lock);
new->index = old->index;
hlist_replace_rcu(&old->index_hash, &new->index_hash);
INIT_HLIST_NODE(&old->index_hash);
spin_unlock_bh(&table->lock);
+ return true;
}
void index_hashtable_remove(struct index_hashtable *table, struct index_hashtable_entry *entry)