net: avoid truncated transport header offsets
Subsystems (7)
Eric Dumazet
maintainercover 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.
Eric Dumazet (5):
ipv6: gro: limit the number of extension headers
ipv6: mcast: use skb_set_transport_header_careful() in
ipv6_mc_check_exthdrs()
net: openvswitch: use skb_set_transport_header_careful() in
parse_ipv6hdr() sctp: use skb_set_transport_header_careful() in sctp_v6_err()
udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
net/ipv6/ip6_offload.c | 8 ++++++++ net/ipv6/mcast_snoop.c | 3 ++- net/ipv6/udp.c | 7 ++++--- net/openvswitch/flow.c | 3 ++- net/sctp/ipv6.c | 5 ++++- 5 files changed, 20 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0
Eric Dumazet
maintainerPATCH 1/5 ipv6: gro: limit the number of extension headers
Hyunwoo Kim reported that a long chain of IPv6 extension headers can push the transport header offset of a GRO packet beyond what the 16-bit skb->transport_header can store. The truncated offset is later used by gro_receive_network_flush() to locate the network header of a packet held in the GRO list, leading to an out-of-bounds read.
Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing"), ip6_protocol_deliver_rcu() drops packets carrying more than IP6_MAX_EXT_HDRS_CNT extension headers, but ipv6_gro_pull_exthdrs() was left unbounded.
There is no point trying to aggregate packets that the stack is going to drop anyway if they are locally delivered. Apply the same limit in ipv6_gro_pull_exthdrs().
When the limit is hit, @proto still designates an extension header. Extension header offloads have no gro_receive() callback, so ipv6_gro_receive() takes its existing "goto out" path with flush set, and the packet is given to the normal receive path. Local delivery drops it with SKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS, while forwarded packets are simply not aggregated.
An extension header being at most 2048 bytes, this bounds a chain to 24576 bytes.
Note that offsets can still accumulate over nested encapsulations, so the places storing them should be hardened separately.
--- net/ipv6/ip6_offload.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/ipv6/ip6_offload.c +8 -0
@@ -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 ;
Signature · 1 line
2.53.0
Re: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
Quoted 26 lines · Eric Dumazet
Hyunwoo Kim reported that a long chain of IPv6 extension headers can push the transport header offset of a GRO packet beyond what the 16-bit
skb->transport_headercan store. The truncated offset is later used bygro_receive_network_flush()to locate the network header of a packet held in the GRO list, leading to an out-of-bounds read.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing"),ip6_protocol_deliver_rcu()drops packets carrying more thanIP6_MAX_EXT_HDRS_CNTextension headers, butipv6_gro_pull_exthdrs()was left unbounded.There is no point trying to aggregate packets that the stack is going to drop anyway if they are locally delivered. Apply the same limit in
ipv6_gro_pull_exthdrs().When the limit is hit, @proto still designates an extension header. Extension header offloads have no
gro_receive()callback, soipv6_gro_receive()takes its existing "goto out" path with flush set, and the packet is given to the normal receive path. Local delivery drops it withSKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS, while forwarded packets are simply not aggregated.An extension header being at most 2048 bytes, this bounds a chain to 24576 bytes.
Quoted 7 lines
Note that offsets can still accumulate over nested encapsulations, so the places storing them should be hardened separately.
Fixes 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")Reported-by Hyunwoo Kim <[email protected]>
Quoted 37 lines
Signed-off-by Eric Dumazet <[email protected]>Cc Daniel Borkmann <[email protected]>Cc David Ahern <[email protected]>Cc Ido Schimmel <[email protected]>--- net/ipv6/ip6_offload.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/ipv6/ip6_offload.c +8
-0@@ -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 ;Signature · 1 line
2.53.0
Re: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
In reply to Eric DumazetQuoted 29 lines · Eric Dumazet
Hyunwoo Kim reported that a long chain of IPv6 extension headers can push the transport header offset of a GRO packet beyond what the 16-bit
skb->transport_headercan store. The truncated offset is later used bygro_receive_network_flush()to locate the network header of a packet held in the GRO list, leading to an out-of-bounds read.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing"),ip6_protocol_deliver_rcu()drops packets carrying more thanIP6_MAX_EXT_HDRS_CNTextension headers, butipv6_gro_pull_exthdrs()was left unbounded.There is no point trying to aggregate packets that the stack is going to drop anyway if they are locally delivered. Apply the same limit in
ipv6_gro_pull_exthdrs().When the limit is hit, @proto still designates an extension header. Extension header offloads have no
gro_receive()callback, soipv6_gro_receive()takes its existing "goto out" path with flush set, and the packet is given to the normal receive path. Local delivery drops it withSKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS, while forwarded packets are simply not aggregated.An extension header being at most 2048 bytes, this bounds a chain to 24576 bytes.
Note that offsets can still accumulate over nested encapsulations, so the places storing them should be hardened separately.
Quoted 8 lines
Fixes 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")Reported-by Hyunwoo Kim <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Daniel Borkmann <[email protected]>Cc David Ahern <[email protected]>Cc Ido Schimmel <[email protected]>
[email protected]
AI reviewRe: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
In reply to Eric DumazetThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
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] This patch caps extension headers per IPv6 GRO layer.
--
ipv6: gro: limit the number of extension headers
The patch caps the number of extension headers that ipv6_gro_pull_exthdrs() walks at IP6_MAX_EXT_HDRS_CNT, matching ip6_protocol_deliver_rcu(). The goal is to keep the GRO transport header offset from overflowing the 16-bit skb->transport_header and causing an out-of-bounds read in gro_receive_network_flush().
Quoted 13 lines
net/ipv6/ip6_offload.c +1
-0@@ -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;
net/ipv6/ip6_offload.c static int ipv6_gro_pull_exthdrs(struct sk_buff *skb, int off, int proto) · line 47
Quoted 9 lines
net/ipv6/ip6_offload.c +6
-0@@ -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 ;
[Severity: High]
Does this fully close the out-of-bounds read ingro_receive_network_flush()?
exthdr_cnt is local and starts at 0 on every call. That bounds each ipv6_gro_receive() pass to roughly 40 + 12 * 2048 bytes, but it does not bound the transport offset of the whole packet.
Within a single GRO pass, sit_ip6ip6_gro_receive() sets encap_mark and calls back into ipv6_gro_receive() for an inner IPv6 header. Each layer's ipv6_gro_pull_exthdrs() call is allowed another 12 extension headers:
ipv6_gro_receive()
ipv6_gro_pull_exthdrs() /* up to 12 exthdrs */
sit_ip6ip6_gro_receive()
ipv6_gro_receive()
ipv6_gro_pull_exthdrs() /* another 12 exthdrs */
skb->transport_header is also measured from skb->head, so headroom counts toward it. __ip6_tnl_rcv() in net/ipv6/ip6_tunnel.c hands the decapsulated skb back to GRO:
gro_cells_receive(&tunnel->gro_cells, skb);
The outer headers stay in the buffer as headroom. That outer layer was only checked by ip6_protocol_deliver_rcu(), which also allows 12 extension headers.
Put together, headroom + outer + inner + inner-inner headers can add up to more than 65535 bytes inside one IPv6 datagram. At that point, this store in ipv6_gro_receive() silently wraps the __u16:
skb_set_transport_header(skb, skb_gro_offset(skb));
inet_gro_receive() in net/ipv4/af_inet.c has the same pattern for an inner IPv4 header.
Suppose a second packet of the same flow then arrives. tcp_gro_receive() takes th2 = tcp_hdr(p) at the wrapped offset. That offset lands in outer header bytes the sender controls, so the port check in tcp_gro_lookup() can be made to match. gro_receive_network_flush() then runs:
int off = skb_transport_offset(p);
...
flush = __gro_receive_network_flush(th, th2, p, off - NAPI_GRO_CB(p)->network_offset, false);off is negative here, so the u16 diff ends up large. In __gro_receive_network_flush(), nh2 = th2 - diff then points tens of KB before p->head. Isn't that the same out-of-bounds read this patch is meant to fix?
The commit message notes that "offsets can still accumulate over nested encapsulations, so the places storing them should be hardened separately". The rest of the series adds skb_set_transport_header_careful() in ipv6_mc_check_exthdrs(), parse_ipv6hdr(), sctp_v6_err() and __udp6_lib_err_encap(). It does not touch the two GRO store sites in ipv6_gro_receive() and inet_gro_receive() that feed gro_receive_network_flush().
The patch carries Fixes: and Cc: stable. Should those two GRO sites also use skb_set_transport_header_careful(), and flush when it fails, so that backports close the reported read as well?
Quoted 3 lines
net/ipv6/ip6_offload.c +0
-0opth =skb_gro_header (skb, off +sizeof (*opth), off);if (unlikely (!opth))break ;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
Re: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
In reply to Eric DumazetQuoted 37 lines · Eric Dumazet
Hyunwoo Kim reported that a long chain of IPv6 extension headers can push the transport header offset of a GRO packet beyond what the 16-bit
skb->transport_headercan store. The truncated offset is later used bygro_receive_network_flush()to locate the network header of a packet held in the GRO list, leading to an out-of-bounds read.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing"),ip6_protocol_deliver_rcu()drops packets carrying more thanIP6_MAX_EXT_HDRS_CNTextension headers, butipv6_gro_pull_exthdrs()was left unbounded.There is no point trying to aggregate packets that the stack is going to drop anyway if they are locally delivered. Apply the same limit in
ipv6_gro_pull_exthdrs().When the limit is hit, @proto still designates an extension header. Extension header offloads have no
gro_receive()callback, soipv6_gro_receive()takes its existing "goto out" path with flush set, and the packet is given to the normal receive path. Local delivery drops it withSKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS, while forwarded packets are simply not aggregated.An extension header being at most 2048 bytes, this bounds a chain to 24576 bytes.
Note that offsets can still accumulate over nested encapsulations, so the places storing them should be hardened separately.
Fixes 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")Reported-by Hyunwoo Kim <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Daniel Borkmann <[email protected]>Cc David Ahern <[email protected]>Cc Ido Schimmel <[email protected]>
Quoted 1 line
---
Eric Dumazet
maintainerPATCH 2/5 ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs()
In reply to Eric Dumazetskb->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.
ipv6_mc_check_exthdrs() stores the offset returned by ipv6_skip_exthdr(), which depends on the extension headers found in the packet. Should the value be truncated, ipv6_mc_check_icmpv6() and ipv6_mc_check_mld_msg() would then validate and parse the MLD message at the wrong place.
Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening.
Use skb_set_transport_header_careful() and treat such a packet as broken (-EINVAL).
--- net/ipv6/mcast_snoop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/mcast_snoop.c +2 -1
@@ -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 ; }
Signature · 1 line
2.53.0
Re: [PATCH net 2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs()
Quoted 16 lines · Eric Dumazet
skb->transport_headeris a 16-bit offset fromskb->head, andU16_MAXis reserved as the "not set" value.skb_set_transport_header()silently truncates an offset that does not fit.
ipv6_mc_check_exthdrs()stores the offset returned byipv6_skip_exthdr(), which depends on the extension headers found in the packet. Should the value be truncated,ipv6_mc_check_icmpv6()andipv6_mc_check_mld_msg()would then validate and parse the MLD message at the wrong place.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing") a single chain is bounded toIP6_MAX_EXT_HDRS_CNTheaders (24576 bytes), so this needs a largeskb->data-skb->headon top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening.
Quoted 6 lines
Use
skb_set_transport_header_careful()and treat such a packet as broken (-EINVAL).Fixes 9afd85c9e455 ("net: Export IGMP/MLD message validation code")Signed-off-by Eric Dumazet <[email protected]>
Eric Dumazet
maintainerPATCH 3/5 net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr()
In reply to Eric Dumazetskb->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.
parse_ipv6hdr() stores the payload offset found by ipv6_find_hdr(), which depends on the extension headers found in the packet. Should the value be truncated, key_extract_l3l4() would parse the L4 header at the wrong place.
Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening.
Use skb_set_transport_header_careful() and return -EPROTO if the offset can not be stored. As for other ipv6_find_hdr() failures, the caller then sets the transport header to the network header and does not parse L4. While at it, use payload_ofs directly, since nh_ofs + nh_len == payload_ofs.
--- net/openvswitch/flow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/openvswitch/flow.c +2 -1
@@ -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; }
Signature · 1 line
2.53.0
Re: [PATCH net 3/5] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr()
Quoted 34 lines · Eric Dumazet
skb->transport_headeris a 16-bit offset fromskb->head, andU16_MAXis reserved as the "not set" value.skb_set_transport_header()silently truncates an offset that does not fit.
parse_ipv6hdr()stores the payload offset found byipv6_find_hdr(), which depends on the extension headers found in the packet. Should the value be truncated,key_extract_l3l4()would parse the L4 header at the wrong place.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing") a single chain is bounded toIP6_MAX_EXT_HDRS_CNTheaders (24576 bytes), so this needs a largeskb->data-skb->headon top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening.Use
skb_set_transport_header_careful()and return-EPROTOif the offset can not be stored. As for otheripv6_find_hdr()failures, the caller then sets the transport header to the network header and does not parse L4. While at it, usepayload_ofsdirectly, sincenh_ofs+nh_len==payload_ofs.Fixes 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")Signed-off-by Eric Dumazet <[email protected]>--- net/openvswitch/flow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/openvswitch/flow.c +0
-0
net/openvswitch/flow.c static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key) · line 445
Quoted 9 lines
net/openvswitch/flow.c +2
-1@@ -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; }
We don't really need the nh_len variable anymore in this function, but I guess it can be used as sort of a documentation for what the function is returning. So, it's OK to keep.
Re: [PATCH net 3/5] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr()
In reply to Eric DumazetQuoted 22 lines · Eric Dumazet
skb->transport_headeris a 16-bit offset fromskb->head, andU16_MAXis reserved as the "not set" value.skb_set_transport_header()silently truncates an offset that does not fit.
parse_ipv6hdr()stores the payload offset found byipv6_find_hdr(), which depends on the extension headers found in the packet. Should the value be truncated,key_extract_l3l4()would parse the L4 header at the wrong place.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing") a single chain is bounded toIP6_MAX_EXT_HDRS_CNTheaders (24576 bytes), so this needs a largeskb->data-skb->headon top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening.Use
skb_set_transport_header_careful()and return-EPROTOif the offset can not be stored. As for otheripv6_find_hdr()failures, the caller then sets the transport header to the network header and does not parse L4. While at it, usepayload_ofsdirectly, sincenh_ofs+nh_len==payload_ofs.
Quoted 4 lines
Fixes 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")Signed-off-by Eric Dumazet <[email protected]>---
Eric Dumazet
maintainerPATCH 4/5 sctp: use skb_set_transport_header_careful() in sctp_v6_err()
In reply to Eric Dumazetskb->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.
sctp_v6_err() stores @offset, computed by icmpv6_notify() from the extension headers of the packet embedded in an ICMPv6 error. Should the value be truncated, sctp_err_lookup() would read the SCTP header at the wrong place.
Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain, since @offset is relative to the IPv6 header embedded in the ICMPv6 error. No reproducer was written, this is hardening.
Use skb_set_transport_header_careful() and ignore the ICMPv6 error if the offset can not be stored. Do this before changing the network header, so that nothing has to be restored on failure.
--- net/sctp/ipv6.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/sctp/ipv6.c +4 -1
@@ -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;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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).
- [Medium] The main part of this concern is fixed later in the series.
--
sctp: use skb_set_transport_header_careful() in sctp_v6_err()
sctp_v6_err() now stores the ICMPv6 inner transport offset with skb_set_transport_header_careful(). If the offset does not fit in the 16-bit skb->transport_header field, the ICMPv6 error is ignored. Before, the offset was silently truncated and sctp_err_lookup() read the SCTP header from the wrong place.
Quoted 5 lines
net/sctp/ipv6.c +0
-0
net/sctp/ipv6.c static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 178
Quoted 10 lines
net/sctp/ipv6.c +4
-1@@ -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);
[Severity: Medium]
This covers native SCTP. Can the SCTP-over-UDPv6 handler in the same file still hand a wrapped transport header to sctp_err_lookup()?
sctp_udp_v6_err() is installed as encap_err_lookup. It still does an unchecked 16-bit add:
net/sctp/ipv6.c:sctp_udp_v6_err() {
...
skb->transport_header += sizeof(struct udphdr);
sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &t);
...
}A later patch in this series ("udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()") makes __udp6_lib_err_encap() store the UDP header offset carefully. That check only makes sure the UDP header offset itself fits and is not U16_MAX, so transport_header can still be as high as 0xFFFE when sctp_udp_v6_err() runs.
For a UDP header offset between 0xFFF7 and 0xFFFE, adding 8 gives a bad value:
- 0xFFF7 becomes 0xFFFF, the "not set" value. With CONFIG_DEBUG_NET this trips the DEBUG_NET_WARN_ON_ONCE() in skb_transport_header().
- 0xFFF8 to 0xFFFE wrap to 0..6, so sctp_hdr(skb) points at
skb->head + 0..6.
In the wrapped case, sctp_err_lookup() reads vtag from the wrong bytes. sctp_v6_from_skb(), called through af->from_skb, also reads sh->source and sh->dest from there for the association lookup. When vtag == 0, the INIT chunk is read with skb_header_pointer() at a negative skb_transport_offset().
The commit message says "Should the value be truncated, sctp_err_lookup() would read the SCTP header at the wrong place". Would it make sense to also check, before the += in sctp_udp_v6_err(), that transport_header + sizeof(struct udphdr) fits in 16 bits and is not U16_MAX? Another option is for __udp6_lib_err_encap() to reserve room for the payload header.
This needs the same large skb->data - skb->head precondition the series describes, and there is no reproducer.
Quoted 2 lines
net/sctp/ipv6.c +0
-0/* Put back, the original pointers. */ skb->network_header = saveip;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
Xin Long
maintainerRe: [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
Quoted 81 lines · On Mon, Nov 16, 2026 at 10:47 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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).
- [Medium] The main part of this concern is fixed later in the series.
--
sctp: use
skb_set_transport_header_careful()insctp_v6_err()
sctp_v6_err()now stores the ICMPv6 inner transport offset withskb_set_transport_header_careful(). If the offset does not fit in the 16-bitskb->transport_headerfield, the ICMPv6 error is ignored. Before, the offset was silently truncated andsctp_err_lookup()read the SCTP header from the wrong place.Quoted 5 lines
net/sctp/ipv6.c +0
-0net/sctp/ipv6.c static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 178
Quoted 10 lines
net/sctp/ipv6.c +4
-1@@ -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);[Severity: Medium]
This covers native SCTP. Can the SCTP-over-UDPv6 handler in the same file still hand a wrapped transport header to
sctp_err_lookup()?
sctp_udp_v6_err()is installed asencap_err_lookup. It still does an unchecked 16-bit add:net/sctp/ipv6.c:sctp_udp_v6_err() { ... skb->transport_header += sizeof(struct udphdr); sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &t); ... }A later patch in this series ("udp: use
skb_set_transport_header_careful()in__udp6_lib_err_encap()") makes__udp6_lib_err_encap()store the UDP header offset carefully. That check only makes sure the UDP header offset itself fits and is notU16_MAX, sotransport_headercan still be as high as0xFFFEwhensctp_udp_v6_err()runs.For a UDP header offset between
0xFFF7and0xFFFE, adding 8 gives a bad value:-
0xFFF7becomes0xFFFF, the "not set" value. WithCONFIG_DEBUG_NETthis trips theDEBUG_NET_WARN_ON_ONCE()inskb_transport_header().
-0xFFF8to0xFFFEwrap to 0..6, sosctp_hdr(skb)points atskb->head + 0..6.In the wrapped case,
sctp_err_lookup()reads vtag from the wrong bytes.sctp_v6_from_skb(), called throughaf->from_skb, also readssh->sourceandsh->destfrom there for the association lookup. When vtag == 0, the INIT chunk is read withskb_header_pointer()at a negativeskb_transport_offset().The commit message says "Should the value be truncated,
sctp_err_lookup()would read the SCTP header at the wrong place". Would it make sense to also check, before the += insctp_udp_v6_err(), thattransport_header+ sizeof(struct udphdr) fits in 16 bits and is notU16_MAX? Another option is for__udp6_lib_err_encap()to reserve room for the payload header.
Quoted 8 lines
This needs the same large
skb->data-skb->headprecondition the series describes, and there is no reproducer.net/sctp/ipv6.c static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 180
Quoted 2 lines
net/sctp/ipv6.c +0
-0/* Put back, the original pointers. */ skb->network_header = saveip;--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
The new skb->transport_header is used by sctp_hdr(skb) in af->from_skb() in sctp_err_lookup(). I think it's better to avoid changing skb->transport_header by passing sctphdr to af->from_skb(), which also makes code cleaner.
Hi Eric, you can either continue with the idea, or discard this patch and leave it to me.
Thanks.
Paolo Abeni
maintainerRe: [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
Quoted 90 lines · Xin Long
Quoted 80 lines · On Mon, Nov 16, 2026 at 10:47 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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).
- [Medium] The main part of this concern is fixed later in the series.
--
sctp: use
skb_set_transport_header_careful()insctp_v6_err()
sctp_v6_err()now stores the ICMPv6 inner transport offset withskb_set_transport_header_careful(). If the offset does not fit in the 16-bitskb->transport_headerfield, the ICMPv6 error is ignored. Before, the offset was silently truncated andsctp_err_lookup()read the SCTP header from the wrong place.Quoted 5 lines
net/sctp/ipv6.c +0
-0net/sctp/ipv6.c static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 178
Quoted 10 lines
net/sctp/ipv6.c +4
-1@@ -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);[Severity: Medium]
This covers native SCTP. Can the SCTP-over-UDPv6 handler in the same file still hand a wrapped transport header to
sctp_err_lookup()?
sctp_udp_v6_err()is installed asencap_err_lookup. It still does an unchecked 16-bit add:net/sctp/ipv6.c:sctp_udp_v6_err() { ... skb->transport_header += sizeof(struct udphdr); sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &t); ... }A later patch in this series ("udp: use
skb_set_transport_header_careful()in__udp6_lib_err_encap()") makes__udp6_lib_err_encap()store the UDP header offset carefully. That check only makes sure the UDP header offset itself fits and is notU16_MAX, sotransport_headercan still be as high as0xFFFEwhensctp_udp_v6_err()runs.For a UDP header offset between
0xFFF7and0xFFFE, adding 8 gives a bad value:-
0xFFF7becomes0xFFFF, the "not set" value. WithCONFIG_DEBUG_NETthis trips theDEBUG_NET_WARN_ON_ONCE()inskb_transport_header().
-0xFFF8to0xFFFEwrap to 0..6, sosctp_hdr(skb)points atskb->head + 0..6.In the wrapped case,
sctp_err_lookup()reads vtag from the wrong bytes.sctp_v6_from_skb(), called throughaf->from_skb, also readssh->sourceandsh->destfrom there for the association lookup. When vtag == 0, the INIT chunk is read withskb_header_pointer()at a negativeskb_transport_offset().The commit message says "Should the value be truncated,
sctp_err_lookup()would read the SCTP header at the wrong place". Would it make sense to also check, before the += insctp_udp_v6_err(), thattransport_header+ sizeof(struct udphdr) fits in 16 bits and is notU16_MAX? Another option is for__udp6_lib_err_encap()to reserve room for the payload header.Quoted 8 lines
This needs the same large
skb->data-skb->headprecondition the series describes, and there is no reproducer.net/sctp/ipv6.c static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 180
Quoted 2 lines
net/sctp/ipv6.c +0
-0/* Put back, the original pointers. */ skb->network_header = saveip;--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
Quoted 7 lines
The new
skb->transport_headeris used bysctp_hdr(skb)inaf->from_skb()insctp_err_lookup(). I think it's better to avoid changingskb->transport_headerby passing sctphdr toaf->from_skb(), which also makes code cleaner.Hi Eric, you can either continue with the idea, or discard this patch and leave it to me.
The rework looks out-of-scope for a 'net' target. I think it should land on net-next.
And I think the missing sctp over udp call-site could be a follow-up.
/P
Eric Dumazet
maintainerPATCH 5/5 udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
In reply to Eric Dumazetskb->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.
__udp6_lib_err_encap() stores @offset, computed by icmpv6_notify() from the extension headers of the packet embedded in an ICMPv6 error. Should the value be truncated, the tunnel encap_err_lookup() and err_handler() callbacks would read the UDP header at the wrong place.
Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain, since @offset is relative to the IPv6 header embedded in the ICMPv6 error. No reproducer was written, this is hardening.
Use skb_set_transport_header_careful() and return an error if the offset can not be stored, in which case udpv6_err() ignores the ICMPv6 error. Do this before changing the network header, so that nothing has to be restored on failure.
--- net/ipv6/udp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv6/udp.c +4 -3
@@ -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);
Signature · 1 line
2.53.0
Re: [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
Quoted 17 lines · On Fri, 13 Nov 2026 13:46:25 +0100 Eric Dumazet <[email protected]> wrote:
skb->transport_headeris a 16-bit offset fromskb->head, andU16_MAXis reserved as the "not set" value.skb_set_transport_header()silently truncates an offset that does not fit.
__udp6_lib_err_encap()stores @offset, computed byicmpv6_notify()from the extension headers of the packet embedded in an ICMPv6 error. Should the value be truncated, the tunnelencap_err_lookup()anderr_handler()callbacks would read the UDP header at the wrong place.Since commit
3744b0964d52("ipv6: Implement limits on extension header parsing") a single chain is bounded toIP6_MAX_EXT_HDRS_CNTheaders (24576 bytes), so this needs a largeskb->data-skb->headon top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain, since @offset is relative to the IPv6 header embedded in the ICMPv6 error. No reproducer was written, this is hardening.
Quoted 4 lines
Use
skb_set_transport_header_careful()and return an error if the offset can not be stored, in which caseudpv6_err()ignores the ICMPv6 error. Do this before changing the network header, so that nothing has to be restored on failure.
Right, we can't call __udp6_lib_err_encap_no_sk() anyway in that case.
Quoted 3 lines
Fixes a36e185e8c85 ("udp: Handle ICMP errors for tunnels with same destination port on both endpoints")Signed-off-by Eric Dumazet <[email protected]>
Thanks for fixing this.
Signature · 1 line
Stefano
Quoted 25 lines · Eric Dumazet
skb->transport_headeris a 16-bit offset fromskb->head, andU16_MAXis 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_CNTlimit toipv6_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 largeskb->data-skb->headto 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.Eric Dumazet (5):
ipv6: gro: limit the number of extension headers
ipv6: mcast: useskb_set_transport_header_careful()inipv6_mc_check_exthdrs() net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr()sctp: use
skb_set_transport_header_careful()insctp_v6_err()
udp: useskb_set_transport_header_careful()in__udp6_lib_err_encap()
Quoted 6 lines
net/ipv6/ip6_offload.c | 8 ++++++++ net/ipv6/mcast_snoop.c | 3 ++- net/ipv6/udp.c | 7 ++++--- net/openvswitch/flow.c | 3 ++- net/sctp/ipv6.c | 5 ++++- 5 files changed, 20 insertions(+), 6 deletions(-)
For the series:
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Fri, 13 Nov 2026 13:46:20 +0100 you wrote:
skb->transport_headeris a 16-bit offset fromskb->head, andU16_MAXis 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_CNTlimit toipv6_gro_pull_exthdrs().[...]
Here is the summary with links:
- [net,1/5] ipv6: gro: limit the number of extension headers
https://git.kernel.org/netdev/net/c/050f2adb6043 - [net,2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs() https://git.kernel.org/netdev/net/c/425b1fe50b71 - [net,3/5] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr() https://git.kernel.org/netdev/net/c/b9b77e243003 - [net,4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err() https://git.kernel.org/netdev/net/c/13391f1a8c58 - [net,5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap() https://git.kernel.org/netdev/net/c/02f578b736f1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html