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: <685c653a6fe42_1608bd100d0@dwillia2-xfh.jf.intel.com.notmuch>
Date: Wed, 25 Jun 2025 14:08:10 -0700
From: <dan.j.williams@...el.com>
To: <dan.j.williams@...el.com>, "Gustavo A. R. Silva"
	<gustavo@...eddedor.com>, Kees Cook <kees@...nel.org>, "Gustavo A. R. Silva"
	<gustavoars@...nel.org>
CC: Dan Williams <dan.j.williams@...el.com>, Vishal Verma
	<vishal.l.verma@...el.com>, Dave Jiang <dave.jiang@...el.com>, Ira Weiny
	<ira.weiny@...el.com>, "Rafael J. Wysocki" <rafael@...nel.org>, Len Brown
	<lenb@...nel.org>, <nvdimm@...ts.linux.dev>, <linux-acpi@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <linux-hardening@...r.kernel.org>
Subject: Re: [PATCH v3][next] acpi: nfit: intel: avoid multiple
 -Wflex-array-member-not-at-end warnings

dan.j.williams@ wrote:
> Gustavo A. R. Silva wrote:
> [..]
> > > I think it would be a pretty small and direct replacement:
> > > 
> > > 	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
> > > 			 struct nd_intel_get_security_state cmd;
> > > 	) nd_cmd = {
> > > 		...
> > 
> > Yes, this works. Hopefully, maintainers will comment on this and let us
> > know what they prefer. :)
> 
> Hey Gustavo, apologies for the latency here. I think TRAILING_OVERLAP()
> looks lovely for this if only because I can read that and have an idea
> what it means vs wondering what this _offset_to_fam is about and needing
> to read the comment.
> 
> If you can get me that patch on top of the TRAILING_OVERLAP() branch I
> can test it out and ack it to let it do in through the KSPP tree.

Just to move this along, I gave this conversion a try and all looks good
here. So feel free to fold this in and add:

Acked-by: Dan Williams <dan.j.williams@...el.com>
Tested-by: Dan Williams <dan.j.williams@...el.com>

...and take it through the KSPP tree with the TRAILING_OVERLAP() merge.

-- 8< --
diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c
index 987d427ec2b6..c88647428715 100644
--- a/drivers/acpi/nfit/intel.c
+++ b/drivers/acpi/nfit/intel.c
@@ -55,17 +55,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm,
 {
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
 	unsigned long security_flags = 0;
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_get_security_state cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_get_security_state cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -127,17 +119,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm,
 static int intel_security_freeze(struct nvdimm *nvdimm)
 {
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_freeze_lock cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_freeze_lock cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_FREEZE_LOCK,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -167,17 +151,9 @@ static int intel_security_change_key(struct nvdimm *nvdimm,
 	unsigned int cmd = ptype == NVDIMM_MASTER ?
 		NVDIMM_INTEL_SET_MASTER_PASSPHRASE :
 		NVDIMM_INTEL_SET_PASSPHRASE;
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_set_passphrase cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_set_passphrase cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_family = NVDIMM_FAMILY_INTEL,
 			.nd_size_in = ND_INTEL_PASSPHRASE_SIZE * 2,
@@ -216,17 +192,9 @@ static int __maybe_unused intel_security_unlock(struct nvdimm *nvdimm,
 		const struct nvdimm_key_data *key_data)
 {
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_unlock_unit cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_unlock_unit cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_UNLOCK_UNIT,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -262,17 +230,9 @@ static int intel_security_disable(struct nvdimm *nvdimm,
 {
 	int rc;
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_disable_passphrase cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_disable_passphrase cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_DISABLE_PASSPHRASE,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -312,17 +272,9 @@ static int __maybe_unused intel_security_erase(struct nvdimm *nvdimm,
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
 	unsigned int cmd = ptype == NVDIMM_MASTER ?
 		NVDIMM_INTEL_MASTER_SECURE_ERASE : NVDIMM_INTEL_SECURE_ERASE;
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_secure_erase cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_secure_erase cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_family = NVDIMM_FAMILY_INTEL,
 			.nd_size_in = ND_INTEL_PASSPHRASE_SIZE,
@@ -360,17 +312,9 @@ static int __maybe_unused intel_security_query_overwrite(struct nvdimm *nvdimm)
 {
 	int rc;
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_query_overwrite cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_query_overwrite cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_QUERY_OVERWRITE,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -403,17 +347,9 @@ static int __maybe_unused intel_security_overwrite(struct nvdimm *nvdimm,
 {
 	int rc;
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_overwrite cmd;
-		};
-	} nd_cmd = {
+        TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+                         struct nd_intel_overwrite cmd;
+        ) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_OVERWRITE,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -463,17 +399,9 @@ const struct nvdimm_security_ops *intel_security_ops = &__intel_security_ops;
 static int intel_bus_fwa_businfo(struct nvdimm_bus_descriptor *nd_desc,
 		struct nd_intel_bus_fw_activate_businfo *info)
 {
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_bus_fw_activate_businfo cmd;
-		};
-	} nd_cmd = {
+        TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+                         struct nd_intel_bus_fw_activate_businfo cmd;
+        ) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO,
 			.nd_family = NVDIMM_BUS_FAMILY_INTEL,
@@ -581,17 +509,9 @@ static enum nvdimm_fwa_capability intel_bus_fwa_capability(
 static int intel_bus_fwa_activate(struct nvdimm_bus_descriptor *nd_desc)
 {
 	struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_bus_fw_activate cmd;
-		};
-	} nd_cmd = {
+        TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+                         struct nd_intel_bus_fw_activate cmd;
+        ) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE,
 			.nd_family = NVDIMM_BUS_FAMILY_INTEL,
@@ -652,17 +572,9 @@ const struct nvdimm_bus_fw_ops *intel_bus_fw_ops = &__intel_bus_fw_ops;
 static int intel_fwa_dimminfo(struct nvdimm *nvdimm,
 		struct nd_intel_fw_activate_dimminfo *info)
 {
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_fw_activate_dimminfo cmd;
-		};
-	} nd_cmd = {
+        TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+                         struct nd_intel_fw_activate_dimminfo cmd;
+        ) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO,
 			.nd_family = NVDIMM_FAMILY_INTEL,
@@ -765,17 +677,9 @@ static int intel_fwa_arm(struct nvdimm *nvdimm, enum nvdimm_fwa_trigger arm)
 {
 	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
 	struct acpi_nfit_desc *acpi_desc = nfit_mem->acpi_desc;
-	/*
-	 * This effectively creates a union between the flexible-array member
-	 * and any members after _offset_to_fam.
-	 */
-	union {
-		struct nd_cmd_pkg pkg;
-		struct {
-			u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
-			struct nd_intel_fw_activate_arm cmd;
-		};
-	} nd_cmd = {
+	TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
+			 struct nd_intel_fw_activate_arm cmd;
+	) nd_cmd = {
 		.pkg = {
 			.nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM,
 			.nd_family = NVDIMM_FAMILY_INTEL,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