summaryrefslogtreecommitdiff
path: root/drivers/net/wireguard/peerlookup.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2020-09-09 11:31:38 -0700
committerDavid S. Miller <davem@davemloft.net>2020-09-09 11:31:38 -0700
commita00d10c8fade0f66f0020160cdac7574a9bc49c0 (patch)
treef0d8b0e96d64dcd62e043afa85abc54e5f91dc73 /drivers/net/wireguard/peerlookup.c
parent7aa3076c843b5df47a067b103ceadabbb6fc8a3a (diff)
parent2e2976a339573a3184cfd731c38778b8b3f312dc (diff)
downloadwireguard-linux-trimmed-a00d10c8fade0f66f0020160cdac7574a9bc49c0.tar.gz
wireguard-linux-trimmed-a00d10c8fade0f66f0020160cdac7574a9bc49c0.zip
Merge branch 'wireguard-fixes'
Jason A. Donenfeld says: ==================== wireguard fixes for 5.9-rc5 Yesterday, Eric reported a race condition found by syzbot. This series contains two commits, one that fixes the direct issue, and another that addresses the more general issue, as a defense in depth. 1) The basic problem syzbot unearthed was that one particular mutation of handshake->entry was not protected by the handshake mutex like the other cases, so this patch basically just reorders a line to make sure the mutex is actually taken at the right point. Most of the work here went into making sure the race was fully understood and making a reproducer (which syzbot was unable to do itself, due to the rarity of the race). 2) Eric's initial suggestion for fixing this was taking a spinlock around the hash table replace function where the null ptr deref was happening. This doesn't address the main problem in the most precise possible way like (1) does, but it is a good suggestion for defense-in-depth, in case related issues come up in the future, and basically costs nothing from a performance perspective. I thought it aided in implementing a good general rule: all mutators of that hash table take the table lock. So that's part of this series as a companion. Both of these contain Fixes: tags and are good candidates for stable. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireguard/peerlookup.c')
-rw-r--r--drivers/net/wireguard/peerlookup.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/net/wireguard/peerlookup.c b/drivers/net/wireguard/peerlookup.c
index e4deb33..f2783aa 100644
--- a/drivers/net/wireguard/peerlookup.c
+++ b/drivers/net/wireguard/peerlookup.c
@@ -167,9 +167,13 @@ bool wg_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;
+ bool ret;
+
spin_lock_bh(&table->lock);
+ ret = !hlist_unhashed(&old->index_hash);
+ if (unlikely(!ret))
+ goto out;
+
new->index = old->index;
hlist_replace_rcu(&old->index_hash, &new->index_hash);
@@ -180,8 +184,9 @@ bool wg_index_hashtable_replace(struct index_hashtable *table,
* simply gets dropped, which isn't terrible.
*/
INIT_HLIST_NODE(&old->index_hash);
+out:
spin_unlock_bh(&table->lock);
- return true;
+ return ret;
}
void wg_index_hashtable_remove(struct index_hashtable *table,