From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185933; b=XwzVipDyJgcSEOFSiMloJ5IifkCZkv1xHLDurbp8JUncdbY42abSewUwxnA8Dd3/uR+T X2shoOItEvWlVLt7AfIxOj+c8wth3RqvTPkWRTrP9wXkEAC2tCercLJy1of2aZjGIHOPZ A9G5Nv63itwV4QmTsdIXcwxWcfEq2p7RTtCq68pQ/pPlxAxAE8pwOG0Tn9l2q/3USE2vt ZJHeHE7pWEURnUn9pEV93F6w7UHNVUsZOjy0tEAP8KZXYpPzTwpHz6sorY14UgUxLXB8K tpx77wM7i+NQox+DDgpxLCLlMHtZl+dllWLWOHxNW0V6puIlpB2k/jQY5YJj6D0NJsA== 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=fKs6PxhJsdrLeXhVwH5lUpJAZf5aZe0iYAoYhY7jvnTrVxmx5mjdd1tSo2QVpE8B8XIZ kLgXaUgYdpWRxBzt4OR5an9DYzgyg2wbStfoNcvp3z9qFTUIKxOiS2g8JEIVpOrh9kZC0 NpgiurW5ow7pnvvJrBC1ZUmbaU/zWPsko+hjDPXFUL1ggKka4FCLCc5A7YxX2oT+ER0P/ Fv8Y0MnJvizHcnSUNe7f13g+eVP5nQx3HQlRMorvwZUuBiFE0U7hMivXoqTQrhU4G0pCx nGUFnxpFXc/qF6gp4nRoT0GTh8ZLiKMRZE6/RxjK+3MwFgG40y3rw8GJMojCY6rBQaw== 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.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 DA85E606A325 for ; Wed, 2 Dec 2026 04:32:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA85E606A325 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-f173.google.com with SMTP id 5a478bee46e88-386ab9ab619so19039114eec.1 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=fkAUlB5ys82hvtWc9G83T59UpRESBhdO7OfoTkYaoF5Div+pxCJ6u7RBcXcJA+GVpp DCcYJsIT1re0CVuL2HnYWf8x4erOQ0V+L85aQbBYjCYnxLK3FpLkEpx0QJ+eFtH2jzXB I6KFg6VNdlZ6qw39LrY2YCQYadNOwQlOsYN1zPu5b/PDQ8ACTJoZChaot+Oy1C/XhleA FyZ3bplOCkpODMEEPjHFWM3xe51wqTv7ey4iyJmLdf9oT6QUEBBLIaSmWtoA1NQMcHZp p5IGe37WVgNIDmpdODn08ukyrua87AYgAfnX9BPTdzJ+ORXGCkzrKvqn6+nYt9Wrg4CR E+qA== X-Forwarded-Encrypted: i=1; AL+hErEwBcm2mJc07n6omtI68dIXhaLe8k/lMw7+Pmv0DGq+SnYhMMs3jTlQ/JGm0CMdUYIYehupXFk=@vger.kernel.org X-Gm-Message-State: APuU4Z8U3JQdyubvxN9cVpln23CJQf91GjVu/rU3uVDSUE7DqI/Nqeyk GzL+m64WW9l7Mv9i0Ki9IIqLNhVP06/OL+RYk6zhEVIiBAxe1y+W1Lnv1AVC2Ad8itYOVinoQbe cKZuHYRI= X-Gm-Gg: AZFdTZcSq8DRjz5+9UvCSra4VIkPKUkV0WtI4PyynCo+OB18seJenFDXFIPeelpz0bq da8TOfww64f5dBJXHAqnWb5JzziTaig9dctwHHzLgFgl8flDY4iKf3F7ITLZrJg61BUEHeER6u0 xAuOY/tFvNEeiqALa64Esihy2Wd1BgfEJroDzb6KaHiZqYuaRSHBoYEPYWgQANzHN3UbjivIeZZ KN1SxnwYa6ToGawYYr3Z5JMnVFFauaPydu1lc1NzvQOWuDEXaS0Zgk7WW4aF0pvXFRtSMS5Fdl4 9sDGVlmwGqIlY09YFmNyUOteBelAuaXgRJbEfyN0VPNQRODvNOxrxx5CDHY2U0QSdqdlczDlRi8 gxKWY/qfa7aki7TdEiHvmGKlAU01uTd+LMvxUzjc5F4XpNhcp/igpVLJrUUwpW2EkGV2SfDgn7W kEmlnHu9gB20eCDjGeXyXp1ZAE9AnzkD86QQ2V4Btm2BKvya1LIzj5Hl8iwwZX8J3mtr4WWEI15 hMSH+/bzbHhcPkhSn0eaj1/GFc/NsYQgs565LfK4NjZ0Tsidzg3HVlMwTLGtSW3p8Wr4FQbvFxz EoH9wyZ7Evm23/Ih/e0IsU6ftIf7JhCVzwXxTOTWyigtxZNAnFzSV0/bU3eFVe2zl+5lWwT5X1K vMmAnnP03ZZNmtIf+Bb9e0XedW+Q= 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: netdev@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);