Skip to content

Commit bb7c543

Browse files
bjking1James Bottomley
authored andcommitted
ipr: Fix incorrect trace indexing
When ipr's internal driver trace was changed to an atomic, a signed/unsigned bug slipped in which results in us indexing backwards in our memory buffer writing on memory that does not belong to us. This patch fixes this by removing the modulo and instead just mask off the low bits. Cc: <stable@vger.kernel.org> Tested-by: Wen Xiong <wenxiong@linux.vnet.ibm.com> Reviewed-by: Wen Xiong <wenxiong@linux.vnet.ibm.com> Reviewed-by: Gabriel Krisman Bertazi <krisman@linux.vnet.ibm.com> Signed-off-by: Brian King <brking@linux.vnet.ibm.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: James Bottomley <JBottomley@Odin.com>
1 parent 36b8e18 commit bb7c543

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

drivers/scsi/ipr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,10 @@ static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
599599
{
600600
struct ipr_trace_entry *trace_entry;
601601
struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
602+
unsigned int trace_index;
602603

603-
trace_entry = &ioa_cfg->trace[atomic_add_return
604-
(1, &ioa_cfg->trace_index)%IPR_NUM_TRACE_ENTRIES];
604+
trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
605+
trace_entry = &ioa_cfg->trace[trace_index];
605606
trace_entry->time = jiffies;
606607
trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
607608
trace_entry->type = type;

drivers/scsi/ipr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ struct ipr_ioa_cfg {
14861486

14871487
#define IPR_NUM_TRACE_INDEX_BITS 8
14881488
#define IPR_NUM_TRACE_ENTRIES (1 << IPR_NUM_TRACE_INDEX_BITS)
1489+
#define IPR_TRACE_INDEX_MASK (IPR_NUM_TRACE_ENTRIES - 1)
14891490
#define IPR_TRACE_SIZE (sizeof(struct ipr_trace_entry) * IPR_NUM_TRACE_ENTRIES)
14901491
char trace_start[8];
14911492
#define IPR_TRACE_START_LABEL "trace"

0 commit comments

Comments
 (0)