Skip to contentSkip to conversation

net: Fix return value of qdisc ingress handling on success

PATCH Applied Paul Blakey 2 participants 4 messages Oct 18, 2022 – Oct 19, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover net: Fix return value of qdisc ingress handling on success

Fix patch + self-test with the currently broken scenario.

v4->v3:
Removed new line in self test and rebase (Paolo).

v2->v3:
Added DROP return to TC_ACT_SHOT case (Cong).

v1->v2:
Changed blamed commit
Added self-test

Paul Blakey (2):
net: Fix return value of qdisc ingress handling on success
selftests: add selftest for chaining of tc ingress handling to egress

 net/core/dev.c                                |  4 +
 tools/testing/selftests/net/Makefile          |  1 +
 .../net/test_ingress_egress_chaining.sh       | 79 +++++++++++++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 tools/testing/selftests/net/test_ingress_egress_chaining.sh
Signature · 1 line
2.30.1
#1 lore raw

PATCH v4 1/2 net: Fix return value of qdisc ingress handling on success

Currently qdisc ingress handling (sch_handle_ingress()) doesn't set a return value and it is left to the old return value of the caller (__netif_receive_skb_core()) which is RX drop, so if the packet is consumed, caller will stop and return this value as if the packet was dropped.

This causes a problem in the kernel tcp stack when having a egress tc rule forwarding to a ingress tc rule.
The tcp stack sending packets on the device having the egress rule will see the packets as not successfully transmitted (although they actually were), will not advance it's internal state of sent data, and packets returning on such tcp stream will be dropped by the tcp stack with reason ack-of-unsent-data. See reproduction in [0] below.

Fix that by setting the return value to RX success if the packet was handled successfully.

[0] Reproduction steps:

 $ ip link add veth1 type veth peer name peer1
 $ ip link add veth2 type veth peer name peer2
 $ ifconfig peer1 5.5.5.6/24 up
 $ ip netns add ns0
 $ ip link set dev peer2 netns ns0
 $ ip netns exec ns0 ifconfig peer2 5.5.5.5/24 up
 $ ifconfig veth2 0 up
 $ ifconfig veth1 0 up

#ingress forwarding veth1 <-> veth2

 $ tc qdisc add dev veth2 ingress
 $ tc qdisc add dev veth1 ingress
 $ tc filter add dev veth2 ingress prio 1 proto all flower \
   action mirred egress redirect dev veth1
 $ tc filter add dev veth1 ingress prio 1 proto all flower \
   action mirred egress redirect dev veth2

#steal packet from peer1 egress to veth2 ingress, bypassing the veth pipe

 $ tc qdisc add dev peer1 clsact
 $ tc filter add dev peer1 egress prio 20 proto ip flower \
   action mirred ingress redirect dev veth1

#run iperf and see connection not running

 $ iperf3 -s&
 $ ip netns exec ns0 iperf3 -c 5.5.5.6 -i 1

#delete egress rule, and run again, now should work

 $ tc filter del dev peer1 egress
 $ ip netns exec ns0 iperf3 -c 5.5.5.6 -i 1
Fixes f697c3e8b35c ("[NET]: Avoid unnecessary cloning for ingress filtering")
---
 net/core/dev.c | 4 ++++
 1 file changed, 4 insertions(+)
net/core/dev.c +4 -0
index fa53830d0683..3be256051e99 100644
@@ -5136,11 +5136,13 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
 	case TC_ACT_SHOT:
 		mini_qdisc_qstats_cpu_drop(miniq);
 		kfree_skb_reason(skb, SKB_DROP_REASON_TC_INGRESS);
+		*ret = NET_RX_DROP;
 		return NULL;
 	case TC_ACT_STOLEN:
 	case TC_ACT_QUEUED:
 	case TC_ACT_TRAP:
 		consume_skb(skb);
+		*ret = NET_RX_SUCCESS;
 		return NULL;
 	case TC_ACT_REDIRECT:
 		/* skb_mac_header check was done by cls/act_bpf, so
@@ -5153,8 +5155,10 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
 			*another = true;
 			break;
 		}
+		*ret = NET_RX_SUCCESS;
 		return NULL;
 	case TC_ACT_CONSUMED:
+		*ret = NET_RX_SUCCESS;
 		return NULL;
 	default:
 		break;
Signature · 1 line
2.30.1
#2 lore raw

PATCH v4 2/2 selftests: add selftest for chaining of tc ingress handling to egress

In reply to Paul Blakey

This test runs a simple ingress tc setup between two veth pairs, then adds a egress->ingress rule to test the chaining of tc ingress pipeline to tc egress piepline.

---
 tools/testing/selftests/net/Makefile          |  1 +
 .../net/test_ingress_egress_chaining.sh       | 79 +++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100644 tools/testing/selftests/net/test_ingress_egress_chaining.sh
tools/testing/selftests/net/Makefile +1 -0
index 2a6b0bc648c4..69c58362c0ed 100644
@@ -70,6 +70,7 @@ TEST_PROGS += io_uring_zerocopy_tx.sh
 TEST_GEN_FILES += bind_bhash
 TEST_GEN_PROGS += sk_bind_sendto_listen
 TEST_GEN_PROGS += sk_connect_zero_addr
+TEST_PROGS += test_ingress_egress_chaining.sh
 
 TEST_FILES := settings
 
tools/testing/selftests/net/test_ingress_egress_chaining.sh new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
2.30.1
#3 lore raw
In reply to Paul Blakey
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Tue, 18 Oct 2022 10:34:37 +0300 you wrote:

Fix patch + self-test with the currently broken scenario.

v4->v3:
Removed new line in self test and rebase (Paolo).

v2->v3:
Added DROP return to TC_ACT_SHOT case (Cong).

[...]

Here is the summary with links:
- [net,v4,1/2] net: Fix return value of qdisc ingress handling on success

    https://git.kernel.org/netdev/net/c/672e97ef689a
  - [net,v4,2/2] selftests: add selftest for chaining of tc ingress handling to egress
    https://git.kernel.org/netdev/net/c/fd602f5cb52e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html