Article View: linux.kernel.netdev
Article #13158[PATCH net] net/sched: release old template when replacing a chain
From: shaos
Date: Mon, 09 Nov 2026 12:14
Date: Mon, 09 Nov 2026 12:14
91 lines
12603 bytes
12603 bytes
Hello,
An action-held traffic-control chain can remain alive after
RTM_DELCHAIN because a goto-chain action still references it.
RTM_NEWCHAIN can reuse the chain. When a new template is supplied,
tc_chain_tmplt_add() creates a template and overwrites the existing
chain->tmplt_ops and chain->tmplt_priv without destroying the old
one.
The old struct fl_flow_tmplt allocation (1160 bytes) becomes
unreachable, along with its classifier module reference. Each repeated
chain recreation leaks one object from kmalloc-2k. The allocation uses
GFP_KERNEL without __GFP_ACCOUNT, and the tested objects remain after
the network namespace that created them is destroyed.
A local user with permission to create unprivileged user and network
namespaces can obtain CAP_NET_ADMIN inside the child network namespace
and trigger the leak without packet traffic or a race. The demonstrated
impact is unbounded host-global kernel memory consumption; no memory
corruption or privilege escalation is demonstrated.
Two fresh QEMU boots of the unpatched Linux 7.3 tree showed
kmalloc-2k active objects increasing from 60 to 192 after 128 cycles.
The no-action and held-chain/no-template controls remained at 60. A
UID 1000 user+network namespace run increased the count from 48 to 204;
the matching control increased it from 48 to 84.
With this patch, two fresh 128-cycle positive boots remained at 60,
and both controls remained at 60. The user-namespace positive and
control runs both showed the same 48-to-84 setup delta, with no
per-cycle increase. The positive PoC reports a failed leak threshold on
the patched kernel because it is written to expect the vulnerable
behavior; the zero delta is the expected fixed result.
The issue was found during an LLM-assisted source review and confirmed
with a userspace PoC in a disposable QEMU VM.
HEAD commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
Git tree: 30fd2ef82912c26cf3a58ad0ba6afc375fa851ac
Source version: Linux 7.3.0
Compiler: gcc 11.4.0, GNU ld 2.38
The console output, kernel config, reproducer, namespace launcher, and
patched-kernel validation logs are available here:
Console output:
https://gist.githubusercontent.com/shaos26/3e31c231ca56bc53ef80b5c8aada2821/raw/7ff5d84b07e0b260952d2f8575ffb1936edcb099/console-output.txt
Kernel config:
https://gist.githubusercontent.com/shaos26/3e31c231ca56bc53ef80b5c8aada2821/raw/aeed6e5360a23b7e36cc06272dc0069f8639c61f/kernel-config.txt
Reproducer:
https://gist.githubusercontent.com/shaos26/3e31c231ca56bc53ef80b5c8aada2821/raw/f73bf112b5d6bd7e6633963e3dee0c0083ffeef0/reproducer.sh
User namespace launcher:
https://gist.githubusercontent.com/shaos26/3e31c231ca56bc53ef80b5c8aada2821/raw/b30237aa0b52e39ebb9da06d790c3f8430b62903/userns_launcher.c
Patched validation:
https://gist.githubusercontent.com/shaos26/3e31c231ca56bc53ef80b5c8aada2821/raw/d769d8afbfa6293e3f7bff967a3408521972dcb5/patch-validation.txt
Run the reproducer as root, or with CAP_NET_ADMIN in a disposable
network namespace, on an unpatched kernel with BusyBox and iproute2:
./reproducer.sh positive 128
./reproducer.sh control-no-action 128
./reproducer.sh control-held-no-template 128
The user-namespace test used userns_launcher.c inside the test
initramfs. It drops to UID 1000 before creating the user and network
namespaces, then runs the same positive trigger.
The patch creates a replacement template first, leaving the old one
intact if creation fails. After successful creation it destroys the
old template and drops its module reference before installing the new
pointer pair.
Fixes: 9f407f1768d3 ("net: sched: introduce chain templates")
Signed-off-by: shaos <shawnq1@163.com>
---
net/sched/cls_api.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index a9f54988561f2..56a706b3dbcab 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -3128,6 +3128,8 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,
module_put(ops->owner);
return PTR_ERR(tmplt_priv);
}
+ /* An action-held chain can retain a template after RTM_DELCHAIN. */
+ tc_chain_tmplt_del(chain->tmplt_ops, chain->tmplt_priv);
chain->tmplt_ops = ops;
chain->tmplt_priv = tmplt_priv;
return 0;
Technical Details
Message-ID:
<20261109121448.2589374-1-shawnq1@163.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-359263-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-359263-linux-kernel-netdev=dewy.ru From: shawnq1@163.com (shaos) Newsgroups: linux.kernel.netdev Subject: [PATCH net] net/sched: release old template when replacing a chain Date: Mon, 9 Nov 2026 12:14:48 +0000 Organization: Usenet Network Message-ID: <20261109121448.2589374-1-shawnq1@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="348948"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:4JUshLFaYgl8qwtd+Evlqbhuf4Q= sha256:xP6jBYqRlkwXfs/rd1qZ/63hzk1Tff9Bq+peljK/87Q= sha1:Zr13xwtNb1dp9Pu7NaRfrptCLRk= sha256:+8utDunatL2PQ/Sd+lXhl0dFkKIZzzY/lUTNbUVE6Y8= 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 280311137C4; Mon, 9 Nov 2026 15:18:02 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.048 X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, 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.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=163.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 dYtTeF4hD4Oe; Mon, 9 Nov 2026 15:17:58 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359263-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id EB5D811378E; Mon, 9 Nov 2026 15:17:49 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 54861C8831; Mon, 9 Nov 2026 12:15:54 +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=1794226554; b=K3T8o0BHtLYlEk6xwC62mmNFMCJLYr9x+ETTcKAyd+hrpmKoEAKcD9I+kEAViYPBf5I3 CEvU9/8LWmVVA/AZnUY82XqF/3hhnlvH7RLMMzzkPb75P5yttXiJ/4GVmrB7ho+oeG34I tSFG4wAKSmCvf8AXd+VYEV1BLDRZVOnhvHnJKf6lNC3ihjcV0cjy02MuC5xLDVbcNaIdT 9wG6fDfxB9IxCVs9e39ukJzYaQytDSCNHu/GmqrVpLZ/LOjMTLm8208/jaU+SU+l5xQqB XSQd6vROI7xjyVziaRUp97rc2pYFJcTAPKIcZQcJrs48EkBpcFUdAo9g9MQALG2WrsA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794226554; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature: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-Transfer-Encoding:X-CM-TRANSID: X-Coremail-Antispam:X-CM-SenderInfo; bh=8jvHBme6zPqyADTvxOn21MVTvYy0GCMqqQxDtMJ34xs=; b=oSGOKLMgcHxMJrwGgEjcpL+jIvJrPQsEwJoQosMHJ5TXtpUGjfMYKmbM9GxMdi2O7Lcz dJpmzsO3bnNByDsjEztMnCDpTNNAHQqsa8GmRys+Ez1oXc+qnKYZAPZSvCzak2raL4RTi kqh2rg+2MYVAxludG4qLZxRlDWK55hjuylR1MGkAMRUuwE4mrRhlvAibdhXeH0ezth1ng Vf/osJxhPQpfjL6zqQWvt4BZAQuTovpktTne4diC3Mgu+Z01U086ZfWcipX40BJV+qOzd 9bJ2IOoP+11EFA4bdnfnpCxZOLW8E2/UxQy0aJ1Hndtblx2Ia1U65+gBQ6h6o1w2qmA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ZlAyCLV6; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.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 25644606A331; Mon, 9 Nov 2026 12:15:54 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ZlAyCLV6 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.3 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794226541; b=bqb4GxiJKBMsWFdnWOP/y+IwEiXDhhnhFjbmDW1McqKipLjQv90z8DYlIdTUi0w63ruz 8pQvDVknFjShDOkPVB1luXlMp98FXUPwoXCApG5npB77BJqZ2EurBzrU1EfZ5XzuP6KF+ rk2m1XjOdr9UOWzHRXK1G0j90VsCEeAtW8z2z7dIg9jrdiidsjCkI5pej21fc926OcxDd Q8bAbZ9KLJhxq44LhLmioh0zsl1dmHB5kYUUkr/X8XazoxaNV41Ht4pSMN3wJP4ziDj5k hPtLDLgsuakKYU2lMaZvQOr4uDMQMy+swwwPoQzkqjwhd57+XeofWTLkG0QOjIrKzfA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794226541; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-CM-TRANSID:X-Coremail-Antispam:X-CM-SenderInfo; bh=8jvHBme6zPqyADTvxOn21MVTvYy0GCMqqQxDtMJ34xs=; b=HZK6VV5YAiznPJmw5M+Cb7uyavS1RU0c46AE6OxWlOByv0Hhq35FLnj3FIXbQgGcxflg dlf0mwnUwT58tzlgzxnUHUWlpxM0Yl7Dlp/93jBsbBKeVDUO5DxcfTrr+lWRVW4sw2EfR cYtpNG3Sv35lGSI2VG1CFKpFSJerf4HurhyRptQ2VtL6GBZACxkrn7QGLQCPjw7/yE971 3mEWYpQsYQwy3jN8cdY+eEEQ6SYtF06//BpR8ucrv5FLXBfSEyCZTCB139W7wWZ9MgqHA boMEIyXrb7X/pnYsMTx2sdMX5x2MwhZcnmSwKoV/jincWwyZtQosEC4pf4L3wSKlwTw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=ZlAyCLV6; arc=none smtp.remote-ip=117.135.210.3 X-Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 976B3606A322; Mon, 9 Nov 2026 12:15:38 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 976B3606A322 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=8j vHBme6zPqyADTvxOn21MVTvYy0GCMqqQxDtMJ34xs=; b=ZlAyCLV6auT/Wi36Wz G3tHhsaxImlPQkGQFv+qnbdQb14mN8N3VlMkJmAl9ybGD+7BUyKnNVSTDiqShfvU pmFCGi8eMQBjNDIVSDlM302cxsSIe+PHMrJZgH/0UTuHLR8hqo4ir6cGj4V+dffu sZCDD3aE9cYLHv+gpoZlXa8IY= X-Received: from shaos.localdomain (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wDXn1A4ufFqsGfQGg--.48849S2; Mon, 09 Nov 2026 20:14:49 +0800 (CST) X-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 X-Mailer: git-send-email 2.34.1 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 X-CM-TRANSID: _____wDXn1A4ufFqsGfQGg--.48849S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw18Xr1rZryrWr1UGw4DArb_yoWrury5pr ZYkw1ftF4UtF1xtFs2yF18W3WSgws3Gw1UCFn5Ww1jyanIgrn2yrWxK3y3uFy8CFZ5GrZ0 qrW5Jan7Xr45CaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jrWrXUUUUU= X-CM-SenderInfo: pvkd40jtr6il2tof0z/xtbC0BqToWrxuTrlYQAA3k