mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Yuchao Zhang <ndaugoing@gmail.com>
Cc: netdev-bot+sashiko@kernel.org, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	toke@redhat.com, jhs@mojatatu.com, jiri@resnulli.us,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] net/sched: sch_cake: prevent shaper corruption and stall in cake_overhead()
Date: Sun, 27 Sep 2026 12:31:17 +0100	[thread overview]
Message-ID: <20260927113117.GI13925@horms.kernel.org> (raw)
In-Reply-To: <20260922084124.36858-1-ndaugoing@gmail.com>

On Tue, Sep 22, 2026 at 04:41:24PM +0800, Yuchao Zhang wrote:
> In cake_overhead(), the header length up to the transport layer is
> computed using logic borrowed from qdisc_pkt_len_segs_init():
> 
>         /* borrowed from qdisc_pkt_len_segs_init() */
>         if (!skb->encapsulation)
>                 hdr_len = skb_transport_offset(skb);
>         else
>                 hdr_len = skb_inner_transport_offset(skb);
> 
> However, cake_overhead() suffers from several issues:
> 
> 1. When segs == 0 (e.g. from dodgy GSO packets where gso_segs is not
>    recomputed), the multi-segment arithmetic underflows: (segs - 1) wraps
>    to 4294967295, causing cake_calc_overhead() * (segs - 1) to produce
>    an enormous length. When charged in cake_advance_shaper(),
>    time_next_packet is pushed decades into the future, permanently
>    stalling the CAKE dequeue queue.
>    Fix this by returning cake_calc_overhead(q, len, off) for segs <= 1.
> 
> 2. When the transport header was never set, skb->transport_header holds
>    the sentinel value ~0U. skb_transport_offset() returns ~65535, which
>    is not caught by a negative offset check. skb_header_pointer() fails,
>    and hdr_len stays ~65535, charging ~66 KB per segment to the shaper.
>    Fix this by mirroring qdisc_pkt_len_segs_init() and checking
>    unlikely(!skb_transport_header_was_set(skb)).
> 
> 3. Both skb_transport_offset() and skb_inner_transport_offset() return
>    signed int, but hdr_len is declared as unsigned int. If post-enqueue
>    mangling (such as BPF packet trimming via bpf_skb_net_shrink())
>    produces a negative offset, hdr_len wraps to near UINT_MAX, causing
>    corrupted header length accounting.
>    Fix this by declaring hdr_len as int and falling back to
>    cake_calc_overhead(q, len, off) if hdr_len is negative.
> 
> Fixes: a41851bea7bf ("net: account for encap headers in qdisc pkt len")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yuchao Zhang <ndaugoing@gmail.com>
> ---
> v2:
>  - Accurately describe the impact as shaper accounting corruption / stall
>    rather than OOB read past the allocation per Sashiko review.
>  - Fix pre-existing high-severity integer underflow when segs == 0 by
>    checking segs <= 1.
>  - Import companion check !skb_transport_header_was_set(skb) from
>    qdisc_pkt_len_segs_init() to prevent unset transport header sentinel
>    (~0U) from inflating packet length to ~66 KB.


Please do include lore.kernel.org links to earlier versions in
the changelog. This helps tremendously with review.

Please do not post updated patch revisions as responses to earlier versions.
Rather, please start a new thread for each version.

Thanks!

      parent reply	other threads:[~2026-09-27 11:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 12:21 [PATCH 0/2] net: fix negative transport offset handling in GSO pkt len calculation zjamg
2026-09-17 12:21 ` [PATCH 1/2] net: fix OOB read in qdisc_pkt_len_segs_init() on negative transport offset zjamg
2026-09-17 12:21 ` [PATCH 2/2] net/sched: sch_cake: check negative transport offset in cake_overhead() zjamg
2026-09-21 14:20   ` netdev-bot+sashiko
2026-09-22  8:41     ` Yuchao Zhang
2026-09-22  8:41     ` [PATCH v2] net/sched: sch_cake: prevent shaper corruption and stall " Yuchao Zhang
2026-09-25 11:42       ` netdev-bot+sashiko
2026-09-27 11:29         ` Simon Horman
2026-09-27 11:31       ` Simon Horman [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=20260927113117.GI13925@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndaugoing@gmail.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=toke@redhat.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

all inboxes | Powered by JetHome®