Article View: linux.kernel.netdev
Article #12025[PATCH net-next v2] net/sched: cls_fw: allow filter replace without re-specifying mask
From: Wei Tao
Date: Fri, 06 Nov 2026 06:31
Date: Fri, 06 Nov 2026 06:31
108 lines
12517 bytes
12517 bytes
The fw classifier keeps the fwmark mask in the fw_head shared by all
filters of a tcf_proto instance, so the mask is a property of the head
and not of the individual filter: it is set when the head is created
and cannot be changed by a filter that is being replaced. Nevertheless
fw_set_parms() rejects such a replace with -EINVAL whenever the head
mask is not the default 0xFFFFFFFF and the mask is not repeated on the
command line:
# tc qdisc add dev lo clsact
# tc filter add dev lo ingress prio 1 handle 1/0xffff fw classid 1:10
# tc filter replace dev lo ingress prio 1 handle 1 fw classid 1:20
RTNETLINK answers: Invalid argument
The same happens for tc filter change, which calls fw_set_parms() on the
existing filter as well.
The check only makes sense for a newly created filter, where the mask
has to be spelled out so that a filter cannot silently match on a
non-default mask inherited from the existing head. A filter that is
being replaced already shares the head mask and inherits it unchanged,
so the check can be skipped for it.
Tell the two cases apart with a new "new_filter" argument to
fw_set_parms(), which fw_change() sets only when it creates a filter,
and report the error through extack instead of failing silently.
When reviewing commit b72e025ac556 ("net/sched: cls_route: reject
change with no routing attribute") and its parent commit 41e85e54e564
("net/sched: cls_route: Fix in-place replace"), I noticed that the
series separates the create and replace paths in cls_route: a new
filter must use a handle that matches the value built from its
attributes, while a replace is not allowed to change the handle without
specifying routing attributes. Then I analyzed the cls_fw code with
an LLM.
Tested on aarch64:
# tc qdisc add dev lo clsact
# tc filter add dev lo ingress prio 1 handle 1/0xffff fw classid 1:10
# tc filter replace dev lo ingress prio 1 handle 1 fw classid 1:20
# tc filter show dev lo ingress | cut -d' ' -f9-
handle 0x1/0xffff classid 1:20
# tc filter change dev lo ingress prio 1 handle 1 fw classid 1:30
# tc filter show dev lo ingress | cut -d' ' -f9-
handle 0x1/0xffff classid 1:30
# tc filter add dev lo ingress prio 1 handle 2 fw classid 1:40
Error: Mask must be provided for new filter.
Signed-off-by: Wei Tao <taowei@kylinos.cn>
---
v2: https://lore.kernel.org/netdev/20261014024548.37874-1-taowei@kylinos.cn/
- drop the Fixes tag: this is not a regression fix
- describe how the issue was found and add the tested commands
net/sched/cls_fw.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 0f731595f839..3ca0598560c4 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -204,7 +204,8 @@ static const struct nla_policy fw_policy[TCA_FW_MAX + 1] = {
static int fw_set_parms(struct net *net, struct tcf_proto *tp,
struct fw_filter *f, struct nlattr **tb,
- struct nlattr **tca, unsigned long base, u32 flags,
+ struct nlattr **tca, unsigned long base,
+ bool new_filter, u32 flags,
struct netlink_ext_ack *extack)
{
struct fw_head *head = rtnl_dereference(tp->root);
@@ -229,8 +230,10 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
mask = nla_get_u32(tb[TCA_FW_MASK]);
if (mask != head->mask)
return err;
- } else if (head->mask != 0xFFFFFFFF)
+ } else if (head->mask != 0xFFFFFFFF && new_filter) {
+ NL_SET_ERR_MSG(extack, "Mask must be provided for new filter");
return err;
+ }
if (tb[TCA_FW_CLASSID]) {
f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
@@ -291,7 +294,8 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
return err;
}
- err = fw_set_parms(net, tp, fnew, tb, tca, base, flags, extack);
+ err = fw_set_parms(net, tp, fnew, tb, tca, base, false,
+ flags, extack);
if (err < 0) {
tcf_exts_destroy(&fnew->exts);
kfree(fnew);
@@ -340,7 +344,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
f->id = handle;
f->tp = tp;
- err = fw_set_parms(net, tp, f, tb, tca, base, flags, extack);
+ err = fw_set_parms(net, tp, f, tb, tca, base, true, flags, extack);
if (err < 0)
goto errout;
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.25.1
Technical Details
Message-ID:
<20261106063133.98515-1-taowei@kylinos.cn>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357782-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-357782-linux-kernel-netdev=dewy.ru From: taowei@kylinos.cn (Wei Tao) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v2] net/sched: cls_fw: allow filter replace without re-specifying mask Date: Fri, 6 Nov 2026 14:31:33 +0800 Organization: Usenet Network Sender: cs_taowei@163.com Message-ID: <20261106063133.98515-1-taowei@kylinos.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3810576"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:OArUcIxPKIbhMsw8vLwElOeFjHA= sha256:6D+6Az9VkUoRfqkxiIpEDIaejZShlqPYdYUROVYkWHg= sha1:zRGXIsPNKtSUccb6Iq5vzmZDUOs= sha256:46c515W6ypdHirWot+8iIPQNmjiCy6PXLOaG0zuYldg= 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 2C7C411317D; Fri, 6 Nov 2026 09:36:55 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.95 X-Spam-Status: No, score=-2.95 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, 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 WXEihA7DCYzc; Fri, 6 Nov 2026 09:36:45 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-357782-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=kylinos.cn X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 1DF88113175; Fri, 6 Nov 2026 09:36:36 +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 048492D9BD; Fri, 6 Nov 2026 06:32:51 +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=1793946770; b=4iV+f+DCmZFxFswdYZ3hJaFM19fNJcbEt4INxvd3qxTemqFcFKy/1wS01inIXPxZesUd wlrKfleZHrCB1kHvlWNm0GUbUb4uQtni+mukc6hbWFS+WXaKv3zJyATAE0bTP68LlMcfP Uh4PZxRaU6Hr3uMq00CgaU/JUifKA2jUSaRVxRpK0lRaZe9JF1VDD4zSnWhDLANXe63cO 3sImR2Sgcewyvj5buwPvQkem6RnBvRZnctv5zkrm0LdFPlmIVPTNlBVLQulwzO0DJSaRi E6lRa7QAuBvQUpuT6Al07pC8QeLDWOHk/tJmDPKjaz249jYT+Z2VtfxS10JomFAgI4g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793946770; 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:Sender:X-CM-SenderInfo; bh=1Tsmwk+I5UWTMEeAt29TWBBpjf3klwLmGA8oOUh0Rws=; b=Nav5Osp0IeJRfbC5l3gt4+nUgcGpOiJLv1ccQRTMzy5Bb8mDuXbxMCFAAs/cVJILWJ+8 ky41XlUknGDG2Y6lBYFoPEO9O2Lqf4Juu12EC1qSmtVRRZIHJFsiDHagQZLlYbqiiaave 6bTmy3vqqfRU3Q+LPuyt7qkH4C2cLg3UkPKlhAkffZ2UxjudsIaVB9OGKfLRHS272hFbf qWiu5LixVwlUKwaSjtOooB9Y6ZN8I3+H2Zhv4S2qqnxJYybNJtuxkwMtnPdbmJuPDxm7G 138RNvpOxjeAnVMi2CdeoWxL/h8HN5G9A6jkoxMUzGUiYYlsNQ8sO3hQKlzdH8braqg== 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=KBRaFesM; dmarc=none header.from=kylinos.cn; 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 C0F33606A337; Fri, 6 Nov 2026 06:32:50 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=KBRaFesM X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793946764; b=oyJhPTD03SKBLLd6WYUdiTOh0530C20ixibb9PN2MN0wfmtuVskfHFIOWRFTiMNbRTXI GKQQEskBPhgztbx+olAbD7dkhVPFU44hVk92p/A4xTqtA6aD98pt9rFr0A7nagp6/khOr KsmGZ2ZRi8rFIz3zuk5hj3UdYntLEKBYfs3SuP85WIjIpq/NUqVV418StiaWO1NopkDcf +iXcSOZW7o/kb1TviCIFK8tRJf036AW8vkBReKMeXZvsTC/YwIKaFlGFusxUvskvuUOpE 9KDG0kq3NLnAhoAUtAsdQnh/j8O5hsLidgeyeNXWuuKklcQ9qQmiCo+U75r1sbpqVKQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793946764; 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:Sender:X-CM-SenderInfo; bh=1Tsmwk+I5UWTMEeAt29TWBBpjf3klwLmGA8oOUh0Rws=; b=1Rs2tMDDsMOnmiKkw1dGevygjXX/wInNUIePtHMvoDccaIHcWEC4MRc36kO8xZcM3zyk bI/YUh++D6p4j0875LQoeyrOGJAqMq2pzkSobrxfTarF/yCtJZ5ia8flRFcwACzchZoRf YnTuZJvKeEAb2w90Z6tiHgpcuJ9lP7Bx+kOTyh6oJQmZ6aheXw2/OG9o9FnpRNAjC5uit EZ4ebGLTdTU/vdgcZSFFRUSoHrcTZn5fcJK/Tj24sEtnOi9Wt4RSbGetSzMnQ0dpYwIBD 5FPfe2mlf8KIp/h878BRM4jkJVGo/ecpJHAIqg4XZ7bWmtudZW3L5CmGDjhAFwGZ6pw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=kylinos.cn; 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=KBRaFesM; arc=none smtp.remote-ip=220.197.31.5 X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 0DC94606A329; Fri, 6 Nov 2026 06:32:42 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0DC94606A329 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn 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=1T smwk+I5UWTMEeAt29TWBBpjf3klwLmGA8oOUh0Rws=; b=KBRaFesMwOK3t5W0gg nuwxEECK+AuEaUt0MI0Aw0xfADG2NENZF32mwAOtpX87ewzjC9c6GKCkb6ymxuG/ rUnW++apbv6zWLLSnVOeoTaaPF1DHSXepzqglSNcVaQnEnme5GmZBjnj6TgfHJv+ k5rbPEUv5p//dN3+2IAHyDWeQ= X-Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-0 (Coremail) with SMTP id _____wBnj5lmdO1qFrM5FA--.46456S2; Fri, 06 Nov 2026 14:32:08 +0800 (CST) X-Cc: horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Tao <taowei@kylinos.cn> X-Mailer: git-send-email 2.25.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: _____wBnj5lmdO1qFrM5FA--.46456S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZF1kXF1xXry8Cw4DArWxtFb_yoWrAw1UpF s5K3WUGr4DtFyjgrZ7Jw1kt3Wa9rs7JFyxuF10kry5AFZagF4FqrWI93y7W3yUGrZ7C3W2 qF4Yq3yDGasrAFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jA-B_UUUUU= X-CM-SenderInfo: xfvb3tprzhxqqrwthudrp/xtbC4QhNjmrtdGhgTwAA3e