Skip to content

Commit 2dc127b

Browse files
Dan CarpenterJames Bottomley
authored andcommitted
hpsa: fix an sprintf() overflow in the reset handler
The string "cmd %d RESET FAILED, new lockup detected" is not quite large enough so the sprintf() will overflow. I have increased the size of the buffer and also changed the sprintf calls to snprintf. Fixes: 73153fe ('hpsa: use block layer tag for command allocation') Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Don Brace <don.brace@pmcs.com> Signed-off-by: James Bottomley <JBottomley@Odin.com>
1 parent 9c8108a commit 2dc127b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/scsi/hpsa.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,7 +5104,7 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
51045104
int rc;
51055105
struct ctlr_info *h;
51065106
struct hpsa_scsi_dev_t *dev;
5107-
char msg[40];
5107+
char msg[48];
51085108

51095109
/* find the controller to which the command to be aborted was sent */
51105110
h = sdev_to_hba(scsicmd->device);
@@ -5122,16 +5122,18 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
51225122

51235123
/* if controller locked up, we can guarantee command won't complete */
51245124
if (lockup_detected(h)) {
5125-
sprintf(msg, "cmd %d RESET FAILED, lockup detected",
5126-
hpsa_get_cmd_index(scsicmd));
5125+
snprintf(msg, sizeof(msg),
5126+
"cmd %d RESET FAILED, lockup detected",
5127+
hpsa_get_cmd_index(scsicmd));
51275128
hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
51285129
return FAILED;
51295130
}
51305131

51315132
/* this reset request might be the result of a lockup; check */
51325133
if (detect_controller_lockup(h)) {
5133-
sprintf(msg, "cmd %d RESET FAILED, new lockup detected",
5134-
hpsa_get_cmd_index(scsicmd));
5134+
snprintf(msg, sizeof(msg),
5135+
"cmd %d RESET FAILED, new lockup detected",
5136+
hpsa_get_cmd_index(scsicmd));
51355137
hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
51365138
return FAILED;
51375139
}
@@ -5145,7 +5147,8 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
51455147
/* send a reset to the SCSI LUN which the command was sent to */
51465148
rc = hpsa_do_reset(h, dev, dev->scsi3addr, HPSA_RESET_TYPE_LUN,
51475149
DEFAULT_REPLY_QUEUE);
5148-
sprintf(msg, "reset %s", rc == 0 ? "completed successfully" : "failed");
5150+
snprintf(msg, sizeof(msg), "reset %s",
5151+
rc == 0 ? "completed successfully" : "failed");
51495152
hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
51505153
return rc == 0 ? SUCCESS : FAILED;
51515154
}

0 commit comments

Comments
 (0)