* [PATCH net] net/sched: enforce the FQ-PIE memory limit
@ 2026-11-26 12:29 shaos
2026-11-26 12:32 ` netdev-bot+sinfo
2026-11-27 13:14 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: shaos @ 2026-11-26 12:29 UTC (permalink / raw)
To: jhs, jiri
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, netdev, linux-kernel, stable
Hello,
fq_pie_qdisc_enqueue() detects when the incoming skb would
exceed memory_limit, but the memory_limited branch only increments
overmemory. It then continues through PIE admission and can enqueue
the packet. The current check also adds skb->truesize to
memory_limit, which can overflow.
With a 4 KiB memory_limit, the reproducer keeps 49 packets queued,
accounts 110592 bytes in memory_usage, and reports overmemory while
dropping no packets. A 32 MiB limit control accepts the same traffic.
Drop an skb when its truesize exceeds the remaining budget, using
subtraction-based bounds checks to avoid overflow.
The test configures the qdisc and TBF parent as root in a disposable
QEMU guest (CAP_NET_ADMIN). Ordinary UDP traffic then exercises the
enqueue path. This violates the qdisc's documented memory_limit
contract; the test does not demonstrate privilege escalation.
HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: Linux 7.4.0-rc4-g8d7fe9885c62
compiler: gcc 11.4.0, GNU ld 2.38
The Gist contains the complete console output, kernel configuration,
sender source, and initramfs/QEMU helpers:
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/console-output.txt
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/kernel-config.txt
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/send_burst.c
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/guest-init.sh
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/build-initramfs.sh
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/run-qemu-test.sh
https://gist.githubusercontent.com/shaos26/903cfb53571c9271fefaadffde3469e5/raw/a417f18ab4665e1740dc06e06ebaf1c4a07613b8/verify-log.sh
Build the kernel from the HEAD commit above with kernel-config.txt.
The initramfs script requires BusyBox, iproute2, static gcc, cpio,
gzip, and QEMU. Run the same small-limit and large-limit cases:
./build-initramfs.sh
KERNEL=linux/build/arch/x86/boot/bzImage \
INITRAMFS="$PWD/initramfs-fqpie-rebuilt.cpio.gz" \
LOG="$PWD/fqpie-small.log" \
./run-qemu-test.sh positive 1
KERNEL=linux/build/arch/x86/boot/bzImage \
INITRAMFS="$PWD/initramfs-fqpie-rebuilt.cpio.gz" \
LOG="$PWD/fqpie-control.log" \
./run-qemu-test.sh control 1
The unpatched small-limit run accepts the packet burst and exceeds
the configured memory budget. The patched run drops packets once the
budget is reached and keeps memory_used at 2304 bytes, below 4096.
The large-limit control continues to accept the same traffic.
Fixes: ec97ecf1ebe4 ("net: sched: add Flow Queue PIE packet scheduler")
Cc: stable@vger.kernel.org
Signed-off-by: shaos <shawnq1@163.com>
---
net/sched/sch_fq_pie.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/sched/sch_fq_pie.c b/net/sched/sch_fq_pie.c
index 5982847df8f85..2e14467ae6585 100644
--- a/net/sched/sch_fq_pie.c
+++ b/net/sched/sch_fq_pie.c
@@ -134,7 +134,7 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
struct fq_pie_sched_data *q = qdisc_priv(sch);
struct fq_pie_flow *sel_flow;
int ret;
- u8 memory_limited = false;
+ bool memory_limited;
u8 enqueue = false;
u32 pkt_len;
u32 idx;
@@ -152,7 +152,8 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
sel_flow = &q->flows[idx];
/* Checks whether adding a new packet would exceed memory limit */
get_pie_cb(skb)->mem_usage = skb->truesize;
- memory_limited = q->memory_usage > q->memory_limit + skb->truesize;
+ memory_limited = skb->truesize > q->memory_limit ||
+ q->memory_usage > q->memory_limit - skb->truesize;
/* Checks if the qdisc is full */
if (unlikely(qdisc_qlen(sch) >= sch->limit)) {
@@ -160,6 +161,7 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
goto out;
} else if (unlikely(memory_limited)) {
q->overmemory++;
+ goto out;
}
reason = QDISC_DROP_CONGESTED;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] net/sched: enforce the FQ-PIE memory limit
2026-11-26 12:29 [PATCH net] net/sched: enforce the FQ-PIE memory limit shaos
@ 2026-11-26 12:32 ` netdev-bot+sinfo
2026-11-27 13:14 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-26 12:32 UTC (permalink / raw)
To: shaos
Cc: jhs, jiri, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, netdev, linux-kernel, stable
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net/sched: enforce the FQ-PIE memory limit
2026-11-26 12:29 [PATCH net] net/sched: enforce the FQ-PIE memory limit shaos
2026-11-26 12:32 ` netdev-bot+sinfo
@ 2026-11-27 13:14 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 13:14 UTC (permalink / raw)
To: shawnq1
Cc: jhs, jiri, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, stable
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] fq_pie_reset() (net/sched/sch_fq_pie.c:539-556) frees every
queued skb with rtnl_kfree_skbs() but never clears q->memory_usage.
- [Medium] Before this patch, fq_pie never dropped packets because of
memory_limit (since ec97ecf1ebe4).
- [Low] fq_pie now enforces memory_limit at enqueue, but fq_pie_change()
still trims the queue only with `while (sch->q.qlen > sch->limit)`…
- [Low] The commit message is written as an email or bug report, not a
changelog.
--
net/sched: enforce the FQ-PIE memory limit
This patch makes fq_pie_qdisc_enqueue() drop an skb when its truesize
exceeds the remaining memory_limit budget. Previously the memory_limited
branch only incremented the overmemory counter. The patch also rewrites
the check with subtraction so that memory_limit + truesize cannot
overflow.
> Hello,
>
> [ ... ]
>
> HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
> git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
> source version: Linux 7.4.0-rc4-g8d7fe9885c62
> compiler: gcc 11.4.0, GNU ld 2.38
>
> The Gist contains the complete console output, kernel configuration,
> sender source, and initramfs/QEMU helpers:
[ ... ]
[Severity: Low]
This isn't a bug, but several parts of the commit message would end up
in git history permanently:
- the greeting
- the build metadata
- the seven gist URLs
- the QEMU/initramfs reproduction steps
Could these move below the --- line or into a cover letter?
> diff --git a/net/sched/sch_fq_pie.c b/net/sched/sch_fq_pie.c
> index 5982847df8f85..2e14467ae6585 100644
> --- a/net/sched/sch_fq_pie.c
> +++ b/net/sched/sch_fq_pie.c
[ ... ]
> @@ -152,7 +152,8 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
> sel_flow = &q->flows[idx];
> /* Checks whether adding a new packet would exceed memory limit */
> get_pie_cb(skb)->mem_usage = skb->truesize;
> - memory_limited = q->memory_usage > q->memory_limit + skb->truesize;
> + memory_limited = skb->truesize > q->memory_limit ||
> + q->memory_usage > q->memory_limit - skb->truesize;
[Severity: Medium]
This still charges the full skb->truesize for every skb, including skbs
owned by local sockets. With the new goto out, that accounting now causes
drops under the unchanged default from fq_pie_init():
q->memory_limit = SZ_32M;
fq_codel has the same 32 MiB default. Commit 150061a20651 ("net/sched:
fq_codel: local packets no longer count against memory limit") found that
default was not reasonable in practice. fq_codel_enqueue() now does:
get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
Consider a busy host with fq_pie as root and many local TCP/GSO bulk
flows. Once usage passes 32 MiB, could this tail-drop whatever packet
arrives next, including packets from thin flows? Those hosts previously
only saw overmemory increase. fq_codel drops from the fattest flow
instead.
Since this is tagged Cc: stable, should the commit message mention this
change in behaviour? And should fq_pie follow the fq_codel accounting?
>
> /* Checks if the qdisc is full */
> if (unlikely(qdisc_qlen(sch) >= sch->limit)) {
> @@ -160,6 +161,7 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
> goto out;
> } else if (unlikely(memory_limited)) {
> q->overmemory++;
> + goto out;
> }
[Severity: High]
Can fq_pie end up dropping every packet after a reset? fq_pie_reset()
frees all queued skbs but leaves q->memory_usage unchanged:
net/sched/sch_fq_pie.c:fq_pie_reset() {
...
for (idx = 0; idx < q->flows_cnt; idx++) {
struct fq_pie_flow *flow = q->flows + idx;
/* Removes all packets from flow */
rtnl_kfree_skbs(flow->head, flow->tail);
flow->head = NULL;
...
}
The generic qdisc_reset() only zeroes q.qlen and qstats.backlog. The only
place that lowers memory_usage is fq_pie_qdisc_dequeue():
q->memory_usage -= get_pie_cb(skb)->mem_usage;
Before this patch, a stale memory_usage only made the overmemory and
memory_usage stats wrong. Now suppose the queue is close to memory_limit
when a reset happens. The leftover memory_usage sends every later enqueue
down this goto out path. Nothing gets enqueued, so nothing is dequeued,
and memory_usage never comes back down. The interface keeps dropping
traffic until the qdisc is replaced or memory_limit is raised.
qdisc_reset() is reached in three ways:
- dev_deactivate() via dev_reset_queue(), on link down or carrier loss
- a parent reset such as tbf_reset()->qdisc_reset(q->qdisc)
- graft
The sibling qdiscs clear their counter on reset. fq_codel_reset() does:
q->memory_usage = 0;
and dualpi2_reset() does WRITE_ONCE(q->memory_used, 0).
Should fq_pie_reset() also clear q->memory_usage now that enqueue depends
on it being accurate?
[Severity: Low]
Now that enqueue enforces memory_limit, should fq_pie_change() also trim
the queue when memory_limit is lowered? It updates q->memory_limit from
TCA_FQ_PIE_MEMORY_LIMIT, but the trim loop only checks qlen:
net/sched/sch_fq_pie.c:fq_pie_change() {
...
/* Drop excess packets if new limit is lower */
while (sch->q.qlen > sch->limit) {
...
}
fq_codel_change() also trims on memory:
while (sch->q.qlen > sch->limit ||
q->memory_usage > q->memory_limit) {
dualpi2_change() does the same with q->memory_used.
If tc qdisc change sets memory_limit below the current memory_usage,
fq_pie keeps the excess until the queue drains on its own. That can take
a long time if dequeue is stalled, for example behind a slow TBF parent
or a stopped txq.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126122902.1504968-1-shawnq1%40163.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 13:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 12:29 [PATCH net] net/sched: enforce the FQ-PIE memory limit shaos
2026-11-26 12:32 ` netdev-bot+sinfo
2026-11-27 13:14 ` netdev-bot+sashiko
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®