From dfd45e735c21ef774abb61163e5924b083aba64a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 6 Sep 2021 03:04:38 +0000 Subject: [PATCH] scst_copy_mgr: Improve standards compliance Instead of considering designators as equivalent if one is the prefix of another, only accept an exact match of the designator length as required by the SCSI standard. Fixes: 5e90abb64ac7 ("scst_copy_mgr: Implement a workaround for non-compliant initiator systems") Fixes: 3fc775c75af6 ("EXTENDED COPY support") git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9570 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_copy_mgr.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index 7fa922c32..8a1a3fa13 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -2944,24 +2944,20 @@ static int scst_cm_parse_id_tgt_descr(struct scst_cmd *cmd, const uint8_t *seg, /* ToDo: make it hash based */ list_for_each_entry(des, &scst_cm_desig_list, cm_desig_list_entry) { - uint8_t cmp_len; - TRACE_DBG("des %p (tgt_dev %p, lun %lld)", des, des->desig_tgt_dev, (unsigned long long)des->desig_tgt_dev->lun); if (seg[4] != des->desig[0]) continue; if (seg[5] != des->desig[1]) continue; - if (seg[7] > des->desig[3]) + if (seg[7] > 20) { + PRINT_WARNING("Initiator sent non-compliant identification descriptor (len %u > 20)", + seg[7]); continue; - /* - * From SPC-6: "The designator length shall be 20 or less". - * However, both libiscsi and sg_copy may specify a designator - * length > 20 bytes while truncating the designator to 20 - * bytes. Hence the code below that restricts cmp_len to 20. - */ - cmp_len = min_t(u8, min(seg[7], des->desig[3]), 20); - if (memcmp(&des->desig[4], &seg[8], cmp_len) == 0) { + } + if (seg[7] != des->desig[3]) + continue; + if (memcmp(&des->desig[4], &seg[8], seg[7]) == 0) { TRACE_DBG("Tgt_dev %p (lun %lld) found", des->desig_tgt_dev, (unsigned long long)des->desig_tgt_dev->lun);