From: Josef Bacik 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 Signed-off-by: Chris Mason --- 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