From nobody Mon Oct 6 10:13:28 2025 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 E3AC427F163; Tue, 22 Jul 2025 17:18:36 +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=1753204717; cv=none; b=oCzlp+A/vEdCLPOG/T1kwrjmRnYU6qLSxjqbk39VavyVt0PmQkYBTh3AQb35QvViQjnt7FrIdYYYBRVe74ZbYbMihuxVZiguGjxYhgRAiaErl0mZAeUt+lD51AXQzJDh8x5XQElrL9RRpCd7SeJ+wKTVbC/m9afgzdpw5PVQOig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753204717; c=relaxed/simple; bh=NvGUedlgGRAEontrfaw0U9b4fEu2DOIryQsyYB8jpX0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DuV8v+w0k8/xEM2sWVj7kqP4/OBsnn9uHKZy6Mle18gO4+tiCZZ1zb3kzzGNAXb37PlGhWXRDPcN1IV7vGnkA4SqYYtpEnnHuJsyT77B8EZqhtSuniL8F/vO8cqAy8vE4kaxlFceuSo+Z6bMFtmiQK4r+5/xv7Yczksp0ojyNvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yubgvth6; 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="Yubgvth6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5751DC4CEEB; Tue, 22 Jul 2025 17:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753204716; bh=NvGUedlgGRAEontrfaw0U9b4fEu2DOIryQsyYB8jpX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yubgvth6Hpq9EcmCxPU+AobdsX97G3PXw/ufNb3M2CjzTZOo8V1yyFIGD5OwBcKed DCj8TZ/feL0gAnB55pTTyF1lvPy5tnZJw50LiRWq4083OgXWloU9K5FlMiZ/br+wE3 uVlU5FtuSHDySkHdhdyCuNtSaUxlAomX3u7rj/1epxiW99lJF0auaYBERu/pIAFsZL KYWpTkDjVL5rTn/3IQCwC3uAakKo9iiwD0mConN+XCYeBm1Srkf133WKpVkVJmxosF dQYG4ABQZcRToF4Y+5LPsVKKnuOKTZeYucoJf714U6zktFxGv3dUt88ceoiZVWd7SY WdR0ljyPBoChA== From: Kees Cook To: Marcelo Ricardo Leitner Cc: Kees Cook , Jakub Kicinski , "Jason A. Donenfeld" , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Xin Long , Simon Horman , linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-sctp@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH net-next 1/3] ipv6: Add sockaddr_inet unified address structure Date: Tue, 22 Jul 2025 10:18:31 -0700 Message-Id: <20250722171836.1078436-1-kees@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250722171528.work.209-kees@kernel.org> References: <20250722171528.work.209-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2274; i=kees@kernel.org; h=from:subject; bh=NvGUedlgGRAEontrfaw0U9b4fEu2DOIryQsyYB8jpX0=; b=owGbwMvMwCVmps19z/KJym7G02pJDBn1x19E3rVqcHt++ryf//UFt+bwOotW8+2fUpHYmzevz EPj7uzEjlIWBjEuBlkxRZYgO/c4F4+37eHucxVh5rAygQxh4OIUgIkkxDD8lX/N1971+ZH2zTBh bT8dR5HUsORX3A0+Eakl/0J6py28zfA/sb1eZqJ60Z4vbFytD4oa1tf/373vobPRx4ciqn5BG2c wAwA= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are cases in networking (e.g. wireguard, sctp) where a union is used to provide coverage for either IPv4 or IPv6 network addresses, and they include an embedded "struct sockaddr" as well (for "sa_family" and raw "sa_data" access). The current struct sockaddr contains a flexible array, which means these unions should not be further embedded in other structs because they do not technically have a fixed size (and are generating warnings for the coming -Wflexible-array-not-at-end flag addition). But the future changes to make struct sockaddr a fixed size (i.e. with a 14 byte sa_data member) make the "sa_data" uses with an IPv6 address a potential place for the compiler to get upset about object size mismatches. Therefore, we need a sockaddr that cleanly provides both an sa_family member and an appropriately fixed-sized sa_data member that does not bloat member usage via the potential alternative of sockaddr_storage to cover both IPv4 and IPv6, to avoid unseemly churn in the affected code bases. Introduce sockaddr_inet as a unified structure for holding both IPv4 and IPv6 addresses (i.e. large enough to accommodate sockaddr_in6). The structure is defined in linux/in6.h since its max size is sized based on sockaddr_in6 and provides a more specific alternative to the generic sockaddr_storage for IPv4 with IPv6 address family handling. The "sa_family" member doesn't use the sa_family_t type to avoid needing layer violating header inclusions. Signed-off-by: Kees Cook --- include/linux/in6.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/in6.h b/include/linux/in6.h index 0777a21cbf86..403f926d33d8 100644 --- a/include/linux/in6.h +++ b/include/linux/in6.h @@ -18,6 +18,13 @@ =20 #include =20 +/* Large enough to hold both sockaddr_in and sockaddr_in6. */ +struct sockaddr_inet { + unsigned short sa_family; + char sa_data[sizeof(struct sockaddr_in6) - + sizeof(unsigned short)]; +}; + /* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553 * NOTE: Be aware the IN6ADDR_* constants and in6addr_* externals are defi= ned * in network byte order, not in host byte order as are the IPv4 equivalen= ts --=20 2.34.1 From nobody Mon Oct 6 10:13:28 2025 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 19EB4280A56; Tue, 22 Jul 2025 17:18:36 +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=1753204719; cv=none; b=HNkgBkWVAvh7lAJ9whPNXUW4DyUI2BPrf1oVIA5bodeZltNDfHp5dnTqDtsK+hupOR0Jr6ZngPfT4XsA0SZPY7y/eto5kBkiBadVrCrcEfTJHCz8KDLBzimi38LUl1CHIDrnb4N0/2AgEJ6sNQmOrMk5FuzrcVEG7qU4pq1Bl6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753204719; c=relaxed/simple; bh=XaHeIrVkz+npBlw1lyf0qJblIEHGZQRxwothP5DgXpo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oy+mxgx2Er2UyrYhFhX2qxUaQbFQAde+qtyAQIK6/Cw2pZ4ws8Ing86VPtGdQ9lvNvvhXF74QNaeXOSKzbjD0FZ9gcHBw4akIySWnKDrFRKageM3O5kfluN3ZyhLoCTr8SN4L7g9e2ORcxAK5uuQGUlNVDEwjDUnYb9UaztWczE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tj5xUgp9; 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="Tj5xUgp9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C418C4CEF7; Tue, 22 Jul 2025 17:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753204716; bh=XaHeIrVkz+npBlw1lyf0qJblIEHGZQRxwothP5DgXpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tj5xUgp9KQ+VF0Wd1AYYCmGk4/nQ5DWiP7ILBiUrnvuGZjbaCieFkxmcWQcAuZPXD dir1N8q2XCnfd8GlHFMqlZcDYQBbbVMKqmmOrVTY7I4ViQBuCqn4BPkcrniRSML6tV /g5eK40lPYYPwql2757wx4M1U4g845dnVfANTVay4IXjc0bJhHQAIwzPl5d1xFEsGs S4Mhe0iR54QBhh1/3jlLaQLT5TgOQo0fcoZtPdIC2awlU6gB1J5cGQr8N0B201fk0U hxqpPPPqorj2P1gPrvA0yjIu0smr9SyuZTpO6tlzjoQRuSnv/6PCkh4KDyClyD+Bic HDAmZKUC9NTqw== From: Kees Cook To: Marcelo Ricardo Leitner Cc: Kees Cook , "Jason A. Donenfeld" , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, Xin Long , Simon Horman , linux-kernel@vger.kernel.org, linux-sctp@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH net-next 2/3] wireguard: peer: Replace sockaddr with sockaddr_inet Date: Tue, 22 Jul 2025 10:18:32 -0700 Message-Id: <20250722171836.1078436-2-kees@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250722171528.work.209-kees@kernel.org> References: <20250722171528.work.209-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1153; i=kees@kernel.org; h=from:subject; bh=XaHeIrVkz+npBlw1lyf0qJblIEHGZQRxwothP5DgXpo=; b=owGbwMvMwCVmps19z/KJym7G02pJDBn1x1+waS/6eaXHauGh7Jlr3071DrVkMA9uNtHtVvsr8 3Aq55mPHaUsDGJcDLJiiixBdu5xLh5v28Pd5yrCzGFlAhnCwMUpABNxSWL4n+DN9V/bobTOfGpT abnPvEvdApF7tLTXJr22/XDoid3WGIY/nJcY52twtuzIOPChRDHhGxfX2rB7v5z+697k7dTheML ABQA= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As part of the removal of the variably-sized sockaddr for kernel internals, replace struct sockaddr with sockaddr_inet in the endpoint union. No binary changes; the union size remains unchanged due to sockaddr_inet matching the size of sockaddr_in6. Signed-off-by: Kees Cook --- Cc: "Jason A. Donenfeld" Cc: Andrew Lunn Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Cc: --- drivers/net/wireguard/peer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireguard/peer.h b/drivers/net/wireguard/peer.h index 76e4d3128ad4..718fb42bdac7 100644 --- a/drivers/net/wireguard/peer.h +++ b/drivers/net/wireguard/peer.h @@ -20,7 +20,7 @@ struct wg_device; =20 struct endpoint { union { - struct sockaddr addr; + struct sockaddr_inet addr; /* Large enough for both address families= */ struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; --=20 2.34.1 From nobody Mon Oct 6 10:13:28 2025 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 9C5C927E07B; Tue, 22 Jul 2025 17:18:36 +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=1753204716; cv=none; b=O2AUiCwJXuJgSoqFzR4o/MKyAEf+fI9MMMEsh1XmJ9sqA1ISbRw3dp+97tFa79LjRHxt8SIdDhegyW1u9W5MDQcbiH2sjgpUR9k6Qo9xLe8j8KYo0BXi14mgR9kSPRkdoBjjeNIEusfqiDAEUseFfcvw1jTnGJ6t+7LUFRP/T0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753204716; c=relaxed/simple; bh=hKrFfWopkwsW7B2AHVN42+Qytuzm974Tmy5ORbFhuiw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fTTbpBUu8v8AzTAmoA9W5h4WZ62rcaBEHsVcJqjYd79JtrsTGJTXxXR9I9KzxUSuDVj1h+B8brJYZO6j4J0afd7Nbxo1Jpx/T4p0aPf1NUQXjwC8i8htIiQIOndQ8QJUFvDj4rGHykdWvEEPEY8C2ozhrQmZ/co6sBZcXSuMTFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sKNKGse8; 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="sKNKGse8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A3ADC4CEF6; Tue, 22 Jul 2025 17:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753204716; bh=hKrFfWopkwsW7B2AHVN42+Qytuzm974Tmy5ORbFhuiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sKNKGse8eGdOlxo2VuWBWdfYHko0GJTL4K9Hl9HBQGkHeolTrDHtRlbDeEo986F+q jE75o5VTAgf6LrPrOk2DLTAykPW0tnBaD6eWGJ5rnuJDwV3Ccle8dkI4VZ/mlz4Lu8 093RzU1fuVG4knHzmf/ZUPvv3Omz/TUBvJBgSWgSAuULhN4UzBC3m39ipIJaPEHEmH yUTa8ZW2P1UHAlqWE0401f/rs8M0RtF1/MATcYD2RW04moc9Rd7wHJXkWaFFFdxcJJ dYoha0ltrg7/9pDplDaYkBTI8Ah2Xi1MHd+dM0XIzvrnz/1CvqAyhNFyG6+bjiWDtn jIwL8eOwhqs1A== From: Kees Cook To: Marcelo Ricardo Leitner Cc: Kees Cook , Xin Long , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-sctp@vger.kernel.org, netdev@vger.kernel.org, "Jason A. Donenfeld" , Andrew Lunn , linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com, linux-hardening@vger.kernel.org Subject: [PATCH net-next 3/3] sctp: Replace sockaddr with sockaddr_inet in sctp_addr union Date: Tue, 22 Jul 2025 10:18:33 -0700 Message-Id: <20250722171836.1078436-3-kees@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250722171528.work.209-kees@kernel.org> References: <20250722171528.work.209-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1239; i=kees@kernel.org; h=from:subject; bh=hKrFfWopkwsW7B2AHVN42+Qytuzm974Tmy5ORbFhuiw=; b=owGbwMvMwCVmps19z/KJym7G02pJDBn1x18GvmBYyG99a/fba1pvYpQmiBTem5S06N6J1C/q3 UUPe7/0dpSyMIhxMciKKbIE2bnHuXi8bQ93n6sIM4eVCWQIAxenAEyk9CLD//TrN9I4bZ9JPA3h LDbinLMm8K9ER+PX0CURNhpT2NOsDjL8MzsYOSthCYdLxI2rHbVnu39JvQyN2VjZsW9Oe6BBcLU VMwA= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As part of the removal of the variably-sized sockaddr for kernel internals, replace struct sockaddr with sockaddr_inet in the sctp_addr union. No binary changes; the union size remains unchanged due to sockaddr_inet matching the size of sockaddr_in6. Signed-off-by: Kees Cook --- Cc: Marcelo Ricardo Leitner Cc: Xin Long Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Simon Horman Cc: Cc: --- include/net/sctp/structs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index 1ad7ce71d0a7..8a540ad9b509 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -51,9 +51,9 @@ * We should wean ourselves off this. */ union sctp_addr { + struct sockaddr_inet sa; /* Large enough for both address families */ struct sockaddr_in v4; struct sockaddr_in6 v6; - struct sockaddr sa; }; =20 /* Forward declarations for data structures. */ --=20 2.34.1