Netdev List
 help / color / mirror / Atom feed
From: Juan Agustin Niccolini <juanagusnicco@gmail.com>
To: Sabrina Dubroca <sd@queasysnail.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, Kyuwon Cho <kyuwon.cho@skku.edu>,
	Cosmin Ratiu <cratiu@nvidia.com>,
	Haseeb Malik <haseebulhaq55@gmail.com>,
	Paul Blakey <paulb@mellanox.com>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Yossi Kuperman <yossiku@mellanox.com>,
	Jiri Pirko <jiri@resnulli.us>
Subject: [PATCH net 2/2] macsec: drop the conntrack entry of delivered clones to fix a double free
Date: Thu,  3 Dec 2026 01:37:45 -0500	[thread overview]
Message-ID: <20261203063745.75353-3-juanagusnicco@gmail.com> (raw)
In-Reply-To: <20261203063745.75353-1-juanagusnicco@gmail.com>

When validation is not strict, macsec delivers a clone of a frame that
has no SecTAG, or a SecTAG with an unknown SCI, to each macsec device on
the lower device, while the original goes on up the lower device. With
offload, multicast frames are cloned to the macsec device the same way.
The clone keeps the original's conntrack entry. If tc act_ct attached
that entry at the lower device's ingress, it is still unconfirmed, and
netfilter treats an unconfirmed entry as owned by a single skb:
nf_ct_ext_add() moves its extension area with krealloc() without any
locking. When RPS processes the clone on another CPU, the original and
the clone can do this at the same time, and the old area is freed
twice:

  BUG: KASAN: double-free in krealloc_node_align_noprof+0x1c6/0x340
  Free of addr ff11000010e24e00 by task macsec_untagged/218

An unprivileged user can trigger this from a user and network
namespace, with a macsec device set to "validate disabled": RPS can be
enabled there for new devices through net.core.rps_default_mask, and an
nftables "ct expectation" adds an extension on both paths.

Fix this by dropping the conntrack entry of each clone.

Fixes: b57dc7c13ea9 ("net/sched: Introduce action ct")
Cc: stable@vger.kernel.org
Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
---
Reproducer: https://github.com/AgusNicco/macvlan-macsec-double-free/blob/main/macsec_untagged_ct_uaf.c

Tested on mainline 9437ee8b6 with KASAN, in a 4-CPU guest: the
reproducer, run as an unprivileged user, gets the report above on 10 of
10 runs, each within 2000 frames, and none on 10 runs of 100000 frames
with this patch. The macsec device still receives every clone, which
now gets its own conntrack entry in prerouting. The reproducer sends
frames without a SecTAG; the unknown-SCI and offload clones get the
same one-line change but were not run.

 drivers/net/macsec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 240ba0ae0..a50266490 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);
 
@@ -1121,6 +1122,7 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
 		if (!nskb)
 			break;
 
+		nf_reset_ct(nskb);
 		nskb->dev = ndev;
 
 		if (__netif_rx(nskb) == NET_RX_SUCCESS) {
@@ -1364,6 +1366,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
 		if (!nskb)
 			break;
 
+		nf_reset_ct(nskb);
 		macsec_reset_skb(nskb, macsec->secy.netdev);
 
 		ret = __netif_rx(nskb);
-- 
2.43.0


      parent reply	other threads:[~2026-12-03  6:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:37 [PATCH net 0/2] macvlan, macsec: fix double free of conntrack extensions by clones Juan Agustin Niccolini
2026-12-03  6:37 ` [PATCH net 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free Juan Agustin Niccolini
2026-12-03  6:37 ` Juan Agustin Niccolini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203063745.75353-3-juanagusnicco@gmail.com \
    --to=juanagusnicco@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=cratiu@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=haseebulhaq55@gmail.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=kyuwon.cho@skku.edu \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paulb@mellanox.com \
    --cc=sd@queasysnail.net \
    --cc=yossiku@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox