]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
scsi: megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access
authorShivasharan S <shivasharan.srikanteshwara@broadcom.com>
Fri, 10 Feb 2017 08:59:19 +0000 (00:59 -0800)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 1 Jun 2017 21:06:04 +0000 (14:06 -0700)
Orabug: 26096381

Change MR_TargetIdToLdGet return type from u8 to u16.

ld id range check is added at two places in this patch -
@megasas_build_ldio_fusion and @megasas_build_ld_nonrw_fusion.  Previous
driver code used different data type for lds TargetId returned from
MR_TargetIdToLdGet.  Prior to this change, above two functions was
safeguarded due to function always return u8 and maximum value of ld id
returned was 255.

In below check, fw_supported_vd_count as of today is 64 or 256 and valid
range to support is either 0-63 or 0-255. Ideally want to filter
accessing raid map for ld ids which are not valid. With the u16 change,
invalid ld id value is 0xFFFF and we will see kernel panic due to random
memory access in MR_LdRaidGet.  The changes will ensure we do not call
MR_LdRaidGet if ld id is beyond size of ldSpanMap array.

               if (ld < instance->fw_supported_vd_count)

>From firmware perspective,ld id 0xFF is invalid and even though current
driver code forward such command, firmware fails with target not
available.

ld target id issue occurs mainly whenever driver loops to populate raid
map (ea. MR_ValidateMapInfo).  These are the only two places where we
may see out of range target ids and wants to protect raid map access
based on range provided by Firmware API.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit d2d0358bcd09139a8e71afbca35bcd6b219dd1bf)
Signed-off-by: Somasundaram Krishnasamy <somasundaram.krishnasamy@oracle.com>
Signed-off-by: Kirtikar Kashyap <kirtikar.kashyap@oracle.com>
Reviewed-by: Dhaval Giani <dhaval.giani@oracle.com>
drivers/scsi/megaraid/megaraid_sas.h
drivers/scsi/megaraid/megaraid_sas_fp.c
drivers/scsi/megaraid/megaraid_sas_fusion.c

index 899a5beef9379e37275a3f7e46ce24d2346bbc77..ca56425d89fdc5cb850c1628ac43a2ca3bbae216 100644 (file)
@@ -2422,7 +2422,7 @@ MR_BuildRaidContext(struct megasas_instance *instance,
                    struct IO_REQUEST_INFO *io_info,
                    struct RAID_CONTEXT *pRAID_Context,
                    struct MR_DRV_RAID_MAP_ALL *map, u8 **raidLUN);
-u8 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map);
+u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map);
 struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_DRV_RAID_MAP_ALL *map);
 u16 MR_ArPdGet(u32 ar, u32 arm, struct MR_DRV_RAID_MAP_ALL *map);
 u16 MR_LdSpanArrayGet(u32 ld, u32 span, struct MR_DRV_RAID_MAP_ALL *map);
index b16ca88fdf643cb8f35404007ef2981b4e055f2b..cc4e1867c190ba26f805af82e636f171bff40981 100644 (file)
@@ -160,7 +160,7 @@ u16 MR_GetLDTgtId(u32 ld, struct MR_DRV_RAID_MAP_ALL *map)
        return le16_to_cpu(map->raidMap.ldSpanMap[ld].ldRaid.targetId);
 }
 
-u8 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map)
+u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map)
 {
        return map->raidMap.ldTgtIdToLd[ldTgtId];
 }
@@ -1134,7 +1134,7 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 {
        struct fusion_context *fusion;
        struct MR_LD_RAID  *raid;
-       u32         ld, stripSize, stripe_mask;
+       u32         stripSize, stripe_mask;
        u64         endLba, endStrip, endRow, start_row, start_strip;
        u64         regStart;
        u32         regSize;
@@ -1146,6 +1146,7 @@ MR_BuildRaidContext(struct megasas_instance *instance,
        u8          retval = 0;
        u8          startlba_span = SPAN_INVALID;
        u64 *pdBlock = &io_info->pdBlock;
+       u16         ld;
 
        ldStartBlock = io_info->ldStartBlock;
        numBlocks = io_info->numBlocks;
index c665d2b4e242c6e442efc1b301416c3c68c2ddc0..4b66280751477815c706202e7cb8a5fbbddeac6e 100644 (file)
@@ -1119,7 +1119,8 @@ megasas_sync_map_info(struct megasas_instance *instance)
        int i;
        struct megasas_cmd *cmd;
        struct megasas_dcmd_frame *dcmd;
-       u32 size_sync_info, num_lds;
+       u16 num_lds;
+       u32 size_sync_info;
        struct fusion_context *fusion;
        struct MR_LD_TARGET_SYNC *ci = NULL;
        struct MR_DRV_RAID_MAP_ALL *map;
@@ -1597,7 +1598,7 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
                   struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
 {
        struct MR_LD_RAID *raid;
-       u32 ld;
+       u16 ld;
        u64 start_blk = io_info->pdBlock;
        u8 *cdb = io_request->CDB.CDB32;
        u32 num_blocks = io_info->numBlocks;
@@ -2030,10 +2031,11 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 
        local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
        ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
-       raid = MR_LdRaidGet(ld, local_map_ptr);
 
-       if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
-               instance->fw_supported_vd_count) || (!fusion->fast_path_io)) {
+       if (ld < instance->fw_supported_vd_count)
+               raid = MR_LdRaidGet(ld, local_map_ptr);
+
+       if (!raid || (!fusion->fast_path_io)) {
                io_request->RaidContext.raid_context.reg_lock_flags  = 0;
                fp_possible = false;
        } else {
@@ -2204,12 +2206,12 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
 {
        u32 device_id;
        struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
-       u16 pd_index = 0;
+       u16 pd_index = 0, ld;
        struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
        struct fusion_context *fusion = instance->ctrl_context;
        u8                          span, physArm;
        __le16                      devHandle;
-       u32                         ld, arRef, pd;
+       u32                         arRef, pd;
        struct MR_LD_RAID                  *raid;
        struct RAID_CONTEXT                *pRAID_Context;
        u8 fp_possible = 1;
@@ -2232,10 +2234,11 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
                ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
                if (ld >= instance->fw_supported_vd_count)
                        fp_possible = 0;
-
-               raid = MR_LdRaidGet(ld, local_map_ptr);
-               if (!(raid->capability.fpNonRWCapable))
-                       fp_possible = 0;
+               else {
+                       raid = MR_LdRaidGet(ld, local_map_ptr);
+                       if (!(raid->capability.fpNonRWCapable))
+                               fp_possible = 0;
+               }
        } else
                fp_possible = 0;