๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26810

Re: [PATCH net 2/2] macsec: drop the conntrack entry of delivered clones to fix a double free

#26810
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 07:21
147 lines
13432 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] macsec: Fixes trailer cites act_ct instead of macsec clone-path
  commits

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but the double
  free it fixes in macsec can still be triggered through macvlan'sโ€ฆ

--

macsec: drop the conntrack entry of delivered clones to fix a double free

This patch adds nf_reset_ct() to the skb clones that macsec delivers to
its upper devices, in handle_not_macsec() and in the unknown-SCI path of
macsec_handle_frame(). Without it, the clone and the original share one
unconfirmed conntrack entry. Concurrent nf_ct_ext_add() calls on that
entry can then double free ct->ext through krealloc().

> diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
> index 240ba0ae07d1e..a50266490f4a2 100644
> --- a/drivers/net/macsec.c
> +++ b/drivers/net/macsec.c
> @@ -1090,6 +1090,7 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
>  				if (!nskb)
>  					break;
>  
> +				nf_reset_ct(nskb);
>  				nskb->dev = ndev;
>  				eth_skb_pkt_type(nskb, ndev);
>  

[Severity: Low]
The Fixes: tag points at b57dc7c13ea9 ("net/sched: Introduce action
ct"), but that commit only added net/sched/act_ct.c and did not touch
drivers/net/macsec.c. Is it the right commit to blame here?

This hunk patches the offloaded multicast clone in handle_not_macsec(),
which did not exist at b57dc7c13ea9. It was added later by
f428011b90ec ("net: macsec: support multicast/broadcast when
offloading"). A stable tree that has act_ct but not f428011b90ec has
no such skb_clone() for this hunk to apply to. The stable tooling may
still try to pick the patch up there based on the tag.

The other two clones, the untagged delivery in handle_not_macsec() and
the unknown-SCI delivery in macsec_handle_frame(), go back to the
original driver, c09440f7dcb3 ("macsec: introduce IEEE 802.1AE
driver").

act_ct is also not the only way an unconfirmed nf_conn can reach these
clones. Consider macsec stacked on a bridge with bridge netfilter
enabled. br_nf_local_in() and nf_ct_bridge_in() leave the entry
unconfirmed on purpose for PACKET_HOST frames. Such a frame can arrive
at macsec_handle_frame() with an unconfirmed ct attached, and then be
cloned the same way. That points at the macsec clone paths themselves
as the origin of the bug, rather than act_ct.

Would it be more accurate to cite these instead?

Fixes: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")
Fixes: f428011b90ec ("net: macsec: support multicast/broadcast when offloading")

[Severity: Critical]
This isn't a bug introduced by this patch, but can the same double free
still be reached through the macvlan multicast and broadcast receive path?

This series fixes the macsec clones here. It also fixes the macvlan
source-mode clones in "macvlan: drop the conntrack entry of source-mode
clones to fix a double free". Neither commit changes the external branch
of macvlan_handle_frame():

drivers/net/macvlan.c:macvlan_handle_frame() {
    ...
		hash = mc_hash(NULL, eth->h_dest);
		if (test_bit(hash, port->bc_filter))
			macvlan_broadcast_enqueue(port, src, skb);
		else if (test_bit(hash, port->mc_filter))
			macvlan_multicast_rx(port, src, skb);

		return RX_HANDLER_PASS;
    ...
}

The original goes on up the lower device and keeps the unconfirmed ct
that tc act_ct attached at ingress.

macvlan_broadcast_enqueue() calls skb_clone(), so the clone shares the
same _nfct. The clone is queued to bc_work on the unbound system_dfl_wq,
so it can run on another CPU even without RPS. Broadcast is always set in
port->bc_filter, so no extra macvlan configuration is needed.

After that, macvlan_broadcast() clones once per vlan:

drivers/net/macvlan.c:macvlan_broadcast() {
    ...
		nskb = skb_clone(skb, GFP_ATOMIC);
		if (likely(nskb))
			err = macvlan_broadcast_one(nskb, vlan, eth,
					mode == MACVLAN_MODE_BRIDGE) ?:
			      netif_rx(nskb);
    ...
}

For externally received frames, mode is a combined mask such as
PRIVATE|VEPA|PASSTHRU|BRIDGE or VEPA|BRIDGE. That never equals
MACVLAN_MODE_BRIDGE, so local is false. This skips __dev_forward_skb(),
which is the only place that would clear the ct:

drivers/net/macvlan.c:macvlan_broadcast_one() {
    ...
	if (local)
		return __dev_forward_skb(dev, skb);

	skb->dev = dev;
    ...
}

As a result, each clone reaches netif_rx() on the macvlan device while
still holding the shared, unconfirmed ct.

Suppose an nftables "ct expectation" rule matches on both the lower
device and the macvlan device. The original and the clones would then
run this chain at the same time:

nft_ct_expect_obj_eval()
  nf_ct_helper_ext_add()
    nf_ct_ext_add()
      new = krealloc(ct->ext, alloc, gfp);

Would that free the old ct->ext twice, as in the KASAN report in the
commit message? With several macvlan devices, the clones could also race
with each other.

The only nf_reset_ct() in drivers/net/macvlan.c is in
macvlan_forward_source_one().

Should this path also get an nf_reset_ct(nskb) before netif_rx() in
macvlan_broadcast(), or in the non-local branch of
macvlan_broadcast_one()?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203063745.75353-1-juanagusnicco%40gmail.com
Technical Details
Message-ID: <179636888625.3146.13455568232369265321@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377152-linux-kernel-netdev=dewy.ru
References: <20261203063745.75353-3-juanagusnicco@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377152-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 2/2] macsec: drop the conntrack entry of delivered
 clones to fix a double free
Date: Fri, 04 Dec 2026 07:21:26 +0000
Organization: Usenet Network
Message-ID: <179636888625.3146.13455568232369265321@kernel.org>
References: <20261203063745.75353-3-juanagusnicco@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2702062"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/GLL6Mnfu7di2pQELUpcviNVp1o= sha256:oGDxq/it0fyFgPPDDX9p9Am6eKLiLnFiDesSGgOevQI=
	sha1:NhxI+T0ah6gGeiyUuULQvG4pRvs= sha256:6ea7e+q23iQZ2oui1SO41mSItgZaVfYW1nz1NxkVU1Y=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 44B16117B56; Fri,  4 Dec 2026 10:21:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 3iWeOIKyYhPY;
	Fri,  4 Dec 2026 10:21:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-377152-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 80DC3117B52; Fri,  4 Dec 2026 10:21:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 7D1646013C7; Fri,  4 Dec 2026 07:21:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796368888;
	b=rD9/QOV3O2jQBkBw41L5dN7faIQ/vucC+5YSy8kHVSK/8JHqr8am90u9WBViyMDW4W/P
	 s9uwG1eO1qq//18tv36yKH5tXrJHbs46SSb4Ndf/rqRfAzxQOIth+iFCXr3YAGfcjx9QR
	 aTq71Jh4jU8BKoxPhoXZ+LPkwFBSTWX/04sEBsndmrfm+5d+qHtOW5SKOc2frVNHOZEVh
	 4OlqcXoX7hUranbvkbqcgizNzZrugNgr++UH3I+4P3Xiq2qnuMWPjYQ0z+mYTN3iVm6QR
	 OJYDbc/RyXvJE3N34L2b+64T36Ch9Jz9f6KtjvlonmDCr94hkv1xsA5Okp/rZ0IJnbA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796368888;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=lWyjBQ+WCEhroJ6Kho2jtBzP5Y1g2KYY1AklLmG5K1c=;
	b=ZZVLAPBwEf4RaDh9sWjb03qcrwtR2XAWbR/CqHVN5jIvfV4gVKUXEnuP5qEDQMrJa6LU
	 RFb883TQzM1Vkkpx4qD0pp+x/CB1NA1X+futEEvKt3zFY4m0lWsDSb5lFm1CIcogQGIln
	 gsJjMszeTX6vHtxuJ5faioU3qiA9a3vy/5wcLpmsN5u68t/oQqPiHppF5OTadsBd4/mER
	 2ZRFLfANv7F4cv8g7BDm5jbpQG0weesYMBZaEJzQb/oOUA1clCU3bkraCy3jjgSX26hEO
	 dVY37UmDS+Ps80y8ssucZSpqLLojytGqUPo+ndPRLiNEL/EV5Y81Io+22i9eIDms4AA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QD3Hd6b3;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 99196606A32C;
	Fri,  4 Dec 2026 07:21:28 +0000 (UTC)
X-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=QD3Hd6b3
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796368887;
	b=Gs3p23vY4KVPGDBqj6u4dMMk/e6w6zXdQuVgAi2mVt3d2rVNJ7AXWwOyABuwd5GqpCrN
	 E5Ivm9guvl3lbbxVOwnt1krEFc1qIgCLHs+i10i+RCyUxuFXTVrOoARzehYTo+3C3Z/4/
	 0+2Vctn0vQDzZoz1aTX6NCBaeit+DpwND1qmcaIgG1Xag3c62yJ3LjGi7kVqscDc6+lHs
	 uDnancbf3tTTJcV380V+TfT2tfHUJ+jPHCuhTrOb+X3OJusWPMcVHSg6qCX/TYJ+A4NPe
	 VjHcIRqgiW3kcFekLxdNED4qIl1Pam4UNDC/AwmjOeBlJ5qZHC80P/jGshxoGlf6W5A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796368887;
	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=lWyjBQ+WCEhroJ6Kho2jtBzP5Y1g2KYY1AklLmG5K1c=;
	b=OaANtU3bUx8y8PtVqORnmJ1xDfarsS8k0Gf5KO7/j/Y87o1pk4lI70Iz6TOkcgUPGa+I
	 h4d0RJi+5cvSyC/rRlkYQPOL7YyYqwDq9TxEPjeTSxOOgkM/WHhVaPXYeq0Hbyw4qzw0z
	 /yxsNQrF1WTvfMatTRQwEtT0EGHd6LSxRJee9PTQPzwvwy8Lr02by8dStbZ2ZZv/5a4ML
	 5hsyGng2yZkCQp+bY1FdILVUi/gwfq7CulFrI8nJ7vW7p6sNCInM8Az+zW0GKc1eYhq0i
	 erp9OWuAvoGWC38Adv/d6dEsKQqoUfx3HAtSJ/cQYnXMfz5IOGw86ByFM9dGXdW8K8g==
X-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=QD3Hd6b3;
	arc=none smtp.remote-ip=100.103.45.18
X-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))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAC9F606A33C
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 07:21:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6C931F000C2;
	Fri,  4 Dec 2026 07:21:26 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796368887;
	bh=lWyjBQ+WCEhroJ6Kho2jtBzP5Y1g2KYY1AklLmG5K1c=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=QD3Hd6b38nCSDBuw73seV02FZ+PuJVYLC3u9akW4W2JWCYLlNEUjfUuN+HDSgkRcf
	 LqXO7D4ZvsZ37zlCf9kYRNlx0fKDtM+BFq+SY2vZLZBKCRZtiRUyJVtVOrq/SPR+OK
	 o6Nm9BaxEVxpIH7qR4SUA3/BJ7odbJI0ab7KxQBUR2YsTlcgXKZ80ufLbbNtH+9MVg
	 8kJVaakHi2qkbYUOKIGxhEYU9GurAuuN7ggDx9w5sTuYQapgOuZZlreR9EedJgPg4V
	 xAvht3zhDAuXvtFAW0+hyBHx+DtP96ZG5MFqfI9oyHrrO5tTMogvuScXAM8EM2aq2x
	 6P23V/tSVwSbg==
X-Cc: sd@queasysnail.net, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 netdev@vger.kernel.org, kyuwon.cho@skku.edu, cratiu@nvidia.com,
 haseebulhaq55@gmail.com, paulb@mellanox.com, marcelo.leitner@gmail.com,
 yossiku@mellanox.com, jiri@resnulli.us
X-In-Reply-To: <20261203063745.75353-3-juanagusnicco@gmail.com>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list