* [PATCH] ipv6: reject datagrams that leave no room past the fragment header
@ 2026-11-21 6:40 Dai Wenjie
2026-11-21 6:43 ` netdev-bot+sinfo
0 siblings, 1 reply; 3+ messages in thread
From: Dai Wenjie @ 2026-11-21 6:40 UTC (permalink / raw)
To: netdev
Cc: David S . Miller, Jakub Kicinski, Eric Dumazet, Paolo Abeni,
Dai Wenjie
__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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ipv6: reject datagrams that leave no room past the fragment header
2026-11-21 6:40 [PATCH] ipv6: reject datagrams that leave no room past the fragment header Dai Wenjie
@ 2026-11-21 6:43 ` netdev-bot+sinfo
2026-11-21 6:59 ` 逐彡梦
0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-21 6:43 UTC (permalink / raw)
To: Dai Wenjie
Cc: netdev, David S . Miller, Jakub Kicinski, Eric Dumazet,
Paolo Abeni
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ipv6: reject datagrams that leave no room past the fragment header
2026-11-21 6:43 ` netdev-bot+sinfo
@ 2026-11-21 6:59 ` 逐彡梦
0 siblings, 0 replies; 3+ messages in thread
From: 逐彡梦 @ 2026-11-21 6:59 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: netdev, David S . Miller, Jakub Kicinski, Eric Dumazet,
Paolo Abeni
Hi,
thanks for the triage. Answering the question directly: this was not hit
in production and is not from syzbot. It came out of a manual audit of
__ip6_append_data() that started from CVE-2026-53362 (736b380e), with LLM
assistance for the initial code reading; the arithmetic, the reproducer
and the fix were then derived and verified by hand on a real kernel.
Concretely:
- I went through the paged-allocation accounting again after the fraggap
fix, looking for other values that can make the loop fail to make
progress.
- The degenerate case is maxfraglen == fragheaderlen, i.e.
mtu - fragheaderlen in [8,15]. The clamp then leaves zero capacity,
pagedlen underflows, copy cancels back to zero, and
length -= copy + transhdrlen consumes nothing; the loop keeps
allocating one skb per iteration until the socket wmem budget
(2 * sk_sndbuf) is exhausted and returns -ENOBUFS.
- Reproduced on v6.12.96 with a standalone C program: IPV6_MTU=1280 plus
a 1232-byte routing header (fragheaderlen = 1272), then one splice()
with SPLICE_F_MORE. With SO_SNDBUF=128M the call spends 152 ms on-CPU
and allocates about 514 MB of transient kernel memory before returning
ENOBUFS; with the patch it returns -EMSGSIZE in 0.03 ms without
allocating anything.
- The patch was build-tested on v6.12.96, and three cases were verified on
the patched kernel: the degenerate geometry (returns -EMSGSIZE), a
zero-payload datagram of exactly mtu bytes (still sends), and a normal
fragmentation path (unaffected). The series also applies cleanly to
current mainline.
I can post the reproducer if that is useful.
Thanks,
Dai Wenjie
原始邮件
发件人:netdev-bot+sinfo <netdev-bot+sinfo@kernel.org>
发件时间:2026年11月21日 14:43
收件人:Dai Wenjie <3596417740@qq.com>
抄送:netdev <netdev@vger.kernel.org>, David S . Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>
主题:Re: [PATCH] ipv6: reject datagrams that leave no room past the fragment header
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 6:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 6:40 [PATCH] ipv6: reject datagrams that leave no room past the fragment header Dai Wenjie
2026-11-21 6:43 ` netdev-bot+sinfo
2026-11-21 6:59 ` 逐彡梦
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox