Netdev List
 help / color / mirror / Atom feed
* [PATCH net] macvlan: drop the conntrack entry of broadcast clones
@ 2026-12-01  8:04 Kyuwon Cho
  2026-12-03  6:44 ` Juan Agustin Niccolini
  2026-12-05  8:46 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Kyuwon Cho @ 2026-12-01  8:04 UTC (permalink / raw)
  To: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S. Miller,
	Andrew Lunn
  Cc: Pablo Neira Ayuso, Florian Westphal, netdev

macvlan_broadcast_one() hands a clone of a broadcast or multicast frame
to each macvlan device. In bridge mode the clone goes through
__dev_forward_skb(), which drops its conntrack entry, but in the other
modes it keeps the entry of the original skb. If tc act_ct attached an
unconfirmed conntrack entry at the ingress of the lower device, the
original skb and the clones then share one unconfirmed entry, while
netfilter treats an unconfirmed entry as owned by a single skb. When
one of them adds a conntrack extension, e.g. the helper extension that
an nft ct expectation object adds, krealloc() frees the extension area
that the others still read:

  BUG: KASAN: slab-use-after-free in nft_ct_get_eval (include/net/netfilter/nf_conntrack_extend.h:46 include/net/netfilter/nf_conntrack_labels.h:28 net/netfilter/nft_ct.c:117)
  Read of size 1 at addr ff11000013ec5507 by task kworker/u8:0/13
  Call Trace:
   nft_ct_get_eval (net/netfilter/nft_ct.c:117)
   nft_do_chain (net/netfilter/nf_tables_core.c:237 net/netfilter/nf_tables_core.c:285)
   nft_do_chain_ipv4 (net/netfilter/nft_chain_filter.c:24)
   nf_hook_slow (net/netfilter/core.c:633)
   ip_rcv (net/ipv4/ip_input.c:618)
   __netif_receive_skb_one_core (net/core/dev.c:6451)
   process_backlog (net/core/dev.c:6917)
  Freed by task 114:
   krealloc_node_align_noprof (mm/slub.c:7098)
   nf_ct_ext_add (net/netfilter/nf_conntrack_extend.c:115)
   nf_ct_helper_ext_add (net/netfilter/nf_conntrack_helper.c:187)
   nft_ct_expect_obj_eval (net/netfilter/nft_ct.c:1432)
   nft_do_chain (net/netfilter/nf_tables_core.c:232 net/netfilter/nf_tables_core.c:285)

Two such adds free the area twice (KASAN double-free in
krealloc_node_align_noprof()).

Drop the conntrack entry of the clone, as __dev_forward_skb() does and
as act_mirred does since commit d09c548dbf3b ("net: sched: act_mirred:
Reset ct info when mirror/redirect skb").

Fixes: b57dc7c13ea9 ("net/sched: Introduce action ct")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. Any user reaches it from its own
user and network namespace. Our reproducer puts tc act_ct (and a mirred
mirror) on the ingress of a veth peer with two private-mode macvlan
devices on top, adds an nft ct expectation object and a ct labels read
in prerouting, and sends a burst of broadcast UDP frames. Both
use-after-free reads and double frees (KASAN double-free in
krealloc_node_align_noprof()) show up. With the patch the frames go
through and nothing is reported. The reproducer is available on
request.

Found and tested on mainline fe6ff8d5d675 (v7.4-rc5, with KASAN);
the patch is against net (76fca30e8d34).

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

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 4f8416bb5169..237744d6bfc2 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -237,6 +237,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb,
 	if (local)
 		return __dev_forward_skb(dev, skb);
 
+	nf_reset_ct(skb);
 	skb->dev = dev;
 	if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
 		skb->pkt_type = PACKET_BROADCAST;
-- 
2.43.0


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

* Re: [PATCH net] macvlan: drop the conntrack entry of broadcast clones
  2026-12-01  8:04 [PATCH net] macvlan: drop the conntrack entry of broadcast clones Kyuwon Cho
@ 2026-12-03  6:44 ` Juan Agustin Niccolini
  2026-12-05  8:46 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: Juan Agustin Niccolini @ 2026-12-03  6:44 UTC (permalink / raw)
  To: Kyuwon Cho
  Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
	Andrew Lunn, Pablo Neira Ayuso, Florian Westphal, netdev

On Tue, 1 Dec 2026 17:04:20 +0900, Kyuwon Cho wrote:
> --- a/drivers/net/macvlan.c
> +++ b/drivers/net/macvlan.c
> @@ -237,6 +237,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb,
>  	if (local)
>  		return __dev_forward_skb(dev, skb);
>
> +	nf_reset_ct(skb);
>  	skb->dev = dev;
>  	if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
>  		skb->pkt_type = PACKET_BROADCAST;

I reviewed and tested this patch, and it is correct for the case it
aims to fix.

While reviewing it I found two other places that deliver clones which
keep the original's unconfirmed entry, macvlan source mode and macsec,
and sent patches for both:
https://lore.kernel.org/netdev/20261203063745.75353-1-juanagusnicco@gmail.com/

Reviewed-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
Tested-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>

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

