Article View: linux.kernel.netdev
Article #7486Re: [PATCH net 2/2] net/ipv4: fail append when the moved fraggap exceeds the fragment data
From: Eric Dumazet
Date: Mon, 26 Oct 2026 12:20
Date: Mon, 26 Oct 2026 12:20
86 lines
12718 bytes
12718 bytes
Le lun. 26 oct. 2026 à 12:23, tencentos_secure(TencentOS安全公共邮箱)
<tencentos_secure@tencent.com> a écrit :
>
> When the first fragment of a cork is already at maxfraglen, the next
> __ip_append_data() iteration relays the previous fragment's tail,
> fraggap = skb_prev->len - maxfraglen, into the new skb. The moved
> fraggap is charged against datalen by computing
>
> copy = datalen - transhdrlen - fraggap - pagedlen;
>
> but once datalen is capped at maxfraglen - fragheaderlen it can become
> smaller than transhdrlen + fraggap. Then copy goes negative: no payload
> is copied and the iteration makes no progress. Worse, in the paged
> branch (MSG_SPLICE_PAGES / MSG_ZEROCOPY / GSO) pagedlen = datalen -
> transhdrlen - fraggap additionally wraps unsigned, breaking the
> alloclen + pagedlen == fraglen invariant that commit eca856950f7c
> ("ipv4: account for fraggap on the paged allocation path") relies
> on; the loop then either queues skbs with garbage tail accounting
> (silent packet corruption) or, when maxfraglen == fragheaderlen,
> never makes progress and grinds on until -ENOBUFS.
>
> Reject such an append before any allocation: if the moved tail
> (transhdrlen + fraggap) cannot fit in the fragment's datalen, the
> iteration cannot make progress, so fail with -EINVAL. This covers all
> three alloclen branches, including the paged one. With the preceding
> fix fraggap is bounded by the alignment slop, but the condition stays
> reachable with extreme geometries (e.g. an effective mtu too small for
> fragheaderlen + transhdrlen), so pin the geometry explicitly, as
> __ip6_append_data() has done since commit 232cd35d0804 ("ipv6: fix
> out of bound writes in __ip6_append_data()").
>
I do not think this is reachable once patch 1 is applied.
ip_setup_cork() rejects cork->fragsize < 68 (inetdev_valid_mtu()), and
fragheaderlen is at most 60, so a capped datalen is at least 8, and
maxfraglen == fragheaderlen cannot happen.
transhdrlen is non zero only on the first iteration with an empty
queue, where fraggap is 0, and current callers pass at most 8 bytes
(UDP, ICMP, ping). On later iterations transhdrlen is 0 and, with
patch 1, fraggap <= mtu - maxfraglen <= 7.
So transhdrlen + fraggap > datalen can not be true.
Please give a concrete setup that reaches this check after patch 1,
or present the check as defense in depth matching
__ip6_append_data() and drop the Fixes: and Cc: stable tags.
> This cannot reject a send that would otherwise succeed: the guard only
> fires when transhdrlen + fraggap > datalen, which is exactly when copy
> would come out negative, or, on the paged branch, when pagedlen would
> wrap. No send can get past an iteration with a negative copy -- no
> payload is copied, so the loop makes no progress. All callers flush
> the cork on append error, and returning -EINVAL in mid-cork state
> already happens in this function (MSG_ZEROCOPY ubuf mismatch).
>
> 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>
> ---
> net/ipv4/ip_output.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
> index b84d56c..5db8b06 100644
> --- a/net/ipv4/ip_output.c
> +++ b/net/ipv4/ip_output.c
> @@ -1105,6 +1105,11 @@ alloc_new_skb:
> fraglen = datalen + fragheaderlen;
> pagedlen = 0;
>
> + if (unlikely(transhdrlen + fraggap > datalen)) {
> + err = -EINVAL;
> + goto error;
> + }
> +
> alloc_extra = hh_len + 15;
> alloc_extra += exthdrlen;
>
> --
> 2.55.0
>
Technical Details
Message-ID:
<CAL4Wiio2inRipSSWgFKkRjuPA=iLkynvWCXQ7cpe9G5XWi9=7Q@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351884-linux-kernel-netdev=dewy.ruReferences:
<v2-20261026-cover@tencent.com> <98906F734B5D43DA+v2-20261026-p2@tencent.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351884-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 2/2] net/ipv4: fail append when the moved fraggap
exceeds the fragment data
Date: Mon, 26 Oct 2026 13:20:45 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiio2inRipSSWgFKkRjuPA=iLkynvWCXQ7cpe9G5XWi9=7Q@mail.gmail.com>
References: <v2-20261026-cover@tencent.com> <98906F734B5D43DA+v2-20261026-p2@tencent.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1305792"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3S3JU3+DoUe/w05c1x3VDTshee4= sha256:uXnx7ZQhIbbS9ugmOEr4RaNfUyoRPLFm8slBXucpN9o=
sha1:t7XqPVYo+wDAdjYTInF3tqZ0dAs= sha256:1gQeDQqPAm3iWJkzkaGycviroza42euqsuXK90bHYYQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id D9750125BA5; Mon, 26 Oct 2026 15:40:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id Hd764O7FWf10;
Mon, 26 Oct 2026 15:40:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-351884-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id B77C6125BA2; Mon, 26 Oct 2026 15:40:37 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sin.lore.kernel.org (Postfix) with ESMTP id 6C03626B00; Mon, 26 Oct 2026 12:21:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793017260;
b=opjyuv2Ws4d7b0w4CNxDbjoTpzTsA1AhhaVXd5NCa+zpHRoHYvsbsv6dpK8OjURSvNH+
bsAqWaXAABYd7CFhgdDM8+PLDomTXD40cIGaVqXkckZhskAeFdaThIyp8dv2m5zAJeeM/
8qgQm1e3BJ3hULJxolKjhMuZssQi/P4RrqC8DWRmGTu7I3rHq8crGQs19q4eYbZmWHuIX
XTCUCio4oC4TUzok64jXO8n4WOOVvstZT+YhbCt/mQf9eA2FLFBrg0ZXGQ6aQ88vpP/lH
1wm+s0ytWPb9nE9Zl0YCyVxH2ku9wQHM8r9Ooz8o4bsFWWs9OOrnkubAUcNO4BZTTJg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793017260;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Gm-Message-State:X-Received:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=LcYC0pcqWmk2zKW9GbD/mLvZ8FSSvOFC4LfgOjlwTnA=;
b=mYne4AE00uE0dPeRtrfMuUUPDOkw4OIP0WcFXSwMoZHfQDaxwUt3ZBmGSwweRikcTybN
yYlcLF8ykqyjbv/G4QwogVILvslN8Omyyj8oNG0wSFyH5QJUYtSVmwTT2smF3dN534Dzz
uQckbn+UvTCFt07PT5ssWgrKflKattuTcBttXn2zt/y5qVdj++eVrHpPqnavP56Dx7pUP
sR7nFl+QPisSqQHxfLthaLtRT4oLCe4bSFuykSUd7+Prghr4dKblcSvgChpV9rc6aCvzK
xGS4JzxAEhDEJmospNEHX42DLN4jH2+gJil7VzwGDOd1gULRZzH3a1w8A5kGleac/IA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bhX7m79q;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 55E69606A322;
Mon, 26 Oct 2026 12:21:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bhX7m79q
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793017259;
b=q4sBwc+1pJ3magCXMLKPKxU3kTXtiGOYPVrGgpSJhQuKG1UKB0Y/sUN1W5Ay36a8tSbH
dPcPQtNzST0X0J9MTflmjdojbk2mrZrFzOPRM8Ydxi7voCB/xpj+Rn0uiXj/WV5CeNdo1
zf7MRnYkeaVuCCUICizjszutU+RDnTnMM74zvbpqFn+dJ+LXvPzF6EhI2aAJ2+0Ihj4k2
qfzHeiovfdUv0x/Ou8F32/nrkQ1gZfwvLnfKrVEDi6o5HNcbCX7arpZSzE7OrF7QfDFbI
AtAevYqYn/iANqF9Vrdf/OBEPiNjLGy93Cid2Fu0fHHBS8BVinDW9knxeKEWt9PRBDg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793017259;
h=Received:DKIM-Signature:Received:X-Gm-Message-State:X-Received:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=LcYC0pcqWmk2zKW9GbD/mLvZ8FSSvOFC4LfgOjlwTnA=;
b=xHg7eoR6OTMtOPopnGNgX4240qrGzLqqdT5tqn98ZQeToEThghsAmhn5yezZY3gc8x42
Y7okCWsL5MbUrIu24b8N2IM4gUIjDXZ7En7KD2WHV4XjmIzY+0XJLZc2vFYUGNt5MHUEu
Dv7d5VnHirZTf+cXTWyYicXdy2+FKPYtmmzdcvwMLVuxZyzveDcxzkRtK+XmXQ2XEClpN
2vApI1wIQal51sYDF7lHgnp95PxExftkq9A3tfF5TH7Of5TanEop/Mav1+n867xyxFLcp
11z5W7npmPVJEAW+4snMeSutYSdOFS+IE2x30a1nwTCL6CFYLIdbR9fpmDXlnDZC+gg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bhX7m79q;
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2D0B606A31A
for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 12:20:58 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6670E1F01828
for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 12:20:58 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1793017258;
bh=LcYC0pcqWmk2zKW9GbD/mLvZ8FSSvOFC4LfgOjlwTnA=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=bhX7m79q4A0VANpZHq1k4f+ls9oW2b1KkcxTswPRT7tnz6BZrCUDSxG7W9Z9dkECO
nLzEmcSlj+2MRhqYW6skTsTtdoqRsEd1K3J5ZOuUo3yOgMCc9525jGNxRzaxAP5VRO
/ra5HE6reUUOScJMqXlu8bpFXMFNTsAEUUI/AF46VQouBG0yhXQ5g8SuKcws8sia0i
+W+sU4sfN9wOg4jrsEKspuodrBtpoUDNqfa7cnSoGUjl2se5eUq91SriNb0vJBrgDk
badDl/08Jtl31tOS8DhA3lcl3ZevU4uRWAZdOp3E+cIwJVN2FRIQEUdai4Z4ZTlRbR
xkMvRcvF4mseA==
X-Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7fccba9c675so4704519a34.0
for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 05:20:58 -0700 (PDT)
X-Gm-Message-State: AFq9FYLvmBj7OBnF6ShifPLQaaeADcvYluuXyw8S4JPT37BlQTWnF/cj
ZFSj/bB3yu9t5Rrn+tGiQb6DCX70D7tL2fg34oaHdwdUTZzsydx+60v0gUkz5kLrvrCr8FvjO8Q
b+3UtfumdX4XvGytjprMa0qBpvhBEvqc=
X-Received: by 2002:a4a:e90b:0:b0:6f7:3c09:c712 with SMTP id
006d021491bc7-70ba0e4c7f8mr2956542eaf.18.1793017257699; Mon, 26 Oct 2026
05:20:57 -0700 (PDT)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <98906F734B5D43DA+v2-20261026-p2@tencent.com>
X-Gmail-Original-Message-ID: <CAL4Wiio2inRipSSWgFKkRjuPA=iLkynvWCXQ7cpe9G5XWi9=7Q@mail.gmail.com>
X-Gm-Features: AclHuK9gsL_KLEmGFhwsSJDJqQvxzS71W5_99m_JQBg-DTh0wFPoAQnbDZncqng
X-Cc: netdev@vger.kernel.org, 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>, security@kernel.org