All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: netdev@vger.kernel.org, davem@davemloft.net
Subject: [PATCH net 5/7] wireguard: device: do not generate ICMP for non-IP packets
Date: Mon, 22 Feb 2021 17:25:47 +0100	[thread overview]
Message-ID: <20210222162549.3252778-6-Jason@zx2c4.com> (raw)
In-Reply-To: <20210222162549.3252778-1-Jason@zx2c4.com>

If skb->protocol doesn't match the actual skb->data header, it's
probably not a good idea to pass it off to icmp{,v6}_ndo_send, which is
expecting to reply to a valid IP packet. So this commit has that early
mismatch case jump to a later error label.

Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/net/wireguard/device.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c
index cd51a2afa28e..8502e1b083ff 100644
--- a/drivers/net/wireguard/device.c
+++ b/drivers/net/wireguard/device.c
@@ -138,7 +138,7 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
 		else if (skb->protocol == htons(ETH_P_IPV6))
 			net_dbg_ratelimited("%s: No peer has allowed IPs matching %pI6\n",
 					    dev->name, &ipv6_hdr(skb)->daddr);
-		goto err;
+		goto err_icmp;
 	}
 
 	family = READ_ONCE(peer->endpoint.addr.sa_family);
@@ -201,12 +201,13 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
 
 err_peer:
 	wg_peer_put(peer);
-err:
-	++dev->stats.tx_errors;
+err_icmp:
 	if (skb->protocol == htons(ETH_P_IP))
 		icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
 	else if (skb->protocol == htons(ETH_P_IPV6))
 		icmpv6_ndo_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
+err:
+	++dev->stats.tx_errors;
 	kfree_skb(skb);
 	return ret;
 }
-- 
2.30.1


  parent reply	other threads:[~2021-02-22 16:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22 16:25 [PATCH net 0/7] wireguard fixes for 5.12-rc1 Jason A. Donenfeld
2021-02-22 16:25 ` [PATCH net 1/7] wireguard: avoid double unlikely() notation when using IS_ERR() Jason A. Donenfeld
2021-02-22 16:25 ` [PATCH net 2/7] wireguard: socket: remove bogus __be32 annotation Jason A. Donenfeld
2021-02-22 16:25 ` [PATCH net 3/7] wireguard: selftests: test multiple parallel streams Jason A. Donenfeld
2021-02-22 16:25 ` [PATCH net 4/7] wireguard: peer: put frequently used members above cache lines Jason A. Donenfeld
2021-02-22 16:25 ` Jason A. Donenfeld [this message]
2021-02-22 16:25 ` [PATCH net 6/7] wireguard: queueing: get rid of per-peer ring buffers Jason A. Donenfeld
2021-02-22 16:25 ` [PATCH net 7/7] wireguard: kconfig: use arm chacha even with no neon Jason A. Donenfeld
2021-02-24  0:02 ` [PATCH net 0/7] wireguard fixes for 5.12-rc1 Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210222162549.3252778-6-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.