From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.190.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075519; b=of37AOMg7Vl175DDsCWOMdUirlZ2vBRSkW+yhZfpyFsTTG2uYBWaXxuBUxnWsxQGF9St ZVoazeInQVSG1erFCQU1gcLolM0NG/46xMLAeU8eHxIT4XLAHw86aBxojC0hJJDKv7nJk 6nyN7LJP/yDKjMr4mnhTDPN4wdXioL6QferLEtUKUxCMPS3nToXcdFBrLjZbwvDR4hsSn mFTCnqK9M192SaVcxpTzO9ubBXRHXp+bu5s1TUFN8WBXWHu9zQ9QlTc7r8lUcczyJlvBF Xpfx9DFoPX2aX0lQ1beNKJ/tiyGfzEnlFdHGFEajKUxn13xpaX7+RUIF2y/qNLDICoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075519; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Spam-Status:X-Spam-Checker-Version; bh=tZfQIu9jznMqicexxLbxozvEsFtKTGoIZqpfz9Cw35w=; b=ykhzEhSdc1cB32PoI0fHFA+lqU8gLtEwfJA/sgcm7lBuML0U+qx0M5ILTI/JQrp0SSPQ 6sCE+/9dLxtM9eGFmBjeyDkqajrtqDxkBZpmMHicSz3rOsbCJu1ntplwIrUKFZugVeFnI MMn2pmH5p8DdX4lppvZt+QtWZ/eGjXTF4Z0q5p4wLGEVxoe+aFPX7UCFCapcJDaYENwi0 zTN5VxMFkAVTdaEOrRg3LYC0y/M7YVK/K0Ar/lPRuD9bUgTK/phkEQxtk/RfYfoBeoiWi Ng5Ply17uR7ut52hzwAKCiFnPcD2hiSOO1+fudh5gnnPfALXnxhbarQIdaQ0EDjbuRA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=netfilter.org; spf=pass smtp.mailfrom=netfilter.org; dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b="MV/5v0za"; arc=none smtp.remote-ip=217.70.190.124 Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CA5E606A69F; Mon, 30 Nov 2026 21:51:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1CA5E606A69F Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=MV/5v0za DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1796075516; bh=tZfQIu9jznMqicexxLbxozvEsFtKTGoIZqpfz9Cw35w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MV/5v0zaS9HMIgOMLF7vk+xg48nH9RSl3D5Bhjfwa5fzbKC5PcCflU2XgUitDcVlD aSfNA3qlDLRq0tjgNH8Ovg7bhwWVgKQHspY94X8WYCrXx6NCs+ubAlKONz9FjIDKTX HXvH4YolyyRDraLLmeVMBJWV6Rg4fsStoB1KTGiK6Tz+PJQ1eiCpkAYXuSFWbpoodG NicMGNRfSi7ILFG9CMpLDgyjhD7ao9BsgQsPOu7m4AIDPoNjX0b1qajW3ODIY828Yw iytr2sPeDu+X/kSV+u1hAhAQno57XjfkI79I7i1a6T0H1ZvK6exo1mC3APk9totidk aXD2VO4IQHryg== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id F34A26005E; Mon, 30 Nov 2026 22:51:55 +0100 (CET) From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg Subject: [PATCH net 07/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Date: Mon, 30 Nov 2026 22:51:38 +0100 Message-ID: <20261130215141.1009148-8-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130215141.1009148-1-pablo@netfilter.org> References: <20261130215141.1009148-1-pablo@netfilter.org> X-Mailing-List: netdev@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 From: Yiran Qiu ct_seq_show() takes a reference on a conntrack it found by a lockless walk of the hash table, but never checks that the conntrack is confirmed. nf_conntrack is SLAB_TYPESAFE_BY_RCU, so between ct_get_next() and refcount_inc_not_zero() the entry can be freed and its slot reused by init_conntrack() for a new, unconfirmed conntrack. The increment then succeeds and the dump prints a conntrack that is not in any table. nf_ct_key_equal(), gc_worker_skip_ct() and early_drop() reject unconfirmed entries for this reason. Since commit 2ad9d7747c10 ("netfilter: conntrack: free extension area immediately") this is also a use-after-free. An unconfirmed conntrack can still grow its extension area, for example when an nft ct helper object attaches a helper, and nf_ct_ext_add() then frees the old ct->ext through krealloc(). seq_print_acct() and ct_show_delta_time() read ct->ext without a lock, so the dump can read the freed buffer and print what it finds there as counters or a time delta. Skip entries that are not confirmed. Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix and this changelog were also drafted with LLM assistance. Reproduced on a KASAN build of mainline (v7.4-rc3+) that carried timing counters in ct_seq_show() (two ktime_get() per entry) but no added delay: an unprivileged user in its own user and network namespace churns UDP flows through an nft ct helper object while reading /proc/net/nf_conntrack, and KASAN reported a slab-use-after-free in ct_seq_show() after 9 and 41 minutes in two runs. The same build with this patch ran the reproducer for 60 minutes with no report. With only this patch applied to a KASAN build, the conntrack_resize.sh selftest, which compares /proc/net/nf_conntrack with ctnetlink dumps, passed in three runs. Fixes: ea781f197d6a ("netfilter: nf_conntrack: use SLAB_DESTROY_BY_RCU and get rid of call_rcu()") Cc: stable@vger.kernel.org Signed-off-by: Yiran Qiu Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_standalone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index d88a10230862..299691d7ac1e 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -314,6 +314,9 @@ static int ct_seq_show(struct seq_file *s, void *v) /* load ->status after refcount increase */ smp_acquire__after_ctrl_dep(); + if (!nf_ct_is_confirmed(ct)) + goto release; + if (nf_ct_should_gc(ct)) { struct ct_iter_state *st = s->private; -- 2.47.3