Skip to contentSkip to conversation

ACPICA: Replace fake flexible arrays with flexible array members

PATCH Superseded Kees Cook 2 participants 7 messages Nov 18, 2022 – Jan 27, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 ACPICA: Replace fake flexible arrays with flexible array members

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

This results in no differences in binary output.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Robert Moore <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 include/acpi/acrestyp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/acpi/acrestyp.h +5 -2
index a7fb8ddb3dc6..ee945084d46e 100644
@@ -332,7 +332,7 @@ struct acpi_resource_extended_irq {
 	u8 wake_capable;
 	u8 interrupt_count;
 	struct acpi_resource_source resource_source;
-	u32 interrupts[1];
+	u32 interrupts[];
 };
 
 struct acpi_resource_generic_register {
@@ -679,7 +679,10 @@ struct acpi_pci_routing_table {
 	u32 pin;
 	u64 address;		/* here for 64-bit alignment */
 	u32 source_index;
-	char source[4];		/* pad to 64 bits so sizeof() works in all cases */
+	union {
+		char pad[4];	/* pad to 64 bits so sizeof() works in all cases */
+		DECLARE_FLEX_ARRAY(char, source);
+	};
 };
 
 #endif				/* __ACRESTYP_H__ */
Signature · 1 line
2.34.1
author
#1 lore raw
Quoted 2 lines · Kees Cook

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

Any update on this? Upstream is currently unbuildable since October.

Quoted 6 lines

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Quoted 6 lines

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

This results in no differences in binary output.

In the meantime, can you take this patch for Linux, and we can wait for ACPICA to catch up?

Thanks!

-Kees

Quoted 40 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Robert Moore <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 include/acpi/acrestyp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/acpi/acrestyp.h +5 -2
index a7fb8ddb3dc6..ee945084d46e 100644
@@ -332,7 +332,7 @@ struct acpi_resource_extended_irq {
 	u8 wake_capable;
 	u8 interrupt_count;
 	struct acpi_resource_source resource_source;
-	u32 interrupts[1];
+	u32 interrupts[];
 };
 
 struct acpi_resource_generic_register {
@@ -679,7 +679,10 @@ struct acpi_pci_routing_table {
 	u32 pin;
 	u64 address;		/* here for 64-bit alignment */
 	u32 source_index;
-	char source[4];		/* pad to 64 bits so sizeof() works in all cases */
+	union {
+		char pad[4];	/* pad to 64 bits so sizeof() works in all cases */
+		DECLARE_FLEX_ARRAY(char, source);
+	};
 };
 
 #endif				/* __ACRESTYP_H__ */
Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook
#2 lore raw
Quoted 18 lines · Kees Cook
Quoted 2 lines · Kees Cook

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

Any update on this? Upstream is currently unbuildable since October.

Quoted 11 lines

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

Quoted 4 lines
Quoted 1 line

This results in no differences in binary output.

In the meantime, can you take this patch for Linux, and we can wait for ACPICA to catch up?

Applied now (as 6.3 material), sorry for the delay.

Thanks!

Quoted 43 lines
Quoted 38 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Robert Moore <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 include/acpi/acrestyp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/acpi/acrestyp.h +5 -3
index a7fb8ddb3dc6..ee945084d46e 100644
@@ -332,7 +332,7 @@ struct acpi_resource_extended_irq {
      u8 wake_capable;
      u8 interrupt_count;
      struct acpi_resource_source resource_source;
-     u32 interrupts[1];
+     u32 interrupts[];
 };
 
 struct acpi_resource_generic_register {
@@ -679,7 +679,10 @@ struct acpi_pci_routing_table {
      u32 pin;
      u64 address;            /* here for 64-bit alignment */
      u32 source_index;
-     char source[4];         /* pad to 64 bits so sizeof() works in all cases */
+     union {
+             char pad[4];    /* pad to 64 bits so sizeof() works in all cases */
+             DECLARE_FLEX_ARRAY(char, source);
+     };
 };
 
 #endif                               /* __ACRESTYP_H__ */
--
Quoted 2 lines

2.34.1

--
Kees Cook

author
#3 lore raw
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Kees Cook
Quoted 2 lines · Kees Cook

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

Any update on this? Upstream is currently unbuildable since October.

Quoted 11 lines

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

This results in no differences in binary output.

In the meantime, can you take this patch for Linux, and we can wait for ACPICA to catch up?

Applied now (as 6.3 material), sorry for the delay.

Thanks!

Signature · 1 line
Kees Cook
#4 lore raw
Quoted 21 lines · Kees Cook
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Kees Cook
Quoted 2 lines · Kees Cook

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

Any update on this? Upstream is currently unbuildable since October.

Quoted 11 lines

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

This results in no differences in binary output.

In the meantime, can you take this patch for Linux, and we can wait for ACPICA to catch up?

Applied now (as 6.3 material), sorry for the delay.

Thanks!

Unfortunately, this breaks compilation for the ACPI tools in tools/power/acpi/.

Apparently, the problem is that DECLARE_FLEX_ARRAY() is not defined when the tools are built, because kernel headers are not used then.

I guess the changes from your upstream PR need to be backported literally for this to work, so I'll drop this one for the time being. Or please let me know if you have a better idea.

author
#5 lore raw
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Kees Cook
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Kees Cook
Quoted 2 lines · Kees Cook

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

Any update on this? Upstream is currently unbuildable since October.

Quoted 12 lines

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

This results in no differences in binary output.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

In the meantime, can you take this patch for Linux, and we can wait for ACPICA to catch up?

Applied now (as 6.3 material), sorry for the delay.

Thanks!

Unfortunately, this breaks compilation for the ACPI tools in tools/power/acpi/.

What's the make target to test this?

Quoted 2 lines

Apparently, the problem is that DECLARE_FLEX_ARRAY() is not defined when the tools are built, because kernel headers are not used then.

This should exist in the stddef.h tools headers, but perhaps it isn't included already?

Quoted 3 lines

I guess the changes from your upstream PR need to be backported literally for this to work, so I'll drop this one for the time being. Or please let me know if you have a better idea.

I can send a new version if I can reproduce the build failure you see...

Signature · 1 line
Kees Cook
#6 lore raw
Quoted 29 lines · Kees Cook
Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Kees Cook
Quoted 24 lines · Rafael J. Wysocki
Quoted 22 lines · Kees Cook
Quoted 2 lines · Kees Cook

Functionally identical to ACPICA upstream pull request 813:
https://github.com/acpica/acpica/pull/813

Any update on this? Upstream is currently unbuildable since October.

Quoted 6 lines

One-element arrays (and multi-element arrays being treated as dynamically sized) are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.

Quoted 6 lines

Replace one-element array with flexible-array member in struct acpi_resource_extended_irq. Replace 4-byte fixed-size array with 4-byte padding in a union with a flexible-array member in struct acpi_pci_routing_table.

This results in no differences in binary output.

In the meantime, can you take this patch for Linux, and we can wait for ACPICA to catch up?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Applied now (as 6.3 material), sorry for the delay.

Thanks!

Unfortunately, this breaks compilation for the ACPI tools in tools/power/acpi/.

What's the make target to test this?

Just cd to tools/power/acpi in the kernel tree and run make.

Quoted 5 lines
Quoted 2 lines

Apparently, the problem is that DECLARE_FLEX_ARRAY() is not defined when the tools are built, because kernel headers are not used then.

This should exist in the stddef.h tools headers, but perhaps it isn't included already?

No, it isn't AFAICS.

Quoted 5 lines
Quoted 3 lines

I guess the changes from your upstream PR need to be backported literally for this to work, so I'll drop this one for the time being. Or please let me know if you have a better idea.

I can send a new version if I can reproduce the build failure you see...

Sure, thanks!