🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9514

[PATCH 02/14] xfrm: interface: validate the IP header on xmit

#9514
From: Steffen Klassert
Date: Mon, 02 Nov 2026 10:04
53 lines
11073 bytes
From: Qihang <q.h.hack.winter@gmail.com>

Packets injected into an xfrm interface (e.g. AF_PACKET on an xfrmi
device) reach the xfrm output path without IP header validation, but
xfrm4_transport_output() uses iph->ihl for __skb_pull() and memmove()
and expects the header to be valid.

vti_tunnel_xmit() already calls pskb_inet_may_pull() before handing
packets to the xfrm output path.  Do the same in xfrmi_xmit() and
perform the header checks ip_rcv_core()/ip6_rcv_core() do on entry
to the IP stack: reject wrong IP versions and malformed IPv4 header
lengths.

Fixes: f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Qihang <q.h.hack.winter@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_interface_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c
index 688306bf62c5..9835fbe63ccb 100644
--- a/net/xfrm/xfrm_interface_core.c
+++ b/net/xfrm/xfrm_interface_core.c
@@ -531,8 +531,13 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	memset(&fl, 0, sizeof(fl));
 
+	if (!pskb_inet_may_pull(skb))
+		goto tx_err;
+
 	switch (skb->protocol) {
 	case htons(ETH_P_IPV6):
+		if (ipv6_hdr(skb)->version != 6)
+			goto tx_err;
 		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
 		xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6);
 		if (!dst) {
@@ -548,6 +553,9 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 		}
 		break;
 	case htons(ETH_P_IP):
