2023-05-17 21:24:36

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH 1/2][next] scsi: lpfc: 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 arrays with flexible-array
members in a couple of structures, and refactor the rest of the code,
accordingly.

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].

This results in no differences in binary output.

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/295
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/scsi/lpfc/lpfc_ct.c | 6 ++++--
drivers/scsi/lpfc/lpfc_hw.h | 4 ++--
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index f3bdcebe67f5..e880d127d7f5 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -3748,7 +3748,8 @@ lpfc_vmid_cmd(struct lpfc_vport *vport,
rap->obj[0].entity_id_len = vmid->vmid_len;
memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
size = RAPP_IDENT_OFFSET +
- sizeof(struct lpfc_vmid_rapp_ident_list);
+ sizeof(struct lpfc_vmid_rapp_ident_list) +
+ sizeof(struct entity_id_object);
retry = 1;
break;

@@ -3767,7 +3768,8 @@ lpfc_vmid_cmd(struct lpfc_vport *vport,
dap->obj[0].entity_id_len = vmid->vmid_len;
memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
size = DAPP_IDENT_OFFSET +
- sizeof(struct lpfc_vmid_dapp_ident_list);
+ sizeof(struct lpfc_vmid_dapp_ident_list) +
+ sizeof(struct entity_id_object);
write_lock(&vport->vmid_lock);
vmid->flag &= ~LPFC_VMID_REGISTERED;
write_unlock(&vport->vmid_lock);
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h
index 19b2d2754f32..b2123ec4df88 100644
--- a/drivers/scsi/lpfc/lpfc_hw.h
+++ b/drivers/scsi/lpfc/lpfc_hw.h
@@ -1415,12 +1415,12 @@ struct app_id_object {

struct lpfc_vmid_rapp_ident_list {
uint32_t no_of_objects;
- struct entity_id_object obj[1];
+ struct entity_id_object obj[];
};

struct lpfc_vmid_dapp_ident_list {
uint32_t no_of_objects;
- struct entity_id_object obj[1];
+ struct entity_id_object obj[];
};

#define GALLAPPIA_ID_LAST 0x80
--
2.34.1



2023-05-17 23:36:27

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH 1/2][next] scsi: lpfc: Replace one-element array with flexible-array member

On Wed, May 17, 2023 at 03:22:45PM -0600, Gustavo A. R. Silva wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element arrays with flexible-array
> members in a couple of structures, and refactor the rest of the code,
> accordingly.
>
> 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].
>
> This results in no differences in binary output.
>
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/295
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <[email protected]>

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

--
Kees Cook

2023-05-22 22:38:44

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH 1/2][next] scsi: lpfc: Replace one-element array with flexible-array member

On Mon, May 22, 2023 at 06:02:21PM -0400, Martin K. Petersen wrote:
>
> Applied to 6.5/scsi-staging, thanks!

Thanks, Martin.
--
Gustavo

2023-05-22 22:39:40

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH 1/2][next] scsi: lpfc: 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 arrays with flexible-array
> members in a couple of structures, and refactor the rest of the code,
> accordingly.
>
> 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].
>
> This results in no differences in binary output.

Applied to 6.5/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering

2023-05-23 17:47:01

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH 1/2][next] scsi: lpfc: Replace one-element array with flexible-array member

On Mon, May 22, 2023 at 06:02:21PM -0400, Martin K. Petersen wrote:
>
> Gustavo,
>
> > One-element arrays are deprecated, and we are replacing them with flexible
> > array members instead. So, replace one-element arrays with flexible-array
> > members in a couple of structures, and refactor the rest of the code,
> > accordingly.
> >
> > 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].
> >
> > This results in no differences in binary output.
>
> Applied to 6.5/scsi-staging, thanks!

Martin, I think this patch is not right -- can you drop this from
staging for the moment?

--
Kees Cook

2023-05-23 20:17:29

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH 1/2][next] scsi: lpfc: Replace one-element array with flexible-array member



On 5/23/23 11:31, Kees Cook wrote:
> On Mon, May 22, 2023 at 06:02:21PM -0400, Martin K. Petersen wrote:
>>
>> Gustavo,
>>
>>> One-element arrays are deprecated, and we are replacing them with flexible
>>> array members instead. So, replace one-element arrays with flexible-array
>>> members in a couple of structures, and refactor the rest of the code,
>>> accordingly.
>>>
>>> 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].
>>>
>>> This results in no differences in binary output.
>>
>> Applied to 6.5/scsi-staging, thanks!
>
> Martin, I think this patch is not right -- can you drop this from
> staging for the moment?

Martin just took patch 1/2, which is correct:

https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/commit/?h=6.5/scsi-staging&id=e90644b0ce2d700a65579ac74ff594414e8ba30f

--
Gustavo

2023-05-23 20:55:46

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH 1/2][next] scsi: lpfc: Replace one-element array with flexible-array member

On May 23, 2023 12:46:54 PM PDT, "Gustavo A. R. Silva" <[email protected]> wrote:
>
>
>On 5/23/23 11:31, Kees Cook wrote:
>> On Mon, May 22, 2023 at 06:02:21PM -0400, Martin K. Petersen wrote:
>>>
>>> Gustavo,
>>>
>>>> One-element arrays are deprecated, and we are replacing them with flexible
>>>> array members instead. So, replace one-element arrays with flexible-array
>>>> members in a couple of structures, and refactor the rest of the code,
>>>> accordingly.
>>>>
>>>> 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].
>>>>
>>>> This results in no differences in binary output.
>>>
>>> Applied to 6.5/scsi-staging, thanks!
>>
>> Martin, I think this patch is not right -- can you drop this from
>> staging for the moment?
>
>Martin just took patch 1/2, which is correct:
>
>https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/commit/?h=6.5/scsi-staging&id=e90644b0ce2d700a65579ac74ff594414e8ba30f

Oops, yes, I thought both got pulled. 1/2 is fine. :)

-Kees


--
Kees Cook