linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Ebbert <cebbert@redhat.com>
To: IDE/ATA development list <linux-ide@vger.kernel.org>
Subject: [stable patch] backport of "be tolerant of 12-byte ATAPI commands in 16-byte CDBs"
Date: Wed, 28 Nov 2007 18:36:07 -0500	[thread overview]
Message-ID: <474DFB67.5070603@redhat.com> (raw)

Submitted for comment, not compile tested.


Backport of commit 607126c2a21cd6e9bb807fdd415c1a992f7b9009
libata-scsi: be tolerant of 12-byte ATAPI commands in 16-byte CDBs

---
 drivers/ata/libata-scsi.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

--- linux-2.6.23.noarch.orig/drivers/ata/libata-scsi.c
+++ linux-2.6.23.noarch/drivers/ata/libata-scsi.c
@@ -2747,16 +2747,15 @@ static inline int __ata_scsi_queuecmd(st
 				      struct ata_device *dev)
 {
 	int rc = 0;
+	u8 scsi_op = scmd->cmnd[0];
 
-	if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) {
-		DPRINTK("bad CDB len=%u, max=%u\n",
-			scmd->cmd_len, dev->cdb_len);
-		scmd->result = DID_ERROR << 16;
-		done(scmd);
-		return 0;
-	}
+	if (unlikely(!scmd->cmd_len))
+		goto bad_cdb_len;
 
 	if (dev->class == ATA_DEV_ATA) {
+		if (unlikely(scmd->cmd_len > dev->cdb_len))
+			goto bad_cdb_len;
+
 		ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
 							      scmd->cmnd[0]);
 
@@ -2764,10 +2763,22 @@ static inline int __ata_scsi_queuecmd(st
 			rc = ata_scsi_translate(dev, scmd, done, xlat_func);
 		else
 			ata_scsi_simulate(dev, scmd, done);
-	} else
+	} else {
+		int len = COMMAND_SIZE(scsi_op);
+		if (unlikely(len > scmd->cmd_len || len > dev->cdb_len))
+			goto bad_cdb_len;
+
 		rc = ata_scsi_translate(dev, scmd, done, atapi_xlat);
+	}
 
 	return rc;
+
+ bad_cdb_len:
+	DPRINTK("bad CDB len=%u, scsi_op=0x%02x, max=%u\n",
+		scmd->cmd_len, scsi_op, dev->cdb_len);
+	scmd->result = DID_ERROR << 16;
+	done(scmd);
+	return 0;
 }
 
 /**

                 reply	other threads:[~2007-11-28 23:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=474DFB67.5070603@redhat.com \
    --to=cebbert@redhat.com \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).