Skip to content

Commit a63edc0

Browse files
committed
device: do not generate ICMP for non-IP packets
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. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent ad32b95 commit a63edc0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/device.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
146146
else if (skb->protocol == htons(ETH_P_IPV6))
147147
net_dbg_ratelimited("%s: No peer has allowed IPs matching %pI6\n",
148148
dev->name, &ipv6_hdr(skb)->daddr);
149-
goto err;
149+
goto err_icmp;
150150
}
151151

152152
family = READ_ONCE(peer->endpoint.addr.sa_family);
@@ -209,12 +209,13 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
209209

210210
err_peer:
211211
wg_peer_put(peer);
212-
err:
213-
++dev->stats.tx_errors;
212+
err_icmp:
214213
if (skb->protocol == htons(ETH_P_IP))
215214
icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
216215
else if (skb->protocol == htons(ETH_P_IPV6))
217216
icmpv6_ndo_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
217+
err:
218+
++dev->stats.tx_errors;
218219
kfree_skb(skb);
219220
return ret;
220221
}

0 commit comments

Comments
 (0)