🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18201

[PATCH net] ipv4: don't let the transport header offset wrap

#18201
From: Chris Mason
Date: Wed, 18 Nov 2026 00:48
53 lines
9202 bytes
From: Josef Bacik <josef@toxicpanda.com>

skb->network_header and skb->transport_header are 16-bit offsets from
skb->head. ip_rcv_core() computes transport_header as
network_header + ihl * 4.

These offsets are normally small. But a tunnel pulls its outer headers
and hands the same skb back to the stack. skb->head stays where it is,
so skb->data moves further away from it with each decapsulation. After
nested decapsulations the end of the inner IP header can lie beyond what
16 bits can hold.

The fix used here is to set the offset with
skb_set_transport_header_careful(), and to drop the packet if the offset
does not fit.

The helper computes the offset from skb->data, which points to the IP
header in ip_rcv_core(). It does not use network_header. So it also
catches a packet whose network_header was already truncated, where
network_header + ihl * 4 would look valid.

Found by LLM code inspection, and confirmed with LLM generated
reproducers on an unmodified kernel. Fixed by LLM, and tested with
the reproducers and existing kernel selftests.

Fixes: 21d1196a35f5 ("ipv4: set transport header earlier")
Assisted-by: LLM
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Chris Mason <mason@kernel.org>
---
 net/ipv4/ip_input.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 9860178752b8..397043893376 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -572,7 +572,11 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
 	}
 
 	iph = ip_hdr(skb);
-	skb->transport_header = skb->network_header + iph->ihl*4;
+	if (!skb_set_transport_header_careful(skb, iph->ihl * 4)) {
+		drop_reason = SKB_DROP_REASON_PKT_TOO_BIG;
+		__IP_INC_STATS(net, IPSTATS_MIB_INDISCARDS);
+		goto drop;
+	}
 
 	/* Remove any debris in the socket control block */
 	memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
