From: Junyoung Jang <graypanda.inzag@gmail.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>, Jiri Pirko <jiri@resnulli.us>
Cc: Junyoung Jang <graypanda.inzag@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Gwanhyun Lee <gwanhyunlee@gmail.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v2] net/sched: sch_choke: fix skb leak on packet ring wrap
Date: Sat, 5 Dec 2026 12:52:31 +0900 [thread overview]
Message-ID: <20261205035232.2243251-1-graypanda.inzag@gmail.com> (raw)
CHOKe represents an empty ring with q->head == q->tail. When
choke_drop_by_idx() removes a matched packet from an interior slot,
it clears q->tab[idx] and decrements sch->q.qlen without reducing
choke_len(q).
Repeated interior drops can bring choke_len(q) to q->tab_mask while
sch->q.qlen is still below q->limit. The next admitted packet moves
q->tail onto q->head while live skbs remain in q->tab.
choke_dequeue() and choke_reset() then treat the ring as empty,
stalling dequeue and leaking the queued skbs on reset or deletion.
If qlen remains below q->limit, later choke_enqueue() calls also
overwrite live q->tab pointers, leaking skbs during packet processing.
Size q->tab for at least 2 * limit + 1 slots and use choke_compress()
to pack live entries in FIFO order when choke_len(q) reaches
q->tab_mask before admission. The slack allows at least limit + 1
successful admissions between compactions, so the scan has O(1)
amortized cost per admission without premature queue-limit pdrops.
Keep the original skb retention bound in choke_change() when resizing
the ring.
An in-house LLM-based analysis tool developed by the authors
assisted in surfacing this bug candidate and drafting the initial notes.
Root-cause analysis, patch code, and reproducer results were manually
reviewed and independently verified by the authors.
Fixes: 45e144339ac5 ("sched: CHOKe flow scheduler")
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
v2:
- Size the ring for holes and compact it before wrap, following
Paolo Abeni's and Sashiko's feedback on premature pdrops.
- Preserve the existing skb retention limit during qdisc resize.
v1: https://lore.kernel.org/netdev/20261126141137.1261866-1-graypanda.inzag@gmail.com/
Tested on net/main in QEMU/KVM with KASAN and lockdep enabled:
- On the unpatched base, the first matched-drop/refill cycle left
4,095 packets queued. After further admission attempts, deleting
the qdisc freed none of them.
- After 15,000 matched-drop/refill cycles, qlen stayed at 4,095,
pdrop stayed at zero, and qdisc deletion freed all 4,095 skbs.
- After 80 such cycles in a smaller queue, all 64 packets
arrived in FIFO order; qlen and backlog drained to zero.
- Shrinking a live queue from limit 8 to 2 retained three packets,
which were freed on qdisc deletion.
net/sched/sch_choke.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c
index 73d3e673dc7b..1d1e2f63e3da 100644
--- a/net/sched/sch_choke.c
+++ b/net/sched/sch_choke.c
@@ -42,7 +42,7 @@
*/
-/* Upper bound on size of sk_buff table (packets) */
+/* Upper bound on configured queue length (packets) */
#define CHOKE_MAX_QUEUE (128*1024 - 1)
struct choke_sched_data {
@@ -77,6 +77,27 @@ static unsigned int choke_len(const struct choke_sched_data *q)
return (q->tail - q->head) & q->tab_mask;
}
+/* Remove holes from the ring without changing packet order. */
+static void choke_compress(struct choke_sched_data *q)
+{
+ unsigned int write = q->head;
+ unsigned int read = q->head;
+
+ while (read != q->tail) {
+ struct sk_buff *skb = q->tab[read];
+
+ if (skb) {
+ if (read != write) {
+ q->tab[write] = skb;
+ q->tab[read] = NULL;
+ }
+ write = (write + 1) & q->tab_mask;
+ }
+ read = (read + 1) & q->tab_mask;
+ }
+ q->tail = write;
+}
+
/* Is ECN parameter configured */
static int use_ecn(const struct choke_sched_data *q)
{
@@ -269,6 +290,8 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch,
/* Admit new packet */
if (sch->q.qlen < q->limit) {
+ if (choke_len(q) == q->tab_mask)
+ choke_compress(q);
q->tab[q->tail] = skb;
q->tail = (q->tail + 1) & q->tab_mask;
qdisc_qlen_inc(sch);
@@ -342,11 +365,12 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt,
struct choke_sched_data *q = qdisc_priv(sch);
struct nlattr *tb[TCA_CHOKE_MAX + 1];
const struct tc_red_qopt *ctl;
- int err;
struct sk_buff **old = NULL;
+ unsigned int resize_limit;
unsigned int mask;
u32 max_P;
u8 *stab;
+ int err;
if (opt == NULL)
return -EINVAL;
@@ -370,7 +394,9 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt,
if (ctl->limit > CHOKE_MAX_QUEUE)
return -EINVAL;
- mask = roundup_pow_of_two(ctl->limit + 1) - 1;
+ resize_limit = roundup_pow_of_two(ctl->limit + 1) - 1;
+ /* Leave room for holes before compressing the ring. */
+ mask = roundup_pow_of_two(2 * ctl->limit + 1) - 1;
if (mask != q->tab_mask) {
struct sk_buff **ntab;
@@ -390,7 +416,7 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt,
q->head = (q->head + 1) & q->tab_mask;
if (!skb)
continue;
- if (tail < mask) {
+ if (tail < resize_limit) {
ntab[tail++] = skb;
continue;
}
base-commit: 3c8881ee98069d3c8a1a0ad1fd6efd726e466297
--
2.43.0
reply other threads:[~2026-12-05 3:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261205035232.2243251-1-graypanda.inzag@gmail.com \
--to=graypanda.inzag@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=gwanhyunlee@gmail.com \
--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=willemb@google.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