Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/2] net/sched: reject binding actions with a goto chain of another block
@ 2026-12-06 10:20 Muhammad Umer
  2026-12-06 10:20 ` [PATCH net 1/2] net/sched: act_api: reject binding actions that jump to " Muhammad Umer
  2026-12-06 10:20 ` [PATCH net 2/2] selftests/tc-testing: add gact goto chain cross-block bind tests Muhammad Umer
  0 siblings, 2 replies; 3+ messages in thread
From: Muhammad Umer @ 2026-12-06 10:20 UTC (permalink / raw)
  To: jhs, jiri
  Cc: davem, edumazet, kuba, pabeni, horms, willemb, shuah, netdev,
	linux-kselftest

A tc filter can bind an existing action by index. When that action
holds a goto chain of another block, classification continues in that
block and the qdisc owning the binding filter can receive class
pointers belonging to a different qdisc.

Patch 1 rejects such binds, patch 2 adds tc-testing cases for it.

Muhammad Umer (2):
  net/sched: act_api: reject binding actions that jump to another block
  selftests/tc-testing: add gact goto chain cross-block bind tests

 net/sched/act_api.c                           | 28 ++++++++++
 .../actions/gact-goto-chain-block.json        | 54 +++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/gact-goto-chain-block.json

-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net 1/2] net/sched: act_api: reject binding actions that jump to another block
  2026-12-06 10:20 [PATCH net 0/2] net/sched: reject binding actions with a goto chain of another block Muhammad Umer
@ 2026-12-06 10:20 ` Muhammad Umer
  2026-12-06 10:20 ` [PATCH net 2/2] selftests/tc-testing: add gact goto chain cross-block bind tests Muhammad Umer
  1 sibling, 0 replies; 3+ messages in thread
From: Muhammad Umer @ 2026-12-06 10:20 UTC (permalink / raw)
  To: jhs, jiri
  Cc: davem, edumazet, kuba, pabeni, horms, willemb, shuah, netdev,
	linux-kselftest

A filter can bind an existing action by index. If that action was
created by a filter of another block with a "goto chain" control
action, it still holds a chain of that other block: the bind path
returns before any control action handling and leaves goto_chain
as is. tcf_action_exec() then sends classification of the binding
filter into a chain of the other block.

Filters of that chain may carry a tcf_result class bound to the qdisc
owning the other block. The qdisc classifying the packet uses that
class pointer as one of its own classes, which crashes when the two
qdiscs differ, e.g. an htb qdisc reading a drr class.

Before commit 85d0966fa57e ("net/sched: prepare TC actions to properly
validate the control action"), the generic code instead re-pointed
goto_chain to the binding block on every bind, which made the original
filter jump across blocks.

Reject the bind in tcf_action_init_1() when the action's goto chain
belongs to a block other than the one of the binding filter. Doing it
there covers the legacy police path of tcf_exts_validate_ex() too.
Binding an action whose goto chain is in the same block is unchanged.

The issue was discovered by an AI code review agent and confirmed by
triggering it on an unmodified kernel built with KASAN, as an
unprivileged user in a new user and network namespace: KASAN reports a
slab-out-of-bounds read in htb_enqueue() on a drr class, followed by a
general protection fault. Reproducing it did not need any kernel
modification or error injection. A reproducer is available and will be
sent to the maintainers privately.

The fix was tested with that reproducer, which no longer triggers, and
with the tc-testing selftests for gact, matchall, police, hfsc, qfq, drr
and ets, including the cases added in the next patch. The fix was
written with the help of the same AI agent.

Fixes: db50514f9a9c ("net: sched: add termination action to allow goto chain")
Cc: stable@vger.kernel.org
Signed-off-by: Muhammad Umer <mumer.mobi@gmail.com>
---
 net/sched/act_api.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index e142d33dc5e..78d72568f8f 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -1421,6 +1421,20 @@ struct tc_action_ops *tc_action_load_ops(struct nlattr *nla, u32 flags,
 	return a_o;
 }
 
+static bool tcf_action_goto_chain_foreign(const struct tc_action *a,
+					  const struct tcf_proto *tp)
+{
+	const struct tcf_chain *chain;
+	bool foreign;
+
+	rcu_read_lock();
+	chain = rcu_dereference(a->goto_chain);
+	foreign = chain && chain->block != tp->chain->block;
+	rcu_read_unlock();
+
+	return foreign;
+}
+
 struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
 				    struct nlattr *nla, struct nlattr *est,
 				    struct tc_action_ops *a_o, int *init_res,
@@ -1467,6 +1481,20 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
 		goto err_out;
 	*init_res = err;
 
+	/* A filter may bind an existing action by index. If that action
+	 * jumps to a chain of another block, the filter would continue
+	 * classification there, and the qdisc owning this filter would
+	 * receive tcf_result class pointers of another qdisc.
+	 */
+	if ((flags & TCA_ACT_FLAGS_BIND) && tp && err == ACT_P_BOUND &&
+	    tcf_action_goto_chain_foreign(a, tp)) {
+		NL_SET_ERR_MSG(extack,
+			       "Action jumps to a chain of a different block");
+		tcf_idr_release(a, true);
+		err = -EINVAL;
+		goto err_out;
+	}
+
 	if (!police && tb[TCA_ACT_COOKIE])
 		tcf_set_action_cookie(&a->user_cookie, user_cookie);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH net 2/2] selftests/tc-testing: add gact goto chain cross-block bind tests
  2026-12-06 10:20 [PATCH net 0/2] net/sched: reject binding actions with a goto chain of another block Muhammad Umer
  2026-12-06 10:20 ` [PATCH net 1/2] net/sched: act_api: reject binding actions that jump to " Muhammad Umer
@ 2026-12-06 10:20 ` Muhammad Umer
  1 sibling, 0 replies; 3+ messages in thread
