libmultipath: Handle SCSI-2 style vpd page 0x83 descriptors
Benjamin Marzinski
maintainerPATCH 1/1 libmultipath: Handle SCSI-2 style vpd page 0x83 descriptors
Some older SCSI devices return a SCSI-2 style vpd page 0x83, instead of a SPC-2/3 format one. The SCSI-2 page 83 format returns an IEEE WWN in binary encoded hexi-decimal in the 16 bytes following the initial 4-byte page 83 reply header.
Check the 7th byte of the vpd page 83 buffer to determine whether this is a SCSI-2 or SPC-2/3 confomant one. Byte 7 is the 3rd byte of first Identification descriptor in a SPC-2/3 confromant vpd page 83. This is a reserved field, and is guaranteed to be 0. If it is not zero, then it is likely the 3rd byte of a SCSI-2 Identifier (The first 3 bytes of the ID are the Organizationally Unique Identifier). Both the sg_inq and scsi_id commands handle vpd page 83 this way. To make sure that the WWID which multipath reads directly from the device matches, it should handle this format as well.
--- libmultipath/discovery.c | 13 +++++++++ tests/vpd.c | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+)
libmultipath/discovery.c +13 -0
@@ -1208,6 +1208,18 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len,if (out_len <=1 )return 0 ; +/* +* Not a valid SPC-2/3 vpd page 83. Assume it's a SCSI-2 style +* descriptor. +*/ +if (in[6 ] !=0 ) { + len =0 ; + vpd_type =0x3 ; + vpd_len = in_len -4 ; + vpd = in +4 ; + goto decode; + } + d = in +4 ;while (d <= in + in_len -4 ) {bool invalid = false;
@@ -1323,6 +1335,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, vpd_type = vpd[1 ] &0xf ; vpd_len = vpd[3 ]; vpd +=4 ; +decode:/* untaint vpd_len for coverity */ if (vpd_len >WWID_SIZE ) { condlog(1, "%s: suspicious designator length %zu truncated to %u",
tests/vpd.c +58 -0
82 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 5 lines · Benjamin Marzinski
Some older SCSI devices return a SCSI-2 style vpd page
0x83, instead of a SPC-2/3 format one. The SCSI-2 page 83 format returns an IEEE WWN in binary encoded hexi-decimal in the 16 bytes following the initial 4-byte page 83 reply header.
Quoted 9 lines
Check the 7th byte of the vpd page 83 buffer to determine whether this is a SCSI-2 or SPC-2/3 confomant one. Byte 7 is the 3rd byte of first Identification descriptor in a SPC-2/3 confromant vpd page 83. This is a reserved field, and is guaranteed to be 0. If it is not zero, then it is likely the 3rd byte of a SCSI-2 Identifier (The first 3 bytes of the ID are the Organizationally Unique Identifier). Both the
sg_inqandscsi_idcommands handle vpd page 83 this way. To make sure that the WWID which multipath reads directly from the device matches, it should handle this format as well.
Out of curiosity. Did you run into a specific old device that triggered this, or was this found by code inspection ?
Benjamin Marzinski
maintainerQuoted 16 lines · Xose Vazquez Perez
Quoted 5 lines · Benjamin Marzinski
Some older SCSI devices return a SCSI-2 style vpd page
0x83, instead of a SPC-2/3 format one. The SCSI-2 page 83 format returns an IEEE WWN in binary encoded hexi-decimal in the 16 bytes following the initial 4-byte page 83 reply header.Quoted 9 lines
Check the 7th byte of the vpd page 83 buffer to determine whether this is a SCSI-2 or SPC-2/3 confomant one. Byte 7 is the 3rd byte of first Identification descriptor in a SPC-2/3 confromant vpd page 83. This is a reserved field, and is guaranteed to be 0. If it is not zero, then it is likely the 3rd byte of a SCSI-2 Identifier (The first 3 bytes of the ID are the Organizationally Unique Identifier). Both the
sg_inqandscsi_idcommands handle vpd page 83 this way. To make sure that the WWID which multipath reads directly from the device matches, it should handle this format as well.
Quoted 2 lines
Out of curiosity. Did you run into a specific old device that triggered this, or was this found by code inspection ?
It was through code inspection.
-Ben
Quoted 43 lines · Benjamin Marzinski
Some older SCSI devices return a SCSI-2 style vpd page
0x83, instead of
a SPC-2/3 format one. The SCSI-2 page 83 format returns an IEEE WWN in
binary encoded hexi-decimal in the 16 bytes following the initial 4-byte page 83 reply header.Check the 7th byte of the vpd page 83 buffer to determine whether this
is a SCSI-2 or SPC-2/3 confomant one. Byte 7 is the 3rd byte of first Identification descriptor in a SPC-2/3 confromant vpd page 83. This is a
reserved field, and is guaranteed to be 0. If it is not zero, then it is
likely the 3rd byte of a SCSI-2 Identifier (The first 3 bytes of the ID
are the Organizationally Unique Identifier). Both thesg_inqandscsi_id
commands handle vpd page 83 this way. To make sure that the WWID which
multipath reads directly from the device matches, it should handle this
format as well.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/discovery.c | 13 +++++++++
tests/vpd.c | 58
++++++++++++++++++++++++++++++++++++++++2 files changed, 71 insertions(+)libmultipath/discovery.c +0
-0@@ -1208,6 +1208,18 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, if (out_len <= 1) return 0;libmultipath/discovery.c +2
-0+/* +* Not a valid SPC-2/3 vpd page 83. Assume it's a SCSI-2 style
libmultipath/discovery.c parse_vpd_pg83(const unsigned char *in, size_t in_len, · line 1215
Quoted 3 lines
libmultipath/discovery.c +3
-0+* descriptor. +*/ +if (in[6 ] !=0 ) {
Make sure that if in_len is > 6 (or actually, large enough to hold the SCSI-2 ID)?
libmultipath/discovery.c parse_vpd_pg83(const unsigned char *in, size_t in_len, · line 1222
Quoted 7 lines
libmultipath/discovery.c +7
-0+ len =0 ; + vpd_type =0x3 ; + vpd_len = in_len -4 ; + vpd = in +4 ; + goto decode; + } +
Regards,
Martin
Benjamin Marzinski
maintainerQuoted 42 lines · Martin Wilck
Quoted 41 lines · Benjamin Marzinski
Some older SCSI devices return a SCSI-2 style vpd page
0x83, instead of
a SPC-2/3 format one. The SCSI-2 page 83 format returns an IEEE WWN in
binary encoded hexi-decimal in the 16 bytes following the initial 4-byte page 83 reply header.Check the 7th byte of the vpd page 83 buffer to determine whether this
is a SCSI-2 or SPC-2/3 confomant one. Byte 7 is the 3rd byte of first Identification descriptor in a SPC-2/3 confromant vpd page 83. This is a
reserved field, and is guaranteed to be 0. If it is not zero, then it is
likely the 3rd byte of a SCSI-2 Identifier (The first 3 bytes of the ID
are the Organizationally Unique Identifier). Both thesg_inqandscsi_id
commands handle vpd page 83 this way. To make sure that the WWID which
multipath reads directly from the device matches, it should handle this
format as well.Signed-off-by Benjamin Marzinski <[email protected]>---
libmultipath/discovery.c | 13 +++++++++
tests/vpd.c | 58
++++++++++++++++++++++++++++++++++++++++2 files changed, 71 insertions(+)libmultipath/discovery.c +0
-0@@ -1208,6 +1208,18 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, if (out_len <= 1) return 0;libmultipath/discovery.c +1
-0+/*
Quoted 9 lines
libmultipath/discovery.c parse_vpd_pg83(const unsigned char *in, size_t in_len, · line 1215
Quoted 5 lines
libmultipath/discovery.c +1
-0+* Not a valid SPC-2/3 vpd page 83. Assume it's a SCSI-2 style
libmultipath/discovery.c +3
-0+* descriptor. +*/ +if (in[6 ] !=0 ) {Make sure that if
in_lenis > 6 (or actually, large enough to hold the SCSI-2 ID)?
Good call.
-Ben
Quoted 10 lines
libmultipath/discovery.c parse_vpd_pg83(const unsigned char *in, size_t in_len, · line 1222
Quoted 7 lines
libmultipath/discovery.c +7
-0+ len =0 ; + vpd_type =0x3 ; + vpd_len = in_len -4 ; + vpd = in +4 ; + goto decode; + } +Regards,
Martin