From patchwork Thu Oct 24 21:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13849749 X-Patchwork-Delegate: kuba@kernel.org 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 59BE8218D6B; Thu, 24 Oct 2024 21:11:27 +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=1729804288; cv=none; b=pY3CW80W/CFVFoki58eZF77x/8uW0/A+VTWhrV1tq80DiwWR636d8QbcmddrENGPjTlIijsHY19oHLrnnMYg0dvPrPH3X0HJhT/Nc4VD3qU1mlZaLUanW//egbEiyjZlDvwGs9uujszVRhmY2676fgJTYAfOxPaKnpSPbpR2zYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729804288; c=relaxed/simple; bh=qQQ2lofL8ErXlVJyVkxMF6DjGz27PDYgLr96a3mHVqk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dkeBkPOQJN9LgpsrRHZ8D9/1oM/jBiNFlRsxf3KIJA7/+LOxS6tsSmMCOCeY5VpP5Dc2MM47/qtSOmUrh2cMuLXvIocpgojNIkAGceLcjYH4MBzbJ4enEWQzDbhY3E/wpAyHIkXJvQOVgUEAkVmdB+DgDirPOFIo2ZiVOJB8dZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eF5NObvb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eF5NObvb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85CEBC4CEC7; Thu, 24 Oct 2024 21:11:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729804287; bh=qQQ2lofL8ErXlVJyVkxMF6DjGz27PDYgLr96a3mHVqk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eF5NObvb9HPWXTjcRLoFpLFIt5A+QC7aR2J38Fv2syMcG37GGMnuMeESXCA38OzZD dmd5zKmxAdCSrFnEZTg/h606f8Z1npc3j4ge5zegnJk+mJ3K7RCXu9R5DVjPWUyVbV oY9S2jBZONtEysjgFimkout5CZsoynsjcPypKI9xWlHdeUwO5eHZZK/7keahDamOst IQdWAo9VeIDeMeqMZa/HpfGcswefDUdZ3uwMnyNgULOscgKZsXOH9V+VRH9pRhHS4C 7qMrc1ImxYvaCGmvUch5EEQbDfHuaQXc1P4prvfTbpblNGJSAQz4UPPMZt7xf8feF1 162hsDKT79PvA== Date: Thu, 24 Oct 2024 15:11:24 -0600 From: "Gustavo A. R. Silva" To: Andrew Lunn , Johannes Berg , David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Kees Cook , Simon Horman Subject: [PATCH v2 1/4][next] uapi: socket: Introduce struct sockaddr_legacy Message-ID: <23bd38a4bf024d4a92a8a634ddf4d5689cd3a67e.1729802213.git.gustavoars@kernel.org> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We are currently working on enabling the -Wflex-array-member-not-at-end compiler option. This option has helped us detect several objects of the type `struct sockaddr` that appear in the middle of composite structures like `struct rtentry`, `struct compat_rtentry`, and others: include/uapi/linux/wireless.h:751:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:776:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:833:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:857:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:864:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/route.h:33:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/route.h:34:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/route.h:35:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:118:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:119:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:121:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:126:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:127:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/net/compat.h:34:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/net/compat.h:35:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] In order to fix the warnings above, we introduce `struct sockaddr_legacy`. The intention is to use it to replace the type of several struct members in the middle of composite structures, currently of type `struct sockaddr`. These middle struct members are currently causing thousands of warnings because `struct sockaddr` contains a flexible-array member, introduced by commit b5f0de6df6dce ("net: dev: Convert sa_data to flexible array in struct sockaddr"). The new `struct sockaddr_legacy` doesn't include a flexible-array member, making it suitable for use as the type of middle members in composite structs that don't really require the flexible-array member in `struct sockaddr`, thus avoiding -Wflex-array-member-not-at-end warnings. As this new struct will live in UAPI, to avoid breaking user-space code that expects `struct sockaddr`, the `__kernel_sockaddr_legacy` macro is introduced. This macro allows us to use either `struct sockaddr` or `struct sockaddr_legacy` depending on the context in which the code is used: kernel-space or user-space. Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- include/uapi/linux/socket.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h index d3fcd3b5ec53..2e179706bec4 100644 --- a/include/uapi/linux/socket.h +++ b/include/uapi/linux/socket.h @@ -35,4 +35,32 @@ struct __kernel_sockaddr_storage { #define SOCK_TXREHASH_DISABLED 0 #define SOCK_TXREHASH_ENABLED 1 +typedef __kernel_sa_family_t sa_family_t; + +/* + * This is the legacy form of `struct sockaddr`. The original `struct sockaddr` + * was modified in commit b5f0de6df6dce ("net: dev: Convert sa_data to flexible + * array in struct sockaddr") due to the fact that "One of the worst offenders + * of "fake flexible arrays" is struct sockaddr". This means that the original + * `char sa_data[14]` behaved as a flexible array at runtime, so a proper + * flexible-array member was introduced. + * + * This caused several flexible-array-in-the-middle issues: + * https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wflex-array-member-not-at-end + * + * `struct sockaddr_legacy` replaces `struct sockaddr` in all instances where + * objects of this type do not appear at the end of composite structures. + */ +struct sockaddr_legacy { + sa_family_t sa_family; /* address family, AF_xxx */ + char sa_data[14]; /* 14 bytes of protocol address */ +}; + +#ifdef __KERNEL__ +# define __kernel_sockaddr_legacy sockaddr_legacy +#else +# define __kernel_sockaddr_legacy sockaddr +#endif + + #endif /* _UAPI_LINUX_SOCKET_H */ From patchwork Thu Oct 24 21:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13849750 X-Patchwork-Delegate: kuba@kernel.org 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 CC3002178E9; Thu, 24 Oct 2024 21:12:05 +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=1729804325; cv=none; b=UpaNlZLO+EfxdhFNhPzg+Uvm6zPd0Rld7+iiYI0QUa2pSICBgp9ZN7Ex5tPjzYLCDwqCHNb3i1xtpL4DyhjcrWJdkUGu+vD6rQYNwwVw/lig3gZB+QjHOXS6K4S/P9BLUQfKNLeukvQUBULxFvT4geQDXNG1HuasShklLdUdYdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729804325; c=relaxed/simple; bh=skvSucgJHkfhd6K1CWJn3ZKM/xtDS72Rbn/Rvvv+hHY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lezpfJlLZ23vBo3c6VNbjR53mThwoAszsoJrfdcF1cqy42/CN0djRs/pZR5vge/Ipl8Dcjg80YU4+A3Ckf6HRU9T96caqKYohCTggL+odi9OF9/X57v2wdnGFaPsYdgyafPY1vNK4YV0Nm4cOJg6bBuJOlNwMsPZzbmyiml2ORk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZHQCm88X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZHQCm88X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3784EC4CEC7; Thu, 24 Oct 2024 21:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729804325; bh=skvSucgJHkfhd6K1CWJn3ZKM/xtDS72Rbn/Rvvv+hHY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZHQCm88X6Vexv159+xnuhmK9UXJFhnFW7ywaPef/T9++JauCEjr9Q1BodQ+nJ9Xlq E1C6mdgWMGzQjOHbMSl1LKC3xoiKuAZcUJfeJFlbSPs6PLHR0VFiVjA/ywigJn5uaf p279NQW297JgFl0eT+HeySQ8/74vOLfyZQ3AuocVYPG4f6PaGoHz4bteh/COewRxbc OAFzB5rfdNz2NuLEzSI0myZRT/qlUnnW7vXcPufB6Wmj6X8Jga5+mJ9/hEq0OTngh2 obh2WMPKo+J4l9+O3+mmhG5mojCj9FC6Lqd7ODu33Lsd6cCqg+RCKoynmG+J29JrWD t0v/LvMRqN+3w== Date: Thu, 24 Oct 2024 15:12:02 -0600 From: "Gustavo A. R. Silva" To: Andrew Lunn , Johannes Berg , David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Kees Cook , Simon Horman Subject: [PATCH v2 2/4][next] uapi: wireless: Avoid -Wflex-array-member-not-at-end warnings Message-ID: <65f90d60460f831a374d9cd678ba38b31fdd4f93.1729802213.git.gustavoars@kernel.org> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Address the following warnings by changing the type of the middle struct members in various composite structs, which are currently causing trouble, from `struct sockaddr` to `struct __kernel_sockaddr_legacy`. include/uapi/linux/wireless.h:751:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:776:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:833:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:857:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/wireless.h:864:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- include/uapi/linux/wireless.h | 56 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h index 3c2ad5fae17f..d8744113fc89 100644 --- a/include/uapi/linux/wireless.h +++ b/include/uapi/linux/wireless.h @@ -748,10 +748,10 @@ struct iw_missed { * Quality range (for spy threshold) */ struct iw_thrspy { - struct sockaddr addr; /* Source address (hw/mac) */ - struct iw_quality qual; /* Quality of the link */ - struct iw_quality low; /* Low threshold */ - struct iw_quality high; /* High threshold */ + struct __kernel_sockaddr_legacy addr; /* Source address (hw/mac) */ + struct iw_quality qual; /* Quality of the link */ + struct iw_quality low; /* Low threshold */ + struct iw_quality high; /* High threshold */ }; /* @@ -766,15 +766,15 @@ struct iw_thrspy { * current BSS if the driver is in Managed mode and associated with an AP. */ struct iw_scan_req { - __u8 scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */ - __u8 essid_len; - __u8 num_channels; /* num entries in channel_list; - * 0 = scan all allowed channels */ - __u8 flags; /* reserved as padding; use zero, this may - * be used in the future for adding flags - * to request different scan behavior */ - struct sockaddr bssid; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or - * individual address of a specific BSS */ + __u8 scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */ + __u8 essid_len; + __u8 num_channels; /* num entries in channel_list; + * 0 = scan all allowed channels */ + __u8 flags; /* reserved as padding; use zero, this may + * be used in the future for adding flags + * to request different scan behavior */ + struct __kernel_sockaddr_legacy bssid; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or + * individual address of a specific BSS */ /* * Use this ESSID if IW_SCAN_THIS_ESSID flag is used instead of using @@ -827,15 +827,15 @@ struct iw_scan_req { * debugging/testing. */ struct iw_encode_ext { - __u32 ext_flags; /* IW_ENCODE_EXT_* */ - __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ - __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ - struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast - * (group) keys or unicast address for - * individual keys */ - __u16 alg; /* IW_ENCODE_ALG_* */ - __u16 key_len; - __u8 key[]; + __u32 ext_flags; /* IW_ENCODE_EXT_* */ + __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + struct __kernel_sockaddr_legacy addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast + * (group) keys or unicast address for + * individual keys */ + __u16 alg; /* IW_ENCODE_ALG_* */ + __u16 key_len; + __u8 key[]; }; /* SIOCSIWMLME data */ @@ -853,16 +853,16 @@ struct iw_mlme { #define IW_PMKID_LEN 16 struct iw_pmksa { - __u32 cmd; /* IW_PMKSA_* */ - struct sockaddr bssid; - __u8 pmkid[IW_PMKID_LEN]; + __u32 cmd; /* IW_PMKSA_* */ + struct __kernel_sockaddr_legacy bssid; + __u8 pmkid[IW_PMKID_LEN]; }; /* IWEVMICHAELMICFAILURE data */ struct iw_michaelmicfailure { - __u32 flags; - struct sockaddr src_addr; - __u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + __u32 flags; + struct __kernel_sockaddr_legacy src_addr; + __u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ }; /* IWEVPMKIDCAND data */ From patchwork Thu Oct 24 21:13:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13849756 X-Patchwork-Delegate: kuba@kernel.org 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 A6391217338; Thu, 24 Oct 2024 21:13:49 +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=1729804429; cv=none; b=hOIUD81a8vrtAqZRD7BvN1PZW1cB2/QwE/YCk0pqZLewODB3R1PzJ8oCEF73A3cAWRsx08bybroHATufoc16YAcryJTp66XJo6V8lQmBsEGucm09C4hjMuxRpjLGRa4/2iU67mHIqVWrYSVMhOVnHf4jZ2N4woY6LhFUHsTu3xk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729804429; c=relaxed/simple; bh=go564DnfBiEx79xSbk4V/4Kf/fjy5zdl97UH8liwTnw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u3elEEWrqPUzBRYo9Kvn8mR0HQvzoT1KLBPtKn2K+ESs7lLVUr+V9BIS3N7+lA8luykM+trHODq0RG6MHLIPtzuaeb6MmbI3gkaLHytcTG+VsokL/zTSxEnEnVtq780WUo9p2vkcWieTKwaJACEZE/Ynwn7wyP99S8yiaqQAymc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hMkvpFS5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hMkvpFS5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 221F2C4CEC7; Thu, 24 Oct 2024 21:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729804429; bh=go564DnfBiEx79xSbk4V/4Kf/fjy5zdl97UH8liwTnw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hMkvpFS5bU/4cGW/N/i+elpi8q8hEn8bQ6ByXvXB8teAKsSx6SzVXcvVz/6EAqjiz JX/5rjlg6o1Nvpftw4Kfc7s3RoTAbbzeIYbD2+xBWBFpSsAn9fvSn8TxwbmNGTyAss nwV2bj4EzLWZJUh+yRpkjJI97rjvcFTkmwdHgFnfHW+8VgYnnGAQuHeXKbKuDJ1L7/ xLIU+CVXpkWSflPqWlo6BwBYmBzh1oaSxU8zkhRWuzZ+8kAkwpyLeFAHHaOkSqGXcD AEZVZf4X0AR24dSpdlQ/AvsnzH/GW6wJuRuMqz6wE4Jmgs6GtGcJ30ljSDxvtBGOVW Sev3uG064/NGw== Date: Thu, 24 Oct 2024 15:13:45 -0600 From: "Gustavo A. R. Silva" To: Andrew Lunn , Johannes Berg , David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Simon Horman , Kees Cook Subject: [PATCH v2 3/4][next] uapi: net: arp: Avoid -Wflex-array-member-not-at-end warnings Message-ID: <903f37962945fe0aa46e1d05c2a05f39571a53fa.1729802213.git.gustavoars@kernel.org> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org -Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Address the following warnings by changing the type of the middle struct members in a couple of composite structs, which are currently causing trouble, from `struct sockaddr` to `struct __kernel_sockaddr_legacy`. include/uapi/linux/if_arp.h:118:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:119:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:121:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:126:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/if_arp.h:127:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Also, refactor some related code, accordingly. Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- include/uapi/linux/if_arp.h | 18 +++++++++--------- net/ipv4/arp.c | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/uapi/linux/if_arp.h b/include/uapi/linux/if_arp.h index 4783af9fe520..4a25a05125d3 100644 --- a/include/uapi/linux/if_arp.h +++ b/include/uapi/linux/if_arp.h @@ -115,18 +115,18 @@ /* ARP ioctl request. */ struct arpreq { - struct sockaddr arp_pa; /* protocol address */ - struct sockaddr arp_ha; /* hardware address */ - int arp_flags; /* flags */ - struct sockaddr arp_netmask; /* netmask (only for proxy arps) */ - char arp_dev[IFNAMSIZ]; + struct __kernel_sockaddr_legacy arp_pa; /* protocol address */ + struct __kernel_sockaddr_legacy arp_ha; /* hardware address */ + int arp_flags; /* flags */ + struct __kernel_sockaddr_legacy arp_netmask; /* netmask (only for proxy arps) */ + char arp_dev[IFNAMSIZ]; }; struct arpreq_old { - struct sockaddr arp_pa; /* protocol address */ - struct sockaddr arp_ha; /* hardware address */ - int arp_flags; /* flags */ - struct sockaddr arp_netmask; /* netmask (only for proxy arps) */ + struct __kernel_sockaddr_legacy arp_pa; /* protocol address */ + struct __kernel_sockaddr_legacy arp_ha; /* hardware address */ + int arp_flags; /* flags */ + struct sockaddr arp_netmask; /* netmask (only for proxy arps) */ }; /* ARP Flag values. */ diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 11c1519b3699..3a97efe1587b 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1185,7 +1185,7 @@ static int arp_req_get(struct net *net, struct arpreq *r) read_lock_bh(&neigh->lock); memcpy(r->arp_ha.sa_data, neigh->ha, - min(dev->addr_len, sizeof(r->arp_ha.sa_data_min))); + min(dev->addr_len, sizeof(r->arp_ha.sa_data))); r->arp_flags = arp_state_to_flags(neigh); read_unlock_bh(&neigh->lock); From patchwork Thu Oct 24 21:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13849757 X-Patchwork-Delegate: kuba@kernel.org 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 27138217916; Thu, 24 Oct 2024 21:14:34 +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=1729804475; cv=none; b=uuGyawTuCn7fOPPzdoftQuut5thF/p+6394ir9tR0c/hoP110P26OR4kqpAoaIrx0kOOsaxCEc7nUUKnZZG2utcS6OzogYrZ/Fxfk3qHBmJBz322IO7iARw/TMIaEEpBxDaR1GXwUD4qJqstzBSOV6kn3+Ih1eJB3z5NMnuzhoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729804475; c=relaxed/simple; bh=RPrXxToPed4P2qJ+35T7mOSrAPsKyzWjCEbw6Myhtug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gjeoYLrRjmeXHs+4hKadWKsffcCk+YnQJg3T/vR9sNrHwfGsJ+C7udtSg9aEXhLVYaIzcNRRTkWyIb41dO82S/Oynx4Cc/Um2gbhe9kdqXdIpmL9pELCVOyA4byqJ2On75zVeN9RSgdgM2R4gh5t2s36nimXWBsn6QaPIME0KIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I+EJiAOG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I+EJiAOG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71E4AC4CEC7; Thu, 24 Oct 2024 21:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729804474; bh=RPrXxToPed4P2qJ+35T7mOSrAPsKyzWjCEbw6Myhtug=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I+EJiAOGA8nDEX1APRxBItQ26lqqHozHlZlKG+URE0XbdSp2SKozjdFYWQlaabPho hJywnb/DsdCog5/XE5CtCySGmzikp5p6cnjqBOEF70YR1sr0aAhax4FKaciHjDBF/N Wd+1C6FHb4b1jumPp/Qks7mTzPPwIf66lYWJzYf92ce+9xM2VKXC0UE9QE9DncA0+t JQY5iKJ8BQOkltMyeHu8E5qFmlMYsR4naQhNBL2Th6lONjoRykC7Uc3yEqAeUVa955 nL5IwuV/PUHOmjS1kz3uYpbTLCiXzBpzC6/IuO1hn+DpioRMqA1ee5Cxzp3+UHywaf qDdVDfqJn6XZw== Date: Thu, 24 Oct 2024 15:14:31 -0600 From: "Gustavo A. R. Silva" To: Andrew Lunn , Johannes Berg , David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Kees Cook Subject: [PATCH v2 4/4][next] uapi: net: Avoid -Wflex-array-member-not-at-end warnings Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org -Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Address the following warnings by changing the type of the middle struct members in a couple of composite structs, which are currently causing trouble, from `struct sockaddr` to `struct __kernel_sockaddr_legacy` in UAPI, and `struct sockaddr_legacy` for the rest of the kernel code. include/uapi/linux/route.h:33:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/route.h:34:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/uapi/linux/route.h:35:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end include/net/compat.h:34:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] include/net/compat.h:35:25: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Also, update some related code, accordingly. Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- include/net/compat.h | 30 +++++++++++++++--------------- include/uapi/linux/route.h | 28 ++++++++++++++-------------- net/appletalk/ddp.c | 2 +- net/ipv4/af_inet.c | 2 +- net/ipv4/fib_frontend.c | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/net/compat.h b/include/net/compat.h index 84c163f40f38..89e891d8dcf3 100644 --- a/include/net/compat.h +++ b/include/net/compat.h @@ -29,21 +29,21 @@ struct compat_cmsghdr { }; struct compat_rtentry { - u32 rt_pad1; - struct sockaddr rt_dst; /* target address */ - struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ - struct sockaddr rt_genmask; /* target network mask (IP) */ - unsigned short rt_flags; - short rt_pad2; - u32 rt_pad3; - unsigned char rt_tos; - unsigned char rt_class; - short rt_pad4; - short rt_metric; /* +1 for binary compatibility! */ - compat_uptr_t rt_dev; /* forcing the device at add */ - u32 rt_mtu; /* per route MTU/Window */ - u32 rt_window; /* Window clamping */ - unsigned short rt_irtt; /* Initial RTT */ + u32 rt_pad1; + struct sockaddr_legacy rt_dst; /* target address */ + struct sockaddr_legacy rt_gateway; /* gateway addr (RTF_GATEWAY) */ + struct sockaddr_legacy rt_genmask; /* target network mask (IP) */ + unsigned short rt_flags; + short rt_pad2; + u32 rt_pad3; + unsigned char rt_tos; + unsigned char rt_class; + short rt_pad4; + short rt_metric; /* +1 for binary compatibility! */ + compat_uptr_t rt_dev; /* forcing the device at add */ + u32 rt_mtu; /* per route MTU/Window */ + u32 rt_window; /* Window clamping */ + unsigned short rt_irtt; /* Initial RTT */ }; int __get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr *msg, diff --git a/include/uapi/linux/route.h b/include/uapi/linux/route.h index a0de9a7331a2..43fd79f90a47 100644 --- a/include/uapi/linux/route.h +++ b/include/uapi/linux/route.h @@ -29,22 +29,22 @@ /* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */ struct rtentry { - unsigned long rt_pad1; - struct sockaddr rt_dst; /* target address */ - struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ - struct sockaddr rt_genmask; /* target network mask (IP) */ - unsigned short rt_flags; - short rt_pad2; - unsigned long rt_pad3; - void *rt_pad4; - short rt_metric; /* +1 for binary compatibility! */ - char __user *rt_dev; /* forcing the device at add */ - unsigned long rt_mtu; /* per route MTU/Window */ + unsigned long rt_pad1; + struct __kernel_sockaddr_legacy rt_dst; /* target address */ + struct __kernel_sockaddr_legacy rt_gateway; /* gateway addr (RTF_GATEWAY) */ + struct __kernel_sockaddr_legacy rt_genmask; /* target network mask (IP) */ + unsigned short rt_flags; + short rt_pad2; + unsigned long rt_pad3; + void *rt_pad4; + short rt_metric; /* +1 for binary compatibility! */ + char __user *rt_dev; /* forcing the device at add */ + unsigned long rt_mtu; /* per route MTU/Window */ #ifndef __KERNEL__ -#define rt_mss rt_mtu /* Compatibility :-( */ +#define rt_mss rt_mtu /* Compatibility :-( */ #endif - unsigned long rt_window; /* Window clamping */ - unsigned short rt_irtt; /* Initial RTT */ + unsigned long rt_window; /* Window clamping */ + unsigned short rt_irtt; /* Initial RTT */ }; diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index b068651984fe..aac82a4af36f 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c @@ -1832,7 +1832,7 @@ static int atalk_compat_routing_ioctl(struct sock *sk, unsigned int cmd, struct rtentry rt; if (copy_from_user(&rt.rt_dst, &ur->rt_dst, - 3 * sizeof(struct sockaddr)) || + 3 * sizeof(struct sockaddr_legacy)) || get_user(rt.rt_flags, &ur->rt_flags) || get_user(rt.rt_metric, &ur->rt_metric) || get_user(rt.rt_mtu, &ur->rt_mtu) || diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 8095e82de808..3beb52261b4b 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1019,7 +1019,7 @@ static int inet_compat_routing_ioctl(struct sock *sk, unsigned int cmd, struct rtentry rt; if (copy_from_user(&rt.rt_dst, &ur->rt_dst, - 3 * sizeof(struct sockaddr)) || + 3 * sizeof(struct sockaddr_legacy)) || get_user(rt.rt_flags, &ur->rt_flags) || get_user(rt.rt_metric, &ur->rt_metric) || get_user(rt.rt_mtu, &ur->rt_mtu) || diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 53bd26315df5..88c7a79946f2 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -452,7 +452,7 @@ int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, itag); } -static inline __be32 sk_extract_addr(struct sockaddr *addr) +static inline __be32 sk_extract_addr(struct sockaddr_legacy *addr) { return ((struct sockaddr_in *) addr)->sin_addr.s_addr; }