From: Cong Wang <xiyou.wangcong@gmail.com>
To: Savy <savy@syst3mfailure.io>
Cc: Will <willsroot@protonmail.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
jhs@mojatatu.com, jiri@resnulli.us
Subject: Re: [BUG] net/sched: Race Condition and Null Dereference in codel_change, pie_change, fq_pie_change, fq_codel_change, hhf_change
Date: Mon, 5 May 2025 12:44:33 -0700 [thread overview]
Message-ID: <aBkVIY4GZBnrolrq@pop-os.localdomain> (raw)
In-Reply-To: <EBHeQZeq5AJteszZoHrsiJv6EGOnuByQ-XNejgA9WiqQ8g2jIXowzoGjuJowDcV6xi9xBgyMTwNlS8wN0zUOlRl4Bl2Mv-x883IKCvdySyU=@syst3mfailure.io>
On Tue, Apr 29, 2025 at 01:41:19PM +0000, Savy wrote:
>
> On Monday, April 28th, 2025 at 7:53 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> >
> >
> > Excellent analysis!
> >
> > Do you mind testing the following patch?
> >
> > Note:
> >
> > 1) We can't just test NULL, because otherwise we would leak the skb's
> > in gso_skb list.
> >
> > 2) I am totally aware that maybe there are some other cases need the
> > same fix, but I want to be conservative here since this will be
> > targeting for -stable. It is why I intentionally keep my patch minimum.
> >
> > Thanks!
> >
> > --------------->
> >
>
> Hi Cong,
>
> Thank you for the reply. We have tested your patch and can confirm that it resolves the issue.
> However, regarding point [1], we conducted some tests to verify if there is a skb leak in the gso_skb list,
> but the packet remains in the list only for a limited amount of time.
>
> In our POC we set a very low TBF rate, so when the Qdisc runs out of tokens,
> it reschedules itself via qdisc watchdog after approximately 45 seconds.
>
> Returning to the example above, here is what happens when the watchdog timer fires:
>
> [ ... ]
>
> Packet 2 is sent:
>
> [ ... ]
>
> tbf_dequeue()
> qdisc_peek_dequeued()
> skb_peek(&sch->gso_skb) // sch->gso_skb is empty
> codel_qdisc_dequeue() // Codel qlen is 1
> qdisc_dequeue_head()
> // Packet 2 is removed from the queue
> // Codel qlen = 0
> __skb_queue_head(&sch->gso_skb, skb); // Packet 2 is added to gso_skb list
> sch->q.qlen++ // Codel qlen = 1
>
> // TBF runs out of tokens and reschedules itself for later
> qdisc_watchdog_schedule_ns()
>
> codel_change() // Patched, (!skb) break;, does not crash
>
> // ... ~45 seconds later the qdisc watchdog timer fires
>
> tbf_dequeue()
> qdisc_peek_dequeued()
> skb_peek(&sch->gso_skb) // sch->gso_skb is _not_ empty (contains Packet 2)
> // TBF now has enough tokens
> qdisc_dequeue_peeked()
> skb = __skb_dequeue(&sch->gso_skb) // Packet 2 is removed from the gso_skb list
> sch->q.qlen-- // Codel qlen = 0
>
> Notice how the gso_skb list is correctly cleaned up when the watchdog timer fires.
> We also examined some edge cases, such as when the watchdog is canceled
> and there are still packets left in the gso_skb list, and it is always cleaned up:
>
> Qdisc destruction case:
>
> tbf_destroy()
> qdisc_put()
> __qdisc_destroy()
> qdisc_reset()
> __skb_queue_purge(&qdisc->gso_skb);
>
> Qdisc reset case:
>
> tbf_reset()
> qdisc_reset()
> __skb_queue_purge(&qdisc->gso_skb);
>
> Perhaps the skb leak you mentioned occurs in another edge case that we overlooked?
You are right, it is inaccurate to say it is a leak, probably just a
matter of ordering, because ->gso_list is logically the "head" of a
Qdisc.
> In any case, we believe your patch is technically more correct,
> as it makes sense to clean up packets in the gso_skb list first when the limit changes.
>
Thank you for testing! I will add your Reported-and-Tested-by and send
out the patch.
Regards,
Cong
prev parent reply other threads:[~2025-05-05 19:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 14:14 [BUG] net/sched: Race Condition and Null Dereference in codel_change, pie_change, fq_pie_change, fq_codel_change, hhf_change Will
2025-04-26 22:56 ` Cong Wang
2025-04-27 21:26 ` Will
2025-04-28 19:53 ` Cong Wang
2025-04-29 13:41 ` Savy
2025-05-04 15:35 ` Will
2025-05-05 19:44 ` Cong Wang [this message]
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=aBkVIY4GZBnrolrq@pop-os.localdomain \
--to=xiyou.wangcong@gmail.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=savy@syst3mfailure.io \
--cc=willsroot@protonmail.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