Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] macvlan, macsec: fix double free of conntrack extensions by clones
@ 2026-12-04 15:23 Juan Agustin Niccolini
  2026-12-04 15:23 ` [PATCH net v2 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free Juan Agustin Niccolini
  2026-12-04 15:23 ` [PATCH net v2 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini
  0 siblings, 2 replies; 3+ messages in thread
From: Juan Agustin Niccolini @ 2026-12-04 15:23 UTC (permalink / raw)
  To: Sabrina Dubroca, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, Kyuwon Cho, Cosmin Ratiu, Haseeb Malik, Michael Braun,
	Hannes Frederic Sowa, Mark Starovoytov, Igor Russkikh

macvlan in source mode and macsec both have a double free of a
conntrack extension area. Each hands its own device a clone of a
received frame that keeps the original's conntrack entry, which is
still unconfirmed if tc act_ct attached it at the lower device's
ingress, or if the lower device is a bridge and conntrack ran on the
bridge for a frame to the host. When the clone and the original reach
nftables on different CPUs, both reallocate that entry's extension area
and the old area is freed twice.

An unprivileged user can trigger both from a user and network
namespace: RPS can be enabled there for new devices through
net.core.rps_default_mask, which makes the clone run on another CPU.

This is the bug that "macvlan: drop the conntrack entry of broadcast
clones" fixes for macvlan's broadcast clones:
https://lore.kernel.org/netdev/179607207068.562302.5326868635249894085@skku.edu/
These are the other two places that deliver such clones. Both patches
drop the clone's entry, as that patch does, and apply with or without
it.

Both bugs were discovered during an LLM-based review of that patch.
Reproducers for both: https://github.com/AgusNicco/macvlan-macsec-double-free

v2:
- Fixes tags cite the commits that added the clones instead of act_ct
  (Sashiko)
- say that conntrack on a bridge also leaves the entry unconfirmed
v1: https://lore.kernel.org/netdev/20261203063745.75353-1-juanagusnicco@gmail.com/

Juan Agustin Niccolini (2):
  macvlan: drop the conntrack entry of source-mode clones to fix a
    double free
  macsec: drop the conntrack entry of delivered clones to fix a double
    free

 drivers/net/macsec.c  | 3 +++
 drivers/net/macvlan.c | 1 +
 2 files changed, 4 insertions(+)


base-commit: e9d78fc6741ac06d438cf64e314c28e57014432a
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v2 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free
  2026-12-04 15:23 [PATCH net v2 0/2] macvlan, macsec: fix double free of conntrack extensions by clones Juan Agustin Niccolini
@ 2026-12-04 15:23 ` Juan Agustin Niccolini
  2026-12-04 15:23 ` [PATCH net v2 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini
  1 sibling, 0 replies; 3+ messages in thread
From: Juan Agustin Niccolini @ 2026-12-04 15:23 UTC (permalink / raw)
  To: Sabrina Dubroca, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, Kyuwon Cho, Cosmin Ratiu, Haseeb Malik, Michael Braun,
	Hannes Frederic Sowa, Mark Starovoytov, Igor Russkikh

macvlan_forward_source_one() hands a clone of each frame from a listed
source address to a source-mode macvlan device, while the original goes
on up the lower device. The clone keeps the original's conntrack entry.
That entry is still unconfirmed if tc act_ct attached it at the lower
device's ingress, or if the lower device is a bridge and conntrack ran
on the bridge for a frame to the host. 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 ff11000010c04200 by task macvlan_source_/215

An unprivileged user can trigger this from a user and network
namespace: 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 clone's conntrack entry, as __dev_forward_skb()
does when macvlan forwards a frame between its own devices.

Fixes: 79cf79abce71 ("macvlan: add source mode")
Cc: stable@vger.kernel.org
Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
---
v2:
- Fixes: cite 79cf79abce71, which added the clone, instead of act_ct
  (Sashiko)
- say that conntrack on a bridge also leaves the entry unconfirmed
v1: https://lore.kernel.org/netdev/20261203063745.75353-2-juanagusnicco@gmail.com/

Reproducer: https://github.com/AgusNicco/macvlan-macsec-double-free/blob/main/macvlan_source_ct_uaf.c

The code is unchanged since v1, which was 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 6000 frames,
and none on 10 runs of 100000 frames with the patch.

Note for the LLM reviewer:
macvlan's broadcast and multicast clones also keep the original's
unconfirmed conntrack entry. It is known, it is preexisting, and a patch
for it is pending review:
https://lore.kernel.org/netdev/179607207068.562302.5326868635249894085@skku.edu/

 drivers/net/macvlan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 4f8416bb5169..7fb584621fa0 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -422,6 +422,7 @@ static void macvlan_forward_source_one(struct sk_buff *skb,
 		return;
 
 	len = nskb->len + ETH_HLEN;
+	nf_reset_ct(nskb);
 	nskb->dev = dev;
 
 	if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, dev->dev_addr))
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH net v2 2/2] macsec: drop the conntrack entry of delivered clones to fix a double free
  2026-12-04 15:23 [PATCH net v2 0/2] macvlan, macsec: fix double free of conntrack extensions by clones Juan Agustin Niccolini
  2026-12-04 15:23 ` [PATCH net v2 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free Juan Agustin Niccolini
@ 2026-12-04 15:23 ` Juan Agustin Niccolini
  1 sibling, 0 replies; 3+ messages in thread
From: Juan Agustin Niccolini @ 2026-12-04 15:23 UTC (permalink / raw)
  To: Sabrina Dubroca, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, Kyuwon Cho, Cosmin Ratiu, Haseeb Malik, Michael Braun,
	Hannes Frederic Sowa, Mark Starovoytov, Igor Russkikh

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. That entry is still
unconfirmed if tc act_ct attached it at the lower device's ingress, or
if the lower device is a bridge and conntrack ran on the bridge for a
frame to the host. 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: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")
Fixes: f428011b90ec ("net: macsec: support multicast/broadcast when offloading")
Cc: stable@vger.kernel.org
Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
---
v2:
- Fixes: cite c09440f7dcb3 and f428011b90ec, which added the clones,
  instead of act_ct (Sashiko)
- say that conntrack on a bridge also leaves the entry unconfirmed
v1: https://lore.kernel.org/netdev/20261203063745.75353-3-juanagusnicco@gmail.com/

Reproducer: https://github.com/AgusNicco/macvlan-macsec-double-free/blob/main/macsec_untagged_ct_uaf.c

The code is unchanged since v1, which was 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 the patch.

Note for the LLM reviewer:
macvlan's broadcast and multicast clones also keep the original's
unconfirmed conntrack entry. It is known, it is preexisting, and a patch
for it is pending review:
https://lore.kernel.org/netdev/179607207068.562302.5326868635249894085@skku.edu/

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

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 240ba0ae07d1..a50266490f4a 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.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 15:23 [PATCH net v2 0/2] macvlan, macsec: fix double free of conntrack extensions by clones Juan Agustin Niccolini
2026-12-04 15:23 ` [PATCH net v2 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free Juan Agustin Niccolini
2026-12-04 15:23 ` [PATCH net v2 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox