Skip to contentSkip to conversation

Clear secpath on loopback_xmit

PATCH Superseded Benedict Wong 2 participants 2 messages Oct 6, 2018 – Oct 8, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Clear secpath on loopback_xmit

This patch clears the skb->sp when transmitted over loopback. This ensures that the loopback-ed packet does not have any secpath information from the outbound transforms.

At present, this causes XFRM tunnel mode packets to be dropped with XFRMINNOPOLS, due to the outbound state being in the secpath, without a matching inbound policy. Clearing the secpath ensures that all states added to the secpath are exclusively from the inbound processing.

Tests: xfrm tunnel mode tests added for loopback:

    https://android-review.googlesource.com/c/kernel/tests/+/777328
---
 drivers/net/loopback.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/loopback.c +4 -0
index 30612497643c..a6bf54df94bd 100644
@@ -50,6 +50,7 @@
 #include <linux/ethtool.h>
 #include <net/sock.h>
 #include <net/checksum.h>
+#include <net/xfrm.h>
 #include <linux/if_ether.h>	/* For the statistics structure. */
 #include <linux/if_arp.h>	/* For ARPHRD_ETHER */
 #include <linux/ip.h>
@@ -82,6 +83,9 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
 	 */
 	skb_dst_force(skb);
 
+	// Clear secpath to ensure xfrm policy check not tainted by outbound SAs.
+	secpath_reset(skb);
+
 	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw
Quoted 8 lines · Benedict Wong

This patch clears the skb->sp when transmitted over loopback. This ensures that the loopback-ed packet does not have any secpath information from the outbound transforms.

At present, this causes XFRM tunnel mode packets to be dropped with XFRMINNOPOLS, due to the outbound state being in the secpath, without a matching inbound policy. Clearing the secpath ensures that all states added to the secpath are exclusively from the inbound processing.

This looks like a fix, so the target should be the ipsec tree, not ipsec-next.

Quoted 4 lines

Tests: xfrm tunnel mode tests added for loopback:

    https://android-review.googlesource.com/c/kernel/tests/+/777328

Please add a 'Fixes:' tag.

Quoted 17 lines
---
 drivers/net/loopback.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/loopback.c +1 -0
index 30612497643c..a6bf54df94bd 100644
@@ -50,6 +50,7 @@
 #include <linux/ethtool.h>
 #include <net/sock.h>
 #include <net/checksum.h>
+#include <net/xfrm.h>
 #include <linux/if_ether.h>	/* For the statistics structure. */
 #include <linux/if_arp.h>	/* For ARPHRD_ETHER */
 #include <linux/ip.h>

drivers/net/loopback.c static netdev_tx_t loopback_xmit(struct sk_buff *skb, · line 86

Quoted 4 lines
drivers/net/loopback.c +1 -0
@@ -82,6 +83,9 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
 	 */
 	skb_dst_force(skb);
 
+	// Clear secpath to ensure xfrm policy check not tainted by outbound SAs.

Comments should use /* ... */, like it is done below.

Quoted 7 lines
drivers/net/loopback.c +2 -0
+	secpath_reset(skb);
+
 	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
Signature · 1 line
2.19.0.605.g01d371f741-goog