Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp729863lqh; Thu, 28 Mar 2024 14:46:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGFRv1SHQFY2JBD59GyYAIcAqCpxaLquRe/mwtn2rAPzzDVRWylF3PZ7MfJEMQefjNJ0KC/RBuI4awz0StbGBuYduoVSrhWwbVdwaQxw== X-Google-Smtp-Source: AGHT+IG8tgGQOHG52Fsr+C1MOp/tCvPSjlw1KS/mq3d+BwqUalGg3bvAa+RTWWvSQxm0RlcA2s+V X-Received: by 2002:a05:6a20:7d8d:b0:1a5:6ff6:9fcb with SMTP id v13-20020a056a207d8d00b001a56ff69fcbmr975274pzj.19.1711662382038; Thu, 28 Mar 2024 14:46:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711662382; cv=pass; d=google.com; s=arc-20160816; b=hHE5fwCFiCIKiaBBTpb4/hfZDlYZMSp8fwo0RNNYQYd2AaFz7IUnxIeVpWgqJkXYyi juxUCWTrOjwDOsJtyR9Gp1pIaPzM0hi4uXuwTlz6PJvtvd6MlkDKGUqGlZnmIRTo/+8R a4Ojm6AtPBaUZOkn9eooLAYtfntaqLdtmoWiA/7FM3nGQBgyzC93cdxYZMLtDO3hH1Sy 1qHxyHg7Xpdpa+pxlhbtxVGYTolrZhrzy3j1/cCNrT7uzJn5UoO0Mbwcoz1W+fmPVwWl ru0X37OSfiA67EtH5UZXlHryqD34h+Xu46LUq8XwjbOkC0KhyqOKuk1JYTPqejhWrCZI fjlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=xah/SE4ETWg0JZ+gioO9Ep3THuE7QCeldV9BY/5wmXU=; fh=CwsoiskgUKzLBnSkXnbrMtQvpPBim7oWy3d5xZ04i/M=; b=iNVsUldPtihxr3z7TaVB8pPP2Yye5W7m0IubOZ+qkGrVksUxVpFweI3p+VqXPi66o9 oAgsHgj9JMdCTehgMSYxrRJEdJRKELvMFXTqhxuhC2CJZxWyrGrkYaGMK3d82cjOwjz3 QTHQigMW60G1cLkh38dhXfpWGTUqSTeha9WdUaH6RLBlJhZQgbWqooA92h6CcXm496Aa IyIQ+Q+IF8i3Is4Vl8Mc0x5pLyefXkTJ0VtA78by9bdZ9A0z6PNuOU64jCPjT1PgwSRn bWqoLHzHUVBvARwEKVJzAePNR3i3RsaAbAWi5bc+5Qgq3hWzC3qgMni1XQ1OdTNPZZ94 BIjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EAe6Uqtf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p13-20020a63ab0d000000b005e17c9e194fsi2286586pgf.247.2024.03.28.14.46.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 14:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EAe6Uqtf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AFB7A2905AF for ; Thu, 28 Mar 2024 21:46:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64FF813B2BA; Thu, 28 Mar 2024 21:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EAe6Uqtf" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 729DC40852; Thu, 28 Mar 2024 21:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711662372; cv=none; b=oPu2SfoD+LB3rkSexg0fMi9L/+tO11rF5H3TS4r++ZKRxNH6n5QgpRLNOrLwv+VcP/N68YUA8T90jml3KMaa5evVeR9Oou81I2F0Aw6CnsA3uiO5Z11dyGgbuZsBfSQkWStJMEgrHM7qq12L24RLOlwuUZIiYeGmhejhYJy5dnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711662372; c=relaxed/simple; bh=BUuK9Y3a97hKqqVxYQHw0k12luY8EW9jyYTqhMIgmkM=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=egrCuFvGDoN2dTR7pbxF8GdPjg9w60E6lITZr66cRnF54C5v8emOvLH4pRKGWU9lb6Luq03Mz+zUHcboDlOOTybZvrFu9V2kYbahJDP5rP4HU7WqZOHDXkUlSj41eCmdz1xB5duRN159pcNZlgo7jIzddOiKDUVGQ0BF9PU+92I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EAe6Uqtf; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D55E5C433F1; Thu, 28 Mar 2024 21:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711662372; bh=BUuK9Y3a97hKqqVxYQHw0k12luY8EW9jyYTqhMIgmkM=; h=Date:From:To:Cc:Subject:From; b=EAe6Uqtf8Cj1vU1undhD6AgFufnJX8YBReXNOF+4VK8dhd3e+yOaSqblSu5RRkRNn xfk1qjmzJ8JhDfq0DsLtIVKqQQvuTlALY/QzFDxdgIQkHSnqflSpgl97hjbgBf54ej 4Kr7TezJMQ5A1cbWFZF49yqNtyMvghdjWXohOkuet19tM2aazs3lg5slPopEh6n4ki AntoItZr56N8bLxByB8iMJTqIE7PqgijkEC6Lrx/4qRdfUcNq44bGUjWlKl9jie+Hn Z4VOzPjfR/BG/mjqd2yUzEpp7oEX5u4HZDOqPMd0BkQr4OMWqd+UlaMY7tKqU4fAKM eAcEYPAOEXWQg== Date: Thu, 28 Mar 2024 15:46:08 -0600 From: "Gustavo A. R. Silva" To: Wenjia Zhang , Jan Karcher , "D. Wythe" , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , Kees Cook , linux-hardening@vger.kernel.org Subject: [PATCH v3][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. There are currently a couple of objects in `struct smc_clc_msg_proposal_area` that contain a couple of flexible structures: struct smc_clc_msg_proposal_area { ... struct smc_clc_v2_extension pclc_v2_ext; ... struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; ... }; So, in order to avoid ending up with a couple of flexible-array members in the middle of a struct, we use the `struct_group_tagged()` helper to separate the flexible array from the rest of the members in the flexible structure: struct smc_clc_smcd_v2_extension { struct_group_tagged(smc_clc_smcd_v2_extension_fixed, fixed, u8 system_eid[SMC_MAX_EID_LEN]; u8 reserved[16]; ); struct smc_clc_smcd_gid_chid gidchid[]; }; With the change described above, we now declare objects of the type of the tagged struct without embedding flexible arrays in the middle of another struct: struct smc_clc_msg_proposal_area { ... struct smc_clc_v2_extension_fixed pclc_v2_ext; ... struct smc_clc_smcd_v2_extension_fixed pclc_smcd_v2_ext; ... }; We also use `container_of()` when we need to retrieve a pointer to the flexible structures. So, with these changes, fix the following warnings: In file included from net/smc/af_smc.c:42: net/smc/smc_clc.h:186:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 186 | struct smc_clc_v2_extension pclc_v2_ext; | ^~~~~~~~~~~ net/smc/smc_clc.h:188:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 188 | struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; | ^~~~~~~~~~~~~~~~ Reviewed-by: Kees Cook Signed-off-by: Gustavo A. R. Silva --- Changes in v3: - Adjust code to 80 columns. (Wen Gu) - Add a couple of code comments. Changes in v2: - Name the tagged struct *_fixed instead of *_hdr. - Add Kees' RB tag. - Link: https://lore.kernel.org/linux-hardening/ZfCXBykRw5XqBvf0@neat/ v1: - Link: https://lore.kernel.org/linux-hardening/ZeIhOT44ON5rjPiP@neat/ net/smc/smc_clc.c | 6 ++++-- net/smc/smc_clc.h | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c index e55026c7529c..33fa787c28eb 100644 --- a/net/smc/smc_clc.c +++ b/net/smc/smc_clc.c @@ -853,8 +853,10 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, + struct smc_clc_v2_extension, fixed); + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, fixed); gidchids = pclc->pclc_gidchids; trl = &pclc->pclc_trl; diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h index 7cc7070b9772..f37d9a72b635 100644 --- a/net/smc/smc_clc.h +++ b/net/smc/smc_clc.h @@ -134,12 +134,15 @@ struct smc_clc_smcd_gid_chid { */ struct smc_clc_v2_extension { - struct smc_clnt_opts_area_hdr hdr; - u8 roce[16]; /* RoCEv2 GID */ - u8 max_conns; - u8 max_links; - __be16 feature_mask; - u8 reserved[12]; + /* New members must be added within the __struct_group() macro below. */ + struct_group_tagged(smc_clc_v2_extension_fixed, fixed, + struct smc_clnt_opts_area_hdr hdr; + u8 roce[16]; /* RoCEv2 GID */ + u8 max_conns; + u8 max_links; + __be16 feature_mask; + u8 reserved[12]; + ); u8 user_eids[][SMC_MAX_EID_LEN]; }; @@ -159,8 +162,11 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */ }; struct smc_clc_smcd_v2_extension { - u8 system_eid[SMC_MAX_EID_LEN]; - u8 reserved[16]; + /* New members must be added within the __struct_group() macro below. */ + struct_group_tagged(smc_clc_smcd_v2_extension_fixed, fixed, + u8 system_eid[SMC_MAX_EID_LEN]; + u8 reserved[16]; + ); struct smc_clc_smcd_gid_chid gidchid[]; }; @@ -183,9 +189,9 @@ struct smc_clc_msg_proposal_area { struct smc_clc_msg_smcd pclc_smcd; struct smc_clc_msg_proposal_prefix pclc_prfx; struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; - struct smc_clc_v2_extension pclc_v2_ext; + struct smc_clc_v2_extension_fixed pclc_v2_ext; u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN]; - struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; + struct smc_clc_smcd_v2_extension_fixed pclc_smcd_v2_ext; struct smc_clc_smcd_gid_chid pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; struct smc_clc_msg_trail pclc_trl; -- 2.34.1