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
7 commit 99fff5264e7ab06f45b0ad60243475be0a8d0559 upstream.
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.
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>
19 drivers/net/wireguard/device.c | 7 ++++---
20 1 file changed, 4 insertions(+), 3 deletions(-)
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);
32 family = READ_ONCE(peer->endpoint.addr.sa_family);
33 @@ -201,12 +201,13 @@ static netdev_tx_t wg_xmit(struct sk_buf
38 - ++dev->stats.tx_errors;
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);
45 + ++dev->stats.tx_errors;