Skip to contentSkip to conversation

net/sched: act_mirred: Fix infinite loop

PATCH In review Jamal Hadi Salim 3 participants 17 messages Nov 24, 2025 – Dec 10, 2025

Subsystems (4)
lore
Share & tools
lore

Jamal Hadi Salim

author maintainer
#0 lore raw

PATCH 1/2 net/sched: act_mirred: Fix infinite loop

When doing multiport mirroring we dont detect infinite loops.

Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress

Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress

Fix this by remembering the source dev where mirred ran as opposed to destination/target dev

Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")
---
 net/sched/act_mirred.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/act_mirred.c +1 -1
index f27b583def78..7315179197fd 100644
@@ -453,7 +453,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
 		return retval;
 	}
 
-	xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+	xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
 	m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
 	m_eaction = READ_ONCE(m->tcfm_eaction);
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 2/2 selftests/tc-testing: Add test cases exercising mirred redirects (with loops)

From: Victor Nogueira <[email protected]>

Add two tdc test cases for mirred which cause loops.
The first one does a redirect dev1 ingress -> dummy egress -> dev1 ingress The second one does a redirect dummy egress -> dev1 ingress -> dummy egress

---
 .../tc-testing/tc-tests/actions/mirred.json   | 103 ++++++++++++++++++
 1 file changed, 103 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/actions/mirred.json +103 -0
index b73bd255ea36..97800f2e26f2 100644
@@ -1052,5 +1052,108 @@
             "$TC qdisc del dev $DEV1 ingress_block 21 clsact",
             "$TC actions flush action mirred"
         ]
+    },
+    {
+        "id": "6941",
+        "name": "Redirect multiport: dev1 ingress -> dummy egress -> dev1 ingress (Loop)",
+        "category": [
+            "filter",
+            "mirred"
+        ],
+        "plugins": {
+            "requires": [
+                "nsPlugin",
+                "scapyPlugin"
+            ]
+        },
+        "scapy": {
+            "iface": "$DEV0",
+            "count": 1,
+            "packet": "Ether()/IP(dst='10.10.10.1', src='10.10.10.10')/ICMP()"
+        },
+        "setup": [
+            "$IP link set dev $DUMMY up || true",
+            "$TC qdisc add dev $DEV1 clsact",
+            "$TC filter add dev $DEV1 ingress protocol ip prio 10 matchall action mirred egress redirect dev $DUMMY index 1",
+            "$IP addr add 10.10.10.10/24 dev $DUMMY || true",
+            "$TC qdisc add dev $DUMMY clsact",
+            "$TC filter add dev $DUMMY egress protocol ip prio 10 matchall action mirred ingress redirect dev $DEV1 index 2"
+        ],
+        "cmdUnderTest": "$TC -j -s actions get action mirred index 1",
+        "expExitCode": "0",
+        "verifyCmd": "$TC -j -s actions get action mirred index 1",
+        "matchJSON": [
+            {
+                "total acts": 0
+            },
+            {
+                "actions": [
+                    {
+                        "order": 1,
+                        "kind": "mirred",
+                        "mirred_action": "redirect",
+                        "direction": "egress",
+                        "index": 1,
+                        "stats": {
+                            "packets": 1
+                        },
+                        "not_in_hw": true
+                    }
+                ]
+            }
+        ],
+        "teardown": [
+            "$TC qdisc del dev $DEV1 clsact",
+            "$TC qdisc del dev $DUMMY clsact"
+        ]
+    },
+    {
+        "id": "ceb4",
+        "name": "Redirect multiport: dummy egress -> dev1 ingress -> dummy egress (Loop)",
+        "category": [
+            "filter",
+            "mirred"
+        ],
+        "plugins": {
+            "requires": [
+                "nsPlugin"
+            ]
+        },
+        "setup": [
+            "$IP link set dev $DUMMY up || true",
+            "$IP addr add 10.10.10.10/24 dev $DUMMY || true",
+            "$TC qdisc add dev $DUMMY clsact",
+            "$TC filter add dev $DUMMY egress protocol ip prio 10 matchall action mirred ingress redirect dev $DEV1 index 1",
+            "$TC qdisc add dev $DEV1 clsact",
+            "$TC filter add dev $DEV1 ingress protocol ip prio 10 matchall action mirred egress redirect dev $DUMMY index 2"
+        ],
+        "cmdUnderTest": "ping -c1 -W0.01 -I $DUMMY 10.10.10.1",
+        "expExitCode": "1",
+        "verifyCmd": "$TC -j -s actions get action mirred index 1",
+        "matchJSON": [
+            {
+                "total acts": 0
+            },
+            {
+                "actions": [
+                    {
+                        "order": 1,
+                        "kind": "mirred",
+                        "mirred_action": "redirect",
+                        "direction": "ingress",
+                        "index": 1,
+                        "stats": {
+                            "packets": 2,
+                            "overlimits": 1
+                        },
+                        "not_in_hw": true
+                    }
+                ]
+            }
+        ],
+        "teardown": [
+            "$TC qdisc del dev $DUMMY clsact",
+            "$TC qdisc del dev $DEV1 clsact"
+        ]
     }
 ]
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Jamal Hadi Salim
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:

When doing multiport mirroring we dont detect infinite loops.

Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress

Quoted 8 lines

Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress

Fix this by remembering the source dev where mirred ran as opposed to destination/target dev

Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")

Hm, this breaks net/fib_tests.sh:

# 23.80 [+0.00] IPv4 rp_filter tests

# 25.63 [+1.84]     TEST: rp_filter passes local packets                                [FAIL]
# 26.65 [+1.02]     TEST: rp_filter passes loopback packets                             [FAIL]

https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout

Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..

Signature · 1 line
pw-bot: cr
author maintainer
#3 lore raw
Quoted 19 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:

When doing multiport mirroring we dont detect infinite loops.

Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress

Quoted 8 lines

Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress

Fix this by remembering the source dev where mirred ran as opposed to destination/target dev

Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")

Hm, this breaks net/fib_tests.sh:

Quoted 8 lines

# 23.80 [+0.00] IPv4 rp_filter tests

# 25.63 [+1.84]     TEST: rp_filter passes local packets                                [FAIL]
# 26.65 [+1.02]     TEST: rp_filter passes loopback packets                             [FAIL]

https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout

Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..

Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!

cheers,
jamal

Quoted 2 lines

--
pw-bot: cr

author maintainer
#4 lore raw
Quoted 27 lines · Jamal Hadi Salim
Quoted 25 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:

When doing multiport mirroring we dont detect infinite loops.

Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress

Quoted 8 lines

Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress

Fix this by remembering the source dev where mirred ran as opposed to destination/target dev

Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")

Hm, this breaks net/fib_tests.sh:

# 23.80 [+0.00] IPv4 rp_filter tests

# 25.63 [+1.84]     TEST: rp_filter passes local packets                                [FAIL]
# 26.65 [+1.02]     TEST: rp_filter passes loopback packets                             [FAIL]

https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout

Quoted 8 lines
Quoted 2 lines

Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..

Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!

Ok, I spent time on this and frankly cant find a way to fix the infinite loop that avoids adding _a lot more_ complexity. We need loop state to be associated with the skb. I will restore the two skb bits and test. From inspection, i see one bit free but i may be able to steal a bit from somewhere. I will post an RFC and at minimal that will start a discussion and maybe someone will come up with a better way of solving this.

Eric, there's another issue as well involving example port0:egress->port0:egress - I have a patch but will post it later after some testing.

cheers,
jamal

#5 lore raw
Quoted 46 lines · Jamal Hadi Salim
Quoted 27 lines · Jamal Hadi Salim
Quoted 25 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:

When doing multiport mirroring we dont detect infinite loops.

Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress

Quoted 8 lines

Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress

Fix this by remembering the source dev where mirred ran as opposed to destination/target dev

Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")

Hm, this breaks net/fib_tests.sh:

# 23.80 [+0.00] IPv4 rp_filter tests

# 25.63 [+1.84]     TEST: rp_filter passes local packets                                [FAIL]
# 26.65 [+1.02]     TEST: rp_filter passes loopback packets                             [FAIL]

https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout

Quoted 8 lines
Quoted 2 lines

Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..

Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!

Ok, I spent time on this and frankly cant find a way to fix the infinite loop that avoids adding _a lot more_ complexity. We need loop state to be associated with the skb. I will restore the two skb bits and test. From inspection, i see one bit free but i may be able to steal a bit from somewhere. I will post an RFC and at minimal that will start a discussion and maybe someone will come up with a better way of solving this.

Quoted 3 lines

Eric, there's another issue as well involving example port0:egress->port0:egress - I have a patch but will post it later after some testing.

Adding bits for mirred in skb would be quite unfortunate.
Argument of 'we have available space, let's use/waste it' is not very appealing.

Do we really need to accept more than one mirred ?

What is a legitimate/realistic use for MIRRED_NEST_LIMIT == 4 ?

author maintainer
#6 lore raw
Quoted 52 lines · Eric Dumazet
Quoted 46 lines · Jamal Hadi Salim
Quoted 27 lines · Jamal Hadi Salim
Quoted 25 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:

When doing multiport mirroring we dont detect infinite loops.

Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress

Quoted 8 lines

Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress

Fix this by remembering the source dev where mirred ran as opposed to destination/target dev

Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")

