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=1795910862; b=cgUACrLYhr5Mp57wpEE8bGp/3EyQ6drjvaYZJL0OWkWTV7eS+OCrhOndZj5u70/52Rs3 FyEq2ZXTQQ59Mi8JGPv1pRY9LvayvKLDFaOwhs95JihvqbK3fNOZ6Iy+v0Dhp/fXEtaAU 2ICsfueEgKTjQlxT7c9AHosgRJLcCK1iqvm55MqiWQAQ800GAd5IRmnrLwrGqnBZ/05rx wB7vh+Mg/LC7C5iZICzzAynujt6N774Ovsu+H1+gpjel2pfMwZFjeV9C75CbMpzBOE8d+ g4OqGY3thOfdKBQE19kDFZ5Q4mICcOHwob/aWa19a5JYZGqA/QrOD41dG1yffDAxPsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910862; 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=G2qIIs9fraEwruPSJSIESHprSU8R0eLNlSiEAelIluHMhcTtkYuegKHushWikYXn+fZ3 +Pk4izTADffY6LqLm1hwjcM4NR6hMTczkWVGqi6aRHLAI8I2iapLHFQPflW6SF5LvSMI0 MXD2YT10Rsh0EO8RepPyMn6OYMHEvzXnW8OUzNXalTsBq2Nq2t7MHpvwPrhNd8RpOq/YO EWOhp+r61OYtlqN6vUZM22nZdHyC79XzfWqLeqQf2RfjqOAFsw9gli8eT1p8RWHfyat+U Hqkh9FA/VuYZ5jOX+pltc3X24htJpVUPZz4DoEVnNvICfOvcy6sJ04pRUmFWPOJJ+WQ== 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=ddVFEQu9; 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 262A1606A683; Sun, 29 Nov 2026 00:07:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 262A1606A683 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=ddVFEQu9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1795910860; bh=tZfQIu9jznMqicexxLbxozvEsFtKTGoIZqpfz9Cw35w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ddVFEQu9lDU0mNrRPMAObCo9FEu0nsc9XxsxGQal+y/9WQ/pOX7zcKqyT1/ckuptk TW6pkqIYqTPPAo5sgc4R/Wfb1REJ5h3VXZgkQJKg6ROqOknRPhd5BiJ3lLh1XZNevH 0oS7XwZpsiHtgLqM9K+zOI/fl5DQGgtdDy23D3Q6ACjUtBMLv6IEZ59yVQMPMr8XiI DthV01rBD6e802R/Q8LyanWYrM0EYTgX9xSlF4U2mbclL/yCBmqmkPTr0DzT1NhVVp aNljs5C99OYcCky1bVURm+Hk5zi1pMwT6/FyuF7+iTZScx09iy4ocs17Zq/dnclYyk qlTMxIYNSGLhw== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id AA3DD60082; Sun, 29 Nov 2026 01:07:39 +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/14] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Date: Sun, 29 Nov 2026 01:07:17 +0100 Message-ID: <20261129000724.797425-8-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261129000724.797425-1-pablo@netfilter.org> References: <20261129000724.797425-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