linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] restrict buffer size to 254 in scsi_id
@ 2004-07-19  9:32 Hannes Reinecke
  2004-07-30 16:48 ` Patrick Mansfield
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Reinecke @ 2004-07-19  9:32 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

Hi all,

this patch restricts the max buffer size to 254 in scsi_id. According to 
our SCSI-god-in-residence this is needed as some Wide-SCSI device might 
behave nasty if asked for odd lengths.
We had a rather lengthy bugzilla for it and even Patrick agreed that 
this is a good thing.
Patrick, is this correct? If so, could you also apply it for the scsi_id 
program?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke			hare@suse.de
SuSE Linux AG				S390 & zSeries
Maxfeldstraße 5				+49 911 74053 688
90409 Nürnberg				http://www.suse.de

[-- Attachment #2: udev-021-maxlen.patch --]
[-- Type: text/x-patch, Size: 2732 bytes --]

We have to restrict the maximum length to less than 0xff. However,
according to Kurt Garloff:

Also, you probably send a 6 byte command, max alloc length would be 255, 
and we'd better round that down to 254 then. (Uneven counts on wide SCSI 
busses are a bit nasty and tend to trigger bugs in the LLDs w.r.t. handling 
of the IGNORE_RESIDUAL msg.) 

So we'll be using 254 throughout.

Index: udev-021/extras/scsi_id/scsi_serial.c
===================================================================
--- udev-021.orig/extras/scsi_id/scsi_serial.c	2004-03-03 01:01:32.000000000 +0100
+++ udev-021/extras/scsi_id/scsi_serial.c	2004-06-24 17:03:16.000000000 +0200
@@ -303,7 +303,7 @@ static int scsi_inquiry(struct sysfs_dev
 	unsigned char *buffer;
 	int retry = 3; /* rather random */
 
-	if (buflen > 255) {
+	if (buflen > 254) {
 		log_message(LOG_WARNING, "buflen %d too long\n", buflen);
 		return -1;
 	}
@@ -356,6 +356,7 @@ resend:
 	return retval;
 }
 
+/* Get list of supported EVPD pages */
 static int do_scsi_page0_inquiry(struct sysfs_device *scsi_dev, int fd,
 				 char *buffer, int len)
 {
@@ -544,6 +561,7 @@ static int check_fill_0x83_id(struct sys
 	return 0;
 }
 
+/* Get device identification VPD page */
 static int do_scsi_page83_inquiry(struct sysfs_device *scsi_dev, int fd,
 				  char *serial, int len)
 {
@@ -552,7 +570,7 @@ static int do_scsi_page83_inquiry(struct
 	unsigned char page_83[256];
 
 	memset(page_83, 0, 256);
-	retval = scsi_inquiry(scsi_dev, fd, 1, 0x83, page_83, 255);
+	retval = scsi_inquiry(scsi_dev, fd, 1, 0x83, page_83, 254);
 	if (retval < 0)
 		return 1;
 
@@ -601,6 +619,7 @@ static int do_scsi_page83_inquiry(struct
 	return 1;
 }
 
+/* Get unit serial number VPD page */
 static int do_scsi_page80_inquiry(struct sysfs_device *scsi_dev, int fd,
 				  char *serial, int max_len)
 {
@@ -611,7 +630,7 @@ static int do_scsi_page80_inquiry(struct
 	unsigned char buf[256];
 
 	memset(buf, 0, 256);
-	retval = scsi_inquiry(scsi_dev, fd, 1, 0x80, buf, 255);
+	retval = scsi_inquiry(scsi_dev, fd, 1, 0x80, buf, 254);
 	if (retval < 0)
 		return retval;
 
@@ -649,7 +668,8 @@ int scsi_get_serial (struct sysfs_device
 	int ind;
 	int retval;
 
-	if (len > 255) {
+	if (len > 254) {
+		len = 254;
 	}
 	memset(serial, 0, len);
 	dprintf("opening %s\n", devname);
@@ -686,7 +706,7 @@ int scsi_get_serial (struct sysfs_device
 	 * Get page 0, the page of the pages. By default, try from best to
 	 * worst of supported pages: 0x83 then 0x80.
 	 */
-	if (do_scsi_page0_inquiry(scsi_dev, fd, page0, 255)) {
+	if (do_scsi_page0_inquiry(scsi_dev, fd, page0, 254)) {
 		/*
 		 * Don't try anything else. Black list if a specific page
 		 * should be used for this vendor+model, or maybe have an

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

* Re: [PATCH] restrict buffer size to 254 in scsi_id
  2004-07-19  9:32 [PATCH] restrict buffer size to 254 in scsi_id Hannes Reinecke
@ 2004-07-30 16:48 ` Patrick Mansfield
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Mansfield @ 2004-07-30 16:48 UTC (permalink / raw)
  To: linux-hotplug

On Mon, Jul 19, 2004 at 11:32:00AM +0200, Hannes Reinecke wrote:
> Hi all,
> 
> this patch restricts the max buffer size to 254 in scsi_id. According to 
> our SCSI-god-in-residence this is needed as some Wide-SCSI device might 
> behave nasty if asked for odd lengths.
> We had a rather lengthy bugzilla for it and even Patrick agreed that 
> this is a good thing.
> Patrick, is this correct? If so, could you also apply it for the scsi_id 
> program?

Hannes -

Looks good, thanks.

I applied, only change was to remove what had been a dumb no-op if check in
scsi_get_serial, since the passed in buffer size can never be too large,
just too small. 

There are some buffer sizes that should change to match the 254 (should
have just been a define), I'll change those.

-- Patrick Mansfield


-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

end of thread, other threads:[~2004-07-30 16:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-19  9:32 [PATCH] restrict buffer size to 254 in scsi_id Hannes Reinecke
2004-07-30 16:48 ` Patrick Mansfield

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).