From: Muhammad Umer @ 2026-12-06 10:20 UTC (permalink / raw)
  To: jhs, jiri
  Cc: davem, edumazet, kuba, pabeni, horms, willemb, shuah, netdev,
	linux-kselftest

Add two gact cases: binding an action whose goto chain belongs to the
block of another qdisc must fail and leave the action untouched, while
binding it from a filter of the same block keeps working.

The first case fails without the previous patch and passes with it.
These tests were written with the help of an AI assistant.

Signed-off-by: Muhammad Umer <mumer.mobi@gmail.com>
---
 .../actions/gact-goto-chain-block.json        | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/gact-goto-chain-block.json

diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/gact-goto-chain-block.json b/tools/testing/selftests/tc-testing/tc-tests/actions/gact-goto-chain-block.json
new file mode 100644
index 00000000000..147c5200b52
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/gact-goto-chain-block.json
@@ -0,0 +1,54 @@
+[
+    {
+        "id": "23ab",
+        "name": "Reject binding an action whose goto chain is in another block",
+        "category": [
+            "actions",
+            "gact"
+        ],
+        "plugins": {
+            "requires": "nsPlugin"
+        },
+        "setup": [
+            "$TC qdisc add dev $DUMMY root handle 1: drr",
+            "$TC class add dev $DUMMY parent 1: classid 1:1 drr",
+            "$TC filter add dev $DUMMY parent 1: chain 5 protocol all prio 1 matchall classid 1:1",
+            "$TC filter add dev $DUMMY parent 1: chain 0 protocol all prio 1 matchall action gact goto chain 5 index 77",
+            "$TC qdisc add dev $DEV1 root handle 2: htb"
+        ],
+        "cmdUnderTest": "$TC filter add dev $DEV1 parent 2: protocol all prio 1 matchall action gact pass index 77",
+        "expExitCode": "2",
+        "verifyCmd": "$TC actions get action gact index 77",
+        "matchPattern": "index 77 ref 1 bind 1",
+        "matchCount": "1",
+        "teardown": [
+            "$TC qdisc del dev $DEV1 root",
+            "$TC qdisc del dev $DUMMY root"
+        ]
+    },
+    {
+        "id": "8ada",
+        "name": "Bind an action whose goto chain is in the same block",
+        "category": [
+            "actions",
+            "gact"
+        ],
+        "plugins": {
+            "requires": "nsPlugin"
+        },
+        "setup": [
+            "$TC qdisc add dev $DUMMY root handle 1: drr",
+            "$TC class add dev $DUMMY parent 1: classid 1:1 drr",
+            "$TC filter add dev $DUMMY parent 1: chain 5 protocol all prio 1 matchall classid 1:1",
+            "$TC filter add dev $DUMMY parent 1: chain 0 protocol all prio 1 matchall action gact goto chain 5 index 77"
+        ],
+        "cmdUnderTest": "$TC filter add dev $DUMMY parent 1: chain 0 protocol all prio 2 matchall action gact pass index 77",
+        "expExitCode": "0",
+        "verifyCmd": "$TC actions get action gact index 77",
+        "matchPattern": "index 77 ref 2 bind 2",
+        "matchCount": "1",
+        "teardown": [
+            "$TC qdisc del dev $DUMMY root"
+        ]
+    }
+]
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-06 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 10:20 [PATCH net 0/2] net/sched: reject binding actions with a goto chain of another block Muhammad Umer
2026-12-06 10:20 ` [PATCH net 1/2] net/sched: act_api: reject binding actions that jump to " Muhammad Umer
2026-12-06 10:20 ` [PATCH net 2/2] selftests/tc-testing: add gact goto chain cross-block bind tests Muhammad Umer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox