* [PATCH net 0/2] macvlan, macsec: fix double free of conntrack extensions by clones
@ 2026-12-03 6:37 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 ` [PATCH net 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini
0 siblings, 2 replies; 5+ messages in thread
From: Juan Agustin Niccolini @ 2026-12-03 6:37 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, Paul Blakey,
Marcelo Ricardo Leitner, Yossi Kuperman, Jiri Pirko
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, still
unconfirmed if tc act_ct attached it at the lower device's ingress.
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
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: 5584a17feee004afa77ffb0df938011d7239de87
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free 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 ` Juan Agustin Niccolini 2026-12-04 7:21 ` netdev-bot+sashiko 2026-12-03 6:37 ` [PATCH net 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini 1 sibling, 1 reply; 5+ messages in thread From: Juan Agustin Niccolini @ 2026-12-03 6:37 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, Paul Blakey, Marcelo Ricardo Leitner, Yossi Kuperman, Jiri Pirko 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. 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 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: 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/macvlan_source_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 6000 frames, and none on 10 runs of 100000 frames with this patch. The source-mode device still receives every clone, which now gets its own conntrack entry in prerouting. drivers/net/macvlan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 4f8416bb5..7fb584621 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.43.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 1/2] macvlan: drop the conntrack entry of source-mode clones to fix a double free 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-04 7:21 ` netdev-bot+sashiko 0 siblings, 0 replies; 5+ messages in thread From: netdev-bot+sashiko @ 2026-12-04 7:21 UTC (permalink / raw) To: juanagusnicco Cc: sd, andrew+netdev, davem, edumazet, kuba, pabeni, netdev, kyuwon.cho, cratiu, haseebulhaq55, paulb, marcelo.leitner, yossiku, jiri Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · 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] The fix is incomplete. - [Low] macvlan: Fixes tag cites act_ct instead of macvlan source-mode commit -- macvlan: drop the conntrack entry of source-mode clones to fix a double free This patch calls nf_reset_ct() on the clone that macvlan_forward_source_one() creates. The clone handed to a source-mode macvlan device then no longer shares the original skb's unconfirmed conntrack entry. Without this, the original and the clone can both run nf_ct_ext_add() on the same entry from different CPUs and double free ct->ext. > diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c > index 4f8416bb5169b..7fb584621fa06 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)) [Severity: Low] Is b57dc7c13ea9 the right commit for the Fixes tag? That commit introduced net/sched/act_ct.c and did not touch drivers/net/macvlan.c. The clone that this patch resets is created in macvlan_forward_source_one(). That function came in with 79cf79abce71 ("macvlan: add source mode"), and it has never dropped the clone's _nfct. The bridge path below does not depend on act_ct at all. Take a source-mode macvlan stacked on a bridge with br_netfilter enabled. Conntrack is attached at the bridge's prerouting hook. For a unicast PACKET_HOST frame, br_nf_local_in() then returns early: net/bridge/br_netfilter_hooks.c:br_nf_local_in() { ... if (!nfct || skb->pkt_type == PACKET_HOST) return NF_ACCEPT; ... } br_netif_receive_skb() then hands the skb to netif_receive_skb() on the bridge device. The unconfirmed _nfct is still attached, and the bridge device's rx_handler is macvlan_handle_frame(). From there, macvlan_forward_source_one() clones it just as in the act_ct case. The original and the clone then share the same unconfirmed nf_conn, with no tc involved. Stable tooling uses the Fixes tag to decide which trees get the backport. Pointing it at act_ct suggests the problem only exists once act_ct is present, and that does not seem to be the case. Should this be Fixes: 79cf79abce71 ("macvlan: add source mode") instead? [Severity: High] Can the broadcast/multicast RX path in this driver still hit the same double free? In macvlan_handle_frame(), a broadcast or multicast frame is cloned, and then the original keeps going up the lower device: 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 broadcast address is always set in port->bc_filter (see macvlan_compute_filter()). macvlan_broadcast_enqueue() uses skb_clone(), and skb_clone() keeps _nfct. macvlan_process_broadcast() then handles the clone on the unbound system_dfl_wq. That worker can run on another CPU even without RPS. macvlan_process_broadcast()->macvlan_multicast_rx()->macvlan_broadcast() then clones once for each matching 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); ... } On RX, mode is a mask such as MACVLAN_MODE_VEPA | MACVLAN_MODE_BRIDGE. That makes local false, so macvlan_broadcast_one() never calls __dev_forward_skb(): drivers/net/macvlan.c:macvlan_broadcast_one() { ... if (local) return __dev_forward_skb(dev, skb); skb->dev = dev; ... } Each clone therefore reaches netif_rx() still pointing at the shared unconfirmed nf_conn. In prerouting, the original on the lower device and the clones on the macvlan devices can then call nf_ct_ext_add() on the same ct at the same time. One way in is nft "ct expectation" -> nf_ct_helper_ext_add(), which only requires !nf_ct_is_confirmed(ct). Both paths end up here: net/netfilter/nf_conntrack_extend.c:nf_ct_ext_add() { ... new = krealloc(ct->ext, alloc, gfp); ... } No lock is held there. This is the double free the commit message describes, reached with broadcast traffic instead of source mode. The commit message names __dev_forward_skb() as the model for this fix. However, only the local (TX bridge) branch of macvlan_broadcast_one() uses it. The later patch in this series, "macsec: drop the conntrack entry of delivered clones to fix a double free", only touches drivers/net/macsec.c. The macvlan broadcast path is therefore still unfixed at the end of the series. Could nf_reset_ct() also be called at one of these points? - on the clone in macvlan_broadcast_enqueue() - on each clone in macvlan_broadcast() - in macvlan_broadcast_one() when !local These clones also carry a conntrack entry owned by the lower device's netns into macvlan devices that may be in another netns. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203063745.75353-1-juanagusnicco%40gmail.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 2/2] macsec: drop the conntrack entry of delivered clones to fix a double free 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 2026-12-04 7:21 ` netdev-bot+sashiko 1 sibling, 1 reply; 5+ messages in thread From: Juan Agustin Niccolini @ 2026-12-03 6:37 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, Paul Blakey, Marcelo Ricardo Leitner, Yossi Kuperman, Jiri Pirko 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 2/2] macsec: drop the conntrack entry of delivered clones to fix a double free 2026-12-03 6:37 ` [PATCH net 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini @ 2026-12-04 7:21 ` netdev-bot+sashiko 0 siblings, 0 replies; 5+ messages in thread From: netdev-bot+sashiko @ 2026-12-04 7:21 UTC (permalink / raw) To: juanagusnicco Cc: sd, andrew+netdev, davem, edumazet, kuba, pabeni, netdev, kyuwon.cho, cratiu, haseebulhaq55, paulb, marcelo.leitner, yossiku, jiri 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 7:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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-04 7:21 ` netdev-bot+sashiko 2026-12-03 6:37 ` [PATCH net 2/2] macsec: drop the conntrack entry of delivered " Juan Agustin Niccolini 2026-12-04 7:21 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox