Skip to contentSkip to conversation

net: generate icmp redirects after netfilter forward hook

RFC New Florian Westphal 1 participant 1 message Jul 18, 2019

Subsystems (4)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

RFC 1/1 net: generate icmp redirects after netfilter forward hook

Quoting from
https://bugzilla.kernel.org/show_bug.cgi?id=204155

----
1. Configure an PPPoE interface (e.g., ppp0) with an IPv6 address and a prefixlen of 64; e.g., 2001:0DB8::1/64.
2. Configure a Netfilter ip6table rule to drop IN to OUT forwarding of traffic across the PPP interface: ip6tables -A FORWARD -i ppp+ -o ppp+ -j DROP
3. Create a Netfilter NFLOG rule to log all outbound traffic.
4. From an Internet IPv6 Address initiate TCP traffic to an IPv6 address within the /64 IPv6 address space from step 1, but an IPv6 address that is NOT configured on that interface; e.g., nc 2001:0DB8::2 80
5. Observe the NFLOG showing the Netfilter ip6table filter FORWARD rule is matched and therefore the traffic should be dropped.
6. Observe the traffic from step 4, that should have been dropped, resulted in an outbound ICMPv6 Redirect with a source IPv6 address of the PPP interface’s Local Link to the Internet IPv6 Address.
----

Problem is that we emit the redirect before passing the packet to the
netfilter FORWARD hook. The same "problem" exists in ipv4.

There are various counter-arguments to changing this, e.g. we would still emit such redirect when packet is dropped later in the stack (e.g. in POSTROUTING or qdisc).

We will also still emit e.g. ICMPV6 PKTTOOBIG error, as that occurs before FORWARD as well, and moving that seems wrong (packet has to be dropped).

The only argument that I can think of in favor of this change is the lack of a proper alternative to filtering such traffic.

PREROUTING would work, but at that point we lack the "packet will be forwarded from ppp0 to ppp0" information that we only have available in FORWARD.

Compile tested only.

---
 net/ipv4/ip_forward.c | 16 +++++------
 net/ipv6/ip6_output.c | 63 ++++++++++++++++++++++++-------------------
 2 files changed, 44 insertions(+), 35 deletions(-)
net/ipv4/ip_forward.c +8 -8
index 06f6f280b9ff..33c46470c966 100644
@@ -69,6 +69,14 @@ static int ip_forward_finish(struct net *net, struct sock *sk, struct sk_buff *s
 	__IP_INC_STATS(net, IPSTATS_MIB_OUTFORWDATAGRAMS);
 	__IP_ADD_STATS(net, IPSTATS_MIB_OUTOCTETS, skb->len);
 
+	/*
+	 *	We now generate an ICMP HOST REDIRECT giving the route
+	 *	we calculated.
+	 */
+	if (IPCB(skb)->flags & IPSKB_DOREDIRECT && !opt->srr &&
+	    !skb_sec_path(skb))
+		ip_rt_send_redirect(skb);
+
 #ifdef CONFIG_NET_SWITCHDEV
 	if (skb->offload_l3_fwd_mark) {
 		consume_skb(skb);
@@ -143,14 +151,6 @@ int ip_forward(struct sk_buff *skb)
 	/* Decrease ttl after skb cow done */
 	ip_decrease_ttl(iph);
 
-	/*
-	 *	We now generate an ICMP HOST REDIRECT giving the route
-	 *	we calculated.
-	 */
-	if (IPCB(skb)->flags & IPSKB_DOREDIRECT && !opt->srr &&
-	    !skb_sec_path(skb))
-		ip_rt_send_redirect(skb);
-
 	if (net->ipv4.sysctl_ip_fwd_update_priority)
 		skb->priority = rt_tos2priority(iph->tos);
 
net/ipv6/ip6_output.c +36 -27

80 lines not on this page · raw message

Signature · 1 line
2.21.0