Hm, this breaks net/fib_tests.sh:

# 23.80 [+0.00] IPv4 rp_filter tests

# 25.63 [+1.84]     TEST: rp_filter passes local packets                                [FAIL]
# 26.65 [+1.02]     TEST: rp_filter passes loopback packets                             [FAIL]

https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout

Quoted 8 lines
Quoted 2 lines

Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..

Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!

Ok, I spent time on this and frankly cant find a way to fix the infinite loop that avoids adding _a lot more_ complexity. We need loop state to be associated with the skb. I will restore the two skb bits and test. From inspection, i see one bit free but i may be able to steal a bit from somewhere. I will post an RFC and at minimal that will start a discussion and maybe someone will come up with a better way of solving this.

Quoted 3 lines

Eric, there's another issue as well involving example port0:egress->port0:egress - I have a patch but will post it later after some testing.

Quoted 6 lines

Adding bits for mirred in skb would be quite unfortunate.
Argument of 'we have available space, let's use/waste it' is not very appealing.

Do we really need to accept more than one mirred ?

What is a legitimate/realistic use for MIRRED_NEST_LIMIT == 4 ?

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

cheers,
jamal

#7 lore raw
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);
author maintainer
#8 lore raw
Quoted 29 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +3 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 10 lines
net/sched/act_mirred.c +2 -0
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Will try this in a bit. From outset i dont think it will help. But here's what i tested and it works. Of course needs a lot more scrutiny and testing but should be able to explain the idea.

cheers,
jamal

author maintainer
#9 lore raw
In reply to Eric Dumazet
Quoted 29 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +3 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 10 lines
net/sched/act_mirred.c +2 -0
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice? I dont have time today but will continue early AM.

cheers,
jamal

#10 lore raw
Quoted 36 lines · Jamal Hadi Salim
Quoted 34 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +4 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
Quoted 7 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 5 lines
net/sched/act_mirred.c +1 -0
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Quoted 4 lines

I dont have time today but will continue early AM.

cheers,
jamal

author maintainer
#11 lore raw
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
Quoted 7 lines
Quoted 4 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 2 lines
net/sched/act_mirred.c +0 -0
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.

cheers,
jamal

#12 lore raw
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
Quoted 7 lines
Quoted 4 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 2 lines
net/sched/act_mirred.c +0 -0
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Quoted 6 lines

Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.

I am not familiar with this stuff, can the direction be known and taken into account ?

Really, anything but adding new bits in sk_buff.

author maintainer
#13 lore raw
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
Quoted 7 lines
Quoted 4 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 2 lines
net/sched/act_mirred.c +0 -0
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Quoted 6 lines

Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.

Quoted 3 lines

I am not familiar with this stuff, can the direction be known and taken into account ?

Yes, it can.
To figure the target direction see tcf_mirred_act_wants_ingress() and to get what the current direction see code like:
at_ingress = skb_at_tc_ingress(skb);

Quoted 1 line

Really, anything but adding new bits in sk_buff.

