Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] net: sched: fully initialize tcf_chain before  publishing it with RCU
@ 2026-11-30  9:02 Binbin Deng
  2026-11-30  9:09 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Binbin Deng @ 2026-11-30  9:02 UTC (permalink / raw)
  To: jhs, jiri, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, Binbin Deng

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.

Fixes: 437192981932 ("net: sched: Change the block's chain list to an rcu list")
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30  9:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  9:02 [PATCH net v2] net: sched: fully initialize tcf_chain before publishing it with RCU Binbin Deng
2026-11-30  9:09 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox