* [PATCH net 1/5] ipv6: gro: limit the number of extension headers
2026-11-13 12:46 [PATCH net 0/5] net: avoid truncated transport header offsets Eric Dumazet
@ 2026-11-13 12:46 ` Eric Dumazet
2026-11-13 12:58 ` Hyunwoo Kim
` (2 more replies)
2026-11-13 12:46 ` [PATCH net 2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs() Eric Dumazet
` (4 subsequent siblings)
5 siblings, 3 replies; 13+ messages in thread
From: Eric Dumazet @ 2026-11-13 12:46 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp,
dev, Eric Dumazet, stable
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.
Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")
Cc: stable@vger.kernel.org
Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
Link: https://lore.kernel.org/netdev/avTTQNyvwPP6LtGx@v4bel/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@kernel.org>
Cc: Ido Schimmel <idosch@nvidia.com>
---
net/ipv6/ip6_offload.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
index 700f1861d8eb..01642900c0fa 100644
--- a/net/ipv6/ip6_offload.c
+++ b/net/ipv6/ip6_offload.c
@@ -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.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
2026-11-13 12:46 ` [PATCH net 1/5] ipv6: gro: limit the number of extension headers Eric Dumazet
@ 2026-11-13 12:58 ` Hyunwoo Kim
2026-11-16 11:33 ` Ido Schimmel
2026-11-16 15:47 ` netdev-bot+sashiko
2 siblings, 0 replies; 13+ messages in thread
From: Hyunwoo Kim @ 2026-11-13 12:58 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, netdev, linux-sctp, dev, stable,
imv4bel
On Fri, Nov 13, 2026 at 01:46:21PM +0100, Eric Dumazet wrote:
> 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.
>
> Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")
> Cc: stable@vger.kernel.org
> Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
> Link: https://lore.kernel.org/netdev/avTTQNyvwPP6LtGx@v4bel/
Tested-by: Hyunwoo Kim <imv4bel@gmail.com>
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: David Ahern <dsahern@kernel.org>
> Cc: Ido Schimmel <idosch@nvidia.com>
> ---
> net/ipv6/ip6_offload.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
> index 700f1861d8eb..01642900c0fa 100644
> --- a/net/ipv6/ip6_offload.c
> +++ b/net/ipv6/ip6_offload.c
> @@ -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.53.0
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
2026-11-13 12:46 ` [PATCH net 1/5] ipv6: gro: limit the number of extension headers Eric Dumazet
2026-11-13 12:58 ` Hyunwoo Kim
@ 2026-11-16 11:33 ` Ido Schimmel
2026-11-16 15:47 ` netdev-bot+sashiko
2 siblings, 0 replies; 13+ messages in thread
From: Ido Schimmel @ 2026-11-16 11:33 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
David Ahern, Willem de Bruijn, Marcelo Ricardo Leitner, Xin Long,
Aaron Conole, Eelco Chaudron, Ilya Maximets, Daniel Borkmann,
Justin Iurman, Linus Lüssing, Sabrina Dubroca,
Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp, dev, stable
On Fri, Nov 13, 2026 at 01:46:21PM +0100, Eric Dumazet wrote:
> 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.
>
> Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")
> Cc: stable@vger.kernel.org
> Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
> Link: https://lore.kernel.org/netdev/avTTQNyvwPP6LtGx@v4bel/
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: David Ahern <dsahern@kernel.org>
> Cc: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH net 1/5] ipv6: gro: limit the number of extension headers
2026-11-13 12:46 ` [PATCH net 1/5] ipv6: gro: limit the number of extension headers Eric Dumazet
2026-11-13 12:58 ` Hyunwoo Kim
2026-11-16 11:33 ` Ido Schimmel
@ 2026-11-16 15:47 ` netdev-bot+sashiko
2 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 15:47 UTC (permalink / raw)
To: edumazet
Cc: davem, kuba, pabeni, horms, dsahern, idosch,
willemdebruijn.kernel, marcelo.leitner, lucien.xin, aconole,
echaudro, i.maximets, daniel, justin.iurman, linus.luessing, sd,
sbrivio, imv4bel, netdev, linux-sctp, dev, stable
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().
Link: https://lore.kernel.org/netdev/avTTQNyvwPP6LtGx@v4bel/
> diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
> index 700f1861d8eb7..01642900c0fa3 100644
> --- a/net/ipv6/ip6_offload.c
> +++ b/net/ipv6/ip6_offload.c
> @@ -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;
[Severity: High]
Does this fully close the out-of-bounds read in
gro_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?
> opth = skb_gro_header(skb, off + sizeof(*opth), off);
> if (unlikely(!opth))
> break;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs()
2026-11-13 12:46 [PATCH net 0/5] net: avoid truncated transport header offsets Eric Dumazet
2026-11-13 12:46 ` [PATCH net 1/5] ipv6: gro: limit the number of extension headers Eric Dumazet
@ 2026-11-13 12:46 ` Eric Dumazet
2026-11-16 11:45 ` Ido Schimmel
2026-11-13 12:46 ` [PATCH net 3/5] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr() Eric Dumazet
` (3 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Eric Dumazet @ 2026-11-13 12:46 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp,
dev, Eric Dumazet, stable
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.
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).
Fixes: 9afd85c9e455 ("net: Export IGMP/MLD message validation code")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/ipv6/mcast_snoop.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/mcast_snoop.c b/net/ipv6/mcast_snoop.c
index 04d5fcdfa6e0..7abf79815aa2 100644
--- a/net/ipv6/mcast_snoop.c
+++ b/net/ipv6/mcast_snoop.c
@@ -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;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH net 2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs()
2026-11-13 12:46 ` [PATCH net 2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs() Eric Dumazet
@ 2026-11-16 11:45 ` Ido Schimmel
0 siblings, 0 replies; 13+ messages in thread
From: Ido Schimmel @ 2026-11-16 11:45 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
David Ahern, Willem de Bruijn, Marcelo Ricardo Leitner, Xin Long,
Aaron Conole, Eelco Chaudron, Ilya Maximets, Daniel Borkmann,
Justin Iurman, Linus Lüssing, Sabrina Dubroca,
Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp, dev, stable
On Fri, Nov 13, 2026 at 01:46:22PM +0100, Eric Dumazet wrote:
> 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.
>
> 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).
>
> Fixes: 9afd85c9e455 ("net: Export IGMP/MLD message validation code")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 3/5] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr()
2026-11-13 12:46 [PATCH net 0/5] net: avoid truncated transport header offsets Eric Dumazet
2026-11-13 12:46 ` [PATCH net 1/5] ipv6: gro: limit the number of extension headers Eric Dumazet
2026-11-13 12:46 ` [PATCH net 2/5] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs() Eric Dumazet
@ 2026-11-13 12:46 ` Eric Dumazet
2026-11-13 12:46 ` [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err() Eric Dumazet
` (2 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Eric Dumazet @ 2026-11-13 12:46 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp,
dev, Eric Dumazet, stable
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.
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.
Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/openvswitch/flow.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 3734416b518d..5fbeb0cca9dc 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -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;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
2026-11-13 12:46 [PATCH net 0/5] net: avoid truncated transport header offsets Eric Dumazet
` (2 preceding siblings ...)
2026-11-13 12:46 ` [PATCH net 3/5] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr() Eric Dumazet
@ 2026-11-13 12:46 ` Eric Dumazet
2026-11-16 15:47 ` netdev-bot+sashiko
2026-11-13 12:46 ` [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap() Eric Dumazet
2026-11-14 20:17 ` [PATCH net 0/5] net: avoid truncated transport header offsets Justin Iurman
5 siblings, 1 reply; 13+ messages in thread
From: Eric Dumazet @ 2026-11-13 12:46 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp,
dev, Eric Dumazet, stable
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.
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.
Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/sctp/ipv6.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 97390569c4bd..ad5c951efdf0 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -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;
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
2026-11-13 12:46 ` [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err() Eric Dumazet
@ 2026-11-16 15:47 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 15:47 UTC (permalink / raw)
To: edumazet
Cc: davem, kuba, pabeni, horms, dsahern, idosch,
willemdebruijn.kernel, marcelo.leitner, lucien.xin, aconole,
echaudro, i.maximets, daniel, justin.iurman, linus.luessing, sd,
sbrivio, imv4bel, netdev, linux-sctp, dev, stable
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.
> diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
> index 97390569c4bdc..ad5c951efdf06 100644
> --- a/net/sctp/ipv6.c
> +++ b/net/sctp/ipv6.c
> @@ -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.
> /* 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
2026-11-13 12:46 [PATCH net 0/5] net: avoid truncated transport header offsets Eric Dumazet
` (3 preceding siblings ...)
2026-11-13 12:46 ` [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err() Eric Dumazet
@ 2026-11-13 12:46 ` Eric Dumazet
2026-11-15 14:40 ` Stefano Brivio
2026-11-14 20:17 ` [PATCH net 0/5] net: avoid truncated transport header offsets Justin Iurman
5 siblings, 1 reply; 13+ messages in thread
From: Eric Dumazet @ 2026-11-13 12:46 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp,
dev, Eric Dumazet, stable
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.
__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.
Fixes: a36e185e8c85 ("udp: Handle ICMP errors for tunnels with same destination port on both endpoints")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/ipv6/udp.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 9dcefa162522..a6886a0432f9 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -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.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap()
2026-11-13 12:46 ` [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap() Eric Dumazet
@ 2026-11-15 14:40 ` Stefano Brivio
0 siblings, 0 replies; 13+ messages in thread
From: Stefano Brivio @ 2026-11-15 14:40 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Justin Iurman, Linus Lüssing,
Sabrina Dubroca, Hyunwoo Kim, netdev, linux-sctp, dev, stable
On Fri, 13 Nov 2026 13:46:25 +0100
Eric Dumazet <edumazet@kernel.org> wrote:
> 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.
>
> __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.
Right, we can't call __udp6_lib_err_encap_no_sk() anyway in that case.
> Fixes: a36e185e8c85 ("udp: Handle ICMP errors for tunnels with same destination port on both endpoints")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Thanks for fixing this.
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
--
Stefano
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 0/5] net: avoid truncated transport header offsets
2026-11-13 12:46 [PATCH net 0/5] net: avoid truncated transport header offsets Eric Dumazet
` (4 preceding siblings ...)
2026-11-13 12:46 ` [PATCH net 5/5] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap() Eric Dumazet
@ 2026-11-14 20:17 ` Justin Iurman
5 siblings, 0 replies; 13+ messages in thread
From: Justin Iurman @ 2026-11-14 20:17 UTC (permalink / raw)
To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, David Ahern, Ido Schimmel, Willem de Bruijn,
Marcelo Ricardo Leitner, Xin Long, Aaron Conole, Eelco Chaudron,
Ilya Maximets, Daniel Borkmann, Linus Lüssing,
Sabrina Dubroca, Stefano Brivio, Hyunwoo Kim, netdev, linux-sctp,
dev
On 11/13/26 13:46, Eric Dumazet wrote:
> 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(-)
For the series:
Reviewed-by: Justin Iurman <justin.iurman@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread