Netdev List
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: netdev@vger.kernel.org, jiri@resnulli.us, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	david.ward@ll.mit.edu, vega@nebusec.ai, victor@mojatatu.com,
	zhanxusheng1024@gmail.com, stable@vger.kernel.org
Subject: Re: [PATCH net v2] net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
Date: Thu, 20 Aug 2026 19:27:39 +0100	[thread overview]
Message-ID: <20260820182739.GC265046@horms.kernel.org> (raw)
In-Reply-To: <20260818095927.15901-1-jhs@mojatatu.com>

On Tue, Aug 18, 2026 at 05:59:27AM -0400, Jamal Hadi Salim wrote:
> gred_enqueue(), bfifo_enqueue() and plug_enqueue() admit a packet when the
> current backlog plus the packet length fits within the queue limit:
> 
>   sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit (gred default VQ)
>   gred_backlog+qdisc_pkt_len(skb) <= q->limit  (gred configured VQ)
>   sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit (bfifo)
>   sch->qstats.backlog + skb->len <= q->limit             (plug)
> 
> sch->qstats.backlog and q->backlog are u32, and qdisc_pkt_len()/skb->len
> are unsigned int, so all sums are computed in 32 bits and wrap at 2^32.
> Once the true backlog exceeds 4 GiB the wrapped sum becomes small and
> admission keeps succeeding, so the queue grows without bound and the kernel
> can be driven to OOM.
> 
> Promote the sums to u64 so admission stops once the true backlog exceeds
> the limit.  The limit is u32, so the bounded queue stays below 2^32 and
> the stored u32 backlog never wraps.
> 
> The bug can only be reproduced as root (albeit with ridiculous setup):
>  attach a gred (or bfifo/plug) qdisc with a limit near 4 GiB,
>  leaving the default VQ unconfigured (for gred), and drive >4 GiB of
>  queued traffic (e.g. via a size table / stab to inflate qdisc_pkt_len,
>  or sustained high-rate traffic). The u32 backlog+len sum wraps at 2^32,
>  admission keeps succeeding, and the queue grows unboundedly to OOM.
> 
> Fixes: a3eb95f891d6 ("net_sched: gred: add TCA_GRED_LIMIT attribute")
> Reported-by: vega@nebusec.ai
> Tested-by: Victor Nogueira <victor@mojatatu.com>
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> ---
> v1->v2:
> 
> 1. Added bfifo+plug into the same patch as gred since it is the same
>    pattern. Flagged by Zhan Xusheng and Sashiko[1][2].
> 2. Starting this patch, and for the rest of AI found bugs,  i will start
>    adding the conditions required to reproduce the patch (see the
>    above commentary "The bug can only be reproduced as root...").
> 
> [1] https://sashiko.dev/#/patchset/20260809091657.879929-1-jhs@mojatatu.com
> [2] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260809091657.879929-1-jhs@mojatatu.com

Reviewed-by: Simon Horman <horms@kernel.org>


  reply	other threads:[~2026-08-20 18:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  9:59 [PATCH net v2] net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue Jamal Hadi Salim
2026-08-20 18:27 ` Simon Horman [this message]
2026-08-20 20:40 ` patchwork-bot+netdevbpf

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=20260820182739.GC265046@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=david.ward@ll.mit.edu \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=vega@nebusec.ai \
    --cc=victor@mojatatu.com \
    --cc=zhanxusheng1024@gmail.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