net: gro: avoid truncating transport header offsets
Subsystems (3)
PATCH v2 1/1 net: gro: avoid truncating transport header offsets
skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is reserved as the unset transport header value. A long IPv6 extension header chain can make the final offset exceed the field's range. skb_set_transport_header() then truncates it.
In the UDP reproducer, UDP_GRO is enabled on the receiving socket and the first packet is held on the GRO list. The truncated offset makes udp_hdr(p) point to the source MAC address. The first four bytes of the source MAC address match the UDP source and destination ports, allowing the second packet in the same flow to pass the port comparison.
gro_receive_network_flush() then derives the first packet's IPv6 header address from the truncated transport header offset. ipv6_gro_flush() consequently reads from an address 65,536 bytes before the first packet's actual IPv6 header. Both UDP and TCP GRO call gro_receive_network_flush().
KASAN reports:
BUG: KASAN: use-after-free in udp_gro_receive+0x1f37/0x2680 Read of size 4 at addr ffff8881065f005e by task swapper/1/0 ... Call Trace: <IRQ> ... udp_gro_receive+0x1f37/0x2680 udp6_gro_receive+0x23e/0x11d0 ipv6_gro_receive+0x1200/0x2750 ... dev_gro_receive+0x1a7c/0x2600 gro_receive_skb+0x271/0x970 virtnet_receive_done+0x3b5/0x12c0 receive_buf+0x33a/0x4b40 ... virtnet_poll+0xc69/0x1980 ... __napi_poll+0xa0/0x530 net_rx_action+0x8ff/0x1280 ... </IRQ>
The out-of-bounds address was in a free page, so KASAN reported a use-after-free. This classification reflects the state of that page, not the lifetime of the skb. The invalid read was caused by truncation of the 16-bit transport header offset.
The IP6_MAX_EXT_HDRS_CNT limit in ipv6_gro_pull_exthdrs() prevents this reproducer. However, nested encapsulations can each add an extension header chain, so the accumulated offset can still exceed the range of skb->transport_header. inet_gro_receive() can also be reached with such an offset.
Use skb_set_transport_header_careful() in ipv6_gro_receive() and inet_gro_receive() to validate the final offset before assigning it. If the offset cannot be represented, the skb is not held as a new GRO head and is instead delivered through the normal receive path.
This issue was found through AI-based auditing.
---
Changes in v2:
- Base v2 on a tree with Eric's [1] patch applied. (Eric)
- Handle unrepresentable transport header offsets in inet_gro_receive(). (Eric)
- Explain why nested encapsulations still require the checked assignments. (Eric)
- State that the issue was found through AI-based auditing. (Eric)
- Change the subject prefix from ipv6: gro: to net: gro:.
- v1: https://lore.kernel.org/all/avTTQNyvwPP6LtGx@v4bel/
- [1]: https://lore.kernel.org/all/[email protected]/
--- net/ipv4/af_inet.c | 5 ++++- net/ipv6/ip6_offload.c | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/af_inet.c +4 -1
@@ -1530,7 +1530,10 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb)* as we already checked checksum over ipv4 header was 0 */ skb_gro_pull (skb,sizeof (*iph)); -skb_set_transport_header (skb,skb_gro_offset (skb)); +if (!skb_set_transport_header_careful (skb,skb_gro_offset (skb))) { + flush =1 ; + goto out; + } pp =indirect_call_gro_receive (tcp4_gro_receive, udp4_gro_receive, ops->callbacks.gro_receive, head, skb);
net/ipv6/ip6_offload.c +2 -1
@@ -249,7 +249,8 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,skb_gro_pull (skb,sizeof (*iph)); } -skb_set_transport_header (skb,skb_gro_offset (skb)); +if (!skb_set_transport_header_careful (skb,skb_gro_offset (skb))) + goto out;NAPI_GRO_CB (skb)->proto = proto;
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
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] ipv6: gro: u16 off truncation in ipv6_gro_receive() inflates data_offset
- [Low] The commit message says the reproducer is already blocked by a GRO extension-header limit.
--
net: gro: avoid truncating transport header offsets
This patch replaces skb_set_transport_header() with skb_set_transport_header_careful() in ipv6_gro_receive() and inet_gro_receive(). If the GRO transport offset does not fit in the 16-bit skb->transport_header, the skb is not held as a new GRO head and goes through the normal receive path instead.
Quoted 5 lines
The
IP6_MAX_EXT_HDRS_CNTlimit inipv6_gro_pull_exthdrs()prevents this reproducer. However, nested encapsulations can each add an extension header chain, so the accumulated offset can still exceed the range ofskb->transport_header.inet_gro_receive()can also be reached with such an offset.
[Severity: Low]
Is this paragraph accurate for the tree this patch applies to? Here, ipv6_gro_pull_exthdrs() in net/ipv6/ip6_offload.c is still an unbounded loop with no header counter:
net/ipv6/ip6_offload.c:ipv6_gro_pull_exthdrs() {
for (;;) {
int len;
ops = rcu_dereference(inet6_offloads[proto]);
if (unlikely(!ops))
break;
if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
break;
...
}IP6_MAX_EXT_HDRS_CNT is not referenced anywhere in ip6_offload.c.
The limit appears to come from Eric's prerequisite patch. That patch is only mentioned in the v2 notes below the --- line, and git am drops those notes. The permanent log would then describe a cap that is not in this tree, and nothing would point to the patch that adds it. In this tree, this change is the only thing that stops the KASAN reproducer.
Could the prerequisite be referenced in the changelog itself, for example with a Link: tag? Or could the sentence be reworded?
The nested encapsulation argument could also be more specific. With a 12-header cap, one GRO pass handles at most two L3 layers through encap_mark. That comes to about 2 x 12 x 2048 bytes, roughly 49 KB, plus a small amount of driver headroom. That total is still below 64 KB.
Which path still exceeds the range? One candidate is a second GRO pass through gro_cells after decapsulation, where the pulled outer headers become headroom. Could the changelog name the concrete path?
Also, skb_set_transport_header_careful() was added by commit f12c2de4f542 ("batman-adv: reject unrepresentable multicast TVLV offsets"). This patch carries Fixes: 4b0ebbca3e16 and Cc: stable, so stable trees would need f12c2de4f542 as well. Should that dependency be noted in the changelog?
[ ... ]
net/ipv6/ip6_offload.c INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, · line 256
Quoted 13 lines
net/ipv6/ip6_offload.c +2
-1@@ -249,7 +249,8 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,skb_gro_pull (skb,sizeof (*iph)); } -skb_set_transport_header (skb,skb_gro_offset (skb)); +if (!skb_set_transport_header_careful (skb,skb_gro_offset (skb))) + goto out;NAPI_GRO_CB (skb)->proto = proto;
[Severity: High]
Can this early exit turn a truncated inner offset into a heap overflow?
Suppose outer layers advance skb_gro_offset() to just below the limit, so the outer transport offset still passes the new careful check. A tunnel and L2 callback such as gre_gro_receive() followed by eth_gro_receive() can then pull a few more bytes without any U16_MAX check. The inner ipv6_gro_receive() is entered with off above 65535. It stores off into the u16 network_offsets[] slot before anything validates it, so the slot holds off - 65536.
If the inner nexthdr is an extension header, ipv6_gro_pull_exthdrs() then does:
net/ipv6/ip6_offload.c:ipv6_gro_pull_exthdrs() {
...
skb_gro_pull(skb, off - skb_gro_receive_network_offset(skb));
...
}Subtracting the truncated value advances data_offset by an extra 65536. On a linear skb the extension headers were read through frag0, so frag0_len is still set.
Before this patch, tcp6_gro_receive() or udp6_gro_receive() called skb_gro_header() with the inflated offset. That went through skb_gro_header_slow(), which invalidated frag0. With this change the careful check fails first. We jump to out with data_offset far past skb_headlen() and frag0_len still non-zero.
dev_gro_receive() then takes the normal path and calls gro_try_pull_from_frag0(). grow is roughly 64KB and frag0_len is non-zero, so gro_pull_from_frag0() copies that many bytes to skb_tail_pointer(skb), past skb->end. That overwrites skb_shared_info and the memory after the head buffer.
A single linear skb slightly over 64KB is enough to reach this. virtio_net, veth, tun/tap and loopback can all deliver one. That includes devices an unprivileged user sets up in a user and network namespace.
Could the representability check move to the top of ipv6_gro_receive(), before off is stored in network_offsets[] and before ipv6_gro_pull_exthdrs() runs? Making ipv6_gro_pull_exthdrs() pull relative to skb_gro_offset() would avoid the inflation, but the truncated network_offsets[] entry would still be wrong for any later user. inet_gro_receive() stores a truncated network_offsets[] entry the same way, although it does not inflate data_offset.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/avcJ_0-OqgDlD5GB%40v4bel
Quoted 96 lines · On Tue, Nov 17, 2026 at 01:30:35PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
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] ipv6: gro: u16 off truncation in
ipv6_gro_receive()inflatesdata_offset
- [Low] The commit message says the reproducer is already blocked by a GRO extension-header limit.--
net: gro: avoid truncating transport header offsets
This patch replaces
skb_set_transport_header()withskb_set_transport_header_careful()inipv6_gro_receive()andinet_gro_receive(). If the GRO transport offset does not fit in the 16-bitskb->transport_header, the skb is not held as a new GRO head and goes through the normal receive path instead.Quoted 5 lines
The
IP6_MAX_EXT_HDRS_CNTlimit inipv6_gro_pull_exthdrs()prevents this reproducer. However, nested encapsulations can each add an extension header chain, so the accumulated offset can still exceed the range ofskb->transport_header.inet_gro_receive()can also be reached with such an offset.[Severity: Low]
Is this paragraph accurate for the tree this patch applies to? Here,ipv6_gro_pull_exthdrs()innet/ipv6/ip6_offload.cis still an unbounded loop with no header counter:net/ipv6/ip6_offload.c:ipv6_gro_pull_exthdrs() { for (;;) { int len; ops = rcu_dereference(inet6_offloads[proto]); if (unlikely(!ops)) break; if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) break; ... }
IP6_MAX_EXT_HDRS_CNTis not referenced anywhere inip6_offload.c.The limit appears to come from Eric's prerequisite patch. That patch is only mentioned in the v2 notes below the --- line, and git am drops those notes. The permanent log would then describe a cap that is not in this tree, and nothing would point to the patch that adds it. In this tree, this change is the only thing that stops the KASAN reproducer.
Could the prerequisite be referenced in the changelog itself, for example with a Link: tag? Or could the sentence be reworded?
The nested encapsulation argument could also be more specific. With a 12-header cap, one GRO pass handles at most two L3 layers through
encap_mark. That comes to about 2 x 12 x 2048 bytes, roughly 49 KB, plus a small amount of driver headroom. That total is still below 64 KB.Which path still exceeds the range? One candidate is a second GRO pass through
gro_cellsafter decapsulation, where the pulled outer headers become headroom. Could the changelog name the concrete path?Also,
skb_set_transport_header_careful()was added by commitf12c2de4f542("batman-adv: reject unrepresentable multicast TVLV offsets"). This patch carries Fixes:4b0ebbca3e16and Cc: stable, so stable trees would needf12c2de4f542as well. Should that dependency be noted in the changelog?[ ... ]
net/ipv6/ip6_offload.c INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, · line 256
Quoted 13 lines
net/ipv6/ip6_offload.c +2
-1@@ -249,7 +249,8 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,skb_gro_pull (skb,sizeof (*iph)); } -skb_set_transport_header (skb,skb_gro_offset (skb)); +if (!skb_set_transport_header_careful (skb,skb_gro_offset (skb))) + goto out;NAPI_GRO_CB (skb)->proto = proto;[Severity: High]
Can this early exit turn a truncated inner offset into a heap overflow?
Quoted 5 lines
Suppose outer layers advance
skb_gro_offset()to just below the limit, so the outer transport offset still passes the new careful check. A tunnel and L2 callback such asgre_gro_receive()followed byeth_gro_receive()can then pull a few more bytes without anyU16_MAXcheck. The inneripv6_gro_receive()is entered with off above 65535.
This concern seems plausible, but I could not find a path where skb_gro_offset() exceeds 65535 in the current upstream tree with v2 applied. The two capped IPv6 header chains in this path stay below 50KB, and skb headroom is not part of skb_gro_offset().
I will not send a v3.
Quoted 43 lines
It stores off into the u16 network_offsets[] slot before anything validates it, so the slot holds off - 65536.
If the inner nexthdr is an extension header,
ipv6_gro_pull_exthdrs()then does:net/ipv6/ip6_offload.c:ipv6_gro_pull_exthdrs() { ... skb_gro_pull(skb, off - skb_gro_receive_network_offset(skb)); ... }Subtracting the truncated value advances
data_offsetby an extra 65536. On a linear skb the extension headers were read through frag0, sofrag0_lenis still set.Before this patch,
tcp6_gro_receive()orudp6_gro_receive()calledskb_gro_header()with the inflated offset. That went throughskb_gro_header_slow(), which invalidated frag0. With this change the careful check fails first. We jump to out withdata_offsetfar pastskb_headlen()andfrag0_lenstill non-zero.
dev_gro_receive()then takes the normal path and callsgro_try_pull_from_frag0(). grow is roughly 64KB andfrag0_lenis non-zero, sogro_pull_from_frag0()copies that many bytes toskb_tail_pointer(skb), pastskb->end. That overwritesskb_shared_infoand the memory after the head buffer.A single linear skb slightly over 64KB is enough to reach this.
virtio_net, veth, tun/tap and loopback can all deliver one. That includes devices an unprivileged user sets up in a user and network namespace.Could the representability check move to the top of
ipv6_gro_receive(), before off is stored in network_offsets[] and beforeipv6_gro_pull_exthdrs()runs? Makingipv6_gro_pull_exthdrs()pull relative toskb_gro_offset()would avoid the inflation, but the truncated network_offsets[] entry would still be wrong for any later user.inet_gro_receive()stores a truncated network_offsets[] entry the same way, although it does not inflatedata_offset.Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/avcJ_0-OqgDlD5GB%40v4bel