From: Dai Wenjie <3596417740@qq.com>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Dai Wenjie <3596417740@qq.com>
Subject: [PATCH] ipv6: reject datagrams that leave no room past the fragment header
Date: Sat, 21 Nov 2026 14:40:48 +0800 [thread overview]
Message-ID: <tencent_BE8DC9842FFF55349D2FCCDE456B9C6EB709@qq.com> (raw)
__ip6_append_data() does not check that fragmenting can make progress.
When the MTU leaves only 8..15 bytes past fragheaderlen, maxfraglen
collapses to fragheaderlen and the clamp below reduces datalen to zero:
if (datalen > (cork->length <= mtu ? mtu : maxfraglen) - fragheaderlen)
datalen = maxfraglen - fragheaderlen - rt->dst.trailer_len;
The paged allocation path (MSG_SPLICE_PAGES, MSG_ZEROCOPY) then computes
pagedlen = datalen - transhdrlen - fraggap (underflows)
copy = datalen - transhdrlen - fraggap - pagedlen
where the two underflows cancel and copy evaluates to zero, while
skb_put(skb, fraglen - pagedlen) wraps back to a valid size. length -=
copy + transhdrlen therefore consumes nothing, and the loop re-enters
alloc_new_skb, allocating one skb per iteration until the socket wmem
budget (2 * sk_sndbuf) is exhausted; it then fails with -ENOBUFS and
ip6_flush_pending_frames() drops the queued skbs.
A 64-byte UDPv6 datagram with IPV6_MTU=1280 and a 1232-byte routing
header (fragheaderlen 1272) reproduces this on 6.12.96: with SO_SNDBUF
set to 128M, splice() spends 152 ms on-CPU and allocates 514 MB of
transient kernel memory before returning ENOBUFS.
The non-paged path is not affected: pagedlen is zero there and the
existing copy < 0 check returns -EINVAL.
Reject the datagram with -EMSGSIZE when the room left after the
fragment headers cannot hold rt->dst.trailer_len followed by
transhdrlen and fraggap. The arithmetic stays unsigned throughout:
maxfraglen, fragheaderlen and fraggap are unsigned, and the subtractions
are guarded so that neither maxfraglen - fragheaderlen nor
room - trailer can wrap.
The check has to sit inside the clamp instead of next to the earlier
maxfraglen validation: a zero-payload datagram of exactly mtu bytes
fits in a single packet, is never clamped, and must keep working.
Signed-off-by: Dai Wenjie <3596417740@qq.com>
---
net/ipv6/ip6_output.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 50b41be5d..de033a35e 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1610,8 +1610,18 @@ static int __ip6_append_data(struct sock *sk,
*/
datalen = length + fraggap;
- if (datalen > (cork->length <= mtu ? mtu : maxfraglen) - fragheaderlen)
- datalen = maxfraglen - fragheaderlen - rt->dst.trailer_len;
+ if (datalen > (cork->length <= mtu ? mtu : maxfraglen) - fragheaderlen) {
+ unsigned int need = (unsigned int)transhdrlen + fraggap;
+ unsigned int room = maxfraglen - fragheaderlen;
+ unsigned int trailer = (unsigned int)rt->dst.trailer_len;
+
+ if (maxfraglen <= fragheaderlen || room <= trailer ||
+ room - trailer < need) {
+ err = -EMSGSIZE;
+ goto error;
+ }
+ datalen = room - trailer;
+ }
fraglen = datalen + fragheaderlen;
pagedlen = 0;
--
2.43.0
next reply other threads:[~2026-11-21 6:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 6:40 Dai Wenjie [this message]
2026-11-21 6:43 ` [PATCH] ipv6: reject datagrams that leave no room past the fragment header netdev-bot+sinfo
2026-11-21 6:59 ` 逐彡梦
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=tencent_BE8DC9842FFF55349D2FCCDE456B9C6EB709@qq.com \
--to=3596417740@qq.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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