Netdev List
 help / color / mirror / Atom feed
From: Binbin Deng <18983559317@163.com>
To: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Binbin Deng <18983559317@163.com>
Subject: [PATCH net v1] net: sched: fully initialize tcf_chain before publishing it with RCU
Date: Mon, 30 Nov 2026 16:47:51 +0800	[thread overview]
Message-ID: <20261130084751.151177-1-18983559317@163.com> (raw)

tcf_chain_create() publishes a newly allocated struct tcf_chain with
list_add_tail_rcu() before initializing chain->block, chain->index and
chain->refcnt; mutex_init(&chain->filter_chain_lock) also happens after
the publication.

tcf_chain_lookup_rcu() walks block->chain_list without any lock and
reads chain->index for every packet that is classified with a tc chain
redirect (TC_SKB_EXT) attached. A concurrent lookup can therefore
observe a half-initialized chain, e.g. match chain index 0 against a
chain whose index has not been stored yet, or fail to match a chain
that is being created; traffic falling into the window is transiently
dropped or steered into the wrong chain.

Fix by initializing all fields before the RCU publication, so a chain
is only ever visible to readers fully initialized.

Signed-off-by: Binbin Deng <18983559317@163.com>
---
 net/sched/cls_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index c47d2ee13641..a3302dffd3c4 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -520,13 +520,13 @@ static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
 	chain = kzalloc_obj(*chain);
 	if (!chain)
 		return NULL;
-	list_add_tail_rcu(&chain->list, &block->chain_list);
 	mutex_init(&chain->filter_chain_lock);
 	chain->block = block;
 	chain->index = chain_index;
 	chain->refcnt = 1;
 	if (!chain->index)
 		block->chain0.chain = chain;
+	list_add_tail_rcu(&chain->list, &block->chain_list);
 	return chain;
 }
 
-- 
2.43.0


             reply	other threads:[~2026-11-30  8:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  8:47 Binbin Deng [this message]
2026-11-30  8:53 ` [PATCH net v1] net: sched: fully initialize tcf_chain before publishing it with RCU netdev-bot+sinfo

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=20261130084751.151177-1-18983559317@163.com \
    --to=18983559317@163.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --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