All of lore.kernel.org
 help / color / mirror / Atom feed
From: Himanshu Madhani <himanshu.madhani@cavium.com>
To: target-devel@vger.kernel.org, bart.vanassche@gmail.com,
	hch@infradead.org, nab@linux-iscsi.org
Cc: giridhar.malavali@cavium.com, linux-scsi@vger.kernel.org,
	himanshu.madhani@cavium.com
Subject: [PATCH 07/10] qla2xxx: Terminate exchange if corrputed.
Date: Mon, 19 Dec 2016 20:33:41 -0800	[thread overview]
Message-ID: <1482208424-12358-8-git-send-email-himanshu.madhani@cavium.com> (raw)
In-Reply-To: <1482208424-12358-1-git-send-email-himanshu.madhani@cavium.com>

From: Quinn Tran <quinn.tran@cavium.com>

Corrupted ATIO is defined as length of fcp_header & fcp_cmd
payload is less than 0x38. It's the minimum size for a frame to
carry 8..16 bytes SCSI CDB. The exchange will be dropped or
terminated if corrupted.

Signed-off-by: Quinn Tran <quinn.tran@cavium.com>
Signed-off-by: Himanshu Madhani <himanshu.madhani@cavium.com>
---
 drivers/scsi/qla2xxx/qla_def.h    |  3 ++-
 drivers/scsi/qla2xxx/qla_target.c | 22 +++++++++++++++++++---
 drivers/scsi/qla2xxx/qla_target.h | 17 ++++++++++++++++-
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index f7df01b..b14455e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -1556,7 +1556,8 @@ struct link_statistics {
 struct atio {
 	uint8_t		entry_type;		/* Entry type. */
 	uint8_t		entry_count;		/* Entry count. */
-	uint8_t		data[58];
+	uint16_t	attr_n_length;
+	uint8_t		data[56];
 	uint32_t	signature;
 #define ATIO_PROCESSED 0xDEADDEAD		/* Signature */
 };
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 5037b51..7ae179a 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -6451,12 +6451,28 @@ static void qlt_disable_vha(struct scsi_qla_host *vha)
 	if (!vha->flags.online)
 		return;
 
-	while (ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) {
+	while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) ||
+		   FCPCMD_IS_CORRUPTED(ha->tgt.atio_ring_ptr)) {
 		pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
 		cnt = pkt->u.raw.entry_count;
 
-		qlt_24xx_atio_pkt_all_vps(vha, (struct atio_from_isp *)pkt,
-		    ha_locked);
+		if (unlikely(FCPCMD_IS_CORRUPTED(ha->tgt.atio_ring_ptr))) {
+			/* This packet is corrupted.  The header + payload
+			 * can not be trusted.  There is no point in passing
+			 * it further up.
+			 */
+			ql_log(ql_log_warn, vha, 0xffff,
+			    "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
+			    pkt->u.isp24.fcp_hdr.s_id,
+			    be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
+			    le32_to_cpu(pkt->u.isp24.exchange_addr), pkt);
+
+			ADJ_CORRUPTED_ATIO(pkt);
+			qlt_send_term_exchange(vha, NULL, pkt, ha_locked, 0);
+		} else {
+			qlt_24xx_atio_pkt_all_vps(vha,
+			    (struct atio_from_isp *)pkt, ha_locked);
+		}
 
 		for (i = 0; i < cnt; i++) {
 			ha->tgt.atio_ring_index++;
diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h
index f26c5f6..15359f0 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -427,13 +427,28 @@ struct atio_from_isp {
 		struct {
 			uint8_t  entry_type;	/* Entry type. */
 			uint8_t  entry_count;	/* Entry count. */
-			uint8_t  data[58];
+			uint16_t attr_n_length;
+#define FCP_CMD_LENTH_MASK 0x0fff
+#define FCP_CMD_LENTH_MIN  0x38
+			uint8_t  data[56];
 			uint32_t signature;
 #define ATIO_PROCESSED 0xDEADDEAD		/* Signature */
 		} raw;
 	} u;
 } __packed;
 
+#define FCPCMD_IS_CORRUPTED(_a)						\
+	((_a->entry_type == ATIO_TYPE7) && 				\
+	 ((le16_to_cpu(_a->attr_n_length) & FCP_CMD_LENTH_MASK) < 	\
+	  FCP_CMD_LENTH_MIN))
+
+/* adjust corrupted atio so we won't trip over the same entry again. */
+#define ADJ_CORRUPTED_ATIO(_a)						\
+{									\
+	_a->u.raw.attr_n_length = cpu_to_le16(FCP_CMD_LENTH_MIN);	\
+	((struct atio_from_isp *)_a)->u.isp24.fcp_cmnd.add_cdb_len = 0;	\
+}
+
 #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
 
 /*
-- 
1.8.3.1

  parent reply	other threads:[~2016-12-20  4:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-20  4:33 [PATCH 00/10] qla2xxx: Bug fixes for driver Himanshu Madhani
2016-12-20  4:33 ` [PATCH 01/10] qla2xxx: Fix wrong IOCB type assumption Himanshu Madhani
2016-12-20 14:10   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 02/10] qla2xxx: Include ATIO queue in firmware dump when in target mode Himanshu Madhani
2016-12-20 14:10   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 03/10] qla2xxx: Set tcm_qla2xxx version to automatically track qla2xxx version Himanshu Madhani
2016-12-20 14:11   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 04/10] qla2xxx: Reset reserved field in firmware options to 0 Himanshu Madhani
2016-12-20 14:11   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 05/10] qla2xxx: Collect additional information to debug fw dump Himanshu Madhani
2016-12-20 14:11   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 06/10] qla2xxx: Fix crash due to null pointer access Himanshu Madhani
2016-12-20 14:12   ` Christoph Hellwig
2016-12-20  4:33 ` Himanshu Madhani [this message]
2016-12-20 14:13   ` [PATCH 07/10] qla2xxx: Terminate exchange if corrputed Christoph Hellwig
2016-12-20  4:33 ` [PATCH 08/10] qla2xxx: Reduce exess wait during chip reset Himanshu Madhani
2016-12-20 14:14   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 09/10] qla2xxx: Fix invalid handle erroneous message Himanshu Madhani
2016-12-20 14:15   ` Christoph Hellwig
2016-12-20  4:33 ` [PATCH 10/10] qla2xxx: Disable Out-of-order processing by default in Firmware Himanshu Madhani
2016-12-20 14:15   ` Christoph Hellwig

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=1482208424-12358-8-git-send-email-himanshu.madhani@cavium.com \
    --to=himanshu.madhani@cavium.com \
    --cc=bart.vanassche@gmail.com \
    --cc=giridhar.malavali@cavium.com \
    --cc=hch@infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=target-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.