* Re: [PATCH net] macvlan: drop the conntrack entry of broadcast clones
  2026-12-01  8:04 [PATCH net] macvlan: drop the conntrack entry of broadcast clones Kyuwon Cho
  2026-12-03  6:44 ` Juan Agustin Niccolini
@ 2026-12-05  8:46 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05  8:46 UTC (permalink / raw)
  To: kyuwon.cho
  Cc: kuba, pabeni, edumazet, davem, andrew+netdev, pablo, fw, netdev

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 2

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: the same macvlan clone path that shares
  an unconfirmed conntrack entry is still reachable through source-mode…
- [Low] The commit message says "In bridge mode the clone goes through
  __dev_forward_skb(), which drops its conntrack entry, but in the other…
- [Low] The commit message (title "drop the conntrack entry of broadcast
  clones", body "Drop the conntrack entry of the clone") presents the…

--

macvlan: drop the conntrack entry of broadcast clones

This patch adds nf_reset_ct() to macvlan_broadcast_one() for the non-local
case. Broadcast and multicast clones handed to macvlan devices then stop
sharing an unconfirmed conntrack entry that tc act_ct attached on the lower
device. Before the patch, one skb could krealloc() the ct extension area
while another skb was still reading it.

> macvlan_broadcast_one() hands a clone of a broadcast or multicast frame
> to each macvlan device. In bridge mode the clone goes through
> __dev_forward_skb(), which drops its conntrack entry, but in the other
> modes it keeps the entry of the original skb.

[Severity: Low]
Does this description match received frames? In macvlan_broadcast(), local
comes from the flood mask the caller passes in, not from the target vlan's
mode:

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

Every RX caller in macvlan_multicast_rx() passes a multi-bit mask, either
MACVLAN_MODE_VEPA | MACVLAN_MODE_BRIDGE or that pair plus
MACVLAN_MODE_PRIVATE and MACVLAN_MODE_PASSTHRU. So local is false for
every target, bridge-mode macvlans included. Only the TX flood in
macvlan_queue_xmit() passes exactly MACVLAN_MODE_BRIDGE.

That means bridge-mode macvlans receiving broadcast or multicast from the
lower device were affected just like private or VEPA ones before this
patch. Could the commit message be reworded so it doesn't suggest
bridge-mode setups were safe?

> Drop the conntrack entry of the clone, as __dev_forward_skb() does and
> as act_mirred does since commit d09c548dbf3b ("net: sched: act_mirred:
> Reset ct info when mirror/redirect skb").

[Severity: Low]
The subject and this paragraph say only clones are affected. However,
macvlan_handle_frame() also calls macvlan_broadcast_one() on the original,
non-cloned skb:

drivers/net/macvlan.c:macvlan_handle_frame() {
    ...
			if (mode != MACVLAN_MODE_VEPA &&
			    mode != MACVLAN_MODE_BRIDGE) {
				/* forward to original port. */
				vlan = src;
				ret = macvlan_broadcast_one(skb, vlan, eth, 0) ?:
				      __netif_rx(skb);
    ...
}

Since local is 0 here, the new nf_reset_ct() also drops the ct of the
original skb. This happens when a multicast frame's source MAC belongs to
a private, passthru or source-mode macvlan. Netfilter on the upper device
used to see that entry, for example one set by tc act_ct with a zone on
the lower device, and now it won't.

This is probably intended and matches __dev_forward_skb(). Could the
commit message mention it?

> diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
> index 4f8416bb5169b..237744d6bfc2d 100644
> --- a/drivers/net/macvlan.c
> +++ b/drivers/net/macvlan.c
> @@ -237,6 +237,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb,
>  	if (local)
>  		return __dev_forward_skb(dev, skb);
>  
> +	nf_reset_ct(skb);

[Severity: High]
Does the source-mode clone path in the same receive handler need the same
reset? macvlan_forward_source_one() clones the skb and passes the clone to
__netif_rx() without dropping its conntrack entry:

drivers/net/macvlan.c:macvlan_forward_source_one() {
    ...
	nskb = skb_clone(skb, GFP_ATOMIC);
	if (!nskb)
		return;

	len = nskb->len + ETH_HLEN;
	nskb->dev = dev;
    ...
	ret = __netif_rx(nskb);
    ...
}

skb_clone()->__copy_skb_header()->__nf_copy() copies _nfct and takes a
reference. The clone therefore shares the original skb's unconfirmed
nf_conn.

macvlan_handle_frame() calls macvlan_forward_source() on both the
multicast branch and the unicast branch. Unless a matching vlan has
MACVLAN_FLAG_NODST, the original skb keeps going with the same ct. It can
return RX_HANDLER_PASS, be retargeted with RX_HANDLER_ANOTHER, or go
through the broadcast/multicast or forward-to-original-port paths. Several
source-mode macvlans can also register the same source MAC, which gives
more than one clone.

With tc act_ct on the lower device's ingress, wouldn't this trigger the
same use-after-free and double-free from the commit message? The path is
nft_ct_expect_obj_eval()->nf_ct_helper_ext_add()->nf_ct_ext_add() and its
krealloc(). The only difference is a source-mode macvlan (ip link add ...
type macvlan mode source) in place of a private-mode one.

Would adding nf_reset_ct(nskb) after skb_clone() in
macvlan_forward_source_one() fix this too?

>  	skb->dev = dev;
>  	if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
>  		skb->pkt_type = PACKET_BROADCAST;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179607207068.562302.5326868635249894085%40skku.edu

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

end of thread, other threads:[~2026-12-05  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  8:04 [PATCH net] macvlan: drop the conntrack entry of broadcast clones Kyuwon Cho
2026-12-03  6:44 ` Juan Agustin Niccolini
2026-12-05  8:46 ` 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