FAILED: patch "[PATCH] ipv6: gro: limit the number of extension headers" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 050f2adb60434a2b4dee2cf3350269379a32cf72
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026120232-ozone-exemplary-0302@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 050f2adb60434a2b4dee2cf3350269379a32cf72 Mon Sep 17 00:00:00 2001
From: Eric Dumazet <[email protected]>
Date: Fri, 13 Nov 2026 13:46:21 +0100
Subject: [PATCH] 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 -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 ;
Sasha Levin
maintainerPATCH 1/2 ipv6: Implement limits on extension header parsing
From: Daniel Borkmann <[email protected]>
[ Upstream commit 3744b0964d5267c0b651bcd8f8c25db6bf4ccbac ]
ipv6_{skip_exthdr,find_hdr}() and ip6_{tnl_parse_tlv_enc_lim, protocol_deliver_rcu}() iterate over IPv6 extension headers until they find a non-extension-header protocol or run out of packet data. The loops have no iteration counter, relying solely on the packet length to bound them. For a crafted packet with 8-byte extension headers filling a 64KB jumbogram, this means a worst case of up to ~8k iterations with a skb_header_pointer call each. ipv6_skip_exthdr(), for example, is used where it parses the inner quoted packet inside an incoming ICMPv6 error:
- icmpv6_rcv
- checksum validation
- case ICMPV6_DEST_UNREACH
- icmpv6_notify
- pskb_may_pull() <- pull inner IPv6 header
- ipv6_skip_exthdr() <- iterates here
- pskb_may_pull()
- ipprot->err_handler() <- sk lookup
The per-iteration cost of ipv6_skip_exthdr itself is generally light, but skb_header_pointer becomes more costly on reassembled
packets: the first ~1232 bytes of the inner packet are in the skb's linear area, but the remaining ~63KB are in the frag_list where skb_copy_bits is needed to read data.
Initially, the idea was to add a configurable limit via a new sysctl knob with default 8, in line with knobs from commit 47d3d7ac656a ("ipv6: Implement limits on Hop-by-Hop and Destination options"), but two reasons eventually argued against it:
- It adds to UAPI that needs to be maintained forever, and upcoming work is restricting extension header ordering anyway, leaving little reason for another sysctl knob
- exthdrs_core.c is always built-in even when CONFIG_IPV6=n, where struct net has no .ipv6 member, so the read site would need an ifdef'd fallback to a constant anyway
Therefore, just use a constant (IP6_MAX_EXT_HDRS_CNT). All four extension header walking functions are now bound by this limit.
Note that the check in ip6_protocol_deliver_rcu() happens right before the goto resubmit, such that we don't have to have a test for ipv6_ext_hdr() in the fast-path.
There's an ongoing IETF draft-iurman-6man-eh-occurrences to enforce IPv6 extension headers ordering and occurrence. The latter also discusses security implications. As per RFC8200 section 4.1, the occurrence rules for extension headers provide a practical upper bound which is 8. In order to be conservative, let's define IP6_MAX_EXT_HDRS_CNT as 12 to leave enough room for quirky setups. In the unlikely event that this is still not enough, then we might need to reconsider a sysctl.
Stable-dep-of: 050f2adb6043 ("ipv6: gro: limit the number of extension headers")
--- include/net/dropreason-core.h | 6 ++++++ include/net/ipv6.h | 3 +++ net/ipv6/exthdrs_core.c | 7 +++++++ net/ipv6/ip6_input.c | 5 +++++ net/ipv6/ip6_tunnel.c | 4 ++++ 5 files changed, 25 insertions(+)
include/net/dropreason-core.h +6 -0
@@ -88,6 +88,7 @@ FN(FRAG_TOO_FAR) \ FN(TCP_MINTTL) \ FN(IPV6_BAD_EXTHDR) \ + FN(IPV6_TOO_MANY_EXTHDRS) \ FN(IPV6_NDISC_FRAG) \ FN(IPV6_NDISC_HOP_LIMIT) \ FN(IPV6_NDISC_BAD_CODE) \
@@ -425,6 +426,11 @@ enum skb_drop_reason {SKB_DROP_REASON_TCP_MINTTL ,/** @SKB_DROP_REASON_IPV6_BAD_EXTHDR: Bad IPv6 extension header. */ SKB_DROP_REASON_IPV6_BAD_EXTHDR , +/** +* @SKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS: Number of IPv6 extension +* headers in the packet exceeds IP6_MAX_EXT_HDRS_CNT. +*/ +SKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS ,/** @SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc). */ SKB_DROP_REASON_IPV6_NDISC_FRAG,/** @SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit. */
include/net/ipv6.h +3 -0
@@ -90,6 +90,9 @@ struct ip_tunnel_info;#define IP6_DEFAULT_MAX_DST_OPTS_LEN INT_MAX/* No limit */ #define IP6_DEFAULT_MAX_HBH_OPTS_LEN INT_MAX/* No limit */ +/* Hard limit on traversed IPv6 extension headers */ +#define IP6_MAX_EXT_HDRS_CNT 12 +/* * Addr type *
net/ipv6/exthdrs_core.c +7 -0
@@ -73,6 +73,7 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, __be16 *frag_offp) {u8 nexthdr = *nexthdrp; +int exthdr_cnt =0 ; *frag_offp =0 ;
@@ -82,6 +83,8 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp,if (nexthdr ==NEXTHDR_NONE )return -1 ; +if (unlikely (exthdr_cnt++ >=IP6_MAX_EXT_HDRS_CNT )) +return -1 ; hp =skb_header_pointer (skb, start,sizeof (_hdr), &_hdr);if (!hp)return -1 ;
@@ -191,6 +194,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, {unsigned int start =skb_network_offset (skb) +sizeof (struct ipv6hdr );u8 nexthdr =ipv6_hdr (skb)->nexthdr; +int exthdr_cnt =0 ;bool found;if (fragoff)
@@ -217,6 +221,9 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,return -ENOENT ; } +if (unlikely (exthdr_cnt++ >=IP6_MAX_EXT_HDRS_CNT )) +return -EBADMSG ; + hp =skb_header_pointer (skb, start,sizeof (_hdr), &_hdr);if (!hp)return -EBADMSG ;
net/ipv6/ip6_input.c +5 -0
@@ -363,6 +363,7 @@ INDIRECT_CALLABLE_DECLARE(int tcp_v6_rcv(struct sk_buff *));void ip6_protocol_deliver_rcu (struct net *net,struct sk_buff *skb,int nexthdr,bool have_final) { +int exthdr_cnt =IP6CB (skb)->flags &IP6SKB_HOPBYHOP ?1 :0 ;const struct inet6_protocol *ipprot;struct inet6_dev *idev;unsigned int nhoff;
@@ -451,6 +452,10 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, nexthdr = ret; goto resubmit_final; }else { +if (unlikely (exthdr_cnt++ >=IP6_MAX_EXT_HDRS_CNT )) { +SKB_DR_SET (reason,IPV6_TOO_MANY_EXTHDRS ); + goto discard; + } goto resubmit; } }else if (ret ==0 ) {
net/ipv6/ip6_tunnel.c +4 -0
@@ -400,11 +400,15 @@ __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw)unsigned int nhoff = raw - skb->data;unsigned int off = nhoff +sizeof (*ipv6h);u8 nexthdr = ipv6h->nexthdr; +int exthdr_cnt =0 ;while (ipv6_ext_hdr (nexthdr) && nexthdr !=NEXTHDR_NONE ) {struct ipv6_opt_hdr *hdr;u16 optlen; +if (unlikely (exthdr_cnt++ >=IP6_MAX_EXT_HDRS_CNT )) +break ; +if (!pskb_may_pull (skb, off +sizeof (*hdr)))break ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ipv6: gro: limit the number of extension headers
From: Eric Dumazet <[email protected]>
[ Upstream commit 050f2adb60434a2b4dee2cf3350269379a32cf72 ]
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
@@ -42,6 +42,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;
@@ -54,6 +55,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