+		if (ip_hdr(skb)->version != 4 || ip_hdr(skb)->ihl < 5 ||
+		    !pskb_network_may_pull(skb, ip_hdr(skb)->ihl * 4))
+			goto tx_err;
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
 		xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET);
 		if (!dst) {
-- 
2.53.0
Technical Details
Message-ID: <20261102100451.2505200-3-steffen.klassert@secunet.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-354517-linux-kernel-netdev=dewy.ru
References: <20261102100451.2505200-1-steffen.klassert@secunet.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-354517-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: [PATCH 02/14] xfrm: interface: validate the IP header on xmit
Date: Mon, 2 Nov 2026 10:04:00 +0000
Organization: Usenet Network
Message-ID: <20261102100451.2505200-3-steffen.klassert@secunet.com>
References: <20261102100451.2505200-1-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2877357"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:GAfxxpZgiONkE6ECBgFQ1zbmFnc= sha256:9Rurg4BUum9K4GH1BwErGEYRGAfhNbn8qPIY237KlUc=
	sha1:7eiivEOwjHQI8yicuxWxwDiS4G4= sha256:u0J+9uAicTV62yVfUthSheAz0Opt6YNvrQXnUnlMnZw=
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 D9A50112455; Mon,  2 Nov 2026 11:06:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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=secunet.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 Ai4kbQp2nNdi;
	Mon,  2 Nov 2026 11:06:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-354517-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 69CB6112451; Mon,  2 Nov 2026 11:05:50 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 4949A606B5C; Mon,  2 Nov 2026 08:05:11 +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=1793606697;
	b=hjZXm8l7NaW7N5fHlHVjVIZJ7BbGvjaFMWQkT0cuWqHLL5+sx6hTndpQhlETf/QPqkX4
	 U97tcRXRUoMiZPVMzMImC1WIblpOL3bYGOR0m3ygNFDWrLOqQbS0qqPDY+m6ZqPuGCK/M
	 DzaoYODjRe0oSgoN0ma0xSu8m0eBdTQH3I/cVLuXvnx0oJ+KfsS2r7wsDlVGICb6X1pUk
	 3LrtJU5lGAWZdxr6IoW5Biz7s3C61R0n10RTr//YbkSQZxtHcZ6mwKtARmglUxK8Ls/L9
	 erfjcoISRYqwKbWIhAslKxJtSBQlY1ChD/xWrVb1oIXytdsMBmnlqacaRT5VID/3Srg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793606697;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:From:
	 To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy;
	bh=JJOfP7vZWx1DyOE/pLYhFXf4iaTgGdCc9z1px/f6kZM=;
	b=o7tsW1YOEcp6w697wDJrybmEcxI7vuJsYXaWR7D8pw1u7nQHhoXd5gij6BXsPwIdKP0e
	 R063Yd+GS3hXk8zZlpIjhxmpGTbEnkEPL0OBocjK8TjeXjqwhYWHqbzPKuMpZaRiopVHf
	 uGAFEfVOj3SggdM/apA5EuFF1j9MBbJ7yb974IJvZ8BG0tzrdZEvQRhB2/EOXCgStC7wD
	 /kiDx77lSIaCsiXLzaiDs7IHRWUCZ+0uZAHWOAhNV1oiF3KvtqYFZ+8JCzMjMNlLhDp1l
	 rF6Y+jSRFrdVY5Vy8LmlFWzioaImOt1u2Wf7RPVLeLDrJVknQx9ORfsiwGUdxxSGbog==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=bQtHIzSC;
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.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 4CBD660A2614;
	Mon,  2 Nov 2026 08:04:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=bQtHIzSC
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793606691;
	b=xLi8K8jbCIS16D9dbkdDGpzv8ZoV/93P+2/M6whdCZtMzMiA575+YId1CbZcv+RHgCYj
	 VIvjK2G1iiT4c/qR0SbDOTbkL5sYuSpzkJQhIHavyPCDR2srBSHwMFjq/+pJdcl3nHRdi
	 gT76j6djUAr+LIAea+6wFOEf7Dcfe0LAqLP3quQClBxF5/kPIpWb5qTL4aSTkV5K6EGO3
	 VfXiKo8ZO9OaN+nOF1nwGh3/EGv97oUuK26FI6hKe6f0fSvOptenwr9nRswLbvKVCuK/G
	 B1v9wJXroynseOkmBUgg9g8SAkDBu7Dsy4P1pr8B/+1AXmg5V4yiJERb7OCoG9EI2Bg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793606691;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy;
	bh=JJOfP7vZWx1DyOE/pLYhFXf4iaTgGdCc9z1px/f6kZM=;
	b=oKR8mw/Ue5QwTxOLlMi8CEsVGpL6iv80gpRPnn2JXKObB9UfTTFRVOM73HfbtTB4lgnp
	 VMJoG1EVYJLnFhpMWMNTEhNwMEv/FNlBXXscxOzOUKjBeIOt5ntKsyosP9kcvAYAzwEJw
	 HvvUcmheRrwFJRB+xBzmhjScOsq1/P78xIQrvVKI1VvDVDHgxKZ40JearXVczTpOzIz9y
	 jt+L2I8MbCexZqMCH0xcFZ/xE9q3YB0mYF5C2irxfFViUABntqmhoka07munezlFemBob
	 h1xvZkp4rvqJswH38CtAjUSrHnUFYtSuVagdPlBDJAnWPFhVPfpSWuOqPdg5LXgftuQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=bQtHIzSC;
	arc=none smtp.remote-ip=62.96.220.36
X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54D9660A2602
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 08:04:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 54D9660A2602
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com
X-Received: from localhost (localhost [127.0.0.1])
	by mx1.secunet.com (Postfix) with ESMTP id E2631207D1;
	Mon,  2 Nov 2026 09:04:48 +0100 (CET)
X-Virus-Scanned: by secunet
X-Received: from mx1.secunet.com ([127.0.0.1])
 by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id m6-uLOdAyCt9; Mon,  2 Nov 2026 09:04:48 +0100 (CET)
X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mx1.secunet.com (Postfix) with ESMTPS id 5C12B207B0;
	Mon,  2 Nov 2026 09:04:48 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 5C12B207B0
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1793606688;
	bh=JJOfP7vZWx1DyOE/pLYhFXf4iaTgGdCc9z1px/f6kZM=;
	h=From:To:CC:Subject:Date:In-Reply-To:References:From;
	b=bQtHIzSC+wy1e7QsEZVp214Yok5ICZVd2cwsExsheQ4UGkxP3/0p1mdbS2MEFriCh
	 575vMNzQq55vuwdwVFQfVElHxS8ihUVuTOfyg08KP1Z2ebJzsM6FzopugemWRqZzGL
	 1aI0dGHRwghXz4nAbiRibNeUrUxAa7aZPfJkRgW0kyp39wyrj4z/h4awYIqGW5Q+M5
	 FT9gYlSa3FprR3/XCrRhcekuaDS4eTNx2KNvTolvHTxv9APdIjdg9uSuL/xC9d5hlq
	 Za7v+l8Zp4gNf1MH1/pH4uTzsU5RyHfbyhM/a9nKJYgOkvh+xGr0r8i+8XOn7QDK3h
	 xfwACm5QORs1w==
X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Mon, 2 Nov
 2026 09:04:47 +0100
X-Received: (nullmailer pid 2505894 invoked by uid 1000);
	Mon, 02 Nov 2026 10:04:58 -0000
X-CC: Herbert Xu <herbert@gondor.apana.org.au>, Steffen Klassert
	<steffen.klassert@secunet.com>, <netdev@vger.kernel.org>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261102100451.2505200-1-steffen.klassert@secunet.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
X-ClientProxiedBy: EXCH-03.secunet.de (10.32.0.183) To EXCH-01.secunet.de
 (10.32.0.171)