Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp621568lqg; Fri, 1 Mar 2024 16:09:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXEPKsA5H5GkrotBnTh8NGMyaXlZqKVebEpr1nMxR0wR5LB5z6oBEDhgjf5eGgrRV7qbaXJxfO6UE8917/UnKseHe20+iJL5l6BMOyN+Q== X-Google-Smtp-Source: AGHT+IG36Eoq+roRPuUB/yzj59TUXL579rBGEqAVx1f01KCbKqjAr4t8KCqNScsa95s05VeBFoqT X-Received: by 2002:a17:907:390:b0:a44:a0d4:d7bc with SMTP id ss16-20020a170907039000b00a44a0d4d7bcmr2035088ejb.28.1709338185871; Fri, 01 Mar 2024 16:09:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709338185; cv=pass; d=google.com; s=arc-20160816; b=mebHmVoi9SxUZYsdlb1p1A0pPQYzgRIs6g+ACFP0CsBzoCJWKSvZB/mTFwQ5mzUyUv kSPtiQaDUR5x9Yymqf2fY8udmHDeVe5ZckP4o0QULubDLCAVWKsgvHuC9AgibOmXd5cg jAPfkl+FphuwewrCdBPDK6oTWdqPSi7IN+7VQLvWkEvB6Yxa17N/00LVmqa63j3megNQ egchmcCDeFguL2e5GHS4i69dU3Utn0fZe97bRVY84xRgcpMayov2Mjfxe6O9G4ussHMu +Aw0CVlObSvsfw0mD3OLMqOJssRCXEnMHpozTFxLjXL9nZD8ER0JlCu7wk81gokVvp/v Xtgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PlEMlXrKVoQ/VI5q1b4zpBL3OsqlVw7CAlvaBiVG6mY=; fh=ygM99Ksafn7jBeWgsrDwr14M1Qrle1/Z99SZnYbOl5A=; b=pBo2wxhrkSNuTNi1jtDe5BF8sTfNUDTFUNoWqg9nuzaJukHzCfPVKaMmyNmGPZHM0Y 2FNRCdnHdTbkwIptEYa9g39exML718rUOHv+QvLM0adaXKqwXdqUal2gtFtYUMMhtR3o /LQwtdJTALpRcx70AsKGFu0NxpL24CVrf6lcJHy9LAL2GmLr6G3nA9LU6aQ+RH81UNch wpF5OdKn6shDjQQOWeYnhWVcLVnXrCmMz5r//oK8IEst8CTw0usFgLfZj6l6d2qpUrrF 8q/8N0WZ9QUs/Y3rf5HTFh+B3hKP4dWmsQC9P9vRBF8p/kLmVJngH6ZfWGiXXfnj3Jqq 5HoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MOuTRwXE; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-89247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i14-20020a170906264e00b00a43f3f8d3f6si1781363ejc.383.2024.03.01.16.09.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 16:09:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MOuTRwXE; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-89247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 70E001F233DD for ; Sat, 2 Mar 2024 00:09:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46BFD15B3; Sat, 2 Mar 2024 00:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MOuTRwXE" Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1215680 for ; Sat, 2 Mar 2024 00:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709338174; cv=none; b=NhE5ynPYFOVsrDko2euf9iAouoDefEFs+N5jt9WLG/b0phCxqVaTDGWWMkyBzHRZw45TLxdB+FCz/NEptSdYk1z/7Zly5xiKzRt1uocbld/4hdEQcxlDLEMx8kEfia0HPTvBmIwP2MYA3D5SzYVePOrrVH+QHxEez8M3t3xbjGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709338174; c=relaxed/simple; bh=dH+R3CHq13HZg3o2FiRpD3Sc4l20ml1BM78TmQhj43s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qmXQaXWhKX9mNlF5opSINCCbv8bsDh6ma5AesW0xG42x/GVCWiFD8m8qxiOsNKQ6888+Dcffsl3m6OHuuIcvTlI3bFnYE4CrpnvMzLC1r37xkHIK8cj9sN4XrIKoHdmJMEvbWyHsf3AmzJKBTpPBdcvsmbalfMbml29tBW+wYxw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=MOuTRwXE; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5cdbc4334edso1958950a12.3 for ; Fri, 01 Mar 2024 16:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709338171; x=1709942971; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=PlEMlXrKVoQ/VI5q1b4zpBL3OsqlVw7CAlvaBiVG6mY=; b=MOuTRwXEhIPRWgSif23piWeAVFPc+vdnbxKruPntORcbsZe7Ootk7sViJ1qaDdgx2M F3cD09TiuqgzusAKPhmQtslpHuPNr8SczIuJMXdnnZ9haIVfdI5Vs3KAVlvjNTx8pfTd yhjULxFjOZValpASY13e1gED6NXKg4FVa6fj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709338171; x=1709942971; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PlEMlXrKVoQ/VI5q1b4zpBL3OsqlVw7CAlvaBiVG6mY=; b=Pfo9OPBVp3cQysYzffDBZItd8SSDNtr4bKTB+1yTMv9eocfyPybgqH0yXowSDP/Jcj URifFwCUbDsao1CaIpyp8h75gqkSmA1yEmEAiPAtaG7FXXCxp/h37AWTvPCpyTifu0jl HkKD3gJvT1zXQJqT0pxJNkiBzStGXxMbe7DxYRxuPB788DU4mgxsjfs/4N5LcH+8ueRV hTFJlY/3Bgclbw8VhkYKAK00ViaUHdjkCSKML7ntH47Vv58L1fK0MxeFudKT5bBN1zzR vxfvBI/P5uVobKtA9dxQyQEPqEr58tCT0SXgRI0qO6X4kgjjbx72eG/OsWf1v6lMV7gY V8mQ== X-Forwarded-Encrypted: i=1; AJvYcCXiW3eq3hA4sRpYAHqD4RD+sPC1TSUz/V1mvUBGLNTjPXZ1vb8ioi47TztmFzsYN387l/7Oh2OWXfsrG0U27TNT4jQl7j2nvFKeJ6en X-Gm-Message-State: AOJu0YyC38Cju0NMLEIek+eTBEJPWR7lhAngrMXxd/WQaudnQy83nIiv U2z1EURR1eayB8soScMy83z9GbLUMDbN6gQ7pP4xXPcGIQFncTYDxHw3dkPUog== X-Received: by 2002:a05:6a20:6a22:b0:1a1:461a:36ac with SMTP id p34-20020a056a206a2200b001a1461a36acmr494126pzk.11.1709338171344; Fri, 01 Mar 2024 16:09:31 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id x11-20020aa784cb000000b006e45c5d7720sm3611474pfn.93.2024.03.01.16.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 16:09:30 -0800 (PST) Date: Fri, 1 Mar 2024 16:09:29 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Wenjia Zhang , Jan Karcher , "D. Wythe" , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings Message-ID: <202403011607.8E903049@keescook> References: 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 In-Reply-To: On Fri, Mar 01, 2024 at 12:40:57PM -0600, 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_hdr, hdr, > 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_hdr pclc_v2_ext; > ... > struct smc_clc_smcd_v2_extension_hdr 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; > | ^~~~~~~~~~~~~~~~ > > Signed-off-by: Gustavo A. R. Silva I think this is a nice way to deal with these flex-array cases. Using the struct_group() and container_of() means there is very little collateral impact. Since this is isolated to a single file, I wonder if it's easy to check that there are no binary differences too? I wouldn't expect any -- container_of() is all constant expressions, so the assignment offsets should all be the same, etc. Reviewed-by: Kees Cook -Kees -- Kees Cook