kernel: 5.4: import wireguard backport
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0122-wireguard-device-do-not-generate-ICMP-for-non-IP-pac.patch
1 From 49da2a610d63cef849f0095e601821ad6edfbef7 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Mon, 22 Feb 2021 17:25:47 +0100
4 Subject: [PATCH 122/124] wireguard: device: do not generate ICMP for non-IP
5 packets
6
7 commit 99fff5264e7ab06f45b0ad60243475be0a8d0559 upstream.
8
9 If skb->protocol doesn't match the actual skb->data header, it's
10 probably not a good idea to pass it off to icmp{,v6}_ndo_send, which is
11 expecting to reply to a valid IP packet. So this commit has that early
12 mismatch case jump to a later error label.
13
14 Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
15 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
16 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
18 ---
19 drivers/net/wireguard/device.c | 7 ++++---
20 1 file changed, 4 insertions(+), 3 deletions(-)
21
22 --- a/drivers/net/wireguard/device.c
23 +++ b/drivers/net/wireguard/device.c
24 @@ -138,7 +138,7 @@ static netdev_tx_t wg_xmit(struct sk_buf
25 else if (skb->protocol == htons(ETH_P_IPV6))
26 net_dbg_ratelimited("%s: No peer has allowed IPs matching %pI6\n",
27 dev->name, &ipv6_hdr(skb)->daddr);
28 - goto err;
29 + goto err_icmp;
30 }
31
32 family = READ_ONCE(peer->endpoint.addr.sa_family);
33 @@ -201,12 +201,13 @@ static netdev_tx_t wg_xmit(struct sk_buf
34
35 err_peer:
36 wg_peer_put(peer);
37 -err:
38 - ++dev->stats.tx_errors;
39 +err_icmp:
40 if (skb->protocol == htons(ETH_P_IP))
41 icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
42 else if (skb->protocol == htons(ETH_P_IPV6))
43 icmpv6_ndo_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
44 +err:
45 + ++dev->stats.tx_errors;
46 kfree_skb(skb);
47 return ret;
48 }