aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/receive.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-11 03:07:40 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-10-11 15:50:29 +0200
commit60ca1ed044669b1ed382515d642cd05aa4792f15 (patch)
treebe3bc89f0164206c85585521fcb4790444ff96ef /src/receive.c
parenttools: man: include kill-switch documentation using fwmark (diff)
downloadwireguard-monolithic-historical-60ca1ed044669b1ed382515d642cd05aa4792f15.tar.xz
wireguard-monolithic-historical-60ca1ed044669b1ed382515d642cd05aa4792f15.zip
receive: disable bh before using stats seq lock
Otherwise we might get a situation like this: CPU0 CPU1 ---- ---- lock(tstats lock); local_irq_disable(); lock(queue lock); lock(tstats lock); <Interrupt> lock(queue lock); CPU1 is waiting for CPU0 to release tstats lock. But CPU0, in the interrupt handler, is waiting for CPU1 to release queue lock. The solution is to disable interrupts on CPU0, so that this can't happen. Note that this only affects 32-bit, since u64_stats_update_begin nops out on native 64-bit platforms. Reported-by: René van Dorst <opensource@vdorst.com>
Diffstat (limited to '')
-rw-r--r--src/receive.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/receive.c b/src/receive.c
index 3ad790b..6efbc08 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -13,6 +13,7 @@
#include <linux/udp.h>
#include <net/ip_tunnels.h>
+/* Must be called with bh disabled. */
static inline void rx_stats(struct wireguard_peer *peer, size_t len)
{
struct pcpu_sw_netstats *tstats = get_cpu_ptr(peer->device->dev->tstats);
@@ -150,7 +151,10 @@ static void receive_handshake_packet(struct wireguard_device *wg, struct sk_buff
BUG_ON(!peer);
+ local_bh_disable();
rx_stats(peer, skb->len);
+ local_bh_enable();
+
timers_any_authenticated_packet_received(peer);
timers_any_authenticated_packet_traversal(peer);
peer_put(peer);