From: Chris Mason <mason@kernel.org>
To: mason@kernel.org, dsahern@kernel.org, idosch@nvidia.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, willemb@google.com,
kuniyu@google.com, netdev@vger.kernel.org, josef@toxicpanda.com
Subject: [PATCH net] ipv4: don't let the transport header offset wrap
Date: Tue, 17 Nov 2026 19:48:50 -0500 [thread overview]
Message-ID: <20261118004850.52808-1-mason@kernel.org> (raw)
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
reply other threads:[~2026-11-18 0:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118004850.52808-1-mason@kernel.org \
--to=mason@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.