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>,
	Michael Braun <michael-dev@fami-braun.de>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	Mark Starovoytov <mstarovo@pm.me>,
	Igor Russkikh <irusskikh@marvell.com>
Subject: [PATCH net v2 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free
Date: Fri,  4 Dec 2026 10:23:44 -0500	[thread overview]
Message-ID: <20261204152345.9806-2-juanagusnicco@gmail.com> (raw)
In-Reply-To: <20261204152345.9806-1-juanagusnicco@gmail.com>

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


  reply	other threads:[~2026-12-04 15:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-04 15:23 ` [PATCH net v2 2/2] macsec: drop the conntrack entry of delivered clones to fix a double free Juan Agustin Niccolini

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=20261204152345.9806-2-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=hannes@stressinduktion.org \
    --cc=haseebulhaq55@gmail.com \
    --cc=irusskikh@marvell.com \
    --cc=kuba@kernel.org \
    --cc=kyuwon.cho@skku.edu \
    --cc=michael-dev@fami-braun.de \
    --cc=mstarovo@pm.me \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /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