2022-09-22 19:33:04

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH] scsi: pm8001: Replace one-element array with flexible-array member

One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct fw_control_info.

This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [1].

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/207
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1]
Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/scsi/pm8001/pm8001_sas.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h
index c5e3f380a01c..b08f52673889 100644
--- a/drivers/scsi/pm8001/pm8001_sas.h
+++ b/drivers/scsi/pm8001/pm8001_sas.h
@@ -612,7 +612,7 @@ struct fw_control_info {
operations.*/
u32 reserved;/* padding required for 64 bit
alignment */
- u8 buffer[1];/* Start of buffer */
+ u8 buffer[];/* Start of buffer */
};
struct fw_control_ex {
struct fw_control_info *fw_control;
--
2.34.1


2022-09-23 06:57:08

by Jinpu Wang

[permalink] [raw]
Subject: Re: [PATCH] scsi: pm8001: Replace one-element array with flexible-array member

On Thu, Sep 22, 2022 at 9:30 PM Gustavo A. R. Silva
<[email protected]> wrote:
>
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element array with flexible-array
> member in struct fw_control_info.
>
> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
> routines on memcpy() and help us make progress towards globally
> enabling -fstrict-flex-arrays=3 [1].
>
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/207
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1]
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
Acked-by: Jack Wang <[email protected]>
> ---
> drivers/scsi/pm8001/pm8001_sas.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h
> index c5e3f380a01c..b08f52673889 100644
> --- a/drivers/scsi/pm8001/pm8001_sas.h
> +++ b/drivers/scsi/pm8001/pm8001_sas.h
> @@ -612,7 +612,7 @@ struct fw_control_info {
> operations.*/
> u32 reserved;/* padding required for 64 bit
> alignment */
> - u8 buffer[1];/* Start of buffer */
> + u8 buffer[];/* Start of buffer */
> };
> struct fw_control_ex {
> struct fw_control_info *fw_control;
> --
> 2.34.1
>

2022-09-24 05:50:28

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] scsi: pm8001: Replace one-element array with flexible-array member

On Thu, Sep 22, 2022 at 02:30:28PM -0500, Gustavo A. R. Silva wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element array with flexible-array
> member in struct fw_control_info.

I think this changelog should include some explanation of why this change
is safe. As far as I can see, it would be:

This is the only change needed; struct fw_control_info is only ever used
for casting to existing allocations. No sizeof() is used on any of the
resulting variables.

> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
> routines on memcpy() and help us make progress towards globally
> enabling -fstrict-flex-arrays=3 [1].
>
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/207
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1]
> Signed-off-by: Gustavo A. R. Silva <[email protected]>

Another one down! :)

Reviewed-by: Kees Cook <[email protected]>

--
Kees Cook

2022-09-25 17:40:39

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH] scsi: pm8001: Replace one-element array with flexible-array member


Gustavo,

> One-element arrays are deprecated, and we are replacing them with
> flexible array members instead. So, replace one-element array with
> flexible-array member in struct fw_control_info.

Applied to 6.1/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering