081-wireguard-device-do-not-generate-ICMP-for-non-IP-pac.patch 1.6 KB

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