From: Ido Schimmel <idosch@nvidia.com>
To: Chris Mason <mason@kernel.org>
Cc: dsahern@kernel.org, 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, carges@cloudflare.com
Subject: Re: [PATCH net] ipv4: don't let the transport header offset wrap
Date: Wed, 18 Nov 2026 13:16:32 +0200 [thread overview]
Message-ID: <20261118111632.GA1168718@shredder> (raw)
In-Reply-To: <20261118004850.52808-1-mason@kernel.org>
On Tue, Nov 17, 2026 at 07:48:50PM -0500, Chris Mason wrote:
> 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>
Chris Arges is going to post a more comprehensive patch soon.
> ---
> 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
>
prev parent reply other threads:[~2026-11-18 11:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 0:48 [PATCH net] ipv4: don't let the transport header offset wrap Chris Mason
2026-11-18 11:16 ` Ido Schimmel [this message]
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=20261118111632.GA1168718@shredder \
--to=idosch@nvidia.com \
--cc=carges@cloudflare.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=mason@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox