From mboxrd@z Thu Jan 1 00:00:00 1970 From: Luben Tuikov Subject: Re: [PATCH] sd: Fix regression in sd_read_cache_type Date: Wed, 23 Mar 2011 07:06:31 -0700 (PDT) Message-ID: <469812.82249.qm@web31812.mail.mud.yahoo.com> References: Reply-To: ltuikov@yahoo.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from nm15.bullet.mail.bf1.yahoo.com ([98.139.212.174]:43480 "HELO nm15.bullet.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751711Ab1CWOMO convert rfc822-to-8bit (ORCPT ); Wed, 23 Mar 2011 10:12:14 -0400 In-Reply-To: Sender: linux-scsi-owner@vger.kernel.org List-Id: linux-scsi@vger.kernel.org To: James Bottomley , Alan Stern Cc: Richard Senior , SCSI development list --- On Mon, 3/21/11, Alan Stern wrote: > From: Alan Stern > Subject: [PATCH] sd: Fix regression in sd_read_cache_type > To: "James Bottomley" > Cc: "Richard Senior" , "Luben Tuikov" <= ltuikov@yahoo.com>, "SCSI development list" > Date: Monday, March 21, 2011, 2:29 PM > This patch (as1454) fixes a > regression in the sd driver.=A0 Commit > 24d720b726c1a85f1962831ac30ad4d2ef8276b1 ([SCSI] Retrieve > the Caching > mode page) recently introduced the strategy of asking for > all pages > (page code 0x3F) instead of asking for the caching page > (0x08) on > devices that might not support it.=A0 This ought to be > safe, because sd > already uses page code 0x3F when checking for write > protection. >=20 > Unfortunately, the commit did not copy the checks used by > sd_read_write_protect_flag().=A0 Some devices don't > support page code > 0x3F, and others require a fixed transfer length of 192 > bytes.=A0 This > patch adds those checks into sd_read_cache_type(). >=20 > Without this fix, some USB mass-storage devices crash when > they > receive a MODE SENSE command with page code 0x3F asking for > only 4 > bytes of data. >=20 > Signed-off-by: Alan Stern > Reported-and-tested-by: Richard Senior > CC: Luben Tuikov > CC: Acked-by: Luben Tuikov >=20 > --- >=20 > The only stable kernel requiring this fix is 2.6.38; > earlier kernels > are okay. >=20 >=20 > drivers/scsi/sd.c |=A0=A0=A014 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) >=20 > Index: usb-2.6/drivers/scsi/sd.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usb-2.6.orig/drivers/scsi/sd.c > +++ usb-2.6/drivers/scsi/sd.c > @@ -1904,17 +1904,23 @@ sd_read_cache_type(struct scsi_disk > *sdk > =20 > =A0=A0=A0 int dbd; > =A0=A0=A0 int modepage; > +=A0=A0=A0 int first_len; > =A0=A0=A0 struct scsi_mode_data data; > =A0=A0=A0 struct scsi_sense_hdr sshdr; > =A0=A0=A0 int old_wce =3D sdkp->WCE; > =A0=A0=A0 int old_rcd =3D sdkp->RCD; > =A0=A0=A0 int old_dpofua =3D sdkp->DPOFUA; > =20 > +=A0=A0=A0 first_len =3D 4; > =A0=A0=A0 if (sdp->skip_ms_page_8) { > =A0=A0=A0 =A0=A0=A0 if (sdp->type =3D=3D > TYPE_RBC) > =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > goto defaults; > =A0=A0=A0 =A0=A0=A0 else { > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > if (sdp->skip_ms_page_3f) > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > =A0=A0=A0 goto defaults; > =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > modepage =3D 0x3F; > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > if (sdp->use_192_bytes_for_3f) > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > =A0=A0=A0 first_len =3D 192; > =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > dbd =3D 0; > =A0=A0=A0 =A0=A0=A0 } > =A0=A0=A0 } else if (sdp->type =3D=3D TYPE_RBC) { > @@ -1926,13 +1932,15 @@ sd_read_cache_type(struct scsi_disk > *sdk > =A0=A0=A0 } > =20 > =A0=A0=A0 /* cautiously ask */ > -=A0=A0=A0 res =3D sd_do_mode_sense(sdp, dbd, > modepage, buffer, 4, &data, &sshdr); > +=A0=A0=A0 res =3D sd_do_mode_sense(sdp, dbd, > modepage, buffer, first_len, > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > &data, &sshdr); > =20 > =A0=A0=A0 if (!scsi_status_is_good(res)) > =A0=A0=A0 =A0=A0=A0 goto bad_sense; > =20 > =A0=A0=A0 if (!data.header_length) { > =A0=A0=A0 =A0=A0=A0 modepage =3D 6; > +=A0=A0=A0 =A0=A0=A0 first_len =3D 0; > =A0=A0=A0 =A0=A0=A0 sd_printk(KERN_ERR, > sdkp, "Missing header in MODE_SENSE response\n"); > =A0=A0=A0 } > =20 > @@ -1952,7 +1960,9 @@ sd_read_cache_type(struct scsi_disk > *sdk > =A0=A0=A0 } > =20 > =A0=A0=A0 /* Get the data */ > -=A0=A0=A0 res =3D sd_do_mode_sense(sdp, dbd, > modepage, buffer, len, &data, &sshdr); > +=A0=A0=A0 if (len > first_len) > +=A0=A0=A0 =A0=A0=A0 res =3D > sd_do_mode_sense(sdp, dbd, modepage, buffer, len, > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 > =A0=A0=A0 &data, &sshdr); > =20 > =A0=A0=A0 if (scsi_status_is_good(res)) { > =A0=A0=A0 =A0=A0=A0 int offset =3D > data.header_length + data.block_descriptor_length; >=20 >=20 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html