🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25251

[PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy

#25251
From: Steffen Klassert
Date: Tue, 01 Dec 2026 12:41
94 lines
12553 bytes
From: Andrii Tereshchenko <opensource@andrii.net>

xfrm_user_policy() compiles a 32-bit task's translated socket policy
with the untranslated length, 4 bytes short, so the policy loses its
last template: an ESP-required socket policy then sends in clear
text. Have the translator return the translated length.

Made with an AI coding assistant, reviewed by the submitter.

Fixes: 96392ee5a13b ("xfrm/compat: Translate 32-bit user_policy from sockptr")
Cc: stable@vger.kernel.org
Signed-off-by: Andrii Tereshchenko <opensource@andrii.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/xfrm.h     |  2 +-
 net/xfrm/xfrm_compat.c | 18 ++++++++++++++----
 net/xfrm/xfrm_state.c  |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 1866e5a3b911..5fbb73474e32 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -2331,7 +2331,7 @@ struct xfrm_translator {
 			struct netlink_ext_ack *extack);
 
 	/* Translate 32-bit user_policy from sockptr */
-	int (*xlate_user_policy_sockptr)(u8 **pdata32, int optlen);
+	int (*xlate_user_policy_sockptr)(u8 **pdata32, int *optlen);
 
 	struct module *owner;
 };
diff --git a/net/xfrm/xfrm_compat.c b/net/xfrm/xfrm_compat.c
index 670e3512fc09..af5cb36d691e 100644
--- a/net/xfrm/xfrm_compat.c
+++ b/net/xfrm/xfrm_compat.c
@@ -642,16 +642,25 @@ static struct nlmsghdr *xfrm_user_rcv_msg_compat(const struct nlmsghdr *h32,
 	return h64;
 }
 
-static int xfrm_user_policy_compat(u8 **pdata32, int optlen)
+static int xfrm_user_policy_compat(u8 **pdata32, int *optlen)
 {
 	struct compat_xfrm_userpolicy_info *p = (void *)*pdata32;
 	u8 *src_templates, *dst_templates;
 	u8 *data64;
 
-	if (optlen < sizeof(*p))
+	/* The 64-bit layout only adds tail padding, and the templates
+	 * after it are the same in both layouts.
+	 */
+	BUILD_BUG_ON(sizeof(struct xfrm_userpolicy_info) -
+		     sizeof(struct compat_xfrm_userpolicy_info) != 4);
+	BUILD_BUG_ON(offsetof(struct xfrm_userpolicy_info, share) !=
+		     offsetof(struct compat_xfrm_userpolicy_info, share));
+	BUILD_BUG_ON(__alignof__(struct xfrm_user_tmpl) > 4);
+
+	if (*optlen < sizeof(*p))
 		return -EINVAL;
 
-	data64 = kmalloc_track_caller(optlen + 4, GFP_USER | __GFP_NOWARN);
+	data64 = kmalloc_track_caller(*optlen + 4, GFP_USER | __GFP_NOWARN);
 	if (!data64)
 		return -ENOMEM;
 
@@ -660,10 +669,11 @@ static int xfrm_user_policy_compat(u8 **pdata32, int optlen)
 
 	src_templates = *pdata32 + sizeof(*p);
 	dst_templates = data64 + sizeof(*p) + 4;
-	memcpy(dst_templates, src_templates, optlen - sizeof(*p));
+	memcpy(dst_templates, src_templates, *optlen - sizeof(*p));
 
 	kfree(*pdata32);
 	*pdata32 = data64;
+	*optlen += 4;
 	return 0;
 }
 
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index f4a4ddaeb9b3..eb984ed11888 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -3115,7 +3115,7 @@ int xfrm_user_policy(struct sock *sk, int optname, sockptr_t optval, int optlen)
 			return -EOPNOTSUPP;
 		}
 
-		err = xtr->xlate_user_policy_sockptr(&data, optlen);
+		err = xtr->xlate_user_policy_sockptr(&data, &optlen);
 		xfrm_put_translator(xtr);
 		if (err) {
 			kfree(data);
-- 
2.53.0
Technical Details
Message-ID: <20261201124252.1163254-18-steffen.klassert@secunet.com>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375041-linux-kernel-netdev=dewy.ru
References: <20261201124252.1163254-1-steffen.klassert@secunet.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375041-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy
Date: Tue, 1 Dec 2026 13:41:43 +0100
Organization: Usenet Network
Message-ID: <20261201124252.1163254-18-steffen.klassert@secunet.com>
References: <20261201124252.1163254-1-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1711836"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:AV2US1Ynjw26nQxRQ32kA8aSXhc= sha256:nJ3XXkBgV3p3f09GJW+EeofiTc/XZ4pf7nv2Y6VgPF0=
	sha1:Mv9Rkw8RvZKhzfVw/kgh4SGFvWk= sha256:iJjgUIgs0E27F5AjFkpKJIp2Wl34Et1IDbhw0YZUkVo=
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 B1A17117390; Tue,  1 Dec 2026 15:44:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, 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, URIBL_BLOCKED=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 dhXfnR-Ueouw;
	Tue,  1 Dec 2026 15:44:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375041-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id D8427117387; Tue,  1 Dec 2026 15:44:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 41C6229303; Tue,  1 Dec 2026 12:44:18 +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=1796129050;
	b=bv+tOGbaq8Xbh9ecZRZXfQWPQ/Vv7QYdVwlPFBCoBjRegIav1xtXegbKJgnjrAt7wklq
	 KNq9qcJKOqv4PiMZuv9bhk1L4wcLiMYqfv11IYVwpRH1ViJqP8WNKvtnFVMkk+rO+GPu3
	 2MZiyo3k2gTRETHerkfyqSOuEspW2r1yHwiU8SNs/AoHqaNkFmjDd6NVsdUfsfuvacTHf
	 b9p/6jcxOiIPgEqTP8IEvmOGiZrepQTLVVgc6OvdxjIx4Wl0ST7AHJI1RRBpwJj4uSbJC
	 GKGykckzOZfbhO/3QzsKIJnhWst//0j+I53DFWa2bZfQiD2RdBAGw5Xa9Wix32KHvMA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796129050;
	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=DCCIXdYM4ZtYykyaMpkjMVXxISfrFcojSpEg7vcw/iU=;
	b=kYYbrecFi8UODC6kfzt/WDWcem+wCaxRSnd2HHyU+yENdG+5HNX6NjhUIdz4Ek6/hKJ3
	 e2pRxVf2tmOR4BnQb9oJYLXb7EbTcFuqCXjKv/aUx4Q59uLfLwSuHOMI3ubDtmfiGszj/
	 LtLXLMK3YjETi5BkqWf+AgMYviXRqb1529DIqQTO5FbeNIORGTktzwgyGWZfbZWMaUvjx
	 +5HT0qwGprAAVr6+O3z76Js0IeiE8KEHNHm8fpY2b2ERKpCs+EhT4SPMTewD73OZPf1Z/
	 QUSKD8+EcMs5vl+ysPpf1t61IKJ81mBrrgD112uiOMX2s0HrPfVeyh5IP5V6bMc4j1w==
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=WU1yzWza;
	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 2D707606A6AA;
	Tue,  1 Dec 2026 12:44:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=WU1yzWza
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=1796129049;
	b=tgrAmcrOAMM4dRbZyquWSPUw/12ARJmQyROmhiDTOektb9LZa7NxBLCCXbylq+R0cVaZ
	 t1bEavzPmmecqCUUeaZI66/YKO0/KsYeS4tDQcpVpeSZ+4dpJfyezwcIiKIuCV/RXmk3k
	 muxOuGuwlTA61tG6i9ESqU9FQNdgy5InuSIHEkvugiZOSw3oMUa8PI6To9SVWmU3J4LXS
	 O3pSJMtCcmFb4PbjnkOlpjIZNZNrF7cOFnhWF2dmHk8i8VVeZ4BUxenwYu9/2pYINhL8r
	 yH6r9/+LJMdfLqXEKvwP1cU08CysrR2Pjl6Y/BRu0QCLZ6QxOtbc2MaDwFsOV0v1xPw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796129049;
	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=DCCIXdYM4ZtYykyaMpkjMVXxISfrFcojSpEg7vcw/iU=;
	b=l0a2qmpK1ImcmzC0Z82cJLoPKEaMU+cKWLdRVeiBvEjGq40Oo3H8/ahwF0nv2vy8MN8s
	 cGe33u0AvP+6yE4lKVnhWHgKMwGbUgowQkcfoWwSsoCknQ7B3mKJ5hzmx3sdopcPLj5Oa
	 p0zL4IMTRDoV0IjIkAE6nXVPS+Xeu7MOVRd2k+NQQ4CMjADmN+y7HdGMI/P18hA7Wzes0
	 YYMr92khnsh8mUZ7pnljG8SJy0H2gVuKe/buldrsurSkIq5D7T678LC3KNNGaxapDOn2k
	 c9lAnlvgaJ0p183COGG+ZsYF1xGtSEQ8AsyBzXAHENQep2DY8BI5R4UPg2JceES2l4Q==
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=WU1yzWza;
	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 B084E606A332
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 12:44:08 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B084E606A332
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 73ECB204D9;
	Tue,  1 Dec 2026 13:44:07 +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 4Ole5VWIc6oQ; Tue,  1 Dec 2026 13:44:06 +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 B4F342080B;
	Tue,  1 Dec 2026 13:44:06 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com B4F342080B
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1796129046;
	bh=DCCIXdYM4ZtYykyaMpkjMVXxISfrFcojSpEg7vcw/iU=;
	h=From:To:CC:Subject:Date:In-Reply-To:References:From;
	b=WU1yzWzarjEOgdJTfq2hreGXJCgAvPav6P+CErCJg8BhWOihCLtgdkI4M9IaP7xwr
	 HPw1UGDG1SgULS7fGTiLOcmGmTuSNH6nlr3MhZjuN/p7h5Bo9PDBcmdP+BOoIwEE+w
	 BhKCutNltOtRrJ/QD0o5e6b85/h34q1BPbXmzgrswYmF44LPsGG5XijFJJVohmufYy
	 HycOrM7dYP4t6B0oETXOa6tQpeK0/NsW3dQ0sQvyjjy3Udz41mAnOCfL4ySZUAySXB
	 DuCRUwUyHlPuP+jQsAQxipSEhwCztpPfZs1CSlAJi7PytPHfWuGTbrQamcc/Jl46nl
	 ouOBrfDRmuJrw==
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; Tue, 1 Dec
 2026 13:44:06 +0100
X-Received: (nullmailer pid 1165822 invoked by uid 1000);
	Tue, 01 Dec 2026 12:43:56 -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: <20261201124252.1163254-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-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de
 (10.32.0.171)