From 108c373f7c959ed96a7cf4b782391f6a8597e6a4 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 10 Oct 2019 16:37:51 +0900 Subject: [PATCH] lib/iscsi: Move checking header digests before handling payload If PDU header digest error is detected, it indicates that the length field of the header may have been corrupted. Hence it's may not be possible to identify the location of the beginning of a later PDU. So move checking header digest before handling payload and then close the connection if header digest error is detected. Signed-off-by: Shuhei Matsumoto Change-Id: I56f6bc082dc0b244e71ad996b4da08e0203f8cdd Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471014 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/iscsi/iscsi.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 7787b7bbf..9ee0c1a2a 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -4651,6 +4651,15 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn) } } + if (conn->header_digest) { + crc32c = spdk_iscsi_pdu_calc_header_digest(pdu); + rc = MATCH_DIGEST_WORD(pdu->header_digest, crc32c); + if (rc == 0) { + SPDK_ERRLOG("header digest error (%s)\n", conn->initiator_name); + goto error; + } + } + data_len = ISCSI_ALIGN(DGET24(pdu->bhs.data_segment_len)); if (data_len != 0 && pdu->data_buf == NULL) { @@ -4714,15 +4723,7 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn) spdk_trace_record(TRACE_ISCSI_READ_PDU, conn->id, pdu->data_valid_bytes, (uintptr_t)pdu, pdu->bhs.opcode); - /* check digest */ - if (conn->header_digest) { - crc32c = spdk_iscsi_pdu_calc_header_digest(pdu); - rc = MATCH_DIGEST_WORD(pdu->header_digest, crc32c); - if (rc == 0) { - SPDK_ERRLOG("header digest error (%s)\n", conn->initiator_name); - goto error; - } - } + /* check data digest */ if (conn->data_digest && data_len != 0) { crc32c = spdk_iscsi_pdu_calc_data_digest(pdu); rc = MATCH_DIGEST_WORD(pdu->data_digest, crc32c);