Skip to contentSkip to conversation

xfrm: interface: Don't hide plain packets from netfilter

PATCH Superseded Phil Sutter 2 participants 2 messages Dec 7, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 xfrm: interface: Don't hide plain packets from netfilter

With an IPsec tunnel without dedicated interface, netfilter sees locally generated packets twice as they exit the physical interface: Once as "the inner packet" with IPsec context attached and once as the encrypted (ESP) packet.

With xfrm_interface, the inner packet did not traverse NF_INET_LOCAL_OUT hook anymore, making it impossible to match on both inner header values and associated IPsec data from that hook.

Fix this by looping packets transmitted from xfrm_interface through NF_INET_LOCAL_OUT before passing them on to dst_output(), which makes behaviour consistent again from netfilter's point of view.

Fixes f203b76d78092 ("xfrm: Add virtual xfrm interfaces")
---
 net/xfrm/xfrm_interface.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/xfrm/xfrm_interface.c +2 -1
index aa4cdcf69d471..24af61c95b4d4 100644
@@ -317,7 +317,8 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	skb_dst_set(skb, dst);
 	skb->dev = tdev;
 
-	err = dst_output(xi->net, skb->sk, skb);
+	err = NF_HOOK(skb_dst(skb)->ops->family, NF_INET_LOCAL_OUT, xi->net,
+		      skb->sk, skb, NULL, skb_dst(skb)->dev, dst_output);
 	if (net_xmit_eval(err) == 0) {
 		struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
 
Signature · 1 line
2.28.0
maintainer
#1 lore raw
Quoted 24 lines · Phil Sutter

With an IPsec tunnel without dedicated interface, netfilter sees locally generated packets twice as they exit the physical interface: Once as "the inner packet" with IPsec context attached and once as the encrypted (ESP) packet.

With xfrm_interface, the inner packet did not traverse NF_INET_LOCAL_OUT hook anymore, making it impossible to match on both inner header values and associated IPsec data from that hook.

Fix this by looping packets transmitted from xfrm_interface through NF_INET_LOCAL_OUT before passing them on to dst_output(), which makes behaviour consistent again from netfilter's point of view.

Fixes f203b76d78092 ("xfrm: Add virtual xfrm interfaces")
---
 net/xfrm/xfrm_interface.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/xfrm/xfrm_interface.c +0 -0
index aa4cdcf69d471..24af61c95b4d4 100644

net/xfrm/xfrm_interface.c xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) · line 323

Quoted 8 lines
net/xfrm/xfrm_interface.c +2 -1
@@ -317,7 +317,8 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	skb_dst_set(skb, dst);
 	skb->dev = tdev;
 
-	err = dst_output(xi->net, skb->sk, skb);
+	err = NF_HOOK(skb_dst(skb)->ops->family, NF_INET_LOCAL_OUT, xi->net,
+		      skb->sk, skb, NULL, skb_dst(skb)->dev, dst_output);
 	if (net_xmit_eval(err) == 0) {
 		struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);

This is networking code, so please send your patch also to the netdev list:
[email protected]