Skip to contentSkip to conversation

netfilter: nf_reject_ipv6: fix locally generated packet to local address

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Oct 21

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/1 netfilter: nf_reject_ipv6: fix locally generated packet to local address

Set on skb dst before checking if this packet is in the inet/ingress path. The inet/ingress hook runs before prerouting, no skb dst should be found in most cases.

This fixes reject for locally generated packet that are sent to a local address on ethX arrives through lo, really perform the same handling as ip6_rcv_core().

Reported by sashiko.

Fixes 73a73d442f99 ("netfilter: nf_reject: initialize IPCB at inet ingress")

---
v2: - clarify that inet/ingress does not have skb dst in most cases
(LLM gets confused and think that skb dst is always set on in this path ...)
- be wary and check that does not return NULL.

 net/ipv6/netfilter/nf_reject_ipv6.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
net/ipv6/netfilter/nf_reject_ipv6.c +14 -4
index 5e08d8529cc8..59a6ec45b529 100644
@@ -444,14 +444,24 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,
 	if (hooknum == NF_INET_LOCAL_OUT && skb_in->dev == NULL)
 		skb_in->dev = net->loopback_dev;
 
+	if (!skb_valid_dst(skb_in) && nf_reject6_fill_skb_dst(skb_in) < 0)
+		return;
+
 	if (hooknum == NF_INET_INGRESS) {
 		memset(IP6CB(skb_in), 0, sizeof(*IP6CB(skb_in)));
-		IP6CB(skb_in)->iif = skb_in->skb_iif;
+		if (skb_valid_dst(skb_in)) {
+			const struct inet6_dev *idev;
+
+			idev = ip6_dst_idev(skb_dst(skb_in));
+			if (idev)
+				IP6CB(skb_in)->iif = idev->dev->ifindex;
+			else
+				IP6CB(skb_in)->iif = skb_in->dev->ifindex;
+		} else {
+			IP6CB(skb_in)->iif = skb_in->dev->ifindex;
+		}
 	}
 
-	if (!skb_valid_dst(skb_in) && nf_reject6_fill_skb_dst(skb_in) < 0)
-		return;
-
 	icmpv6_send(skb_in, ICMPV6_DEST_UNREACH, code, 0);
 }
 EXPORT_SYMBOL_GPL(nf_send_unreach6);
Signature · 1 line
2.47.3