Article View: linux.kernel.netdev
Article #6057[PATCH net] net/sched: gred: keep the qdisc lock while updating the table
From: Dudu Lu
Date: Wed, 21 Oct 2026 15:54
Date: Wed, 21 Oct 2026 15:54
95 lines
14099 bytes
14099 bytes
gred_change_table_def() publishes table->DPs/def/red_flags under
sch_tree_lock(), drops the lock, and then keeps writing state the
datapath reads without it:
- gred_enable_rio_mode()/gred_disable_rio_mode()/gred_disable_wred_mode()
set/clear table->flags;
- the red_flags_changed loop writes table->tab[i]->red_flags;
- the shadowed-VQ loop frees table->tab[i] and clears the slot.
gred_enqueue() and gred_dequeue() read those same fields (test_bit on
table->flags, q->red_flags, t->tab[]/t->DPs) under the same root lock on
another CPU, so the post-unlock writes race with the enqueue path:
BUG: KCSAN: data-race in gred_change_table_def [sch_gred] / gred_enqueue [sch_gred]
read (marked) to 0xffff000007ad3b00 of 8 bytes by task 110 on cpu 0:
gred_enqueue+0x88/0xc60 [sch_gred]
dev_qdisc_enqueue+0x4c/0x19c
__dev_queue_xmit+0x10a4/0x1ea4
The comment justifying the early unlock only covers the DP-vs-DPs check,
which the shadowed-VQ free loop relies on; it does not cover the scalar
mode bits and per-VQ red_flags written afterwards. Move the unlock below
those updates so everything the datapath reads is published under the
lock that protects it.
Fixes: 6639607ed9de ("[PKT_SCHED]: GRED: Use a central table definition change procedure")
Assisted-by: LLM
Signed-off-by: Dudu Lu <phx0fer@gmail.com>
---
Tested base
-----------
Detected on Linux 7.3-rc4 (commit 93f51579e7df), arm64 QEMU guest.
Re-checked against mainline f47d223627f8 (v7.3-341): the affected code
is unchanged between the two, so the bug is still present there.
Checked against linux-next next-20261021 (commit 9a482184d910): the
affected code is unchanged there as well, so the bug is still present in
linux-next too.
Reproducer status
-----------------
A reproducer was written and executed on an arm64 QEMU guest with
CONFIG_NET_SCH_GRED=m; KCSAN reported the race at the claimed sink. The
reproducer source is not posted here per Documentation/process/security-bugs.rst;
it is available on request.
Triggering conditions
---------------------
CAP_NET_ADMIN to reconfigure the qdisc; the race is stochastic (long clean
stretches between reports).
Notes
-----
Built and checkpatch-clean: this patch was applied on top of 7.3-rc4
(commit 93f51579e7df) and a full arm64 kernel (defconfig) was built with
it -- no new warnings or errors. scripts/checkpatch.pl reports 0 errors,
0 warnings.
net/sched/sch_gred.c | 18 ++++++++++--------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index f04f425c6c44..f3d9a7252949 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -442,13 +442,6 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
red_flags_changed = table->red_flags != sopt->flags;
table->red_flags = sopt->flags;
- /*
- * Every entry point to GRED is synchronized with the above code
- * and the DP is checked against DPs, i.e. shadowed VQs can no
- * longer be found so we can unlock right here.
- */
- sch_tree_unlock(sch);
-
if (sopt->grio) {
gred_enable_rio_mode(table);
gred_disable_wred_mode(table);
@@ -474,6 +467,15 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
}
}
+ /*
+ * Keep the lock until every field the datapath reads (the
+ * RIO/WRED mode bits, the per-VQ red_flags and the tab[] slots)
+ * has been updated: gred_enqueue()/gred_dequeue() read them under
+ * the same lock, so publishing them after the unlock races with
+ * the enqueue path.
+ */
+ sch_tree_unlock(sch);
+
gred_offload(sch, TC_GRED_REPLACE);
return 0;
}
Technical Details
Message-ID:
<20261021155434.66572-1-phx0fer@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350090-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350090-linux-kernel-netdev=dewy.ru
From: phx0fer@gmail.com (Dudu Lu)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] net/sched: gred: keep the qdisc lock while updating the table
Date: Wed, 21 Oct 2026 23:54:33 +0800
Organization: Usenet Network
Message-ID: <20261021155434.66572-1-phx0fer@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="4188864"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:MlePSH+w5eokr4+qblg5FfIYsyg= sha256:u/cUdgVaTFG3MzPQIHlqvr9PvoutrrtHANcqFx2kowI=
sha1:0XnJnPhiPfGoT3JvmtZAlTbXj9Y= sha256:bdIPrwxhiEfLsJrq29ZKS+v9AkWgqB8AlkGtd4HJSQU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 0033B11105E; Wed, 21 Oct 2026 18:56:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id N7mNfAsT5EaR;
Wed, 21 Oct 2026 18:56:52 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-350090-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 1C3BB110F5D; Wed, 21 Oct 2026 18:56:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 63629609BBB; Wed, 21 Oct 2026 15:54:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792598081;
b=eomP+m/y5FdKedZe2tY3Krpjk24dSWAHw+zk08ahyXqkCRg34sWYLpNBZX6wZEkWmz56
hoUBJiOmiM3uUHm0Xe6yt0Jl9BKkg343dDEe5l81q2v9PUrv1TUffoyZhPZ91OCLuFzwz
QZV28IJO4YdWovrrh/fg4Eh7qUFYTcJPw5uxMXGft/7F+9geA+iqMr/NQwoa1sa4JGZ42
swo+eA5vzUFqqEt3uc7LZMWm70n5BPdoOJ2gdO4c14Ika5gqmDqlkgDMhgTNQuJU2Eqm4
Ue5my4hIdhHKWram4iXEnIquSgws3tamizEM1bnRdHOWdw3un/9WKfPqhuazCLZw6HQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792598081;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=wjEig9clHR6aSVdxUT5EImtsz/5Z13pmefiOyn+eLYY=;
b=sVk7rEG7KCO+p5olypJ+HZ9UTJqlDWQVO0jbTwwXifblZ+vf/pnqepL5Rvy4xHu+eQWz
2mXEV2VqZB1kVwx19c39VTlaNyRm9J+Z1YhB6ouufV0uKlWigyFTz3FtokDj0yXttu+g0
l8zN71h0RbBaFQOTA8A2cEFj+DK74knvhoq06GTxJYfeatrSWis8vFVAQzQCOIP2qyyY3
RLjtICE77ExN8U37TxK9QgsClE/cHFQGZnH9XvUiN/aBquWUl8XYpEAOtcmHmHkPXfGHu
DD7BPHkmIc2BJCHZ3WHMLsDPnKt9ev3+zAQqnskEVO212BvdB6TCVHb2kabQOHgPZIg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=lTadkrYi;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 43792606A321;
Wed, 21 Oct 2026 15:54:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=lTadkrYi
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.181
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792598080;
b=Kuy6weddi6JHpL3y9P/srhYbgTNLl3Hy6DkaG1vl67tpN6uxbHT6jWWobLQpFoP6iJ/9
8hSJfjGSC7y0DLCFUH72eV1o6N72/EPeFBlke6yN9il2vhbzKyk95QXg6mBP6va9Msz4J
XigE/YYOoQi29nrvSom8cS1urek0lsdjCKejMHY+Gml/nfTvbF3/Lu83cbWuaU7JDwOvp
G1OXgX7llvMqj7HaKfW7owMhiNyd1Ql80CGdjO0efJLal7hwri7rIrfXe8r00uSjqAPuq
esozssm5sI/R52nWTUzf3UuKZ0YDf2HVCKXgBLCbBf85LpUjciAYoMWnwu1tpQ5GRfg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792598080;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-Id:X-Mailer:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=wjEig9clHR6aSVdxUT5EImtsz/5Z13pmefiOyn+eLYY=;
b=a1uBqaQZnLy7aDYltahC5O9WpBO1oPdKm/u0O+oWhzzjPkwada2DesA2hLgxrQpugKhm
eq0TqWzFoIq/UaMnQByAlFcbTordFk+DSEhRNGE4TiRibB8edovyISZHFLavdjm2foViM
exVYdB1Lu/uBRycQJuC/m5BxGDqclfvBfoZx95xLT5PH8b8Sb6OyS397sgShckRSdPTPB
k0m83vMOc39UlsfCvRU+t0UehQrkc5a39oZqXn/Toe7pDsPTWA1ryKWQmjBFDZQTZkzvi
LqVAhdfR6476u5EPZnDsOf3ee+ut7LIGJ/zspKYjjacT/zuC4VO5efNTjj5dC1Di4rQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=lTadkrYi;
arc=none smtp.remote-ip=209.85.214.181
X-Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A2A4606A319
for <netdev@vger.kernel.org>; Wed, 21 Oct 2026 15:54:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0A2A4606A319
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2e831e86ebfso5090175ad.1
for <netdev@vger.kernel.org>; Wed, 21 Oct 2026 08:54:39 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792598079; x=1793202879; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:message-id:date
:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=wjEig9clHR6aSVdxUT5EImtsz/5Z13pmefiOyn+eLYY=;
b=lTadkrYiMRc0uaYYxJ07adNpwg3iR+wHFyg/0ElZf1jAjjF/N02uvNuJi+2BUwcCGC
Ru2LK9ag9idsM17vk5uVPDIoi+gevI/kKY69Q6+9fgqeEdu0ef+PVHkW7t9adEmjYNgh
gKpiOpYJkVnPx1f4USj0Y2RcN/7OCkPoI61y6qPC9Fd2psqaLWq8Zf1G7IkyV9lwY+6p
Hb9z4xtSaHYRD9dR2N7SwEsveDZizKcZHb177NppRWwph6xW5MMoSL2nNQoBzyd7kVDR
R9VM0XDqJsMKLqh+ttFo1TFBRTy71Zjqik3FN31odyKrIP2Tog6RtOYxHBwqcPDdP6xC
WZ7A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792598079; x=1793202879;
h=content-transfer-encoding:content-type:mime-version:message-id:date
:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=wjEig9clHR6aSVdxUT5EImtsz/5Z13pmefiOyn+eLYY=;
b=sG06ulj6SgQnUhShasADZfx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0FMejCHVt2HWEKohZfi0lxaVv8B26bUXy8doBsH+CtyM4iQpWiYnA=
X-Received: by 2002:a17:902:da81:b0:2e4:4eed:5cc5 with SMTP id d9443c01a7336-2ea439da841mr21175995ad.38.1792598079292;
Wed, 21 Oct 2026 08:54:39 -0700 (PDT)
X-Received: from localhost.localdomain (69-172-67-073.static.imsbiz.com. [69.172.67.73])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ea3b41096bsm13893475ad.26.2026.10.21.08.54.37
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Wed, 21 Oct 2026 08:54:38 -0700 (PDT)
X-Cc: netdev@vger.kernel.org
X-Mailer: git-send-email 2.39.3 (Apple Git-145)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list