Skip to contentSkip to conversation

scsilun_to_int should ignore the highest 2 bits

PATCH In review Jan Vesely 2 participants 3 messages Jun 6, 2013 SCSI

lore
Share & tools
lore

Jan Vesely

author
#0 lore raw

PATCH 1/1 scsilun_to_int should ignore the highest 2 bits

From: Jan Vesely <[email protected]>

The comment says the function does this but it does not. Reported luns change from weirdly high numbers (like 16640) to something saner (256), when using flat space addressing.

CC James Bottomley <[email protected]>
CC Dan Williams <[email protected]>
---
 drivers/scsi/scsi_scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_scan.c +1 -1
index 3e58b22..38dc093 100644
@@ -1244,7 +1244,7 @@ int scsilun_to_int(struct scsi_lun *scsilun)
 
 	lun = 0;
 	for (i = 0; i < sizeof(lun); i += 2)
-		lun = lun | (((scsilun->scsi_lun[i] << 8) |
+		lun = lun | ((((scsilun->scsi_lun[i] & 0x3f) << 8) |
 			      scsilun->scsi_lun[i + 1]) << (i * 8));
 	return lun;
 }
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 19 lines · Jan Vesely

From: Jan Vesely <[email protected]>

The comment says the function does this but it does not. Reported luns change from weirdly high numbers (like 16640) to something saner (256), when using flat space addressing.

CC James Bottomley <[email protected]>
CC Dan Williams <[email protected]>
---
 drivers/scsi/scsi_scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_scan.c +0 -0
index 3e58b22..38dc093 100644

drivers/scsi/scsi_scan.c int scsilun_to_int(struct scsi_lun *scsilun) · line 1250

Quoted 8 lines
drivers/scsi/scsi_scan.c +1 -1
@@ -1244,7 +1244,7 @@ int scsilun_to_int(struct scsi_lun *scsilun)
 
 	lun = 0;
 	for (i = 0; i < sizeof(lun); i += 2)
-		lun = lun | (((scsilun->scsi_lun[i] << 8) |
+		lun = lun | ((((scsilun->scsi_lun[i] & 0x3f) << 8) |
 			      scsilun->scsi_lun[i + 1]) << (i * 8));
 	return lun;
 }

Bzzt. It's not that simple.

For SCSI-3 _all_ numbers are valid, and doesn't know of any addressing scheme. It's only SPC-2 which introduced the addressing scheme. So at the very least you should be checking the scsi revision before attempting something like this.

But in general doing a sequential scan past 256 is criminally dangerous. Any array / device attempting to is in most cases misconfigured or does not have the correct BLIST flag set.

I know of some older Hitachi and EMC firmware which would pretend to be SCSI-2, but supporting more than 256 LUNs per host. Which, of course, it totally bonkers.

I'll be posting my 64-bit LUN patchset, that should fix this issue.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      zSeries & Storage
[email protected]			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
author
#2 lore raw
Quoted 43 lines · Hannes Reinecke
Quoted 19 lines · Jan Vesely

From: Jan Vesely <[email protected]>

The comment says the function does this but it does not. Reported luns change from weirdly high numbers (like 16640) to something saner (256), when using flat space addressing.

CC James Bottomley <[email protected]>
CC Dan Williams <[email protected]>
---
 drivers/scsi/scsi_scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_scan.c +0 -0
index 3e58b22..38dc093 100644

drivers/scsi/scsi_scan.c int scsilun_to_int(struct scsi_lun *scsilun) · line 1250

Quoted 8 lines
drivers/scsi/scsi_scan.c +1 -1
@@ -1244,7 +1244,7 @@ int scsilun_to_int(struct scsi_lun *scsilun)
 
 	lun = 0;
 	for (i = 0; i < sizeof(lun); i += 2)
-		lun = lun | (((scsilun->scsi_lun[i] << 8) |
+		lun = lun | ((((scsilun->scsi_lun[i] & 0x3f) << 8) |
 			      scsilun->scsi_lun[i + 1]) << (i * 8));
 	return lun;
 }

Bzzt. It's not that simple.

For SCSI-3 _all_ numbers are valid, and doesn't know of any addressing scheme. It's only SPC-2 which introduced the addressing scheme. So at the very least you should be checking the scsi revision before attempting something like this.

But in general doing a sequential scan past 256 is criminally dangerous. Any array / device attempting to is in most cases misconfigured or does not have the correct BLIST flag set.

I know of some older Hitachi and EMC firmware which would pretend to be SCSI-2, but supporting more than 256 LUNs per host. Which, of course, it totally bonkers.

Quoted 5 lines

I'll be posting my 64-bit LUN patchset, that should fix this issue.

Cheers,

Hannes

thanks for your response.

I'm concerned with iSCSI. it uses SAM2 LUN addressing scheme, and since I found that comment I did not investigate further.

I'll wait for your lun64 patches,
thanks again
--
Jan Vesely <[email protected]>