Skip to contentSkip to conversation

hptiop: avoid buffer overflow when returning sense data

PATCH In review [email protected] 1 participant 1 message Oct 16, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 7/7 hptiop: avoid buffer overflow when returning sense data

From: HighPoint Linux Team <[email protected]>

avoid buffer overflow when returning sense data.

With current adapter firmware the driver is working but future firmware updates may return sense data larger than 96 bytes, causing overflow on scp->sense_buffer and a kernel crash.

This fix should be backported to earlier kernels.

---

 drivers/scsi/hptiop.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/hptiop.c renamed from drivers/scsi/hptiop.c~hptiop-avoid-buffer-overflow-when-returning-sense-data +3 -2
diff -puN drivers/scsi/hptiop.c~hptiop-avoid-buffer-overflow-when-returning-sense-data drivers/scsi/hptiop.c
@@ -375,8 +375,9 @@ static void hptiop_host_request_callback
 		scp->result = SAM_STAT_CHECK_CONDITION;
 		memset(&scp->sense_buffer,
 				0, sizeof(scp->sense_buffer));
-		memcpy(&scp->sense_buffer,
-			&req->sg_list, le32_to_cpu(req->dataxfer_length));
+		memcpy(&scp->sense_buffer, &req->sg_list,
+				min(sizeof(scp->sense_buffer),
+					le32_to_cpu(req->dataxfer_length)));
 		break;
 
 	default:

_