powerpc/rtas: Replace one-element arrays with flexible arrays
PATCH 1/1 powerpc/rtas: Replace one-element arrays with flexible arrays
Using a one-element array as a fake flexible array is deprecated.
Replace the one-element flexible arrays in rtas-types.h with C99 standard flexible array members instead.
This helps us move towards enabling -fstrict-flex-arrays=3 in future.
Found using scripts/coccinelle/misc/flexible_array.cocci.
--- arch/powerpc/include/asm/rtas-types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/rtas-types.h +2 -2
@@ -44,7 +44,7 @@ struct rtas_error_log {*/ u8 byte3;/* General event or error*/ __be32 extended_log_length;/* length in bytes */ -unsigned char buffer[1 ];/* Start of extended log */ +unsigned char buffer[];/* Start of extended log */ /* Variable length. */ };
@@ -85,7 +85,7 @@ struct rtas_ext_event_log_v6 {/* that defines the format for */ /* the vendor specific log type */ /* Byte 16-end of log */ -u8 vendor_log[1 ];/* Start of vendor specific log */ +u8 vendor_log[];/* Start of vendor specific log */ /* Variable length. */ };
Signature · 1 line
2.39.1
Quoted 33 lines · Andrew Donnellan
Using a one-element array as a fake flexible array is deprecated.
Replace the one-element flexible arrays in
rtas-types.hwith C99 standard flexible array members instead.This helps us move towards enabling -fstrict-flex-arrays=3 in future.
Found using
scripts/coccinelle/misc/flexible_array.cocci.Cc Nathan Lynch <[email protected]>Cc Leonardo Bras <[email protected]>Signed-off-by Andrew Donnellan <[email protected]>--- arch/powerpc/include/asm/rtas-types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/include/asm/rtas-types.h +1
-1@@ -44,7 +44,7 @@ struct rtas_error_log {*/ u8 byte3;/* General event or error*/ __be32 extended_log_length;/* length in bytes */ -unsigned char buffer[1 ];/* Start of extended log */ +unsigned char buffer[];/* Start of extended log */ /* Variable length. */ };
arch/powerpc/include/asm/rtas-types.h struct rtas_ext_event_log_v6 { · line 91
Quoted 8 lines
arch/powerpc/include/asm/rtas-types.h +1
-1@@ -85,7 +85,7 @@ struct rtas_ext_event_log_v6 {/* that defines the format for */ /* the vendor specific log type */ /* Byte 16-end of log */ -u8 vendor_log[1 ];/* Start of vendor specific log */ +u8 vendor_log[];/* Start of vendor specific log */ /* Variable length. */ };
LGTM.
FWIW:
Quoted 33 lines · Andrew Donnellan
Using a one-element array as a fake flexible array is deprecated.
Replace the one-element flexible arrays in
rtas-types.hwith C99 standard flexible array members instead.This helps us move towards enabling -fstrict-flex-arrays=3 in future.
Found using
scripts/coccinelle/misc/flexible_array.cocci.Cc Nathan Lynch <[email protected]>Cc Leonardo Bras <[email protected]>Signed-off-by Andrew Donnellan <[email protected]>--- arch/powerpc/include/asm/rtas-types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/include/asm/rtas-types.h +1
-1@@ -44,7 +44,7 @@ struct rtas_error_log {*/ u8 byte3;/* General event or error*/ __be32 extended_log_length;/* length in bytes */ -unsigned char buffer[1 ];/* Start of extended log */ +unsigned char buffer[];/* Start of extended log */ /* Variable length. */ };
arch/powerpc/include/asm/rtas-types.h struct rtas_ext_event_log_v6 { · line 90
Quoted 7 lines
arch/powerpc/include/asm/rtas-types.h +1
-1@@ -85,7 +85,7 @@ struct rtas_ext_event_log_v6 {/* that defines the format for */ /* the vendor specific log type */ /* Byte 16-end of log */ -u8 vendor_log[1 ];/* Start of vendor specific log */ +u8 vendor_log[];/* Start of vendor specific log */ /* Variable length. */ };
I see at least one place that consults the size of one of these structs, in get_pseries_errorlog():
/* Check that we understand the format */ if (ext_log_length < sizeof(struct rtas_ext_event_log_v6) || ...
Don't all such sites need to be audited/adjusted for changes like this?
Quoted 45 lines · Nathan Lynch
Quoted 33 lines · Andrew Donnellan
Using a one-element array as a fake flexible array is deprecated.
Replace the one-element flexible arrays in
rtas-types.hwith C99 standard flexible array members instead.This helps us move towards enabling -fstrict-flex-arrays=3 in future.
Found using
scripts/coccinelle/misc/flexible_array.cocci.Cc Nathan Lynch <[email protected]>Cc Leonardo Bras <[email protected]>Signed-off-by Andrew Donnellan <[email protected]>--- arch/powerpc/include/asm/rtas-types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/include/asm/rtas-types.h +1
-1@@ -44,7 +44,7 @@ struct rtas_error_log {*/ u8 byte3;/* General event or error*/ __be32 extended_log_length;/* length in bytes */ -unsigned char buffer[1 ];/* Start of extended log */ +unsigned char buffer[];/* Start of extended log */ /* Variable length. */ };arch/powerpc/include/asm/rtas-types.h struct rtas_ext_event_log_v6 { · line 90
Quoted 7 lines
arch/powerpc/include/asm/rtas-types.h +1
-1@@ -85,7 +85,7 @@ struct rtas_ext_event_log_v6 {/* that defines the format for */ /* the vendor specific log type */ /* Byte 16-end of log */ -u8 vendor_log[1 ];/* Start of vendor specific log */ +u8 vendor_log[];/* Start of vendor specific log */ /* Variable length. */ };I see at least one place that consults the size of one of these structs, in
get_pseries_errorlog():
Quoted 4 lines
/* Check that we understand the format */ if (ext_log_length < sizeof(struct rtas_ext_event_log_v6) || ...Don't all such sites need to be audited/adjusted for changes like this?
Yeah, I'd expect a binary comparison[1] before/after to catch things like this. E.g. the following C files mention those structs:
arch/powerpc/platforms/pseries/io_event_irq.carch/powerpc/platforms/pseries/ras.carch/powerpc/kernel/rtasd.carch/powerpc/kernel/rtas.c
-Kees
[1] https://outflux.net/blog/archives/2022/06/24/finding-binary-differences/
Signature · 1 line
Kees Cook
Quoted 10 lines · Nathan Lynch
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
I see at least one place that consults the size of one of these structs,
inget_pseries_errorlog():/* Check that we understand the format */
if (ext_log_length< sizeof(structrtas_ext_event_log_v6)
||
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Don't all such sites need to be audited/adjusted for changes like
this?
I did actually see that site, and concluded that for the purposes of that particular check, removing a single extra byte is irrelevant (maybe it makes the check more strictly correct, what if the vendor_log is actually of length 0?)
Doing a binary diff, as Kees suggests, over the object files in arch/powerpc:
- there's no difference at all caused by changing rtas_ext_event_log_v6.vendor_log, which kind of surprises me given the above.
- changing rtas_error_log.buffer does seem to change some code generation in arch/powerpc/platforms/pseries/ras.o, I can't quite see why.
Andrew
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited