mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: shaos <shawnq1@163.com>
To: jhs@mojatatu.com
Cc: Jiri Pirko <jiri@resnulli.us>,
	"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
Subject: [PATCH net] net/sched: gred: reject table shrink with queued packets
Date: Mon,  9 Nov 2026 16:36:48 +0000	[thread overview]
Message-ID: <20261109163648.301164-1-shawnq1@163.com> (raw)
In-Reply-To: <20261022144811.66149-1-shawnq1@163.com>

GRED frees VQs above the configured DP count when its table is
shrunk. Queued skbs keep their DP number. If the table is later
expanded and that VQ is recreated, dequeue subtracts the old skb
length from the new VQ's zeroed u32 backlog.

Reject a shrink while a removed VQ has accounted backlog or an skb
in gso_skb still carries a removed DP. This keeps the per-VQ
accounting state alive until all packets using it are drained.

The issue was identified by LLM-assisted source analysis and
reproduced with a purpose-built AF_PACKET/tc test in QEMU. The test
requires CAP_NET_ADMIN and CAP_NET_RAW in its network namespace; it
does not modify the kernel or use error injection.

On Linux 7.4-rc2, the unpatched reproducer wrapped VQ5 backlog to
4294964296 bytes and dropped a probe. With this patch, shrinking
returns -EBUSY while VQ5 has queued packets. After the queue drains,
shrinking and re-expanding succeeds, and the probe is accepted.

The modified sch_gred.o builds with W=1 under allmodconfig and
allyesconfig. Full-tree W=1 builds stop on unrelated warnings in
lib/tests/stackinit_kunit.c, arch/x86/kernel/callthunks.c, and
net/8021q/vlan.c. The QEMU regression passes; tc-testing was not run.

Fixes: 6639607ed9de ("[PKT_SCHED]: GRED: Use a central table definition change procedure")
Link: https://lists.openwall.net/linux-kernel/2026/10/22/1545
Signed-off-by: shaos <shawnq1@163.com>
---
 net/sched/sch_gred.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index f3d9a7252949d..8ddbd7f058a6b 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -408,8 +408,9 @@ static inline void gred_destroy_vq(struct gred_sched_data *q)
 static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
 				 struct netlink_ext_ack *extack)
 {
-	struct gred_sched *table = qdisc_priv(sch);
 	struct tc_gred_sopt *sopt;
+	struct gred_sched *table = qdisc_priv(sch);
+	struct sk_buff *skb;
 	bool red_flags_changed;
 	int i;
 
@@ -437,6 +438,25 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
 	}
 
 	sch_tree_lock(sch);
+	skb_queue_walk(&sch->gso_skb, skb) {
+		if (tc_index_to_dp(skb) >= sopt->DPs) {
+			sch_tree_unlock(sch);
+			NL_SET_ERR_MSG_MOD(extack,
+					   "cannot remove a GRED VQ with queued packets");
+			return -EBUSY;
+		}
+	}
+
+	for (i = sopt->DPs; i < MAX_DPs; i++) {
+		struct gred_sched_data *q = table->tab[i];
+
+		if (q && q->backlog) {
+			sch_tree_unlock(sch);
+			NL_SET_ERR_MSG_MOD(extack,
+					   "cannot remove a GRED VQ with queued packets");
+			return -EBUSY;
+		}
+	}
 	table->DPs = sopt->DPs;
 	table->def = sopt->def_DP;
 	red_flags_changed = table->red_flags != sopt->flags;


  reply	other threads:[~2026-11-09 16:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 14:48 [BUG] net/sched: GRED VQ shrink can orphan queued packets and wrap backlog shaos
2026-11-09 16:36 ` shaos [this message]
2026-11-11 16:37   ` [PATCH net] net/sched: gred: reject table shrink with queued packets netdev-bot+sashiko

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=20261109163648.301164-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 \
    /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®