linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] cciss: fix a couple minor bugs
@ 2011-06-03 14:54 Stephen M. Cameron
  2011-06-03 14:54 ` [PATCH 1/2] cciss: Use the correct size when mapping in the config table Stephen M. Cameron
  2011-06-03 14:54 ` [PATCH 2/2] cciss: 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:54 UTC (permalink / raw)
  To: axboe; +Cc: mikem, akpm, thenzl, linux-kernel, smcameron

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

---

Stephen M. Cameron (2):
      cciss: Use the correct size when mapping in the config table
      cciss: fix potential overrun while memcpy'ing sense data

-- 
-- steve

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

* [PATCH 1/2] cciss: Use the correct size when mapping in the config table
  2011-06-03 14:54 [PATCH 0/2] cciss: fix a couple minor bugs Stephen M. Cameron
@ 2011-06-03 14:54 ` Stephen M. Cameron
  2011-06-03 14:54 ` [PATCH 2/2] cciss: 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:54 UTC (permalink / raw)
  To: axboe; +Cc: mikem, akpm, thenzl, linux-kernel, smcameron

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

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

diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 8f4ef65..f7154a8 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -4185,7 +4185,7 @@ static int __devinit cciss_find_cfgtables(ctlr_info_t *h)
 	if (rc)
 		return rc;
 	h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev,
-		cfg_base_addr_index) + cfg_offset, sizeof(h->cfgtable));
+		cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable));
 	if (!h->cfgtable)
 		return -ENOMEM;
 	rc = write_driver_ver_to_cfgtable(h->cfgtable);


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

* [PATCH 2/2] cciss: fix potential overrun while memcpy'ing sense data
  2011-06-03 14:54 [PATCH 0/2] cciss: fix a couple minor bugs Stephen M. Cameron
  2011-06-03 14:54 ` [PATCH 1/2] cciss: Use the correct size when mapping in the config table Stephen M. Cameron
@ 2011-06-03 14:54 ` Stephen M. Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen M. Cameron @ 2011-06-03 14:54 UTC (permalink / raw)
  To: axboe; +Cc: mikem, akpm, thenzl, linux-kernel, smcameron

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/block/cciss_scsi.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 6961002..2405412 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -726,6 +726,7 @@ static void complete_scsi_command(CommandList_struct *c, int timeout,
 	struct scsi_cmnd *cmd;
 	ctlr_info_t *h;
 	ErrorInfo_struct *ei;
+	unsigned long sense_data_size;
 
 	ei = c->err_info;
 
@@ -750,11 +751,14 @@ static void complete_scsi_command(CommandList_struct *c, int timeout,
 	/* printk("Scsistatus is 0x%02x\n", ei->ScsiStatus);  */
 
 	/* copy the sense data whether we need to or not. */
+	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, 
-		ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
-			SCSI_SENSE_BUFFERSIZE : 
-			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:54 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:54 [PATCH 0/2] cciss: fix a couple minor bugs Stephen M. Cameron
2011-06-03 14:54 ` [PATCH 1/2] cciss: Use the correct size when mapping in the config table Stephen M. Cameron
2011-06-03 14:54 ` [PATCH 2/2] cciss: 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).