From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796455930; b=KqmW2GvRC19jXZnitnmfsKvi+/0ss/Yy2isrLWYwRd7Ci6IsEjwDGTbgBP209o8fh0nI 3cwjjR6GKXj28ivWQybENQe26YRol/uOfhyPI2GgNyqqqx8Ayh7Gb2trWa9RwLDNhzvPH qXw+o66YhGrYcKCSiwc3H3wW9Zq6F/nuI8XGJ6/QAMUymjXe5P/O4+3l1UldJG/gDGwFc g9sQ8CwI4sLvx9eg2Yt0Vv0B4bn3BuqUNoaf4S89hQJZxq+jVaE+ASw1oWBl0iCP8ThMr nFByYyHwbjgbR5ACzfud1uA8+nupe3t08Ntb9dcOi6/kp6Fa2uEjHjpSA7BX8a/ijQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796455930; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=/N8DECiTzc9SG5PVYyNoermqMU1V/taFVNdgxXdD5Xw=; b=rcRXmf4W1VjOzuV1C/GXz8rTN46tICol2m/fPuYBCNQIozm4eWfnXm+GMm5wZ7IUuIxI XF0g1O6Ywt1E22vWfKOxXpOFsWuW/Sto7OURjKNGRlTa+or39FYSBRbzlLOr9yfTBI4hQ KYNxxhT2a7fofJTKz/MseJ/Twn0KA+8ACFj6/gSteDbUHASk8lzOZg/9qTKKo+wiJRIgW nkOXRjUm4Co7uYp9JMQPuXRynOw/jELLgHf8FQ8ElzKixl0bwDQ6Vz++hNls5CC/GkXdk mL+4FvfKeIHkay3JQpPUrPdz2G3/+pnBaN7FxqqfDgQ34FQDuU5GD7IRyrWfSeIPguA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Amu7k0kW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 B6AB4606A322; Sat, 5 Dec 2026 07:32:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Amu7k0kW Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD6DF1F0092B; Sat, 5 Dec 2026 07:32:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796455930; bh=/N8DECiTzc9SG5PVYyNoermqMU1V/taFVNdgxXdD5Xw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Amu7k0kWI4NMMFUuHGJfLvu4PGs5k+MsVOTwNUdMVLkwPOwBO8Y+YVfZonIx18fJN eNNUhiGQm+yXiAgOmdF9BlxzPKyozSpO6plvnPjhyh9JZvaLsY74hHk0dg3Qz9tZpf 1Hm194UfJH6GhjLl7PGJDurBtIr2j3CSTYNZqLdOt+o3WiahPjuehskWHbEJzGhI0a Q3QUrVaBcC82GaANBeFU1z/mbfFYtsysMK7w+W3vfMMV//ym+WLGSZ+30UIYZrL7ZN KeijZbM4ul23856sO8WmSxRRIT/2tBXBdE4K+HS+LvRYEdG6SX0holVdbTlUlIyxKD eRACiYAnxanPg== Subject: Re: [PATCH v3] netfilter: nft_ct: reject shared conntrack extension updates From: netdev-bot+sashiko@kernel.org To: alex000young@gmail.com Cc: pablo@netfilter.org, fw@strlen.de, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Date: Sat, 05 Dec 2026 07:32:09 +0000 Message-ID: <179645592917.3146.13419841774383123592@kernel.org> In-Reply-To: <20261204071902.36828-1-alex000young@gmail.com> References: <20261204071902.36828-1-alex000young@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider. Critical: 0 · High: 2 · Medium: 3 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] nf_ct_is_unconfirmed_shared() treats any unconfirmed conntrack with refcount > 1 as 'shared', and the four new call sites then return… - [High] The commit message describes the bug class as concurrent clones calling nf_ct_ext_add() on the same unconfirmed ct, where krealloc()… - [Medium] The commit message says 'Cloned skbs can otherwise reach nft_ct extension paths concurrently' and adds a Fixes: tag, presenting… - [Medium] nf_ct_is_unconfirmed_shared() reads IPS_CONFIRMED_BIT again, even though every caller has just checked nf_ct_is_confirmed():… - [Medium] nf_ct_is_unconfirmed_shared() reads 'refcount_read(&ct->ct_general.use) > 1' on an unconfirmed ct as proof… - [Low] The new public helper nf_ct_is_unconfirmed_shared() in include/net/netfilter/nf_conntrack.h repeats the predicate already… -- netfilter: nft_ct: reject shared conntrack extension updates This commit adds nf_ct_is_unconfirmed_shared(). The helper treats an unconfirmed conntrack with a refcount above one as shared. It is called from nft_ct_set_eval(), nft_ct_timeout_obj_eval(), nft_ct_helper_obj_eval() and nft_ct_expect_obj_eval(), which drop the packet before nf_ct_ext_add() can krealloc() ct->ext. > Cloned skbs can otherwise reach nft_ct extension paths concurrently and > call nf_ct_ext_add() on the same ct->ext. [Severity: Medium] Is there a known path where this happens concurrently without a test harness? The attached report says: "The exact shared-skbs network path has not yet been shown without the test harness." The in-tree clone sites seem to process their clones one after another on the same CPU: ip_mr_forward() skb2 = skb_clone(skb, GFP_ATOMIC) ipmr_queue_fwd_xmit(net, mrt, true_vifi, skb2, psend) NF_HOOK(NF_INET_FORWARD, ...) deliver_clone() skb = skb_clone(skb, GFP_ATOMIC) __br_forward(fwd, skb, local_orig) The known asynchronous cases look like they are already handled: - nf_ct_drop_unconfirmed() in nfnetlink_queue drops shared unconfirmed conntracks. - nf_ct_bridge_in() and br_nf_local_in() detach or reset an unconfirmed ct before passing frames up. That covers the macvlan on top of a bridge case. This patch has a Fixes: tag and changes when packets get dropped. Could the commit message name the concurrent path, or say that the race has not been confirmed? > diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h > index c39425e54d87d..e6c47178af5bc 100644 > --- a/include/net/netfilter/nf_conntrack.h > +++ b/include/net/netfilter/nf_conntrack.h > @@ -271,6 +271,16 @@ static inline int nf_ct_is_confirmed(const struct nf_conn *ct) > return test_bit(IPS_CONFIRMED_BIT, &ct->status); > } > > +/* > + * Unconfirmed conntracks are mutable and assume exclusive skb ownership. > + * Cloned skbs can otherwise race on extension reallocation. > + */ > +static inline bool nf_ct_is_unconfirmed_shared(const struct nf_conn *ct) > +{ > + return !nf_ct_is_confirmed(ct) && [Severity: Medium] Every caller has already checked nf_ct_is_confirmed() before calling this helper. If clones really can run concurrently, can another CPU confirm the ct between the two reads? CPU0 CPU1 nft_ct_helper_obj_eval() nf_ct_is_confirmed(ct) -> false __nf_conntrack_confirm() __nf_conntrack_insert_prepare(ct) __nf_conntrack_hash_insert(...) set_bit(IPS_CONFIRMED_BIT, ...) nf_ct_is_unconfirmed_shared(ct) !nf_ct_is_confirmed(ct) -> false nf_ct_helper_ext_add(ct, GFP_ATOMIC) nf_ct_ext_add() WARN_ON(nf_ct_is_confirmed(ct)) krealloc(ct->ext, ...) In that window the helper returns false at the moment the ct is being shared. nf_ct_ext_add() only warns, then reallocates ct->ext on a ct that is now in the hash table. The same pattern exists in the expect, timeout and event mask callers. The callers have already seen the ct as unconfirmed. Would testing only the refcount here close this window? > + refcount_read(&ct->ct_general.use) > 1; [Severity: High] Can a refcount above one tell concurrent clones apart from clones that are handled one after another? ip_mr_forward() clones the skb for each output vif. It runs each clone through the forward and postrouting hooks synchronously, while the original skb still holds its _nfct reference: net/ipv4/ipmr.c:ip_mr_forward() { ... struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); if (skb2) ipmr_queue_fwd_xmit(net, mrt, true_vifi, skb2, psend); ... } Bridge flooding works the same way through deliver_clone() -> __br_forward() -> NF_BR_FORWARD, plus the inet forward hooks when br_netfilter is used. The comments in nf_ct_drop_unconfirmed() and __nf_conntrack_confirm() say these clones are expected. Before this patch, the first clone added the extension and was confirmed in NF_INET_POST_ROUTING. Later clones skipped the add because nf_ct_is_confirmed() returned true. With this patch, a ct helper set, ct timeout set, ct expectation set or ct event set rule in forward or postrouting sees refcount 2 and drops the first clone. A dropped clone never confirms the ct, so every later clone is dropped too. Only the original skb can pass, and only once the refcount is back to 1. In the local multicast branch above, and in bridge flooding with local_rcv, every forwarded copy is dropped. Local delivery then confirms the ct without the configured helper, timeout or event policy. For NFT_CT_EVENTMASK, the packet used to be accepted even when nf_ct_ecache_ext_add() failed. It is now dropped. Is this regression intended? The commit message does not mention it. [Severity: Medium] Can this also return true for a ct that only one skb owns? nf_conn objects are SLAB_TYPESAFE_BY_RCU. Hash walkers can briefly take a reference on an object that was just recycled into a new unconfirmed conntrack, as init_conntrack() notes: /* Other CPU might have obtained a pointer to this object before it was * released. Because refcount is 0, refcount_inc_not_zero() will fail. * * After refcount_set(1) it will succeed; ... Walkers that do this include nf_ct_gc_expired() (reached from ____nf_conntrack_find()), __nf_conntrack_find_get(), early_drop_list() and gc_worker(). While one of them holds its reference, a first packet that was never cloned reads refcount 2 here, and the four nft_ct callers drop it. early_drop_list() runs when the table is under pressure, which is also when new conntracks are being created quickly. Is a lifetime refcount a reliable test for exclusive ownership here? > +} [Severity: Low] This isn't a bug, but the same predicate is already open-coded in nf_ct_drop_unconfirmed() in net/netfilter/nfnetlink_queue.c: if (!ct || nf_ct_is_confirmed(ct)) return false; ... return refcount_read(&ct->ct_general.use) > 1; br_nf_local_in() tests the same condition as: refcount_read(&nfct->use) != 1 Neither of these is converted to the new helper. The tree now has three copies of the check with three different policies: - nfqueue drops the packet. - br_netfilter warns, resets the ct and accepts. - nft_ct drops the packet. Should the existing users switch to the new helper? Is there a reason nft_ct follows the nfqueue policy and not the br_netfilter one? > diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c > index 5a8db55920364..5dad764fb5763 100644 > --- a/net/netfilter/nft_ct.c > +++ b/net/netfilter/nft_ct.c > @@ -323,8 +323,13 @@ static void nft_ct_set_eval(const struct nft_expr *expr, > break; > } > > - if (ctmask && !nf_ct_is_confirmed(ct)) > + if (ctmask && !nf_ct_is_confirmed(ct)) { > + if (nf_ct_is_unconfirmed_shared(ct)) { > + regs->verdict.code = NF_DROP; > + break; > + } > nf_ct_ecache_ext_add(ct, ctmask, 0, GFP_ATOMIC); > + } > break; > } > #endif [Severity: High] If clones can run concurrently on different CPUs, as the commit message says, does guarding these four nft_ct call sites close the race? nf_ct_ext_add() has no lock and no sharing check. Other packet path writers still reallocate ct->ext on an unconfirmed ct: nft_masq / masquerade target nf_nat_masquerade_ipv4() nf_ct_nat_ext_add() nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC) nft_nat nf_nat_setup_info() /* Non-atomic: we own this at the moment. */ nfct_seqadj_ext_add() act_ct tcf_ct_act() __nf_ct_try_assign_helper() nft_ct also accesses ct->ext before the new check is reached. Just above this hunk, nft_ct_set_eval() does: struct nf_conntrack_ecache *e = nf_ct_ecache_find(ct); ... if (e) { if (e->ctmask != ctmask) e->ctmask = ctmask; break; } The same is true for nf_ct_timeout_find() in nft_ct_timeout_obj_eval(), nfct_help() in nft_ct_expect_obj_eval(), and the extension reads in nft_ct_get_eval(). Suppose clone A is masqueraded on CPU0 while clone B runs a ct event set rule on CPU1: CPU0 CPU1 nft_ct_set_eval() e = nf_ct_ecache_find(ct) nf_nat_masquerade_ipv4() nf_ct_nat_ext_add() krealloc(ct->ext, ...) e->ctmask = ctmask Would that write go into the freed ct->ext? Two concurrent masquerades would also hit the same krealloc() double free seen in the report. Would enforcing exclusivity in one place cover all of these? That could be nf_ct_ext_add() itself, or the point where clones are created or diverge, as nf_ct_bridge_in(), br_nf_local_in() and nf_ct_drop_unconfirmed() already do. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204071902.36828-1-alex000young%40gmail.com