Message ID | 201507141641.t6EGfXmA021616@d01av05.pok.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
>>>>> "Brian" == Brian King <brking@linux.vnet.ibm.com> writes: Brian> Fixes another signed / unsigned array indexing bug in the ipr Brian> driver. Currently, when hrrq_index wraps, it becomes a negative Brian> number. We do the modulo, but still have a negative number, so we Brian> end up indexing backwards in the array. Given where the hrrq Brian> array is located in memory, we probably won't actually reference Brian> memory we don't own, but nonetheless ipr is still looking at data Brian> within struct ipr_ioa_cfg and interpreting it as struct Brian> ipr_hrr_queue data, so bad things could certainly happen. Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
diff -puN drivers/scsi/ipr.c~ipr_hrrq_index_fix drivers/scsi/ipr.c --- linux/drivers/scsi/ipr.c~ipr_hrrq_index_fix 2015-07-14 11:12:59.029505136 -0500 +++ linux-bjking1/drivers/scsi/ipr.c 2015-07-14 11:12:59.036505101 -0500 @@ -1052,10 +1052,15 @@ static void ipr_send_blocking_cmd(struct static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg) { + unsigned int hrrq; + if (ioa_cfg->hrrq_num == 1) - return 0; - else - return (atomic_add_return(1, &ioa_cfg->hrrq_index) % (ioa_cfg->hrrq_num - 1)) + 1; + hrrq = 0; + else { + hrrq = atomic_add_return(1, &ioa_cfg->hrrq_index); + hrrq = (hrrq % (ioa_cfg->hrrq_num - 1)) + 1; + } + return hrrq; } /**