mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: shaos <shawnq1@163.com>
To: jhs@mojatatu.com, jiri@resnulli.us
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH net] net/sched: enforce the FQ-PIE memory limit
Date: Thu, 26 Nov 2026 12:29:02 +0000	[thread overview]
Message-ID: <20261126122902.1504968-1-shawnq1@163.com> (raw)

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


             reply	other threads:[~2026-11-26 12:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 12:29 shaos [this message]
2026-11-26 12:32 ` netdev-bot+sinfo

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=20261126122902.1504968-1-shawnq1@163.com \
    --to=shawnq1@163.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /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®