Skip to content

Commit

Permalink
hpsa: fix an sprintf() overflow in the reset handler
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Don Brace <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
  • Loading branch information
Dan Carpenter authored and James Bottomley committed Jul 30, 2015
1 parent 9c8108a commit 2dc127b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions drivers/scsi/hpsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -5104,7 +5104,7 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
int rc;
struct ctlr_info *h;
struct hpsa_scsi_dev_t *dev;
char msg[40];
char msg[48];

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

/* if controller locked up, we can guarantee command won't complete */
if (lockup_detected(h)) {
sprintf(msg, "cmd %d RESET FAILED, lockup detected",
hpsa_get_cmd_index(scsicmd));
snprintf(msg, sizeof(msg),
"cmd %d RESET FAILED, lockup detected",
hpsa_get_cmd_index(scsicmd));
hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
return FAILED;
}

/* this reset request might be the result of a lockup; check */
if (detect_controller_lockup(h)) {
sprintf(msg, "cmd %d RESET FAILED, new lockup detected",
hpsa_get_cmd_index(scsicmd));
snprintf(msg, sizeof(msg),
"cmd %d RESET FAILED, new lockup detected",
hpsa_get_cmd_index(scsicmd));
hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
return FAILED;
}
Expand All @@ -5145,7 +5147,8 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
/* send a reset to the SCSI LUN which the command was sent to */
rc = hpsa_do_reset(h, dev, dev->scsi3addr, HPSA_RESET_TYPE_LUN,
DEFAULT_REPLY_QUEUE);
sprintf(msg, "reset %s", rc == 0 ? "completed successfully" : "failed");
snprintf(msg, sizeof(msg), "reset %s",
rc == 0 ? "completed successfully" : "failed");
hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
return rc == 0 ? SUCCESS : FAILED;
}
Expand Down

0 comments on commit 2dc127b

Please sign in to comment.