* [PATCH net] ipv4: don't let the transport header offset wrap
@ 2026-11-18 0:48 Chris Mason
0 siblings, 0 replies; only message in thread
From: Chris Mason @ 2026-11-18 0:48 UTC (permalink / raw)
To: mason, dsahern, idosch, davem, edumazet, kuba, pabeni, horms,
willemb, kuniyu, netdev, josef
From: Josef Bacik <josef@toxicpanda.com>
skb->network_header and skb->transport_header are 16-bit offsets from
skb->head. ip_rcv_core() computes transport_header as
network_header + ihl * 4.
These offsets are normally small. But a tunnel pulls its outer headers
and hands the same skb back to the stack. skb->head stays where it is,
so skb->data moves further away from it with each decapsulation. After
nested decapsulations the end of the inner IP header can lie beyond what
16 bits can hold.
The fix used here is to set the offset with
skb_set_transport_header_careful(), and to drop the packet if the offset
does not fit.
The helper computes the offset from skb->data, which points to the IP
header in ip_rcv_core(). It does not use network_header. So it also
catches a packet whose network_header was already truncated, where
network_header + ihl * 4 would look valid.
Found by LLM code inspection, and confirmed with LLM generated
reproducers on an unmodified kernel. Fixed by LLM, and tested with
the reproducers and existing kernel selftests.
Fixes: 21d1196a35f5 ("ipv4: set transport header earlier")
Assisted-by: LLM
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Chris Mason <mason@kernel.org>
---
net/ipv4/ip_input.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 9860178752b8..397043893376 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -572,7 +572,11 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
}
iph = ip_hdr(skb);
- skb->transport_header = skb->network_header + iph->ihl*4;
+ if (!skb_set_transport_header_careful(skb, iph->ihl * 4)) {
+ drop_reason = SKB_DROP_REASON_PKT_TOO_BIG;
+ __IP_INC_STATS(net, IPSTATS_MIB_INDISCARDS);
+ goto drop;
+ }
/* Remove any debris in the socket control block */
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 0:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 0:48 [PATCH net] ipv4: don't let the transport header offset wrap Chris Mason
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.