Skip to contentSkip to conversation

ipr: Fix incorrect trace indexing

PATCH RESEND In review Brian King 2 participants 2 messages Jul 14, 2015 – Jul 17, 2015

Subsystems (3)
lore
Share & tools
lore

Brian King

author
#0 lore raw

PATCH RESEND 2/3 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.

---

 drivers/scsi/ipr.c |    5 +++--
 drivers/scsi/ipr.h |    1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/ipr.h renamed from drivers/scsi/ipr.h~ipr_trace_index_fix +1 -0
diff -puN drivers/scsi/ipr.h~ipr_trace_index_fix drivers/scsi/ipr.h
@@ -1486,6 +1486,7 @@ struct ipr_ioa_cfg {
 
 #define IPR_NUM_TRACE_INDEX_BITS	8
 #define IPR_NUM_TRACE_ENTRIES		(1 << IPR_NUM_TRACE_INDEX_BITS)
+#define IPR_TRACE_INDEX_MASK		(IPR_NUM_TRACE_ENTRIES - 1)
 #define IPR_TRACE_SIZE	(sizeof(struct ipr_trace_entry) * IPR_NUM_TRACE_ENTRIES)
 	char trace_start[8];
 #define IPR_TRACE_START_LABEL			"trace"
drivers/scsi/ipr.c renamed from drivers/scsi/ipr.c~ipr_trace_index_fix +3 -2
diff -puN drivers/scsi/ipr.c~ipr_trace_index_fix drivers/scsi/ipr.c
@@ -599,9 +599,10 @@ static void ipr_trc_hook(struct ipr_cmnd
 {
 	struct ipr_trace_entry *trace_entry;
 	struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
+	unsigned int trace_index;
 
-	trace_entry = &ioa_cfg->trace[atomic_add_return
-			(1, &ioa_cfg->trace_index)%IPR_NUM_TRACE_ENTRIES];
+	trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
+	trace_entry = &ioa_cfg->trace[trace_index];
 	trace_entry->time = jiffies;
 	trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
 	trace_entry->type = type;

_

Reviewed-by on v1 2/3
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Brian" == Brian King <[email protected]> writes:

Brian> When ipr's internal driver trace was changed to an atomic, a Brian> signed/unsigned bug slipped in which results in us indexing Brian> backwards in our memory buffer writing on memory that does not Brian> belong to us. This patch fixes this by removing the modulo and Brian> instead just mask off the low bits.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering