* [PATCH net v2] net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
@ 2026-08-18 9:59 Jamal Hadi Salim
2026-08-20 18:27 ` Simon Horman
2026-08-20 20:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jamal Hadi Salim @ 2026-08-18 9:59 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, jiri, davem, edumazet, kuba, pabeni, horms,
david.ward, vega, victor, zhanxusheng1024, stable
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
---
net/sched/sch_fifo.c | 2 +-
net/sched/sch_gred.c | 4 ++--
net/sched/sch_plug.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/sched/sch_fifo.c b/net/sched/sch_fifo.c
index e6bfd39ff339..1b6388d50967 100644
--- a/net/sched/sch_fifo.c
+++ b/net/sched/sch_fifo.c
@@ -19,7 +19,7 @@
static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch,
struct sk_buff **to_free)
{
- if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <=
+ if (likely((u64)sch->qstats.backlog + qdisc_pkt_len(skb) <=
READ_ONCE(sch->limit)))
return qdisc_enqueue_tail(skb, sch);
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index fcc1a4c03636..f04f425c6c44 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -179,7 +179,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,
* if no default DP has been configured. This
* allows for DP flows to be left untouched.
*/
- if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <=
+ if (likely((u64)sch->qstats.backlog + qdisc_pkt_len(skb) <=
sch->limit))
return qdisc_enqueue_tail(skb, sch);
else
@@ -244,7 +244,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,
break;
}
- if (gred_backlog(t, q, sch) + qdisc_pkt_len(skb) <= q->limit) {
+ if ((u64)gred_backlog(t, q, sch) + qdisc_pkt_len(skb) <= q->limit) {
q->backlog += qdisc_pkt_len(skb);
return qdisc_enqueue_tail(skb, sch);
}
diff --git a/net/sched/sch_plug.c b/net/sched/sch_plug.c
index cefb65201e17..b60ddfee6a68 100644
--- a/net/sched/sch_plug.c
+++ b/net/sched/sch_plug.c
@@ -89,7 +89,7 @@ static int plug_enqueue(struct sk_buff *skb, struct Qdisc *sch,
{
struct plug_sched_data *q = qdisc_priv(sch);
- if (likely(sch->qstats.backlog + skb->len <= q->limit)) {
+ if (likely((u64)sch->qstats.backlog + skb->len <= q->limit)) {
if (!q->unplug_indefinite)
q->pkts_current_epoch++;
return qdisc_enqueue_tail(skb, sch);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
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
2026-08-20 20:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2026-08-20 18:27 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, jiri, davem, edumazet, kuba, pabeni, david.ward, vega,
victor, zhanxusheng1024, stable
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
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
@ 2026-08-20 20:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-20 20:40 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, jiri, davem, edumazet, kuba, pabeni, horms, david.ward,
vega, victor, zhanxusheng1024, stable
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 18 Aug 2026 05:59:27 -0400 you 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)
>
> [...]
Here is the summary with links:
- [net,v2] net: sched: fix 32-bit backlog wrap in gred, bfifo and plug enqueue
https://git.kernel.org/netdev/net/c/4c660ee8c809
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-20 20:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-08-20 20:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox