Merge branch 'net-avoid-truncated-transport-header-offsets'

Eric Dumazet says:

====================
net: avoid truncated transport header offsets

skb->transport_header is a 16-bit offset from skb->head, and U16_MAX
is reserved as the "not set" value. skb_set_transport_header() silently
truncates an offset that does not fit.

The first patch addresses the report from Hyunwoo Kim, by applying
the IP6_MAX_EXT_HDRS_CNT limit to ipv6_gro_pull_exthdrs().

The four following patches convert places storing an offset derived
from an IPv6 extension header walk to skb_set_transport_header_careful().
A single chain being bounded to 24576 bytes, these need a large
skb->data - skb->head to overflow, for instance after nested
decapsulations. They are hardening, no reproducer was written.

The same change for nf_ct_frag6_gather() is sent separately to
the netfilter tree.
====================

Link: https://patch.msgid.link/[email protected]
Signed-off-by: Paolo Abeni <[email protected]>
This commit is contained in:
Paolo Abeni
2026-11-19 13:10:30 +01:00
5 changed files with 20 additions and 6 deletions
+8
View File
@@ -26,6 +26,7 @@ static int ipv6_gro_pull_exthdrs(struct sk_buff *skb, int off, int proto)
{
const struct net_offload *ops = NULL;
struct ipv6_opt_hdr *opth;
int exthdr_cnt = 0;
for (;;) {
int len;
@@ -38,6 +39,13 @@ static int ipv6_gro_pull_exthdrs(struct sk_buff *skb, int off, int proto)
if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
break;
/* Same limit as ip6_protocol_deliver_rcu().
* @proto is left pointing to an extension header,
* so that the caller does not aggregate this packet.
*/
if (unlikely(exthdr_cnt++ >= IP6_MAX_EXT_HDRS_CNT))
break;
opth = skb_gro_header(skb, off + sizeof(*opth), off);
if (unlikely(!opth))
break;
+2 -1
View File
@@ -56,7 +56,8 @@ static int ipv6_mc_check_exthdrs(struct sk_buff *skb)
if (nexthdr != IPPROTO_ICMPV6)
return -ENOMSG;
skb_set_transport_header(skb, offset);
if (!skb_set_transport_header_careful(skb, offset))
return -EINVAL;
return 0;
}
+4 -3
View File
@@ -651,12 +651,13 @@ static struct sock *__udp6_lib_err_encap(struct net *net,
network_offset = skb_network_offset(skb);
transport_offset = skb_transport_offset(skb);
/* Transport header needs to point to the UDP header */
if (unlikely(!skb_set_transport_header_careful(skb, offset)))
return ERR_PTR(-EINVAL);
/* Network header needs to point to the outer IPv6 header inside ICMP */
skb_reset_network_header(skb);
/* Transport header needs to point to the UDP header */
skb_set_transport_header(skb, offset);
if (sk) {
up = udp_sk(sk);
+2 -1
View File
@@ -438,7 +438,8 @@ static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key)
return -EPROTO;
nh_len = payload_ofs - nh_ofs;
skb_set_transport_header(skb, nh_ofs + nh_len);
if (unlikely(!skb_set_transport_header_careful(skb, payload_ofs)))
return -EPROTO;
key->ip.proto = nexthdr;
return nh_len;
}
+4 -1
View File
@@ -170,8 +170,11 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
/* Fix up skb to look at the embedded net header. */
saveip = skb->network_header;
savesctp = skb->transport_header;
if (unlikely(!skb_set_transport_header_careful(skb, offset))) {
__ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
return -EINVAL;
}
skb_reset_network_header(skb);
skb_set_transport_header(skb, offset);
sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
/* Put back, the original pointers. */
skb->network_header = saveip;