scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_FW_RAI...
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 15 Aug 2022 21:40:35 +0000 (16:40 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 1 Sep 2022 03:39:59 +0000 (23:39 -0400)
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 MR_DRV_RAID_MAP and refactor the the rest of the code
accordingly.

This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines
on memcpy().

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/109
Link: https://lore.kernel.org/r/4495ce170c8ef088a10f1abe0e7c227368f43242.1660592640.git.gustavoars@kernel.org
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Enhanced-by: Kees Cook <keescook@chromium.org> # Change in struct MR_FW_RAID_MAP_ALL
drivers/scsi/megaraid/megaraid_sas_base.c
drivers/scsi/megaraid/megaraid_sas_fp.c
drivers/scsi/megaraid/megaraid_sas_fusion.h

index c9b01b155f658b14bfb04aa02f93bb040fc21ac5..43b97376f4e13f8b8ab3c38019c0e7fbb6e9e4e6 100644 (file)
@@ -5157,7 +5157,7 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance)
        } else {
                fusion->old_map_sz =  sizeof(struct MR_FW_RAID_MAP) +
                                        (sizeof(struct MR_LD_SPAN_MAP) *
-                                       (instance->fw_supported_vd_count - 1));
+                                       instance->fw_supported_vd_count);
                fusion->new_map_sz =  sizeof(struct MR_FW_RAID_MAP_EXT);
 
                fusion->max_map_sz =
index 83f69c33b01a97ff71cb9d005799a56739c7d3db..b2ec7a3f7650d77de7f8a7229951c8ea6fef3f7b 100644 (file)
@@ -327,7 +327,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id)
                expected_size = sizeof(struct MR_FW_RAID_MAP_EXT);
        else
                expected_size =
-                       (sizeof(struct MR_FW_RAID_MAP) - sizeof(struct MR_LD_SPAN_MAP) +
+                       (sizeof(struct MR_FW_RAID_MAP) +
                        (sizeof(struct MR_LD_SPAN_MAP) * le16_to_cpu(pDrvRaidMap->ldCount)));
 
        if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) {
index ce84f811e5e10b0bb312b8d94ad6008f9fc97a9f..5530c233fccbb77b527670faa69cc5113b94438e 100644 (file)
@@ -942,7 +942,7 @@ struct MR_FW_RAID_MAP {
        u8                  reserved2[7];
        struct MR_ARRAY_INFO       arMapInfo[MAX_RAIDMAP_ARRAYS];
        struct MR_DEV_HANDLE_INFO  devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
-       struct MR_LD_SPAN_MAP      ldSpanMap[1];
+       struct MR_LD_SPAN_MAP      ldSpanMap[];
 };
 
 struct IO_REQUEST_INFO {
@@ -1148,7 +1148,7 @@ typedef struct LOG_BLOCK_SPAN_INFO {
 
 struct MR_FW_RAID_MAP_ALL {
        struct MR_FW_RAID_MAP raidMap;
-       struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES - 1];
+       struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES];
 } __attribute__ ((packed));
 
 struct MR_DRV_RAID_MAP {