linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hpsa: fix a couple of minor bugs
@ 2011-06-03 14:57 Stephen M. Cameron
  2011-06-03 14:57 ` [PATCH 1/2] hpsa: fix dma unmap error in hpsa_passthru_ioctl Stephen M. Cameron
  2011-06-03 14:57 ` [PATCH 2/2] hpsa: fix potential overrun while memcpy'ing sense data Stephen M. Cameron
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen M. Cameron @ 2011-06-03 14:57 UTC (permalink / raw)
  To: james.bottomley; +Cc: linux-scsi, linux-kernel, smcameron, thenzl, akpm, mikem

The following series fixes a couple of minor bugs in the hpsa driver. 

---

Stephen M. Cameron (2):
      hpsa: fix dma unmap error in hpsa_passthru_ioctl
      hpsa: fix potential overrun while memcpy'ing sense data

-- 
-- steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] hpsa: fix dma unmap error in hpsa_passthru_ioctl
  2011-06-03 14:57 [PATCH 0/2] hpsa: fix a couple of minor bugs Stephen M. Cameron
@ 2011-06-03 14:57 ` Stephen M. Cameron
  2011-06-03 14:57 ` [PATCH 2/2] hpsa: fix potential overrun while memcpy'ing sense data Stephen M. Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen M. Cameron @ 2011-06-03 14:57 UTC (permalink / raw)
  To: james.bottomley; +Cc: linux-scsi, linux-kernel, smcameron, thenzl, akpm, mikem

From: Stephen M. Cameron <scameron@beardog.cce.hp.com>

Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
---
 drivers/scsi/hpsa.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index c6c0434..a75122d 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -2580,7 +2580,8 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
 		c->SG[0].Ext = 0; /* we are not chaining*/
 	}
 	hpsa_scsi_do_simple_cmd_core(h, c);
-	hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL);
+	if (iocommand.buf_size > 0)
+		hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL);
 	check_ioctl_unit_attention(h, c);
 
 	/* Copy the error information out */


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] hpsa: fix potential overrun while memcpy'ing sense data
  2011-06-03 14:57 [PATCH 0/2] hpsa: fix a couple of minor bugs Stephen M. Cameron
  2011-06-03 14:57 ` [PATCH 1/2] hpsa: fix dma unmap error in hpsa_passthru_ioctl Stephen M. Cameron
@ 2011-06-03 14:57 ` Stephen M. Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen M. Cameron @ 2011-06-03 14:57 UTC (permalink / raw)
  To: james.bottomley; +Cc: linux-scsi, linux-kernel, smcameron, thenzl, akpm, mikem

From: Stephen M. Cameron <scameron@beardog.cce.hp.com>

This memcpy:

   memcpy(cmd->sense_buffer, ei->SenseInfo,
	   ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
		   SCSI_SENSE_BUFFERSIZE :
		   ei->SenseLen);

The ei->SenseLen field is filled in by the Smart Array.  For requests to
logical drives, it will not exceed 32 bytes, so should be ok, but for physical
requests it depends on the target device, not the Smart Array.  It's conceivable
that this could exceed the 32 byte size of ei->SenseInfo.  In that case, the memcpy
would read past the end of ei->SenseInfo, copying data from the next command,
as if it were sense data, or, if it happened to be the very last command in the
block of allocated commands, could fall off the end of the allocated area and
crash.  I'm not aware of anyone ever encountering this behavior, but it could
conceivably happen.  This bug was found by Coverity.

Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
---
 drivers/scsi/hpsa.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a75122d..6bba23a 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -1037,6 +1037,7 @@ static void complete_scsi_command(struct CommandList *cp)
 	unsigned char sense_key;
 	unsigned char asc;      /* additional sense code */
 	unsigned char ascq;     /* additional sense code qualifier */
+	unsigned long sense_data_size;
 
 	ei = cp->err_info;
 	cmd = (struct scsi_cmnd *) cp->scsi_cmd;
@@ -1051,10 +1052,14 @@ static void complete_scsi_command(struct CommandList *cp)
 	cmd->result |= ei->ScsiStatus;
 
 	/* copy the sense data whether we need to or not. */
-	memcpy(cmd->sense_buffer, ei->SenseInfo,
-		ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
-			SCSI_SENSE_BUFFERSIZE :
-			ei->SenseLen);
+	if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo))
+		sense_data_size = SCSI_SENSE_BUFFERSIZE;
+	else
+		sense_data_size = sizeof(ei->SenseInfo);
+	if (ei->SenseLen < sense_data_size)
+		sense_data_size = ei->SenseLen;
+
+	memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size);
 	scsi_set_resid(cmd, ei->ResidualCnt);
 
 	if (ei->CommandStatus == 0) {


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-03 14:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03 14:57 [PATCH 0/2] hpsa: fix a couple of minor bugs Stephen M. Cameron
2011-06-03 14:57 ` [PATCH 1/2] hpsa: fix dma unmap error in hpsa_passthru_ioctl Stephen M. Cameron
2011-06-03 14:57 ` [PATCH 2/2] hpsa: fix potential overrun while memcpy'ing sense data Stephen M. Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).