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 <1898…@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