net_sched: no longer use qdisc_tree_flush_backlog()
Subsystems (3)
cover net_sched: no longer use qdisc_tree_flush_backlog()
This series is based on a report from Gerrard Tai.
Essentially, all users of qdisc_tree_flush_backlog() are racy.
We must instead use qdisc_purge_queue().
Eric Dumazet (5):
net_sched: prio: fix a race in prio_tune()
net_sched: red: fix a race in __red_change()
net_sched: tbf: fix a race in tbf_change()
net_sched: ets: fix a race in ets_qdisc_change()
net_sched: remove qdisc_tree_flush_backlog()
include/net/sch_generic.h | 8 -------- net/sched/sch_ets.c | 2 +- net/sched/sch_prio.c | 2 +- net/sched/sch_red.c | 2 +- net/sched/sch_tbf.c | 2 +- 5 files changed, 4 insertions(+), 12 deletions(-)
Signature · 1 line
2.50.0.rc0.642.g800a2b2222-goog
PATCH 1/5 net_sched: prio: fix a race in prio_tune()
Gerrard Tai reported a race condition in PRIO, whenever SFQ perturb timer fires at the wrong time.
The race is as follows:
CPU 0 CPU 1
[1]: lock root
[2]: qdisc_tree_flush_backlog()
[3]: unlock root
| | [5]: lock root | [6]: rehash | [7]: qdisc_tree_reduce_backlog() |
[4]: qdisc_put()
This can be abused to underflow a parent's qlen.
Calling qdisc_purge_queue() instead of qdisc_tree_flush_backlog() should fix the race, because all packets will be purged from the qdisc before releasing the lock.
--- net/sched/sch_prio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_prio.c +1 -1
@@ -211,7 +211,7 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt,memcpy (q->prio2band, qopt->priomap,TC_PRIO_MAX +1 );for (i = q->bands; i < oldbands; i++) -qdisc_tree_flush_backlog (q->queues[i]); +qdisc_purge_queue (q->queues[i]);for (i = oldbands; i < q->bands; i++) { q->queues[i] = queues[i];
Signature · 1 line
2.50.0.rc0.642.g800a2b2222-goog
PATCH 2/5 net_sched: red: fix a race in __red_change()
In reply to Eric DumazetGerrard Tai reported a race condition in RED, whenever SFQ perturb timer fires at the wrong time.
The race is as follows:
CPU 0 CPU 1
[1]: lock root
[2]: qdisc_tree_flush_backlog()
[3]: unlock root
| | [5]: lock root | [6]: rehash | [7]: qdisc_tree_reduce_backlog() |
[4]: qdisc_put()
This can be abused to underflow a parent's qlen.
Calling qdisc_purge_queue() instead of qdisc_tree_flush_backlog() should fix the race, because all packets will be purged from the qdisc before releasing the lock.
--- net/sched/sch_red.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_red.c +1 -1
@@ -285,7 +285,7 @@ static int __red_change(struct Qdisc *sch, struct nlattr **tb, q->userbits = userbits; q->limit = ctl->limit;if (child) { -qdisc_tree_flush_backlog (q->qdisc); +qdisc_purge_queue (q->qdisc); old_child = q->qdisc; q->qdisc = child; }
Signature · 1 line
2.50.0.rc0.642.g800a2b2222-goog
PATCH 3/5 net_sched: tbf: fix a race in tbf_change()
In reply to Eric DumazetGerrard Tai reported a race condition in TBF, whenever SFQ perturb timer fires at the wrong time.
The race is as follows:
CPU 0 CPU 1
[1]: lock root
[2]: qdisc_tree_flush_backlog()
[3]: unlock root
| | [5]: lock root | [6]: rehash | [7]: qdisc_tree_reduce_backlog() |
[4]: qdisc_put()
This can be abused to underflow a parent's qlen.
Calling qdisc_purge_queue() instead of qdisc_tree_flush_backlog() should fix the race, because all packets will be purged from the qdisc before releasing the lock.
--- net/sched/sch_tbf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_tbf.c +1 -1
@@ -452,7 +452,7 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt,sch_tree_lock (sch);if (child) { -qdisc_tree_flush_backlog (q->qdisc); +qdisc_purge_queue (q->qdisc); old = q->qdisc; q->qdisc = child; }
Signature · 1 line
2.50.0.rc0.642.g800a2b2222-goog
PATCH 4/5 net_sched: ets: fix a race in ets_qdisc_change()
In reply to Eric DumazetGerrard Tai reported a race condition in ETS, whenever SFQ perturb timer fires at the wrong time.
The race is as follows:
CPU 0 CPU 1
[1]: lock root
[2]: qdisc_tree_flush_backlog()
[3]: unlock root
| | [5]: lock root | [6]: rehash | [7]: qdisc_tree_reduce_backlog() |
[4]: qdisc_put()
This can be abused to underflow a parent's qlen.
Calling qdisc_purge_queue() instead of qdisc_tree_flush_backlog() should fix the race, because all packets will be purged from the qdisc before releasing the lock.
--- net/sched/sch_ets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_ets.c +1 -1
@@ -661,7 +661,7 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt,for (i = q->nbands; i < oldbands; i++) {if (i >= q->nstrict && q->classes[i].qdisc->q.qlen)list_del_init (&q->classes[i].alist); -qdisc_tree_flush_backlog (q->classes[i].qdisc); +qdisc_purge_queue (q->classes[i].qdisc); }WRITE_ONCE (q->nstrict, nstrict);memcpy (q->prio2band, priomap,sizeof (priomap));
Signature · 1 line
2.50.0.rc0.642.g800a2b2222-goog
PATCH 5/5 net_sched: remove qdisc_tree_flush_backlog()
In reply to Eric DumazetThis function is no longer used after the four prior fixes.
Given all prior uses were wrong, it seems better to remove it.
--- include/net/sch_generic.h | 8 -------- 1 file changed, 8 deletions(-)
include/net/sch_generic.h +0 -8
@@ -973,14 +973,6 @@ static inline void qdisc_qstats_qlen_backlog(struct Qdisc *sch, __u32 *qlen, *backlog = qstats.backlog; } -static inline void qdisc_tree_flush_backlog (struct Qdisc *sch) -{ -__u32 qlen, backlog; - -qdisc_qstats_qlen_backlog (sch, &qlen, &backlog); -qdisc_tree_reduce_backlog (sch, qlen, backlog); -} -static inline void qdisc_purge_queue (struct Qdisc *sch) {__u32 qlen, backlog;
Signature · 1 line
2.50.0.rc0.642.g800a2b2222-goog
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Wed, 11 Jun 2025 11:15:10 +0000 you wrote:
This series is based on a report from Gerrard Tai.
Essentially, all users of
qdisc_tree_flush_backlog()are racy.We must instead use
qdisc_purge_queue().
Quoted 8 lines
Eric Dumazet (5):
net_sched: prio: fix a race inprio_tune()
net_sched: red: fix a race in__red_change()
net_sched: tbf: fix a race intbf_change()
net_sched: ets: fix a race inets_qdisc_change()
net_sched: removeqdisc_tree_flush_backlog()[...]
Here is the summary with links:
- [net,1/5] net_sched: prio: fix a race in prio_tune()
https://git.kernel.org/netdev/net/c/d35acc1be348 - [net,2/5] net_sched: red: fix a race in __red_change() https://git.kernel.org/netdev/net/c/85a3e0ede384 - [net,3/5] net_sched: tbf: fix a race in tbf_change() https://git.kernel.org/netdev/net/c/43eb46604121 - [net,4/5] net_sched: ets: fix a race in ets_qdisc_change() https://git.kernel.org/netdev/net/c/d92adacdd8c2 - [net,5/5] net_sched: remove qdisc_tree_flush_backlog() https://git.kernel.org/netdev/net/c/adcaa890c7a4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html