Skip to contentSkip to conversation

net: sched: fix crash when deleting secondary chains

PATCH Applied Roman Kapl 3 participants 3 messages Nov 20, 2017 – Nov 23, 2017

Subsystems (3)
lore
Share & tools
lore

Roman Kapl

author
#0 lore raw

PATCH v2 1/1 net: sched: fix crash when deleting secondary chains

If you flush (delete) a filter chain other than chain 0 (such as when deleting the device), the kernel may run into a use-after-free. The chain refcount must not be decremented unless we are sure we are done with the chain.

To reproduce the bug, run:
ip link add dtest type dummy
tc qdisc add dev dtest ingress
tc filter add dev dtest chain 1 parent ffff: flower ip link del dtest

Introduced in: commit f93e1cdcf42c ("net/sched: fix filter flushing"), but unless you have KAsan or luck, you won't notice it until commit 0dadc117ac8b ("cls_flower: use tcf_exts_get_net() before call_rcu()")

Fixes f93e1cdcf42c ("net/sched: fix filter flushing")

---
v1 -> v2: Added Fixes and Acked-by tags

The mail was original rejected by vger, this is a re-send to netdev@vger only (with the same message ID). Sorry for any confusion.
---

 net/sched/cls_api.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/sched/cls_api.c +4 -3
index ab255b421781..7d97f612c9b9 100644
@@ -205,13 +205,14 @@ static void tcf_chain_head_change(struct tcf_chain *chain,
 
 static void tcf_chain_flush(struct tcf_chain *chain)
 {
-	struct tcf_proto *tp;
+	struct tcf_proto *tp = rtnl_dereference(chain->filter_chain);
 
 	tcf_chain_head_change(chain, NULL);
-	while ((tp = rtnl_dereference(chain->filter_chain)) != NULL) {
+	while (tp) {
 		RCU_INIT_POINTER(chain->filter_chain, tp->next);
-		tcf_chain_put(chain);
 		tcf_proto_destroy(tp);
+		tp = rtnl_dereference(chain->filter_chain);
+		tcf_chain_put(chain);
 	}
 }
 
Signature · 1 line
2.15.0
Acked-by on v2 1/1
#1 lore raw
Quoted 11 lines · Roman Kapl

If you flush (delete) a filter chain other than chain 0 (such as when deleting the device), the kernel may run into a use-after-free. The chain refcount must not be decremented unless we are sure we are done with the chain.

To reproduce the bug, run:
ip link add dtest type dummy
tc qdisc add dev dtest ingress
tc filter add dev dtest chain 1 parent ffff: flower ip link del dtest

Quoted 7 lines

Introduced in: commit f93e1cdcf42c ("net/sched: fix filter flushing"), but unless you have KAsan or luck, you won't notice it until commit 0dadc117ac8b ("cls_flower: use tcf_exts_get_net() before call_rcu()")

Fixes f93e1cdcf42c ("net/sched: fix filter flushing")
maintainer Applied
#2 lore raw
In reply to Roman Kapl

From: Roman Kapl <[email protected]>
Date: Mon, 20 Nov 2017 22:21:13 +0100

Quoted 11 lines

If you flush (delete) a filter chain other than chain 0 (such as when deleting the device), the kernel may run into a use-after-free. The chain refcount must not be decremented unless we are sure we are done with the chain.

To reproduce the bug, run:
ip link add dtest type dummy
tc qdisc add dev dtest ingress
tc filter add dev dtest chain 1 parent ffff: flower ip link del dtest

Quoted 7 lines

Introduced in: commit f93e1cdcf42c ("net/sched: fix filter flushing"), but unless you have KAsan or luck, you won't notice it until commit 0dadc117ac8b ("cls_flower: use tcf_exts_get_net() before call_rcu()")

Fixes f93e1cdcf42c ("net/sched: fix filter flushing")

Applied, thank you.