From: Dickson Wu <dick…@certik.com>
Several AND containers can point to the same later match sequence.
The ematch walker bounds nesting depth, but it visits that shared
sequence again after each container. A small filter tree can
therefore take exponential work to classify one packet.
An unprivileged user in a user and network namespace can create
such a tree through rtnetlink, and every packet that reaches the
filter then keeps its CPU busy in classification. Bound the number
of evaluated matches in proportion to the configured tree size and
return no match when the budget is exhausted. A tree without
shared or overlapping substructures remains within the budget.
A reproducer is available on request.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Dickson Wu <dick…@certik.com>
---
Matched net-tip x86_64 W=1 ematch.o builds: zero warnings.
KVM with mapped UID 1000: the nonshared control completed on both
images. The base shared-container trigger stalled with RCU traces
at 22 and 85 seconds and timed out at 100 seconds; patched completed
the same K=3, L=31 send in 0.000016 seconds.
Matched basic tdc: 47 passes and 13 shared failures on each image;
three needed unavailable skbedit and ten needed unavailable canid.
There were no patched-only failures.
This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis and the patch
before signing off.
net/sched/ematch.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index a8e06cf053c9..92e568c8e6c2 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -506,9 +506,12 @@ int __tcf_em_tree_match(struct sk_buff *skb, struct tcf_ematch_tree *tree,
int stackp = 0, match_idx = 0, res = 0;
struct tcf_ematch *cur_match;
int stack[CONFIG_NET_EMATCH_STACK];
+ unsigned int budget = 2 * tree->hdr.nmatches + CONFIG_NET_EMATCH_STACK;
proceed:
while (match_idx < tree->hdr.nmatches) {
+ if (unlikely(!budget--))
+ goto match_limit;
cur_match = tcf_em_get_match(tree, match_idx);
if (tcf_em_is_container(cur_match)) {
@@ -546,6 +549,10 @@ int __tcf_em_tree_match(struct sk_buff *skb, struct tcf_ematch_tree *tree,
return res;
+match_limit:
+ net_warn_ratelimited("tc ematch: match limit exceeded\n");
+ return 0;
+
stack_overflow:
net_warn_ratelimited("tc ematch: local stack overflow, increase NET_EMATCH_STACK\n");
return -1;
[PATCH net] net/sched: bound ematch container evaluation
- From
- devn…@kernel.org (Dickson Wu via B4 Relay)
- Organization
- Usenet Network
- Message-ID
- <2026…@certik.com>
- Date
- Newsgroups
- linux.kernel.netdev