From: Cong Wang <xiyou.wangcong@gmail.com>
To: Lion Ackermann <nnamrec@gmail.com>
Cc: netdev@vger.kernel.org, Jiri Pirko <jiri@resnulli.us>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Victor Nogueira <victor@mojatatu.com>,
Mingi Cho <mincho@theori.io>
Subject: Re: [PATCH] net/sched: Always pass notifications when child class becomes empty
Date: Mon, 30 Jun 2025 14:38:29 -0700 [thread overview]
Message-ID: <aGMD1S0F9sTXexBo@pop-os.localdomain> (raw)
In-Reply-To: <d912cbd7-193b-4269-9857-525bee8bbb6a@gmail.com>
On Mon, Jun 30, 2025 at 03:27:30PM +0200, Lion Ackermann wrote:
> Certain classful qdiscs may invoke their classes' dequeue handler on an
> enqueue operation. This may unexpectedly empty the child qdisc and thus
> make an in-flight class passive via qlen_notify(). Most qdiscs do not
> expect such behaviour at this point in time and may re-activate the
> class eventually anyways which will lead to a use-after-free.
>
> The referenced fix commit attempted to fix this behavior for the HFSC
> case by moving the backlog accounting around, though this turned out to
> be incomplete since the parent's parent may run into the issue too.
> The following reproducer demonstrates this use-after-free:
>
> tc qdisc add dev lo root handle 1: drr
> tc filter add dev lo parent 1: basic classid 1:1
> tc class add dev lo parent 1: classid 1:1 drr
> tc qdisc add dev lo parent 1:1 handle 2: hfsc def 1
> tc class add dev lo parent 2: classid 2:1 hfsc rt m1 8 d 1 m2 0
> tc qdisc add dev lo parent 2:1 handle 3: netem
> tc qdisc add dev lo parent 3:1 handle 4: blackhole
>
> echo 1 | socat -u STDIN UDP4-DATAGRAM:127.0.0.1:8888
> tc class delete dev lo classid 1:1
> echo 1 | socat -u STDIN UDP4-DATAGRAM:127.0.0.1:8888
>
> Since backlog accounting issues leading to a use-after-frees on stale
> class pointers is a recurring pattern at this point, this patch takes
> a different approach. Instead of trying to fix the accounting, the patch
> ensures that qdisc_tree_reduce_backlog always calls qlen_notify when
> the child qdisc is empty. This solves the problem because deletion of
> qdiscs always involves a call to qdisc_reset() and / or
> qdisc_purge_queue() which ultimately resets its qlen to 0 thus causing
> the following qdisc_tree_reduce_backlog() to report to the parent. Note
> that this may call qlen_notify on passive classes multiple times. This
> is not a problem after the recent patch series that made all the
> classful qdiscs qlen_notify() handlers idempotent.
>
> Fixes: 3f981138109f ("sch_hfsc: Fix qlen accounting bug when using peek in hfsc_enqueue()")
> Signed-off-by: Lion Ackermann <nnamrec@gmail.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> net/sched/sch_api.c | 19 +++++--------------
> 1 file changed, 5 insertions(+), 14 deletions(-)
I love to see fixing bugs by removing code. :)
Thanks.
next prev parent reply other threads:[~2025-06-30 21:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 10:41 Incomplete fix for recent bug in tc / hfsc Lion Ackermann
2025-06-23 14:43 ` Jamal Hadi Salim
2025-06-24 4:41 ` Cong Wang
2025-06-24 9:24 ` Lion Ackermann
2025-06-24 10:43 ` Lion Ackermann
2025-06-25 14:22 ` Jamal Hadi Salim
2025-06-26 8:08 ` Lion Ackermann
2025-06-28 21:43 ` Jamal Hadi Salim
2025-06-29 14:29 ` Jamal Hadi Salim
2025-06-29 19:50 ` Cong Wang
2025-06-30 9:04 ` Lion Ackermann
2025-06-30 11:34 ` Jamal Hadi Salim
2025-06-30 13:36 ` Lion Ackermann
2025-06-30 14:57 ` Jamal Hadi Salim
2025-06-30 17:52 ` Victor Nogueira
2025-06-30 21:42 ` Cong Wang
2025-07-01 12:41 ` Lion Ackermann
2025-07-01 12:58 ` Victor Nogueira
2025-06-30 11:47 ` Victor Nogueira
2025-06-30 13:27 ` [PATCH] net/sched: Always pass notifications when child class becomes empty Lion Ackermann
2025-06-30 14:56 ` Jamal Hadi Salim
2025-06-30 21:38 ` Cong Wang [this message]
2025-07-01 14:03 ` Jamal Hadi Salim
2025-07-02 21:50 ` patchwork-bot+netdevbpf
2025-06-28 0:35 ` Incomplete fix for recent bug in tc / hfsc Cong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aGMD1S0F9sTXexBo@pop-os.localdomain \
--to=xiyou.wangcong@gmail.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=mincho@theori.io \
--cc=netdev@vger.kernel.org \
--cc=nnamrec@gmail.com \
--cc=victor@mojatatu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox