From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185933; b=rQKGHBSgw5ZXJpeeg7MXrECZjQloY5NcnPLLeBzu/nWLLyXKMFrc7+QLiSCl8ra9Hc1W /oDacqac46bhq/thPn8516amXhmC/hhZhlkSBWbAumLFyIf9Opq+HZ/uQAwxngruR9CSG ReYQ2DtD/qyic21E361crk13vV257QyrSmmIDVXuX14/JRN/c0CrZqvmSxnT9V+ZX+k8b 4B8tsfrdZa3j6yZq0iMcQtDEuO40AkSktN0pQl4SvuVOuVQziqeRZQ6MdVVxv1p0FxEK0 9jPOiMeKo/WmvDW7yLFGgdVzPX72j86hAVkP4MdxC7/plcjdaldtr5Aly5zcGSHP91Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185933; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=A4G+BFmvZolsWQsx4WBwxug2X+sGm9Fuo2Ikk2stkSI=; b=BaZZGgboMp1B6aSOyxrsm8ivmSBAz0OETy3BSnI/s9UqnS7jCGindvTIUBVL87+FdTjb yVRfEWCZYEpu5blF5JTCV0CqcchK32mGK/O/HcwbQ4h7yfjpKcA78eAc8cm1VtZsTVtrO iv0RX8XEqx81nyHJab7oVz9+GQeHcSiKO8HDOtbYMo4yBSQS5VwNUp6qEE6k90MnShVQQ veadae9xipWmmIhjda8Vu38vNG+BmGM5qkyi9szZQEVdCL4Uo3i1SSwmOEgSCC14jZUY5 Z0WN/+ygQXHeysJN6l/1gTf+Eya6g6E9UtDmZe08ZicoHUHGhkgdVS+yPNvHgBXsbiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=ko54LZNT; arc=none smtp.remote-ip=74.125.82.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEA45606A689 for ; Wed, 2 Dec 2026 04:32:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EEA45606A689 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=ko54LZNT Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-3866a784546so17532452eec.0 for ; Tue, 01 Dec 2026 20:32:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796185932; x=1796790732; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=A4G+BFmvZolsWQsx4WBwxug2X+sGm9Fuo2Ikk2stkSI=; b=ko54LZNTJ8bJcjwvNYcudGr68oyifjiXwUgjaIUbg0nMiol6sUCbNmeaVS8Z4SMbEc H+8ouSHlwj+skxQ7SAgUpOTI8PxekW+kJ1Kx6yTbvmQxBLR+FilsISn1FYPvqhC+bhhh f9S3rGk5HFgKdo7CJjHEyksYh+Nw4spHaPWzEOO5J6mKv+wySyviWbLjijFcGsuaHbR+ Oz4+Fxozylpp4Lr9VQGVmGDhYmS6fTkZU8HIPB9t/1Zm2TnheZnct9TppheenKs7ykwj vXbvJSr5I2TDwKonXJywgyfB4hgZOZ7WAMMfuJeveJiEtaCjXikwKEtjI223TX6YYjrL aovg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796185932; x=1796790732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=A4G+BFmvZolsWQsx4WBwxug2X+sGm9Fuo2Ikk2stkSI=; b=Ms9+0/dOxWzkE2PJkRnjgvpKTTshrokcEunK/AwUS8+s/GH7tvyh/HtSr1GBpmOyq2 ykDXd4FyVyHLrxu5GP6b5eULGkEyH2BqzjIFIJuridjmQDF7vmiOg9q9nb8a6tANPOi9 FGK9ShVmfdjfNwR0ljhKj6//EK806hCHH7+W9j0cqNpu1ns3Az3CLMc0WNVkEi82s1RT DUs10e0EZK0FT8SD6Bs5VjL8QICgPoQCnJ3klX7nJgsTH0MtTbst/ZE+7+BqHNi5pwgG w2ibrxP413Ixa3BrpOBJjIDUdrPTvNxXQ0fOmw7YlEAXNpz1s+24MzxsBMdH2srBS3gn ijQw== X-Forwarded-Encrypted: i=1; AL+hErHkmZfcgIkcOHn7a6orxqho81VJtttlAzHEvYBd4mXI030ZcqT+4p0Nn6WlfaF6D6qLqVZcG935W9r1LQY=@vger.kernel.org X-Gm-Message-State: APuU4Z858LtwpxbsjWRm5qChEMDxcIUhlcmuQw6v30mtORk7LK5/xvlg /RW7yLOnbOqluM3/QYExxtxm+46HcTwb5V0SfJ707VIJfXbAMhiw6f0CnVvh8Q2wnVM= X-Gm-Gg: AZFdTZeLTiQnGfpfv64qHB6o9W0+8y8n0bd39mpzHiPCPH9SnhB67i46F54RzPLe2bz 09yb3T/wuuB5dKCaeAYFegFY142xx8mSTT6DNaeoJrbiwf7AW66faiyWts9r9yHq4eCy754xX6T 1LceFNZ6o3qp1fwQx32CsL1NgHqDbF9QnARYV1enZfoXxWrTQRYCenTDud8OiNUVPaskDa/oOsS bx4ZCLS7IJ/ElTW6hZlaC+m/F/BLxVnUSLX++b5TjvpDKYf7Yj+D7lvQeNI+JO/UPUhJREt80tW Z1cxS779CLtN0mzYckOU5NMGfaZxhSpSq0NpbnkfEBWVsWdBt3TPUtWsJIRXpTn2gEqXFvhS+RQ XIzdSzUMLi6FtK3NvSZAn/8QujRRi3Drff597PEoDh1/HRQTYnVFsLH5Wr924l/l1GIazbUO1Tb 3y+beo5ubON8bO5TjwhPOcuutexmjiQ3caU5FHwc6CVER9No5sVeU7hwdR7zx+F0Jz6H4cEKp5p 6FsnGuUCCnCRa5fT4Zpv/TY4KxmFWqEFMdBDAzS7IvIMumGhBwppFNUufRq1r+oonVKb14xEAG/ u1VddMGrqjLjqe594dTewWexbiVH/jVF8ziWjeveoCgR++1t4istaWnO8PadE0UC6/r0Jr/D53o MRYEbLl4gQTHfy3bQkERfbYLYrns= X-Received: by 2002:a05:7301:7e07:b0:36f:9d8:4a33 with SMTP id 5a478bee46e88-38570e21c39mr40356081eec.31.1796185931924; Tue, 01 Dec 2026 20:32:11 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386d605c894sm54632028eec.2.2026.12.01.20.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:32:10 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Simon Horman , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn , David Ahern , Ido Schimmel Subject: [PATCH net-next v6 05/12] amt: forward multicast data over IPv6 Date: Wed, 2 Dec 2026 04:31:53 +0000 Message-ID: <20261202043200.286260-6-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202043200.286260-1-omar@blockcast.net> References: <20261202043200.286260-1-omar@blockcast.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit amt_send_multicast_data() routes and sends the relay's copy of a multicast packet only over IPv4. Size its headroom for the outer family and send it through amt_udp_xmit(). A copy that cannot be sent is now counted in tx_dropped, and one with no route is freed with SKB_DROP_REASON_IP_OUTNOROUTES. The inner protocol stays independent of the outer family. RFC 7450 s5.3.3.6.3.2 forbids a Fragment header on Multicast Data over IPv6, and s5.3.3.6.2.2 has a payload above the tunnel MTU dropped and, if it came from an SSM source, a Packet Too Big sent to it. The scrub in amt_udp_xmit() clears ignore_df, so ip6_fragment() would drop such a packet and send the Packet Too Big to the relay itself. amt_send_multicast_data() therefore routes first and compares the inner packet with the route's MTU less the outer headers and the AMT header, per segment with skb_gso_validate_network_len() for a GSO skb. A route MTU below the outer headers gives a tunnel MTU of zero, not a wrapped one. A packet can match every tunnel, and an attacker can create tunnels, so amt_dev_xmit() sends one Packet Too Big through icmpv6_ndo_send() after walking all of them, with the smallest failing tunnel MTU. It is sent only for an SSM group, ff3x::/32 (RFC 4607 s1); the source of an ASM group is not told. A tunnel MTU below IPV6_MIN_MTU is left out, as a smaller Packet Too Big is ignored. An IPv4 payload is dropped without an ICMP error, as icmp_send() does not answer multicast, and is not fragmented first (s5.3.3.6.2.1), as the IPv4 tunnel does not either. ipv6_mc_check_mld() leaves the transport header just past the fixed IPv6 header, also for a packet it rejects as not MLD. amt_dev_xmit() puts it back to the offset it had on entry, or the per-segment length of a GSO skb would miss extension headers; the forwarding path counts them no better, as in ip6_forward() and ip6_finish_output_gso(). The tunnel MTU follows the route's path MTU, as on every IPv6 UDP tunnel. RFC 7450 s5.3.3.6.1 and s6.1 ask for a way to turn that off. The IPv6 stack gives a tunnel none: udpv6_err() records the lowered MTU before it looks up a socket, and "mtu lock" does not stop it. This series adds none. A forged Packet Too Big, which anyone who can send ICMPv6 to the relay can aim at a gateway's address, lowers the tunnel MTU toward that gateway, down to 1230 (1280 less the 50 bytes of IPv6, UDP and AMT headers), until the route exception expires, 10 minutes by default, and every payload above it is dropped toward that gateway. A forged value M with 1330 <= M < 1490 on a 1500 byte link, where the device MTU is 1440, gives a tunnel MTU of M - 50, which the source of an SSM group is sent if its payload exceeds it, and may apply to the group for every receiver. Sending the Packet Too Big only for SSM narrows who learns of it; it does not authenticate it. amt_v6() is still false for every device, so on an IPv4 relay only the tx_dropped accounting, the drop reason and the transport header restore take effect. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 134 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 94 insertions(+), 40 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 1f4914a63..1780d3dca 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -1237,25 +1237,53 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* A payload above the tunnel MTU is dropped, as RFC 7450 s5.3.3.6 forbids a + * Fragment header. Its source is sent a Packet Too Big only for an SSM group + * (s5.3.3.6.2.2) and not below IPV6_MIN_MTU, which a source would ignore. + * The tunnel MTU follows the route's path MTU, as on any IPv6 UDP tunnel. + */ +static u32 amt_tmtu(const struct dst_entry *dst) +{ + u32 hlen = sizeof(struct ipv6hdr) + sizeof(struct udphdr) + + sizeof(struct amt_header_mcast_data); + u32 mtu = dst_mtu(dst); + + return mtu > hlen ? mtu - hlen : 0; +} + +/* FF3x::/32 is SSM for any scope x (RFC 4607 s1). */ +static bool amt_group6_is_ssm(const struct in6_addr *group) +{ + return (group->s6_addr32[0] & htonl(0xfff0ffff)) == htonl(0xff300000); +} + +static bool amt_tmtu_exceeded(const struct sk_buff *skb, u32 tmtu) +{ + if (skb_is_gso(skb)) + return !skb_gso_validate_network_len(skb, tmtu); + return skb->len > tmtu; +} + /* Route and send an AMT message to @daddr over the device's family. Over * IPv6 @dst may hold the route already looked up; it is consumed. */ static int amt_udp_xmit(struct amt_dev *amt, struct sock *sk, struct sk_buff *skb, const union amt_addr *daddr, - __be16 sport, __be16 dport, dscp_t dscp) + __be16 sport, __be16 dport, dscp_t dscp, + struct dst_entry *dst) { struct rtable *rt; struct flowi4 fl4; if (amt_v6(amt)) { - struct dst_entry *dst; - - dst = amt_route6(amt, sk, &amt->local_ipv6, &daddr->ip6, - sport, dport); - if (IS_ERR(dst)) { - netdev_dbg(amt->dev, "no route to %pI6c\n", - &daddr->ip6); - return PTR_ERR(dst); + if (!dst) { + dst = amt_route6(amt, sk, &amt->local_ipv6, + &daddr->ip6, sport, dport); + if (IS_ERR(dst)) { + netdev_dbg(amt->dev, "no route to %pI6c\n", + &daddr->ip6); + return PTR_ERR(dst); + } } /* Unlike iptunnel_xmit(), udp_tunnel6_xmit_skb() does not scrub * the skb. @@ -1354,26 +1382,55 @@ static bool amt_send_membership_update(struct amt_dev *amt, return false; } +/* Send the relay's copy to one gateway. Over IPv6 a payload that does not + * fit the tunnel MTU is dropped and *@ptb lowered to that MTU, for + * amt_dev_xmit() to send one Packet Too Big after walking every tunnel. + */ static void amt_send_multicast_data(struct amt_dev *amt, const struct sk_buff *oskb, struct amt_tunnel_list *tunnel, - bool v6) + bool v6, u32 *ptb) { struct amt_header_mcast_data *amtmd; + struct dst_entry *dst = NULL; struct sk_buff *skb; - struct iphdr *iph; - struct flowi4 fl4; - struct rtable *rt; struct sock *sk; + int err; sk = rcu_dereference_bh(amt->sk); if (!sk) return; - skb = skb_copy_expand(oskb, sizeof(*amtmd) + sizeof(*iph) + + if (amt_v6(amt)) { + u32 tmtu; + + dst = amt_route6(amt, sk, &amt->local_ipv6, &tunnel->addr.ip6, + amt->relay_port, tunnel->source_port); + if (IS_ERR(dst)) { + netdev_dbg(amt->dev, "no route to %pI6c\n", + &tunnel->addr.ip6); + DEV_STATS_INC(amt->dev, tx_dropped); + return; + } + + tmtu = amt_tmtu(dst); + if (amt_tmtu_exceeded(oskb, tmtu)) { + dst_release(dst); + /* A Packet Too Big below IPV6_MIN_MTU is ignored. */ + if (tmtu >= IPV6_MIN_MTU && (!*ptb || tmtu < *ptb)) + *ptb = tmtu; + DEV_STATS_INC(amt->dev, tx_dropped); + return; + } + } + + skb = skb_copy_expand(oskb, sizeof(*amtmd) + amt_ip_hlen(amt) + sizeof(struct udphdr), 0, GFP_ATOMIC); - if (!skb) + if (!skb) { + dst_release(dst); + DEV_STATS_INC(amt->dev, tx_dropped); return; + } /* amt_dev_xmit() pulled the Ethernet header without moving the mac * header. The tunnelled payload has no link-layer header, so the @@ -1382,18 +1439,8 @@ static void amt_send_multicast_data(struct amt_dev *amt, skb_reset_mac_header(skb); skb_reset_inner_headers(skb); if (udp_tunnel_handle_offloads(skb, true)) { - kfree_skb(skb); - return; - } - - memset(&fl4, 0, sizeof(struct flowi4)); - fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = tunnel->addr.ip4; - fl4.saddr = amt->local_ip; - fl4.flowi4_proto = IPPROTO_UDP; - rt = ip_route_output_key(amt->net, &fl4); - if (IS_ERR(rt)) { - netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->addr.ip4); + dst_release(dst); + DEV_STATS_INC(amt->dev, tx_dropped); kfree_skb(skb); return; } @@ -1407,17 +1454,12 @@ static void amt_send_multicast_data(struct amt_dev *amt, skb_set_inner_protocol(skb, htons(ETH_P_IP)); else skb_set_inner_protocol(skb, htons(ETH_P_IPV6)); - udp_tunnel_xmit_skb(rt, sk, skb, - fl4.saddr, - fl4.daddr, - AMT_TOS, - ip4_dst_hoplimit(&rt->dst), - 0, - amt->relay_port, - tunnel->source_port, - false, - false, - 0); + err = amt_udp_xmit(amt, sk, skb, &tunnel->addr, amt->relay_port, + tunnel->source_port, 0, dst); + if (err) { + DEV_STATS_INC(amt->dev, tx_dropped); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES); + } } /* Send a Membership Query in reply to an unauthenticated Request. @@ -1462,7 +1504,7 @@ static bool amt_send_membership_query(struct amt_dev *amt, else skb_set_inner_protocol(skb, htons(ETH_P_IPV6)); return amt_udp_xmit(amt, sk, skb, daddr, amt->relay_port, dport, - inet_dsfield_to_dscp(AMT_TOS)); + inet_dsfield_to_dscp(AMT_TOS), NULL); } static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) @@ -1480,6 +1522,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) struct iphdr *iph; bool data = false; bool v6 = false; + u32 ptb = 0; u32 hash; iph = ip_hdr(skb); @@ -1504,6 +1547,9 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) group.ip4 = ip_hdr(skb)->daddr; #if IS_ENABLED(CONFIG_IPV6) } else if (iph->version == 6) { + bool th_set = skb_transport_header_was_set(skb); + int th_off = th_set ? skb_transport_offset(skb) : 0; + ip6h = ipv6_hdr(skb); if (!ipv6_addr_is_multicast(&ip6h->daddr)) goto free; @@ -1520,6 +1566,12 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) } } else { data = true; + /* ipv6_mc_check_mld() moved the transport header just + * past the fixed header; restore it, or a GSO skb's + * segments look shorter than they are. + */ + if (th_set) + skb_set_transport_header(skb, th_off); } v6 = true; group.ip6 = ipv6_hdr(skb)->daddr; @@ -1573,8 +1625,10 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) } continue; found: - amt_send_multicast_data(amt, skb, tunnel, v6); + amt_send_multicast_data(amt, skb, tunnel, v6, &ptb); } + if (ptb && v6 && amt_group6_is_ssm(&group.ip6)) + icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, ptb); } dev_kfree_skb(skb);