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 --- 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