Netdev List
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: Savy <savy@syst3mfailure.io>
Cc: netdev@vger.kernel.org, jiri@resnulli.us, jhs@mojatatu.com,
	willsroot@protonmail.com
Subject: Re: [Patch net 1/2] net_sched: Flush gso_skb list too during ->change()
Date: Tue, 6 May 2025 13:40:15 -0700	[thread overview]
Message-ID: <aBpzr1ey7MmHObLR@pop-os.localdomain> (raw)
In-Reply-To: <krDuBwNbhtDxUlG2tgiXBwSA9KUwph1GfKqwvjBxYDSJv6nVQ98S_inVmQxaRBsndKdgg-rh_vN0xouX4zraF6V3UyQHpWNJUv-rvd-Cwfg=@syst3mfailure.io>

On Tue, May 06, 2025 at 02:00:36PM +0000, Savy wrote:
> On Tuesday, May 6th, 2025 at 12:15 AM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> 
> > 
> > the main skb queue was trimmed, potentially leaving packets in the gso_skb
> > list. This could result in NULL pointer dereference when we only check
> > sch->q.qlen against sch->limit.
> > 
> > 
> 
> Hi Cong,
> 
> With this version of the patch, the null-ptr-deref can still be triggered.
> We also need to decrement sch->q.qlen if __skb_dequeue() returns a valid skb.
> 
> We will take Codel as an example.
> 
>         while (sch->q.qlen > sch->limit) {
>                 struct sk_buff *skb = qdisc_dequeue_internal(sch, true);
>                 ...
>         }
> 
> If sch->q.qlen is 1 and there is a single packet in the gso_skb list,
> if sch->limit is dropped to 0 in codel_change, then qdisc_dequeue_internal() -> __skb_dequeue()
> will remove the skb from the gso_skb list, leaving sch->q.qlen unaltered.
> At this point, the while loop continues, as sch->q.qlen is still 1, but now both the main queue and gso_skb are empty,
> so when qdisc_dequeue_internal() is called again, it returns NULL, and the null-ptr-deref occurs.

Excellent catch!

You are right, I missed qlen--.

Also, actually I accidentally messed up the 2nd boolean parameter for
some Qdisc's.

I will update the patch and send out V2 shortly today.

Thanks!

  reply	other threads:[~2025-05-06 20:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06  0:15 [Patch net 0/2] net_sched: Fix gso_skb flushing during qdisc change Cong Wang
2025-05-06  0:15 ` [Patch net 1/2] net_sched: Flush gso_skb list too during ->change() Cong Wang
2025-05-06 14:00   ` Savy
2025-05-06 20:40     ` Cong Wang [this message]
2025-05-06  0:15 ` [Patch net 2/2] selftests/tc-testing: Add qdisc limit trimming tests 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=aBpzr1ey7MmHObLR@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