scsi: megaraid_sas: struct MR_HOST_DEVICE_LIST: Replace 1-element array with flexible array
Subsystems (2)
PATCH 1/1 scsi: megaraid_sas: struct MR_HOST_DEVICE_LIST: Replace 1-element array with flexible array
Replace the deprecated[1] use of a 1-element array in struct MR_HOST_DEVICE_LIST with a modern flexible array.
One binary difference appears in megasas_host_device_list_query():
struct MR_HOST_DEVICE_LIST *ci;
...
ci = instance->host_device_list_buf;
...
memset(ci, 0, sizeof(*ci));The memset() clears only the non-flexible array fields. Looking at the rest of the function, this appears to be fine: firmware is using this region to communicate with the kernel, so it likely never made sense to clear the first MR_HOST_DEVICE_LIST_ENTRY.
---
Cc: Kashyap Desai <[email protected]>
Cc: Sumit Saxena <[email protected]>
Cc: Shivasharan S <[email protected]>
Cc: Chandrakanth patil <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- drivers/scsi/megaraid/megaraid_sas.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/megaraid/megaraid_sas.h +2 -2
@@ -814,12 +814,12 @@ struct MR_HOST_DEVICE_LIST {__le32 size;__le32 count;__le32 reserved[2 ]; -struct MR_HOST_DEVICE_LIST_ENTRY host_device_list[1 ]; + struct MR_HOST_DEVICE_LIST_ENTRY host_device_list[] __counted_by_le(count); } __packed;#define HOST_DEVICE_LIST_SZ (sizeof(struct MR_HOST_DEVICE_LIST) + \ (sizeof(struct MR_HOST_DEVICE_LIST_ENTRY) * \ - (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT - 1))) + (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT)))/*
Signature · 1 line
2.34.1
Quoted 11 lines · Kees Cook
Replace the deprecated[1] use of a 1-element array in struct
MR_HOST_DEVICE_LISTwith a modern flexible array.One binary difference appears in
megasas_host_device_list_query():struct MR_HOST_DEVICE_LIST *ci; ... ci = instance->host_device_list_buf; ... memset(ci, 0, sizeof(*ci));
Quoted 4 lines
The
memset()clears only the non-flexible array fields. Looking at the rest of the function, this appears to be fine: firmware is using this region to communicate with the kernel, so it likely never made sense to clear the firstMR_HOST_DEVICE_LIST_ENTRY.
Yeah, clearing that fist entry seems odd/buggy. So, this patch is probably even fixing a bug. :)
Quoted 3 lines
Signed-off-by Kees Cook <[email protected]>
Thanks
Signature · 1 line
Gustavo
Quoted 32 lines
---
Cc: Kashyap Desai <[email protected]>
Cc: Sumit Saxena <[email protected]>
Cc: Shivasharan S <[email protected]>
Cc: Chandrakanth patil <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/scsi/megaraid/megaraid_sas.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/scsi/megaraid/megaraid_sas.h +2
-2@@ -814,12 +814,12 @@ struct MR_HOST_DEVICE_LIST {__le32 size;__le32 count;__le32 reserved[2 ]; -struct MR_HOST_DEVICE_LIST_ENTRY host_device_list[1 ]; + struct MR_HOST_DEVICE_LIST_ENTRY host_device_list[] __counted_by_le(count); } __packed;#define HOST_DEVICE_LIST_SZ (sizeof(struct MR_HOST_DEVICE_LIST) + \ (sizeof(struct MR_HOST_DEVICE_LIST_ENTRY) * \ - (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT - 1))) + (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT)))/*
James Bottomley
maintainerQuoted 11 lines · Kees Cook
Replace the deprecated[1] use of a 1-element array in struct
MR_HOST_DEVICE_LISTwith a modern flexible array.One binary difference appears in
megasas_host_device_list_query():struct
MR_HOST_DEVICE_LIST*ci;
...
ci =instance->host_device_list_buf;
...
memset(ci, 0, sizeof(*ci));
Quoted 4 lines
The
memset()clears only the non-flexible array fields. Looking at the rest of the function, this appears to be fine: firmware is using this region to communicate with the kernel, so it likely never made sense to clear the firstMR_HOST_DEVICE_LIST_ENTRY.
That's not necessarily a safe assumption: older qlogic for instance uses zeroing an entry to stop the card mailbox processing. Looking at the driver, I think you're right: it's only used for card to host communication, so clearing it is irrelevant, but it could be relevant if it were also used for host to card communication.
Regards,
James
Martin K. Petersen
AppliedKees,
Quoted 2 lines
Replace the deprecated[1] use of a 1-element array in struct
MR_HOST_DEVICE_LISTwith a modern flexible array.
Applied to 6.12/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering