From patchwork Mon Feb 17 20:25:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gal Pressman X-Patchwork-Id: 2048530 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=q3Zi6gZB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YxZ0y5wglz1xrB for ; Tue, 18 Feb 2025 07:25:54 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 0A72B81FBD; Mon, 17 Feb 2025 20:25:55 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id TaSi-pLKsBtx; Mon, 17 Feb 2025 20:25:54 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org D544381FB8 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=q3Zi6gZB Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id D544381FB8; Mon, 17 Feb 2025 20:25:53 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A858EC003A; Mon, 17 Feb 2025 20:25:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 70847C0004 for ; Mon, 17 Feb 2025 20:25:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A6B9981F8A for ; Mon, 17 Feb 2025 20:25:43 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 1p8J9RoCeXVg for ; Mon, 17 Feb 2025 20:25:42 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a01:111:f403:2413::607; helo=nam10-dm6-obe.outbound.protection.outlook.com; envelope-from=gal@nvidia.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 8FFF881F97 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 8FFF881F97 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20607.outbound.protection.outlook.com [IPv6:2a01:111:f403:2413::607]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8FFF881F97 for ; Mon, 17 Feb 2025 20:25:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Chgs4y9QXUvaoKz3M2Y9fZXShnIKAxrLoCoxRDOvsJHXHx3mQFeQ3576oiCAJQZ+hOlePqyY0g/yasntDiAzA0VmCZpsYlVTLInv/gv58m35pkO/vxnhcRYSeFwLKjaBPF3gRGGMRyWKzZowyTiHtCYM89EVrc3Ao0E7lXebuWJcydEy9nStSLeoOZx51rV87t8G7UAmgyedfxHctuOIcSFzz6H15bS3ql5W9SqsM+YRBOi0QMf1nHc1rjCBhhRMVjQANlRVc0naazuHhcLf5Dqnc2p/L2/mtJmEw5iTajG9iE5VrUYE0ceh1UhoDaRj8w4tTsYtUHi0LWkyP+BDFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dDsnLxrwS4iXed8QxH9Bq21n6Ki5LCZ+X8pfnLhY4Yw=; b=Y+k3VwCCXIMvFuTBdwUcEuJ65VJ2RBBZsC2OZkYic6p86jMOe1CJRUF+h+X5YIaXvwjd10810AHLs3DqANSRdLYXUGrjmrbZ0up4gplL9vCu9qpKgv6hjYp2bTqsyh0bPLXiZ5qUxHI/T6kzuqYhGHw949rdT1iJp2Au4YxBOj4bGp9vCzHDhfIfl2ItGxG77l3VtYZnkMYeqiPBEUqxLYPbMGx212ZfWeVjpWTXzpjoRsHKVIu/uQQSrWBu6nbz/r3wVno7IKr8EGQOfa2VFrIN/bGCRSahPf+pKexkEgwjNIzpkGDLs5gTY+aNUKziyDw2NxEEotPUcU6gMEm0RQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dDsnLxrwS4iXed8QxH9Bq21n6Ki5LCZ+X8pfnLhY4Yw=; b=q3Zi6gZBSkM2kJEKYu3gJIBovU3RIY4G4O2VSN/0pq5VfeTcQQrkokWXNNkR8/FH8Xs+f6HQu4W2FeNghDSBZRXpiQuy5PUTttpYwWFxqhM+2OX0lIV4pbl2og6VAScDxg28Xh7Xh74q1BdY0VzslDPyn18GUlEN6Sr0jO50rnVY+2kAE7GRUeFwyq8GkjI/RDR/FNZT9dpe6prXV2yuDO8KsdETOI56e3OuqkuPXuH9MXSJFyjEnc1S9TejIu+QOi/4UmXgB6Hyi0yL6gvA33RYtTqMYum3q09g4frwivMIQMzagRjnST/4Q+qWRQG61uQ+4VEQQEgbXFzmb8dsNg== Received: from BY5PR13CA0020.namprd13.prod.outlook.com (2603:10b6:a03:180::33) by CY8PR12MB8241.namprd12.prod.outlook.com (2603:10b6:930:76::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Mon, 17 Feb 2025 20:25:36 +0000 Received: from SJ5PEPF000001D7.namprd05.prod.outlook.com (2603:10b6:a03:180:cafe::fa) by BY5PR13CA0020.outlook.office365.com (2603:10b6:a03:180::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8466.13 via Frontend Transport; Mon, 17 Feb 2025 20:25:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SJ5PEPF000001D7.mail.protection.outlook.com (10.167.242.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.11 via Frontend Transport; Mon, 17 Feb 2025 20:25:35 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 17 Feb 2025 12:25:19 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 17 Feb 2025 12:25:19 -0800 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 17 Feb 2025 12:25:14 -0800 To: , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Andrew Lunn Date: Mon, 17 Feb 2025 22:25:03 +0200 Message-ID: <20250217202503.265318-3-gal@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20250217202503.265318-1-gal@nvidia.com> References: <20250217202503.265318-1-gal@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D7:EE_|CY8PR12MB8241:EE_ X-MS-Office365-Filtering-Correlation-Id: 59a91478-2d8b-4cd2-352e-08dd4f913c71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|376014|7416014|1800799024|13003099007; X-Microsoft-Antispam-Message-Info: 7jIGNYbguvzWckSsg+Zybqw7tClymCw1koTiMMm//pu8UnQCq6DD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Eb4kCLlYpNyB+DFQFB7omiw+CrORirP+n3OXkN415c8siQezdZTOfAsdeIpvaDH7PVq3fKQafoEfC4N5Oo9hOdpA3+X6S/uMK3ywlJLEFfFCX3xFAKaWnsemur29fq2QbJqENCV+Jd280/Kd56HjZNJZ8wnIjLX6HI1pYD2ll8pNTPEW70dV2Qs+/vRb2NWjdeyMnX78W1y8DymH2biBDMlP/cWyufveGIvnSghzcSli4Azhx7IpBwW2lGrrHHueoj4vkRJTHK3DMKK/jOlZcXnJLHIxgrnOjRNMLjr2dxC+vLUnDYM/FkCe8Ici1did5T8zwn36B+3Dgy18h+qvexu6IKLv+xTiMuPuHJd6fGdNKSo7cN0J/Q727gNPKl/RGSUqANnJla8ixE= X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(82310400026)(376014)(7416014)(1800799024)(13003099007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2025 20:25:35.9070 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59a91478-2d8b-4cd2-352e-08dd4f913c71 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8241 Subject: [ovs-dev] [PATCH net-next v3 2/2] net: Add options as a flexible array to struct ip_tunnel_info X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Gal Pressman via dev From: Gal Pressman Reply-To: Gal Pressman Cc: dev@openvswitch.org, "Gustavo A. R. Silva" , Jiri Pirko , Jamal Hadi Salim , Kees Cook , David Ahern , Yotam Gigi , Tariq Toukan , Alexander Lobakin , linux-hardening@vger.kernel.org, Simon Horman , Cong Wang , Cosmin Ratiu , Gal Pressman , Ilya Maximets Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Remove the hidden assumption that options are allocated at the end of the struct, and teach the compiler about them using a flexible array. With this, we can revert the unsafe_memcpy() call we have in tun_dst_unclone() [1], and resolve the false field-spanning write warning caused by the memcpy() in ip_tunnel_info_opts_set(). The layout of struct ip_tunnel_info remains the same with this patch. Before this patch, there was an implicit padding at the end of the struct, options would be written at 'info + 1' which is after the padding. This will remain the same as this patch explicitly aligns 'options'. The alignment is needed as the options are later casted to different structs, and might result in unaligned memory access. Pahole output before this patch: struct ip_tunnel_info { struct ip_tunnel_key key; /* 0 64 */ /* XXX last struct has 1 byte of padding */ /* --- cacheline 1 boundary (64 bytes) --- */ struct ip_tunnel_encap encap; /* 64 8 */ struct dst_cache dst_cache; /* 72 16 */ u8 options_len; /* 88 1 */ u8 mode; /* 89 1 */ /* size: 96, cachelines: 2, members: 5 */ /* padding: 6 */ /* paddings: 1, sum paddings: 1 */ /* last cacheline: 32 bytes */ }; Pahole output after this patch: struct ip_tunnel_info { struct ip_tunnel_key key; /* 0 64 */ /* XXX last struct has 1 byte of padding */ /* --- cacheline 1 boundary (64 bytes) --- */ struct ip_tunnel_encap encap; /* 64 8 */ struct dst_cache dst_cache; /* 72 16 */ u8 options_len; /* 88 1 */ u8 mode; /* 89 1 */ /* XXX 6 bytes hole, try to pack */ u8 options[] __attribute__((__aligned__(16))); /* 96 0 */ /* size: 96, cachelines: 2, members: 6 */ /* sum members: 90, holes: 1, sum holes: 6 */ /* paddings: 1, sum paddings: 1 */ /* forced alignments: 1, forced holes: 1, sum forced holes: 6 */ /* last cacheline: 32 bytes */ } __attribute__((__aligned__(16))); [1] Commit 13cfd6a6d7ac ("net: Silence false field-spanning write warning in metadata_dst memcpy") Link: https://lore.kernel.org/all/53D1D353-B8F6-4ADC-8F29-8C48A7C9C6F1@kernel.org/ Suggested-by: Kees Cook Reviewed-by: Cosmin Ratiu Reviewed-by: Tariq Toukan Signed-off-by: Gal Pressman --- include/net/dst_metadata.h | 7 ++----- include/net/ip_tunnels.h | 5 +++-- net/core/dst.c | 6 ++++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h index 84c15402931c..4160731dcb6e 100644 --- a/include/net/dst_metadata.h +++ b/include/net/dst_metadata.h @@ -163,11 +163,8 @@ static inline struct metadata_dst *tun_dst_unclone(struct sk_buff *skb) if (!new_md) return ERR_PTR(-ENOMEM); - unsafe_memcpy(&new_md->u.tun_info, &md_dst->u.tun_info, - sizeof(struct ip_tunnel_info) + md_size, - /* metadata_dst_alloc() reserves room (md_size bytes) for - * options right after the ip_tunnel_info struct. - */); + memcpy(&new_md->u.tun_info, &md_dst->u.tun_info, + sizeof(struct ip_tunnel_info) + md_size); #ifdef CONFIG_DST_CACHE /* Unclone the dst cache if there is one */ if (new_md->u.tun_info.dst_cache.cache) { diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 7b54cea5de27..e041e4865373 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -95,8 +95,8 @@ struct ip_tunnel_encap { #define ip_tunnel_info_opts(info) \ _Generic(info, \ - const struct ip_tunnel_info * : ((const void *)((info) + 1)),\ - struct ip_tunnel_info * : ((void *)((info) + 1))\ + const struct ip_tunnel_info * : ((const void *)(info)->options),\ + struct ip_tunnel_info * : ((void *)(info)->options)\ ) struct ip_tunnel_info { @@ -107,6 +107,7 @@ struct ip_tunnel_info { #endif u8 options_len; u8 mode; + u8 options[] __aligned_largest __counted_by(options_len); }; /* 6rd prefix/relay information */ diff --git a/net/core/dst.c b/net/core/dst.c index 9552a90d4772..c99b95cf9cbb 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -286,7 +286,8 @@ struct metadata_dst *metadata_dst_alloc(u8 optslen, enum metadata_type type, { struct metadata_dst *md_dst; - md_dst = kmalloc(sizeof(*md_dst) + optslen, flags); + md_dst = kmalloc(struct_size(md_dst, u.tun_info.options, optslen), + flags); if (!md_dst) return NULL; @@ -314,7 +315,8 @@ metadata_dst_alloc_percpu(u8 optslen, enum metadata_type type, gfp_t flags) int cpu; struct metadata_dst __percpu *md_dst; - md_dst = __alloc_percpu_gfp(sizeof(struct metadata_dst) + optslen, + md_dst = __alloc_percpu_gfp(struct_size(md_dst, u.tun_info.options, + optslen), __alignof__(struct metadata_dst), flags); if (!md_dst) return NULL;