[23/32] ACPICA: struct acpi_nfit_interleave: Replace 1-element array with flexible array

Message ID 2652195.BddDVKsqQX@kreacher
State New
Headers
Series ACPICA: ACPICA 20230331 |

Commit Message

Rafael J. Wysocki April 5, 2023, 1:51 p.m. UTC
  From: Kees Cook <kees@outflux.net>

ACPICA commit e66decc6fca36b59194b0947d87d6a9bec078bc3

Similar to "Replace one-element array with flexible-array", replace the
1-element array with a proper flexible array member as defined by C99.

This allows the code to operate without tripping compile-time and run-
time bounds checkers (e.g. via __builtin_object_size(), -fsanitize=bounds,
and/or -fstrict-flex-arrays=3).

Unlike struct acpi_nfit_flush_address and struct acpi_nfit_smbios, which
had their sizeof() uses adjusted in code, struct acpi_nfit_interleave did
not. This appears to have been a bug. After this change, there is a binary
difference in acpi_dm_dump_nfit() since the size of the structure now has
the correct size, as the prior result was including the trailing U32:

-       mov    $0x14,%ebp
+       mov    $0x10,%ebp

Link: https://github.com/acpica/acpica/commit/e66decc6
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/nfit/core.c | 2 +-
 include/acpi/actbl2.h    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

Dan Williams April 6, 2023, 12:36 a.m. UTC | #1
Rafael J. Wysocki wrote:
> From: Kees Cook <kees@outflux.net>
> 
> ACPICA commit e66decc6fca36b59194b0947d87d6a9bec078bc3
> 
> Similar to "Replace one-element array with flexible-array", replace the
> 1-element array with a proper flexible array member as defined by C99.
> 
> This allows the code to operate without tripping compile-time and run-
> time bounds checkers (e.g. via __builtin_object_size(), -fsanitize=bounds,
> and/or -fstrict-flex-arrays=3).
> 
> Unlike struct acpi_nfit_flush_address and struct acpi_nfit_smbios, which
> had their sizeof() uses adjusted in code, struct acpi_nfit_interleave did
> not. This appears to have been a bug. After this change, there is a binary
> difference in acpi_dm_dump_nfit() since the size of the structure now has
> the correct size, as the prior result was including the trailing U32:
> 
> -       mov    $0x14,%ebp
> +       mov    $0x10,%ebp
> 
> Link: https://github.com/acpica/acpica/commit/e66decc6
> Signed-off-by: Bob Moore <robert.moore@intel.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Dan Williams <dan.j.williams@intel.com>
  

Patch

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 981f8b0f595d..a398f32dfd68 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -3476,7 +3476,7 @@  static __init int nfit_init(void)
 	BUILD_BUG_ON(sizeof(struct acpi_table_nfit) != 40);
 	BUILD_BUG_ON(sizeof(struct acpi_nfit_system_address) != 64);
 	BUILD_BUG_ON(sizeof(struct acpi_nfit_memory_map) != 48);
-	BUILD_BUG_ON(sizeof(struct acpi_nfit_interleave) != 20);
+	BUILD_BUG_ON(sizeof(struct acpi_nfit_interleave) != 16);
 	BUILD_BUG_ON(sizeof(struct acpi_nfit_smbios) != 8);
 	BUILD_BUG_ON(sizeof(struct acpi_nfit_control_region) != 80);
 	BUILD_BUG_ON(sizeof(struct acpi_nfit_data_region) != 40);
diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h
index 6d3251ea4c53..a51fd4090d27 100644
--- a/include/acpi/actbl2.h
+++ b/include/acpi/actbl2.h
@@ -1700,7 +1700,7 @@  struct acpi_nfit_interleave {
 	u16 reserved;		/* Reserved, must be zero */
 	u32 line_count;
 	u32 line_size;
-	u32 line_offset[1];	/* Variable length */
+	u32 line_offset[];	/* Variable length */
 };
 
 /* 3: SMBIOS Management Information Structure */