All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] SCSI core: always store >= 36 bytes of INQUIRY data
@ 2006-10-26 21:11 Alan Stern
  2006-10-27 21:43 ` Patrick Mansfield
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Stern @ 2006-10-26 21:11 UTC (permalink / raw)
  To: James Bottomley; +Cc: SCSI development list

This patch (as810) sets the length of the INQUIRY data to a minimum of
36 bytes, even if the device claims that not all of them are valid.
Using the data sent by the device is better than allocating a short
buffer and then reading beyond the end of it, which is what we do now.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

Index: usb-2.6/drivers/scsi/scsi_scan.c
===================================================================
--- usb-2.6.orig/drivers/scsi/scsi_scan.c
+++ usb-2.6/drivers/scsi/scsi_scan.c
@@ -575,6 +575,19 @@ static int scsi_probe_lun(struct scsi_de
 	 * short INQUIRY), an abort here prevents any further use of the
 	 * device, including spin up.
 	 *
+	 * On the whole, the best approach seems to be to assume the first
+	 * 36 bytes are valid no matter what the device says.  That's
+	 * better than copying < 36 bytes to the inquiry-result buffer
+	 * and displaying garbage for the Vendor, Product, and Revision
+	 * strings.
+	 */
+	if (sdev->inquiry_len < 36) {
+		printk(KERN_INFO "scsi scan: INQUIRY result too short (%d),"
+				" using 36\n", sdev->inquiry_len);
+		sdev->inquiry_len = 36;
+	}
+
+	/*
 	 * Related to the above issue:
 	 *
 	 * XXX Devices (disk or all?) should be sent a TEST UNIT READY,


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] SCSI core: always store >= 36 bytes of INQUIRY data
@ 2006-11-10 16:11 Alan Stern
  0 siblings, 0 replies; 11+ messages in thread
From: Alan Stern @ 2006-11-10 16:11 UTC (permalink / raw)
  To: Andrew Morton; +Cc: James Bottomley, Kernel development list

This patch (as810c) copies a minimum of 36 bytes of INQUIRY data,
even if the device claims that not all of them are valid.  Often badly
behaved devices put plausible data in the Vendor, Product, and Revision
strings but set the Additional Length byte to a small value.  Using
potentially valid data is certainly better than allocating a short
buffer and then reading beyond the end of it, which is what we do now.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

On Thu, 9 Nov 2006, Andrew Morton wrote:

> So Alan, I think Greg is out of town somewhere.  If you have a final patch
> you'd like merged, please send her over.

This is the final version submitted to James Bottomley on Oct. 31.  
Apparently he hasn't applied it yet, and there hasn't been any word back 
on whether he intends to.

Alan Stern


Index: usb-2.6/drivers/scsi/scsi_scan.c
===================================================================
--- usb-2.6.orig/drivers/scsi/scsi_scan.c
+++ usb-2.6/drivers/scsi/scsi_scan.c
@@ -631,12 +631,22 @@ static int scsi_add_lun(struct scsi_devi
 	 * scanning run at their own risk, or supply a user level program
 	 * that can correctly scan.
 	 */
-	sdev->inquiry = kmalloc(sdev->inquiry_len, GFP_ATOMIC);
-	if (sdev->inquiry == NULL) {
+
+	/*
+	 * Copy at least 36 bytes of INQUIRY data, so that we don't
+	 * dereference unallocated memory when accessing the Vendor,
+	 * Product, and Revision strings.  Badly behaved devices may set
+	 * the INQUIRY Additional Length byte to a small value, indicating
+	 * these strings are invalid, but often they contain plausible data
+	 * nonetheless.  It doesn't matter if the device sent < 36 bytes
+	 * total, since scsi_probe_lun() initializes inq_result with 0s.
+	 */
+	sdev->inquiry = kmemdup(inq_result,
+				max_t(size_t, sdev->inquiry_len, 36),
+				GFP_ATOMIC);
+	if (sdev->inquiry == NULL)
 		return SCSI_SCAN_NO_RESPONSE;
-	}
 
-	memcpy(sdev->inquiry, inq_result, sdev->inquiry_len);
 	sdev->vendor = (char *) (sdev->inquiry + 8);
 	sdev->model = (char *) (sdev->inquiry + 16);
 	sdev->rev = (char *) (sdev->inquiry + 32);


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

end of thread, other threads:[~2006-11-10 16:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-26 21:11 [PATCH] SCSI core: always store >= 36 bytes of INQUIRY data Alan Stern
2006-10-27 21:43 ` Patrick Mansfield
2006-10-27 22:10   ` Douglas Gilbert
2006-10-28 15:41     ` Alan Stern
2006-10-30 16:40       ` Douglas Gilbert
2006-10-28 15:33   ` Alan Stern
2006-10-28 18:30     ` Patrick Mansfield
2006-10-30 15:20   ` Alan Stern
2006-10-30 16:32     ` Stefan Richter
2006-10-31 21:26       ` Alan Stern
  -- strict thread matches above, loose matches on Subject: below --
2006-11-10 16:11 Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.