From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.3 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796028525; b=H9kzAW3NMmADJm3xf1916Ovmma8yC91PuCa7BdlgV3os14HucwViDxTeClwM28BVLk5T oEH+CxLpQqsnzdZ5sBHTjWtn4tplRiym1SfAMcZBm+KWYWvWHOis7WKwEgnBV/AbVV14I zNCI+ehXsewMWMNx0twhZhmh+AaWkj6x3ZvOgNVBxOvdpQjwMJIJ8iviSI4qZltbDTybP i2q3fPAacC6KI+TwgLQIrZPkbT1+ZLVZZk5ksrLL/Sbmu061g0wn2XFH8vPUg6cKUbgcl AUa94xH3VSc2bfXQA76Lbjb21kNnWqc53brde3xWqcj8sZgAvTQ8mkXbUrW5C8pwM0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796028525; 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=PAGbqr8kfVB7TF6p6uQ+3fM7pGJ8vhXBy057mxNlOCE=; b=puevP410Pj4rIBnCV/byXyJlq4oqjgZM7q9T/MfJd7ARQNn+plpYaN6CZYfSUbRq7EYt HeDO+HfzpTub7CUxh/0bWPC+ArK2YWkRMDKujaol4ebotX3nURh+cZsCYJvUREXwQcycC HWYQ4lxfJnFU30FZUMo8y8F9fb04/2W6ePSAi16x1oEO09647kki9VpC/02vnTrVObQ6X ge3RnbH5Hh8Ns0pHFlRymKUatMp00eN63hPVmql1xKZYhLv1l5oplgeZgkEjCAmz91+Sa Y6kECa6CxpqhLKaVXa1TK5iR37+EnX0ZzB5DAJjFhSKuB2TzPDbJKSsq6Vq60nZNiJw== 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="D/xEYVyx"; arc=none smtp.remote-ip=220.197.31.3 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 155D3606A6A2; Mon, 30 Nov 2026 08:48:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 155D3606A6A2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com 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=D/xEYVyx 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=PA Gbqr8kfVB7TF6p6uQ+3fM7pGJ8vhXBy057mxNlOCE=; b=D/xEYVyxFMuIqq0I0y I6smoWzfSqEyOII1csclOP8fuQBr+udrAdiA5rfH+UsyjEG0nz55PVfgthY0Oe3J Cu5mwBV6j1rUbFRfAt3ILmQXamdXmR9fBbATZ3cbSup7mz2TAJzi3Cqb7jOmDU6I jhOikSttUns8W7W3Y/TmwHupk= Received: from colol4bi5.localdomain (unknown []) by gzga-smtp-mtada-g0-3 (Coremail) with SMTP id _____wAXBzk5OA1r1fjyLQ--.10604S2; Mon, 30 Nov 2026 16:47:54 +0800 (CST) 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 Message-ID: <20261130084751.151177-1-18983559317@163.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wAXBzk5OA1r1fjyLQ--.10604S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr17tr1kXFW5CF45WrW5trb_yoW8WrWUpr sxW348K34DWryxXrs5J3W7Gr1xKw4xW3WUZrZ8Ka1IyrnxWrsrK3Z8Ka129FyrGr42yrnF qFWfXry5Zrs8AF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pimsU_UUUUU= X-CM-SenderInfo: jprymmytvvmjmrxbiqqrwthudrp/xtbC4Bo6HmsNODq9WQAA3e 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