Commit 7ada701d authored by Shivasharan S's avatar Shivasharan S Committed by Martin K. Petersen

scsi: megaraid_sas: Error handling for invalid ldcount provided by firmware in RAID map

Currently driver does not validate ldcount provided by firmware.  If the
value is invalid, fail RAID map validation accordingly.  This issue is
rare to hit in field and is fixed as part of code review.
Signed-off-by: default avatarSumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: default avatarShivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 41fae9a4
...@@ -168,7 +168,7 @@ static struct MR_LD_SPAN *MR_LdSpanPtrGet(u32 ld, u32 span, ...@@ -168,7 +168,7 @@ static struct MR_LD_SPAN *MR_LdSpanPtrGet(u32 ld, u32 span,
/* /*
* This function will Populate Driver Map using firmware raid map * This function will Populate Driver Map using firmware raid map
*/ */
void MR_PopulateDrvRaidMap(struct megasas_instance *instance) static int MR_PopulateDrvRaidMap(struct megasas_instance *instance)
{ {
struct fusion_context *fusion = instance->ctrl_context; struct fusion_context *fusion = instance->ctrl_context;
struct MR_FW_RAID_MAP_ALL *fw_map_old = NULL; struct MR_FW_RAID_MAP_ALL *fw_map_old = NULL;
...@@ -259,7 +259,7 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance) ...@@ -259,7 +259,7 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
ld_count = (u16)le16_to_cpu(fw_map_ext->ldCount); ld_count = (u16)le16_to_cpu(fw_map_ext->ldCount);
if (ld_count > MAX_LOGICAL_DRIVES_EXT) { if (ld_count > MAX_LOGICAL_DRIVES_EXT) {
dev_dbg(&instance->pdev->dev, "megaraid_sas: LD count exposed in RAID map in not valid\n"); dev_dbg(&instance->pdev->dev, "megaraid_sas: LD count exposed in RAID map in not valid\n");
return; return 1;
} }
pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count); pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
...@@ -285,6 +285,12 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance) ...@@ -285,6 +285,12 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
fusion->ld_map[(instance->map_id & 1)]; fusion->ld_map[(instance->map_id & 1)];
pFwRaidMap = &fw_map_old->raidMap; pFwRaidMap = &fw_map_old->raidMap;
ld_count = (u16)le32_to_cpu(pFwRaidMap->ldCount); ld_count = (u16)le32_to_cpu(pFwRaidMap->ldCount);
if (ld_count > MAX_LOGICAL_DRIVES) {
dev_dbg(&instance->pdev->dev,
"LD count exposed in RAID map in not valid\n");
return 1;
}
pDrvRaidMap->totalSize = pFwRaidMap->totalSize; pDrvRaidMap->totalSize = pFwRaidMap->totalSize;
pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count); pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec; pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec;
...@@ -300,6 +306,8 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance) ...@@ -300,6 +306,8 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
sizeof(struct MR_DEV_HANDLE_INFO) * sizeof(struct MR_DEV_HANDLE_INFO) *
MAX_RAIDMAP_PHYSICAL_DEVICES); MAX_RAIDMAP_PHYSICAL_DEVICES);
} }
return 0;
} }
/* /*
...@@ -317,8 +325,8 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance) ...@@ -317,8 +325,8 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
u16 ld; u16 ld;
u32 expected_size; u32 expected_size;
if (MR_PopulateDrvRaidMap(instance))
MR_PopulateDrvRaidMap(instance); return 0;
fusion = instance->ctrl_context; fusion = instance->ctrl_context;
drv_map = fusion->ld_drv_map[(instance->map_id & 1)]; drv_map = fusion->ld_drv_map[(instance->map_id & 1)];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment