lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230619091215.2731541-3-arnd@kernel.org>
Date: Mon, 19 Jun 2023 11:12:11 +0200
From: Arnd Bergmann <arnd@...nel.org>
To: Edward Cree <ecree.xilinx@...il.com>,
	Martin Habets <habetsm.xilinx@...il.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>
Cc: Arnd Bergmann <arnd@...db.de>,
	netdev@...r.kernel.org,
	linux-net-drivers@....com,
	linux-kernel@...r.kernel.org
Subject: [PATCH 3/3] sfc: selftest: fix struct packing

From: Arnd Bergmann <arnd@...db.de>

Three of the sfc drivers define a packed loopback_payload structure with an
ethernet header followed by an IP header. However, the kernel definition
of iphdr specifies that this is 4-byte aligned, causing a W=1 warning:

net/ethernet/sfc/siena/selftest.c:46:15: error: field ip within 'struct efx_loopback_payload' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
        struct iphdr ip;

As the iphdr packing is not easily changed without breaking other code,
change the three structures to use a local definition instead.

Signed-off-by: Arnd Bergmann <arnd@...db.de>
---
 drivers/net/ethernet/sfc/falcon/selftest.c | 21 ++++++++++++++++++++-
 drivers/net/ethernet/sfc/selftest.c        | 21 ++++++++++++++++++++-
 drivers/net/ethernet/sfc/siena/selftest.c  | 21 ++++++++++++++++++++-
 3 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/sfc/falcon/selftest.c b/drivers/net/ethernet/sfc/falcon/selftest.c
index 6a454ac6f8763..fb7fcd27a33a5 100644
--- a/drivers/net/ethernet/sfc/falcon/selftest.c
+++ b/drivers/net/ethernet/sfc/falcon/selftest.c
@@ -40,7 +40,26 @@
  */
 struct ef4_loopback_payload {
 	struct ethhdr header;
-	struct iphdr ip;
+	struct {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+		__u8	ihl:4,
+			version:4;
+#elif defined (__BIG_ENDIAN_BITFIELD)
+		__u8	version:4,
+			ihl:4;
+#else
+#error	"Please fix <asm/byteorder.h>"
+#endif
+		__u8	tos;
+		__be16	tot_len;
+		__be16	id;
+		__be16	frag_off;
+		__u8	ttl;
+		__u8	protocol;
+		__sum16	check;
+		__be32	saddr;
+		__be32	daddr;
+	} __packed ip; /* unaligned struct iphdr */
 	struct udphdr udp;
 	__be16 iteration;
 	char msg[64];
diff --git a/drivers/net/ethernet/sfc/selftest.c b/drivers/net/ethernet/sfc/selftest.c
index 3c5227afd4977..440a57953779c 100644
--- a/drivers/net/ethernet/sfc/selftest.c
+++ b/drivers/net/ethernet/sfc/selftest.c
@@ -43,7 +43,26 @@
  */
 struct efx_loopback_payload {
 	struct ethhdr header;
-	struct iphdr ip;
+	struct {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+		__u8	ihl:4,
+			version:4;
+#elif defined (__BIG_ENDIAN_BITFIELD)
+		__u8	version:4,
+			ihl:4;
+#else
+#error	"Please fix <asm/byteorder.h>"
+#endif
+		__u8	tos;
+		__be16	tot_len;
+		__be16	id;
+		__be16	frag_off;
+		__u8	ttl;
+		__u8	protocol;
+		__sum16	check;
+		__be32	saddr;
+		__be32	daddr;
+	} __packed ip; /* unaligned struct iphdr */
 	struct udphdr udp;
 	__be16 iteration;
 	char msg[64];
diff --git a/drivers/net/ethernet/sfc/siena/selftest.c b/drivers/net/ethernet/sfc/siena/selftest.c
index 07715a3d6beab..b8a8b0495f661 100644
--- a/drivers/net/ethernet/sfc/siena/selftest.c
+++ b/drivers/net/ethernet/sfc/siena/selftest.c
@@ -43,7 +43,26 @@
  */
 struct efx_loopback_payload {
 	struct ethhdr header;
-	struct iphdr ip;
+	struct {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+		__u8	ihl:4,
+			version:4;
+#elif defined (__BIG_ENDIAN_BITFIELD)
+		__u8	version:4,
+			ihl:4;
+#else
+#error	"Please fix <asm/byteorder.h>"
+#endif
+		__u8	tos;
+		__be16	tot_len;
+		__be16	id;
+		__be16	frag_off;
+		__u8	ttl;
+		__u8	protocol;
+		__sum16	check;
+		__be32	saddr;
+		__be32	daddr;
+	} __packed ip; /* unaligned struct iphdr */
 	struct udphdr udp;
 	__be16 iteration;
 	char msg[64];
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