Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1210586lqz; Sun, 31 Mar 2024 20:34:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3zmNk/lnwB/0CEo9mCSEtmhamf/e7UsycGnVy3DljOZqNhcV6ieXxxK+RxcGlH0K5svbg6QoEQdy/cqz6sh/bJ6ZMeZRshuRRjhELgw== X-Google-Smtp-Source: AGHT+IGn+i5QTHGzHJ7AaZ+Cgp8WLttEQOH1JFxiqW1sctANs/qeYSQ3412rv7LBdSFc0yiaOhrc X-Received: by 2002:ac2:4f0f:0:b0:513:177e:4254 with SMTP id k15-20020ac24f0f000000b00513177e4254mr7223920lfr.14.1711942497630; Sun, 31 Mar 2024 20:34:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711942497; cv=pass; d=google.com; s=arc-20160816; b=KRG91hXT1JyiHTpT0/PMa24g3Gqqakokcp37Ax5uBrDntoyOxT/94579c4S3nHRRow UvHWBdaGyrNfPPlmXnov1Bo1AO40fUb+TS/5cIUpUHuIh2zzLYZhW3zZMdzTl73tgx7n Kuwhb1wx/Biy8+7+SwxmeOtiPtZgz8J2RbYUXe+58DUsfgtZtp1uIqtfyeHrMjlqcqXw kJxBc/hNIm6nJBBMx+EEIZC10Kz7jc6I/dq1GlVAXbJHKMk0JcaJ8ux6poxx5bpBrG9C LNU9CNdiOJJ+CqrFYFZWjOdZdqTfTt9i9ektKdYCWRwpVW4aaSJOxNuwer6J79xkrdIB thmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=u6JtRxYTExUsoUZBmyKeockMJYiorsrS2DZFcMH0Xu4=; fh=O6TyZGLOjH174jlw1lvxgCza8k+qzj1h7an4XFR45Fg=; b=RgEKlW9+m00PmEXRBvXyy5TPuBfDR35lIV3Hv2iKyvV2D3KzePGqKPdHy4XrCAKK5f kbHnRK9X97YdIkE1okKftuO5hY2vf+vCJ1+TRyVyTf9Y64b3KH1NVyUrd/R9z3oqO2Ju AAI6u6KEev8FlFLXof2z3TzmtrsxwvJk0KLSyz0Km/5g0gjnG8Dgcwgkld9If7UGfdr6 UDFcmNnjFiszlC4qNDmlYrg398XByjR06WXyKErd3ZshdZcuqsK1Si4rrXRsNNexyghg YBs811Ue+oDxcES4lScN/epPFL6IhqSTeXUsch3cdoQsI9c0Tz8lFqbVHTkUPKkyzd/Y UYoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=tpa4oVSa; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-126426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126426-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q20-20020a1709060f9400b00a474e73906bsi4192129ejj.796.2024.03.31.20.34.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Mar 2024 20:34:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-126426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=tpa4oVSa; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-126426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126426-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0674D1F2147B for ; Mon, 1 Apr 2024 03:34:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBFCC79DD; Mon, 1 Apr 2024 03:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="tpa4oVSa" Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (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 D8470522E; Mon, 1 Apr 2024 03:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711942483; cv=none; b=aJLvaLHSAObTSj86iOQoVdxErZA+BC0+3fiBllTgQQC7UxQLvG3jkWmvXYhqgILvZjDxYAHBEzu8t9RxC3ynLbfXVKFVpCZDbLgG8OFVQmJmduhvCF/8h56AUHMR/Smgq9ygP66HL+Fl8h+zjaKi9MdrDJNKRrBM86HEFJxHLs0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711942483; c=relaxed/simple; bh=TrJcj01Er00eAvFKR0jzYuUqobdc2zMMASuC79JwpO0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TaSBJlFInsLcxtPVY3mbmKjqlz0xmKoklnBEfqHieo06goLveeHSZoErymNPUDTmpxh8SW0BSuPGkuW++wvjmmKl/ZrbqwUgYorGLT/WxYSHRCzpEVkaS5QBNBYE7hqEhAnqOJ1xZx1H829dTHvgcOEDLiXszMwrzcTP6/P+Xro= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=tpa4oVSa; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1711942477; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=u6JtRxYTExUsoUZBmyKeockMJYiorsrS2DZFcMH0Xu4=; b=tpa4oVSavKsoHQk2vDb6yBGWJ1VNgesGA+7BZzau0Tr8qCAvUFM/VjSBl/dbbXeRjX1CY3Sipv3HrM5Ym/EZ1ZrV3XldwJiA9IytTdSpXeF8qhaQWEwEJzAIhka4BW5GGbwcdI68GwbRMDqXxWyrCQXk2ajb41VyQoBT3oF/F9o= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W3e3cIV_1711942465; Received: from 30.221.128.183(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0W3e3cIV_1711942465) by smtp.aliyun-inc.com; Mon, 01 Apr 2024 11:34:37 +0800 Message-ID: <45c3042b-4446-40f2-af70-52b8c0f4b108@linux.alibaba.com> Date: Mon, 1 Apr 2024 11:34:25 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings To: "Gustavo A. R. Silva" , Wenjia Zhang , Jan Karcher , "D. Wythe" , Tony Lu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: From: Wen Gu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/3/29 05:52, Gustavo A. R. Silva wrote: > -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 Thank you, Gustavo. Reviewed-by: Wen Gu > --- > Changes v4: > - Fix code comments (due to copy/paste error, aghhh). > > Changes in v3: > - Adjust code to 80 columns. (Wen Gu) > - Add a couple of code comments. > - Link: https://lore.kernel.org/linux-hardening/ZgXlIADfiXSyRz8d@neat/ > > 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..467effb50cd6 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;