From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 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== 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== 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 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 ; Tue, 1 Dec 2026 12:44:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B084E606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com 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 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 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) 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) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com B4F342080B 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== 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 Received: (nullmailer pid 1165822 invoked by uid 1000); Tue, 01 Dec 2026 12:43:56 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Date: Tue, 1 Dec 2026 13:41:43 +0100 Message-ID: <20261201124252.1163254-18-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de (10.32.0.171) From: Andrii Tereshchenko 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 Signed-off-by: Steffen Klassert --- 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