From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: "tencentos_secure(TencentOS安全公共邮箱)"
<tencentos_secure@tencent.com>,
netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
Paolo Abeni <pabeni@redhat.com>,
Jakub Kicinski <kuba@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Steffen Klassert <klassert@kernel.org>,
Eric Dumazet <edumazet@kernel.org>,
security@kernel.org, steffen.klassert@secunet.com
Subject: Re: [PATCH net 1/2] net/ipv4: reserve exthdrlen as headroom instead of counting it in skb->len
Date: Tue, 27 Oct 2026 11:26:46 -0400 [thread overview]
Message-ID: <willemdebruijn.kernel.754d523a3a4@gmail.com> (raw)
In-Reply-To: <589B4474E0A78486+v2-20261026-p1@tencent.com>
tencentos_secure(TencentOS安全公共邮箱) wrote:
> When sending through an xfrm route (rt->dst.header_len > 0),
> __ip_append_data() counts the bundle header space ("exthdrlen")
> into skb->len of the first fragment skb: the skb setup does
>
> skb_reserve(skb, hh_len);
> data = skb_put(skb, fraglen + exthdrlen - pagedlen);
> skb_set_network_header(skb, exthdrlen);
>
> so a fully filled first skb has skb->len == maxfraglen + exthdrlen.
> Since commit 353e5c9abd90 ("ipv4: Fix IPsec slowpath fragmentation
> problem"), the next iteration's fraggap = skb_prev->len - maxfraglen
> therefore inherits the whole bundle header length instead of the
> intended alignment slop.
>
> fraggap is relayed into the next skb by skb_copy_and_csum_bits(), but
> the MSG_MORE (alloclen = mtu) and linear (alloclen = fraglen) branches
> account for fraggap in the allocation only for as long as datalen stays
> uncapped. Once datalen is capped at maxfraglen - fragheaderlen, the
> bytes copied into the fresh skb exceed the skb head allocation and run
> past the end of the buffer, corrupting skb_shared_info. The
> paged-branch accounting of
> commit eca856950f7c ("ipv4: account for fraggap on the paged
> allocation path") relies on datalen accounting for fraggap, which
> stops being true exactly when datalen is capped.
>
> Fix the root cause by reserving exthdrlen as headroom, like IPv6 has
> done since commit 1f85851e17b6 ("ipv6: fix incorrent ipv6 ipsec
> packet fragment") in 2012:
>
> skb_reserve(skb, hh_len + exthdrlen);
> data = skb_put(skb, fraglen - pagedlen);
> skb_reset_network_header(skb);
>
> With this, every fragment skb satisfies skb->len <= maxfraglen, so
> fraggap <= mtu - maxfraglen <= 7 (the alignment slop the relay was
> designed for) and the copy destination is provably in bounds.
>
> Allocation sizes, tail positions, tailroom and truesize are unchanged
> (alloc_extra already carries exthdrlen), and when dst.header_len == 0
> this is a literal no-op.
>
> Fixes: 353e5c9abd90 ("ipv4: Fix IPsec slowpath fragmentation problem")
> Reported-by: TencentOS Corvus AI <corvus@tencent.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Anakin Zhang <tencentos_secure@tencent.com>
LGTM on the general approach:
The XFRM inserted headers must only be inserted once on the first
fragment.
The same approach is already taken in IPv6. Though there the variable
is dst_exthdrlen, not to be confused with exthdrlen.
My main concern is that this code is notoriously fragile, with the
same variables used in different calculations / overlapping uses.
Writing past skb head is obviously bad. Ideally we could catch that
with a patch that is trivially reviewable for stable. Not sure that
exists. But I'm a little hesitant to send to stable something hard
to establish the correctness of.
I can definitely stare at it for longer to increase confidence.
Also Cc:ing the IPSec maintainer for an extra set of expert eyes.
> ---
> net/ipv4/ip_output.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
> index eaa6fab..b84d56c 100644
> --- a/net/ipv4/ip_output.c
> +++ b/net/ipv4/ip_output.c
> @@ -1150,16 +1150,16 @@ alloc_new_skb:
> */
> skb->ip_summed = csummode;
> skb->csum = 0;
> - skb_reserve(skb, hh_len);
> + skb_reserve(skb, hh_len + exthdrlen);
>
> /*
> * Find where to start putting bytes.
> */
> - data = skb_put(skb, fraglen + exthdrlen - pagedlen);
> - skb_set_network_header(skb, exthdrlen);
> + data = skb_put(skb, fraglen - pagedlen);
> + skb_reset_network_header(skb);
> skb->transport_header = (skb->network_header +
> fragheaderlen);
> - data += fragheaderlen + exthdrlen;
> + data += fragheaderlen;
>
> if (fraggap) {
> skb->csum = skb_copy_and_csum_bits(
> --
> 2.55.0
>
next prev parent reply other threads:[~2026-10-27 15:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <v2-20261026-cover@tencent.com>
2026-10-26 9:51 ` [PATCH net 2/2] net/ipv4: fail append when the moved fraggap exceeds the fragment data =?gb18030?B?dGVuY2VudG9zX3NlY3VyZShUZW5jZW50T1Owssiruau5stPKz+Qp?=
2026-10-26 12:20 ` Eric Dumazet
2026-10-26 9:51 ` [PATCH net 1/2] net/ipv4: reserve exthdrlen as headroom instead of counting it in skb->len =?gb18030?B?dGVuY2VudG9zX3NlY3VyZShUZW5jZW50T1Owssiruau5stPKz+Qp?=
2026-10-27 15:26 ` Willem de Bruijn [this message]
2026-10-29 8:29 ` =?gb18030?B?dGVuY2VudG9zX3NlY3VyZShUZW5jZW50T1Owssiruau5stPKz+Qp?=
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=willemdebruijn.kernel.754d523a3a4@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=idosch@nvidia.com \
--cc=klassert@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=security@kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=tencentos_secure@tencent.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