-- 
2.55.0
Technical Details
Message-ID: <20261118004850.52808-1-mason@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365739-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365739-linux-kernel-netdev=dewy.ru
From: mason@kernel.org (Chris Mason)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] ipv4: don't let the transport header offset wrap
Date: Tue, 17 Nov 2026 19:48:50 -0500
Organization: Usenet Network
Message-ID: <20261118004850.52808-1-mason@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2465633"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+EtHZaeTPz6cYQh2Utds5HE053o= sha256:A7wrTcPjuK3ex3SHG4yc9EPu+BLDV1wag2d2S6S3NO0=
	sha1:ZTHGIhKDP+mqR9XA/FoPRzxjHnE= sha256:QevpUDqh2wdiucOFoqX3zxt3IDfgWntX024PKqQ/8D0=
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 2CDEA1150AC; Wed, 18 Nov 2026 03:49:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 qDZssRwR2W8o;
	Wed, 18 Nov 2026 03:49:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365739-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 695AE1150AA; Wed, 18 Nov 2026 03:48:57 +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 E21DA4217C; Wed, 18 Nov 2026 00:48:54 +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=1794962934;
	b=eQx+dAIbSzURQCupKF56/lbfV8PkTkOwuYhma5TetJNiPcWgPBQFUYgt6d0GblOHolPy
	 Iv1Dou0Zw/MdD+cVm0urXmXkHirS52N1UB9cpF2wkkM3/yHQ4Vx3oZ+UHIhND756zjn3U
	 LwZlL1YqRVW7luaT/Y8BYMmsFiAO1RtieiRqUqfwqEgqKyeKulE7s5pBhsju9Mi6iM6Vj
	 0o2CkLrVL/YrD5DiOggi4ADyH2+z6Ykr2Bt/+iT1x/NNNAu89px1nrB2Cg5lAr8Mu9ZTY
	 L+QeSFuSRmIcXExgeVtZt/l/Q8Q1QZNf3Nw3kUKDUOxGlY+iaa18WwNTFT8UOk1jj0Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794962934;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Subject:Date:
	 Message-ID:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=M+o3XGA+ZVeQwU3F3oDZDSpaFvjG+cSYymZrG+icHTg=;
	b=kc8yrbO0HcTCEGpSCF9oVro+DIkambhOK66d7JdYRnnoUwhpATo7UWHkaJFgWnSwYvL6
	 BDo9hsFsQJjExLtw3cq1KaQAdKk1wfHjDr+BIUFwgn/w++S8nQUhmzeVjvnMfNbC6RTna
	 +1wQ7KJwPv6z3JIJDV/uvFMETte8GqBnmU/GY+bfJfQBXg+EPvzdhVYON6aOMrqS8Mbof
	 EosspuE3NQRKb7Ve/hOiNc6iHmI1IgZVIitbjkNWrx+ieCPT1nVaWdRyDiCA/JbmQaFi4
	 6t79feEyPh7oLjY/S5wzrcKL8MeABEiEoWQ3iNMOgXiZIM2Gmym91lZKjx6/IuVQiEg==
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=LeX1FwkO;
	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 0D1A9606A33D;
	Wed, 18 Nov 2026 00:48:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LeX1FwkO
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=1794962933;
	b=ZMQ+oDiMqsC6M5By/s1xjxAWPv3ozIj8kz8+l+jKe/GwfSIR4gy7uGYLiY9+HxO2irCe
	 7utjVxajwTTBX81bP0MIHR2SbYXT00S7ANlX3OIvLBImZtWW0UM1XIVw66KrnhTkDzvhO
	 +8btcCKR8DRbzTwxfT7w82k3b47SmIS2uI0dJGoR/fP6mwASkOYYNACeP/jbl41Gcz/ml
	 4mkisdOsegS64Q0cZe5OiQ2zpS4eaXFZIYtDTfij4g/7NQBadOBQn4sEbBT52vpTskd4s
	 F5x15S5HBdjsPrjmZEul5IRdx8DWI6HH12YpNI0Scyf7N1BsfTgaO4MNgGa2JuZ6Pqg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794962933;
	h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version:
	 Content-Type:Content-Transfer-Encoding;
	bh=M+o3XGA+ZVeQwU3F3oDZDSpaFvjG+cSYymZrG+icHTg=;
	b=LEyyYoHwZAInl8r2tDNUhr7qGwLSWHiFl19yNzyGAuQSDIyyOwXTYeArq4djzI64n0I8
	 7BxanIYrjepI60uOgpDglUvV9RVFxKsWTxSb+Y0eGrk3w88NCka2SN0MuqUDqPYue6t/p
	 B/ZzC1jd+VqpOnZWFIy1Q8lxhdqiYKlyyQ5JCeB35YXIEcznWzmOQVWaAaJwDLUEkmTBM
	 e7wcj10EZ4wnnE0KIb0GlRGMqHFjOXfDgX8vjQ3YyJa/pLKdhd0EwvUpVWJcyaGkMhc5s
	 zhf6SNWSfYZyAhgfeo5L1gHKk7G2wXYxDVzYqqYtT7Ak2Ai+3yr25Xa9jrP74mFKGHw==
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=LeX1FwkO;
	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 2D5CF606A880
	for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 00:48:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EBB81F000C4;
	Wed, 18 Nov 2026 00:48:51 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794962932;
	bh=M+o3XGA+ZVeQwU3F3oDZDSpaFvjG+cSYymZrG+icHTg=;
	h=From:To:Subject:Date;
	b=LeX1FwkOUexPyXihUG1we8e/75Rvc67d3zP5hQUVC7wcjUCRHze6OgfRQJsdUsiSM
	 6EXhRqtG05pDRYtzIUThE1HdrPtLEihwSRZGWnclJ/QXwkUNFMzCMmSdjmHS3VrdMg
	 sGaCSueNNj46AbEGG/Pvciwzld/ob8CNtPVIuOXcxNfpjgrvWKUhNG5UehI+xvDdsO
	 Agmw7orAhM5/mgh5CgFcu4RmNumOohQeHy+OG3gohql/vzhqAJgy6WNxk5moL4ar6N
	 NRb7lhK7bmff0ISlmzCZFwa4Vgr/NYEK9FvEs33u9UNGtJm6tEkA/3UH6UU8qxpzmh
	 YUV8qd0/m/q/A==
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