If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending the egress->ingress to netif_rx() (see tcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.

cheers,
jamal

author maintainer
#14 lore raw
Quoted 73 lines · Jamal Hadi Salim
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
Quoted 7 lines
Quoted 4 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 2 lines
net/sched/act_mirred.c +0 -0
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Quoted 6 lines

Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.

Quoted 3 lines

I am not familiar with this stuff, can the direction be known and taken into account ?

Yes, it can.
To figure the target direction see tcf_mirred_act_wants_ingress() and to get what the current direction see code like:
at_ingress = skb_at_tc_ingress(skb);

Quoted 1 line

Really, anything but adding new bits in sk_buff.

Quoted 8 lines

If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending the egress->ingress to netif_rx() (see tcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.

BTW, I have the attached patch but was waiting to see how this discussion is heading.
It's when you have something like port0 egress --> port0 egress and you use something like drr as root qdisc.

-- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -281,6 +281,14 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,

        want_ingress = tcf_mirred_act_wants_ingress(m_eaction);

+ if (dev == skb->dev && want_ingress == at_ingress) {
+ pr_notice_once("tc mirred: Loop (%s:%s --> %s:%s)\n",

+                              netdev_name(skb->dev),
+                              at_ingress?"ingress":"egress",
+                              netdev_name(dev),
+                              want_ingress?"ingress":"egress");
+               goto err_cant_do;
+       }
        /* All mirred/redirected skbs should clear previous ct info */
        nf_reset_ct(skb_to_send);
        if (want_ingress && !at_ingress) /* drop dst for egress -> ingress */

cheers,
jamal

author maintainer
#15 lore raw
Quoted 106 lines · Jamal Hadi Salim
Quoted 73 lines · Jamal Hadi Salim
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
Quoted 7 lines
Quoted 4 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 2 lines
net/sched/act_mirred.c +0 -0
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Quoted 6 lines

Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.

Quoted 3 lines

I am not familiar with this stuff, can the direction be known and taken into account ?

Yes, it can.
To figure the target direction see tcf_mirred_act_wants_ingress() and to get what the current direction see code like:
at_ingress = skb_at_tc_ingress(skb);

Quoted 1 line

Really, anything but adding new bits in sk_buff.

Quoted 8 lines

If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending the egress->ingress to netif_rx() (see tcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.

BTW, I have the attached patch but was waiting to see how this discussion is heading.
It's when you have something like port0 egress --> port0 egress and you use something like drr as root qdisc.

-- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c

(quoted diff) +8 -0
@@ -281,6 +281,14 @@ static int tcf_mirred_to_dev(struct sk_buff *skb,
 struct tcf_mirred *m,
 
        want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
 
+       if (dev == skb->dev && want_ingress == at_ingress) {
+               pr_notice_once("tc mirred: Loop (%s:%s --> %s:%s)\n",
+                              netdev_name(skb->dev),
+                              at_ingress?"ingress":"egress",
+                              netdev_name(dev),
+                              want_ingress?"ingress":"egress");
+               goto err_cant_do;
+       }
        /* All mirred/redirected skbs should clear previous ct info */
        nf_reset_ct(skb_to_send);
Quoted 2 lines
        if (want_ingress && !at_ingress) /* drop dst for egress -> ingress */

Eric,
Are you still looking at this?

cheers,
jamal

author maintainer
#16 lore raw
Quoted 98 lines · Jamal Hadi Salim
Quoted 96 lines · Jamal Hadi Salim
Quoted 73 lines · Jamal Hadi Salim
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim

It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress

Have you tried recording both devices ?

net/sched/act_mirred.c +0 -0
index f27b583def78e4afecc7112854b93d59c2520201..711fc2e31cb0451c07a39f9c94226357d5faec09

100644

net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
                return retval;
        }
        for (i = 0; i < xmit->sched_mirred_nest; i++) {
-               if (xmit->sched_mirred_dev[i] != dev)
+               if (xmit->sched_mirred_dev[i] != dev &&
+                   xmit->sched_mirred_dev[i] != skb->dev)
                        continue;
-               pr_notice_once("tc mirred: loop on device %s\n",
-                              netdev_name(dev));
+               pr_notice_once("tc mirred: loop on device %s/%s\n",
+                              netdev_name(dev), netdev_name(skb->dev));
                tcf_action_inc_overlimit_qstats(&m->common);
                return retval;
        }
 
        xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev;
+       xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
 
Quoted 7 lines
Quoted 4 lines

net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461

Quoted 2 lines
net/sched/act_mirred.c +0 -0
        m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
        m_eaction = READ_ONCE(m->tcfm_eaction);

Did you mean not to decrement sched_mirred_nest twice?

No, sorry, we should decrement twice of course.

Quoted 6 lines

Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.

Quoted 3 lines

I am not familiar with this stuff, can the direction be known and taken into account ?

Yes, it can.
To figure the target direction see tcf_mirred_act_wants_ingress() and to get what the current direction see code like:
at_ingress = skb_at_tc_ingress(skb);

Quoted 1 line

Really, anything but adding new bits in sk_buff.

Quoted 8 lines

If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending the egress->ingress to netif_rx() (see tcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.

BTW, I have the attached patch but was waiting to see how this discussion is heading.
It's when you have something like port0 egress --> port0 egress and you use something like drr as root qdisc.

-- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c

(quoted diff) +0 -0
@@ -281,6 +281,14 @@ static int tcf_mirred_to_dev(struct sk_buff *skb,
 struct tcf_mirred *m,
 
        want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
 
Quoted 16 lines
Quoted 10 lines
(quoted diff) +8 -0
+       if (dev == skb->dev && want_ingress == at_ingress) {
+               pr_notice_once("tc mirred: Loop (%s:%s --> %s:%s)\n",
+                              netdev_name(skb->dev),
+                              at_ingress?"ingress":"egress",
+                              netdev_name(dev),
+                              want_ingress?"ingress":"egress");
+               goto err_cant_do;
+       }
        /* All mirred/redirected skbs should clear previous ct info */
        nf_reset_ct(skb_to_send);
Quoted 2 lines
        if (want_ingress && !at_ingress) /* drop dst for egress -> ingress */

Eric,
Are you still looking at this?

i will send a bunch of RFC patches. Maybe one is a clear "easy fix", so i will send that one out against net. Just a bit of testing needed.

cheers,
jamal

Quoted 2 lines

cheers,
jamal