🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11957

Re: [PATCH net v2 2/2] net/ipv4: reject appends with negative fragment copy

#11957
From: Willem de Bruijn
Date: Fri, 06 Nov 2026 02:51
80 lines
14088 bytes
tencentos_secure(TencentOS安全公共邮箱) wrote:
> __ip_append_data() caps datalen at maxfraglen - fragheaderlen when more
> fragments are needed, and later computes
> 
> 	copy = datalen - transhdrlen - fraggap - pagedlen;
> 
> If transhdrlen + fraggap exceeds datalen, copy goes negative in the
> non-paged allocation branches, where pagedlen is zero, invalidating
> the offset/length accounting. In the paged allocation branch,
> pagedlen = datalen - transhdrlen - fraggap wraps unsigned instead.
> The subsequent copy calculation cancels to zero, so checking copy
> alone does not catch this invalid fragment geometry.
> 
> This is reachable independently of the xfrm fraggap bug fixed by the
> preceding patch. icmp_timestamp() passes a 20-byte transport header.
> With a small MTU and IPv4 options, the capped datalen can be smaller
> than that header even when fraggap is zero. The negative copy then
> propagates a negative offset into icmp_glue_bits(), and a timestamp
> reply with corrupted timestamp fields can be emitted.
> 
> For example, with MTU 68 and 40 bytes of IPv4 options, fragheaderlen
> is 60, maxfraglen is 68, datalen is capped at 8, and fraggap is zero,
> so the 20-byte transport header cannot fit.
> 
> Reject this geometry before allocation with -EINVAL, covering all three
> alloclen branches and matching the existing __ip6_append_data() guard.
> A negative copy cannot produce a valid append, so this does not reject a
> send that could otherwise construct a correct packet. 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: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Anakin Zhang <tencentos_secure@tencent.com>

Reviewed-by: Willem de Bruijn <willemb@google.com>

> ---
> v2:
> - Document the independently reachable ICMP Timestamp corruption path.
> - Distinguish negative copy in non-paged allocation branches from
>   unsigned pagedlen wrap in the paged allocation branch.
> - Update the subject and Fixes tag accordingly.
> - Drop the unrelated xfrm Reported-by tag; no code changes.
> 
>  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;

nit: EMSGSIZE might be better

> +				goto error;
> +			}
> +
Technical Details
Message-ID: <willemdebruijn.kernel.20f8423db92c4@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-357701-linux-kernel-netdev=dewy.ru
References: <ipv4.6d58afc075934322860394a26ceaa2e8.0@tencent.com> <306E09760B4212AC+ipv4.6d58afc075934322860394a26ceaa2e8.2@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-357701-linux-kernel-netdev=dewy.ru
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/2] net/ipv4: reject appends with negative
 fragment copy
Date: Thu, 05 Nov 2026 21:51:37 -0500
Organization: Usenet Network
Message-ID: <willemdebruijn.kernel.20f8423db92c4@gmail.com>
References: <ipv4.6d58afc075934322860394a26ceaa2e8.0@tencent.com>
 <306E09760B4212AC+ipv4.6d58afc075934322860394a26ceaa2e8.2@tencent.com>
MIME-Version: 1.0
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3780103"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:M3M4S0cWvSD54xKifeVeH990gog= sha256:XSm6k+snUTxSf4K9f55Vn88+yEC7G/fKGF+Os14zGWg=
	sha1:igvdnLfI+DUC13//Da3Nm+2J8aU= sha256:Fbgt/a23yD87r+On5meZ6aY06rnuYZsfKcdH873ANaw=
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 86CE011312F; Fri,  6 Nov 2026 05:52:01 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	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=gmail.com
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 7ccy803x1jKx;
	Fri,  6 Nov 2026 05:51:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-357701-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 2E5EC112E19; Fri,  6 Nov 2026 05:51:47 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 4D1312A090; Fri,  6 Nov 2026 02:51:41 +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=1793933501;
	b=HeCfA9c6cnsRM3U9i1Mc+87szVCxsCiRTlHeaYG07KXLaIzwNjmUxQ9nmR1bn513D6Gi
	 fYeqhNFfHwc6+WgVQC20SPc91Xdvpn5ZPDFoKJw/7wt1t3HzlfXIbyW8Azps4qfX6Ca3/
	 l0wYs+ZcmVqSHSDQRl73ElEVp04Ij6Ile0PMLvoPLwAEYzzD0wzTSxyyG3zChEA39aBD1
	 hm++KuBIRZprWxj8lHyBWgvb0r2rRresOqyGg8OTn+z0k6kL1goky1dI0OpLPAbWIbiAt
	 GqTWKdLXqqW0m7+8613QqJfWxhxqd/RFE2fsVqZorqgH8LoTpNPsVMM2JjPjgEee1yw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793933501;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:Date:From:To:Cc:Message-ID:In-Reply-To:
	 References:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding;
	bh=C4YKO6ifCvG670/AtfKy+sKSzMH1iQMMQOHq83vJaQY=;
	b=T8k2T3LvFnGqyTEFU4dlACslpXonK19um8GJR5jAAjw1LKBjpZWCLnLd4Asi1FpTDA+8
	 N01vVTRt0INiPuRY/tO634dkLV7mXcXLHhiQJ7UGpeyhX1A1bW8ckfrC8ABbo20QGt/OX
	 E8f2G9IbRRduHsCPeb94e6AQ6Io2XbEGkR6nJodJVaiRbwgsShqSbUw3iE3yfbXcUiuuf
	 w3jHTzY0XjI+D+XXLcH81luZmDCK0Lr97xXHxn6WwOe9LMDPx0nSjJrak9Shlg9wig8mJ
	 zPZ1rYNfp+Sp1w09AU2szIOr1asU2el56fYyvkRefFJUF2g3KfAPGXZuUtPv31Sr0Sw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xhFcBwWj;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 2411A606A32E;
	Fri,  6 Nov 2026 02:51:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xhFcBwWj
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.217.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793933500;
	b=lYl4El0MvQGN6/mYo7miMH6syyPiincMaFKdbKnY5Q2MR5UrMJl5LDK4gOXtXhvMiMAn
	 7oh42Yc5CpxftGyy6I5LEI3SZAqC6UnOTeMPPUGYS6EAJ/dY5f5s9ODpQ5vHDDCLfzYAC
	 J9iwJk88O7O1tO30elmY0v3vdICTYxqr7Pa77KaK1ebtGEpV7MICzyRji0ho5uqDLNKzO
	 wJ7Kai45PcsepUZjGooY+ECUbX7l2rls9Y9D70sGn5cHLNuvu8KBcnQLAyVrvdZLaJY57
	 i7BlVb1AkWO2fa8WFP9Ny74K10DQPnY4QQqCHhEJWS/djxAfEV1WkZBHxBn/lPvL12A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793933500;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:
	 MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=C4YKO6ifCvG670/AtfKy+sKSzMH1iQMMQOHq83vJaQY=;
	b=GG9vLvY3c8yZHM3y/s7smCTLzd2OtEJnSt5+r5SXK9M966hxwWVbTnT44MxkMXtsoRLa
	 vk/EVNMmV3gOGBjMxop33XTQsYCQikENyFqUH3UqftSTSJHSmYWDlHyui1F/d8Fnq70NX
	 sKo7NDezS22dlSPsVPYZL/gBTKpRCMfx22ji6qzHIQYiDHojhVbcxAC8WDRcXTVcbuFKP
	 oTfQa3WUElFr//sswM/h0anyRQefqoOfzVZjrTNfdHLWR8NnstLjUREOG297aQyKv0bxB
	 LKMZGjEWMigWyd+tKLBlasrmeh9fba4DPVsry2fuCNS4pdu4LtUsC8L/Xmr3qRzsJcw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xhFcBwWj;
	arc=none smtp.remote-ip=209.85.217.47
X-Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4BF2606A31B
	for <netdev@vger.kernel.org>; Fri,  6 Nov 2026 02:51:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4BF2606A31B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-vs1-f47.google.com with SMTP id ada2fe7eead31-77bf892b496so83098137.0
        for <netdev@vger.kernel.org>; Thu, 05 Nov 2026 18:51:39 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793933499; x=1794538299; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:mime-version:subject
         :references:in-reply-to:message-id:cc:to:from:date:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=C4YKO6ifCvG670/AtfKy+sKSzMH1iQMMQOHq83vJaQY=;
        b=xhFcBwWjS4HqafxaONQ7+8hoecwIizKVadRymVGlIE2lGD1bXqih5Wexq0npneCZ/t
         E+yxAyS/ApEV1zvgakQ0d4r2cREz4SCssltufK98oeIheG91vDtvayGZfIYOqtviVEyW
         EjMWl+v0xLSMyi/XBftGgfCiWfKpPEunloijI2b1Fyraku4fJm2UjKDmfPT2InTImthv
         2hATAPOFyFtqYF+paljdZ1K4cZNvpXZZEm0JcM5aagBt+WUv2JBaIL+H3J8XKu2E1i6P
         IlScCKiZORvOQ7Wr+vdedsjvweHf5kJAiflrOWyiLzLVlyGrXfJknikZG37Z/8aEvp86
         8Nig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793933499; x=1794538299;
        h=content-transfer-encoding:content-type:mime-version:subject
         :references:in-reply-to:message-id:cc:to:from:date:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=C4YKO6ifCvG670/AtfKy+sKSzMH1iQMMQOHq83vJaQY=;
        b=AL+X2xjabsXKVWXGl0woSiyzZKjAGccVscK5HrVbCVFqsKPY/8fJ65ftd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mSkr2y0JN3Ldb3
	WqUDI2aMNYmInPWROGTTdjbVyDlWNIBWW8leThtEwBfV80XGkQXeNJhrQI1vDr56/k3ExyHWmkW
	u/dCHGqh2hI/Z5KsdBUoeunZPHhKzRAR21zyazk+6V96mU+c8xKMCHGkVqpwYw6qcNLpZOWxXtR
	M0Q6TpH/uTbvTHNKu5ZoPRMXwP+waejksugYzXSNJEBJVD4qPvRY5N2aYWfeDMzq1pAh0+dY=
X-Received: by 2002:a05:6102:dc9:b0:7cc:9d82:ae17 with SMTP id ada2fe7eead31-7d2a1521b83mr797725137.11.1793933498749;
        Thu, 05 Nov 2026 18:51:38 -0800 (PST)
X-Received: from gmail.com (223.230.150.34.bc.googleusercontent.com. [34.150.230.223])
        by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99bab48abe0sm864033241.2.2026.11.05.18.51.37
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 05 Nov 2026 18:51:37 -0800 (PST)
X-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>, 
 Willem de Bruijn <willemdebruijn.kernel@gmail.com>, 
 Steffen Klassert <klassert@kernel.org>, 
 steffen.klassert@secunet.com, 
 Eric Dumazet <edumazet@kernel.org>
X-In-Reply-To: <306E09760B4212AC+ipv4.6d58afc075934322860394a26ceaa2e8.2@tencent.com>
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