From patchwork Thu Jul 2 01:43:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637653 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 020FD6C1 for ; Thu, 2 Jul 2020 01:43:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6934207D4 for ; Thu, 2 Jul 2020 01:43:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="xfo7z3q6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgGBBn3 (ORCPT ); Wed, 1 Jul 2020 21:43:29 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51508 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726038AbgGBBn2 (ORCPT ); Wed, 1 Jul 2020 21:43:28 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621dQSN154856; Thu, 2 Jul 2020 01:43:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=CpsW1stTVGUZ4N8Wn5aCehynrUWbuqkaWE2+YbLkY9I=; b=xfo7z3q6I0XOk8gmTjlkK/HOHWOA9AlSUn9IdJczF63oalGTbnjWqa7/4kiUBZkPH+Wf FEkPYYZ2YXWWAtKFh8jTnn5EJbzFzAKXttqGlZrtKaUet3vL8puLzvuw9WEVxOlrhlq2 +Dh2jSe0wRxMpSvB9Dbw0+OwlU4Hr7u+ijq2rTlqe8bw+AKfFYk/w7YhpSw78ubOrLe9 Wff25hjhnBKyqNVGV9WxmbFJmNj+04R0dk/NdmS9lM22j1EOoGrLbDu1LpZZOCM4IOgt bhAZGlMrhlnmCPWTiqh3P1h7IivPRDZxTTFNTiQLSm2zYVE5t4M4yAGMnncxflBXzCHC sQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 31wxrndng1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:43:25 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621bpP2181445; Thu, 2 Jul 2020 01:43:24 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 31xg204txj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:24 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0621hNcq030498; Thu, 2 Jul 2020 01:43:24 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:23 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 1/7] target: check enforce_pr_isids during registration Date: Wed, 1 Jul 2020 20:43:17 -0500 Message-Id: <1593654203-12442-2-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org Move the check for enforce_pr_isids to the registration code where we can fail at the time an initiator tries to register a path without an isid. In its current place in __core_scsi3_locate_pr_reg, it is too late because it can be registered and be reported in PR in commands and it is stuck in this state because we cannot unregister it. Reviewed-by: Hannes Reinecke Reviewed-by: Lee Duncan Signed-off-by: Mike Christie --- drivers/target/target_core_pr.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 91e41cc..293f518 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -1176,15 +1176,6 @@ static struct t10_pr_registration *__core_scsi3_locate_pr_reg( * ISID, then we have found a match. */ if (!pr_reg->isid_present_at_reg) { - /* - * Determine if this SCSI device server requires that - * SCSI Intiatior TransportID w/ ISIDs is enforced - * for fabric modules (iSCSI) requiring them. - */ - if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) { - if (dev->dev_attrib.enforce_pr_isids) - continue; - } atomic_inc_mb(&pr_reg->pr_res_holders); spin_unlock(&pr_tmpl->registration_lock); return pr_reg; @@ -1591,10 +1582,25 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) continue; dest_rtpi = tmp_lun->lun_rtpi; + iport_ptr = NULL; i_str = target_parse_pr_out_transport_id(tmp_tpg, ptr, &tid_len, &iport_ptr); if (!i_str) continue; + /* + * Determine if this SCSI device server requires that + * SCSI Intiatior TransportID w/ ISIDs is enforced + * for fabric modules (iSCSI) requiring them. + */ + if (tpg->se_tpg_tfo->sess_get_initiator_sid && + dev->dev_attrib.enforce_pr_isids && + !iport_ptr) { + pr_warn("SPC-PR: enforce_pr_isids is set but a isid has not been sent in the SPEC_I_PT data for %s.", + i_str); + ret = TCM_INVALID_PARAMETER_LIST; + spin_unlock(&dev->se_port_lock); + goto out_unmap; + } atomic_inc_mb(&tmp_tpg->tpg_pr_ref_count); spin_unlock(&dev->se_port_lock); From patchwork Thu Jul 2 01:43:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637683 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D565492A for ; Thu, 2 Jul 2020 01:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA5A420672 for ; Thu, 2 Jul 2020 01:45:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="MVaCBzij" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728140AbgGBBp3 (ORCPT ); Wed, 1 Jul 2020 21:45:29 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:34922 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728131AbgGBBp3 (ORCPT ); Wed, 1 Jul 2020 21:45:29 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621d0Ek155850; Thu, 2 Jul 2020 01:45:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=tE3kFlaOk7xz7kinaT/6Uao6WzALtlB8cSTjFtmf16M=; b=MVaCBzijXTqH6no+1xausGKUlF2NhcBh1UYdxf44E5uDfOjr4j4WN2s3wXacfmRtITEP p9vLzScePY24RxlGSieoRtFE0KyFG5aQe+XHRO8NXvVw2EyP4v9mUQOt9ePP+vQReh6Z e82tUIsto+S7vAYtY55QmTZu44pejzxOjCxdtyiQJBdC0J3HTsXODBf9+MycLeyTuVH+ m082RK6atuOgTiIBH76AZ1hF0z5MCmdkLmiCHfNgBwZJ881voqyyrUrvXOeFkS1YACxg goIizCI+oem7/1g4f8n76ZMJbAhDFn6OxKXqmGvAnt3LRJt7FiP+MpmhL+sBqQqCBzzl Rg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 31xx1e2hy6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:45:25 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621glKO050688; Thu, 2 Jul 2020 01:43:25 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 31xg17stfb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:25 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0621hOlh022092; Thu, 2 Jul 2020 01:43:24 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:24 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 2/7] target: fix xcopy sess release leak Date: Wed, 1 Jul 2020 20:43:18 -0500 Message-Id: <1593654203-12442-3-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=2 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020010 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=2 mlxlogscore=999 cotscore=-2147483648 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org transport_init_session can allocate memory via percpu_ref_init, and target_xcopy_release_pt never frees it. This adds a transport_uninit_session function to handle cleanup of resources allocated in the init function. Signed-off-by: Mike Christie --- drivers/target/target_core_internal.h | 1 + drivers/target/target_core_transport.c | 7 ++++++- drivers/target/target_core_xcopy.c | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 8533444..e7b3c6e 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -138,6 +138,7 @@ struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg, void release_se_kmem_caches(void); u32 scsi_get_new_index(scsi_index_t); void transport_subsystem_check_init(void); +void transport_uninit_session(struct se_session *); unsigned char *transport_dump_cmd_direction(struct se_cmd *); void transport_dump_dev_state(struct se_device *, char *, int *); void transport_dump_dev_info(struct se_device *, struct se_lun *, diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 90ecdd7..e6e1fa6 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -236,6 +236,11 @@ int transport_init_session(struct se_session *se_sess) } EXPORT_SYMBOL(transport_init_session); +void transport_uninit_session(struct se_session *se_sess) +{ + percpu_ref_exit(&se_sess->cmd_count); +} + /** * transport_alloc_session - allocate a session object and initialize it * @sup_prot_ops: bitmask that defines which T10-PI modes are supported. @@ -579,7 +584,7 @@ void transport_free_session(struct se_session *se_sess) sbitmap_queue_free(&se_sess->sess_tag_pool); kvfree(se_sess->sess_cmd_map); } - percpu_ref_exit(&se_sess->cmd_count); + transport_uninit_session(se_sess); kmem_cache_free(se_sess_cache, se_sess); } EXPORT_SYMBOL(transport_free_session); diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 0d00ccb..44e15d7 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -474,7 +474,7 @@ int target_xcopy_setup_pt(void) memset(&xcopy_pt_sess, 0, sizeof(struct se_session)); ret = transport_init_session(&xcopy_pt_sess); if (ret < 0) - return ret; + goto destroy_wq; xcopy_pt_nacl.se_tpg = &xcopy_pt_tpg; xcopy_pt_nacl.nacl_sess = &xcopy_pt_sess; @@ -483,12 +483,19 @@ int target_xcopy_setup_pt(void) xcopy_pt_sess.se_node_acl = &xcopy_pt_nacl; return 0; + +destroy_wq: + destroy_workqueue(xcopy_wq); + xcopy_wq = NULL; + return ret; } void target_xcopy_release_pt(void) { - if (xcopy_wq) + if (xcopy_wq) { destroy_workqueue(xcopy_wq); + transport_uninit_session(&xcopy_pt_sess); + } } /* From patchwork Thu Jul 2 01:43:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637667 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A7146C1 for ; Thu, 2 Jul 2020 01:43:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AEE4207D4 for ; Thu, 2 Jul 2020 01:43:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Chb3hAH+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728274AbgGBBnd (ORCPT ); Wed, 1 Jul 2020 21:43:33 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:33894 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727921AbgGBBna (ORCPT ); Wed, 1 Jul 2020 21:43:30 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621cIKZ155693; Thu, 2 Jul 2020 01:43:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=tFE1yMrA+uD5SlqaHhouo3Fj/+2xAemq79ePyl1jqkM=; b=Chb3hAH+DU3bdrHYH171otJywMndy3md9672rjhvcLYEbt0Bey3/12QHFEo1czMEL8kX wjdJ7IMP3AxTXEs/6FY8FIf1gjpOoheAf4+7MhWYRlfybKhRJfzaGjlaVyDHElYypdzi qu3hiYzNFfknaBWthawCoMnyQub6mnxkmtbm/ePLAYcCWSth2F9+xtvu5iFF6wKeVbg8 bXdqNm4RlHeOHpt1zOBUHv8fFJZP5ZiFew7NyU2jDv4Iqj8/hAWIJPYuA9dKS+IsUPjb Vn8LcKUEspJQB58AMjJ7s+RTvhniogAYEB0uRnbxgmYuRXkc12/vF2qUlgfIvGoxBKfb ew== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 31xx1e2hun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:43:26 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621gp30051099; Thu, 2 Jul 2020 01:43:26 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 31xg17stfw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:26 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0621hOfZ017085; Thu, 2 Jul 2020 01:43:24 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:24 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 3/7] target: fix crash during SPEC_I_PT handling Date: Wed, 1 Jul 2020 20:43:19 -0500 Message-Id: <1593654203-12442-4-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=2 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020010 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=2 mlxlogscore=999 cotscore=-2147483648 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org __core_scsi3_add_registration clears the t10_pr_registration pr_reg_deve and does a core_scsi3_lunacl_undepend_item which does an undepend and also does a kref_put from the get done in __core_scsi3_alloc_registration. So when we get to the bottom of core_scsi3_decode_spec_i_port the pr_reg_deve is NULL and we crash when trying to access the local_pr_reg's pr_reg_deve. We've also done an extra undepend for local_pr_reg and if we didn't crash on the NULL we would have done an extra kref_put too. This patch has us do a core_scsi3_lunacl_depend_item for local_pr_reg and then let __core_scsi3_add_registration handle the cleanup for the pr_reg_deve. We then just skip the undepend for the acl and tpg for the local pr_reg. The erorr path then works in a similar way, but we always do the core_scsi3_lunacl_undepend_item since we never call __core_scsi3_add_registration in that code path. Signed-off-by: Mike Christie --- drivers/target/target_core_pr.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 293f518..d5e6344 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -1521,13 +1521,16 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) kfree(tidh_new); return TCM_INSUFFICIENT_REGISTRATION_RESOURCES; } + + if (core_scsi3_lunacl_depend_item(local_pr_reg->pr_reg_deve)) { + kfree(tidh_new); + kref_put(&local_pr_reg->pr_reg_deve->pr_kref, + target_pr_kref_release); + kmem_cache_free(t10_pr_reg_cache, local_pr_reg); + return TCM_INSUFFICIENT_REGISTRATION_RESOURCES; + } + tidh_new->dest_pr_reg = local_pr_reg; - /* - * The local I_T nexus does not hold any configfs dependances, - * so we set tidh_new->dest_se_deve to NULL to prevent the - * configfs_undepend_item() calls in the tid_dest_list loops below. - */ - tidh_new->dest_se_deve = NULL; list_add_tail(&tidh_new->dest_list, &tid_dest_list); if (cmd->data_length < 28) { @@ -1816,12 +1819,9 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) dest_node_acl->initiatorname, i_buf, (dest_se_deve) ? dest_se_deve->mapped_lun : 0); - if (!dest_se_deve) { - kref_put(&local_pr_reg->pr_reg_deve->pr_kref, - target_pr_kref_release); + if (dest_pr_reg == local_pr_reg) continue; - } - core_scsi3_lunacl_undepend_item(dest_se_deve); + core_scsi3_nodeacl_undepend_item(dest_node_acl); core_scsi3_tpg_undepend_item(dest_tpg); } @@ -1835,11 +1835,16 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) * including *dest_pr_reg and the configfs dependances.. */ list_for_each_entry_safe(tidh, tidh_tmp, &tid_dest_list, dest_list) { + bool is_local = false; + dest_tpg = tidh->dest_tpg; dest_node_acl = tidh->dest_node_acl; dest_se_deve = tidh->dest_se_deve; dest_pr_reg = tidh->dest_pr_reg; + if (dest_pr_reg == local_pr_reg) + is_local = true; + list_del(&tidh->dest_list); kfree(tidh); /* @@ -1855,13 +1860,11 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) } kmem_cache_free(t10_pr_reg_cache, dest_pr_reg); + core_scsi3_lunacl_undepend_item(dest_se_deve); - if (!dest_se_deve) { - kref_put(&local_pr_reg->pr_reg_deve->pr_kref, - target_pr_kref_release); + if (is_local) continue; - } - core_scsi3_lunacl_undepend_item(dest_se_deve); + core_scsi3_nodeacl_undepend_item(dest_node_acl); core_scsi3_tpg_undepend_item(dest_tpg); } From patchwork Thu Jul 2 01:43:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637677 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D5CB6C1 for ; Thu, 2 Jul 2020 01:43:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 866D0207D4 for ; Thu, 2 Jul 2020 01:43:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Qnb7mlRB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728194AbgGBBnc (ORCPT ); Wed, 1 Jul 2020 21:43:32 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51518 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgGBBna (ORCPT ); Wed, 1 Jul 2020 21:43:30 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621cMHd153751; Thu, 2 Jul 2020 01:43:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=f3kfZHXzfTx2LxdfncZVcUA3z5V5f5QIMVGhDWfe+Hs=; b=Qnb7mlRBW/TMZS6wVDQQ3B0V0/AlwTvaGPf5xZZkeLduHN0TVXAauVjzKv+Q6Rq1rgFm 6M4kzJrXCpEGsNTJ70SeCzx9HcTaDxGiR5eHeQ7hglU5O0vxDPXPa12D8s1dvLrC851W qHEkc34dxWkwjlsJJ+m1TbpENBpI+Y1b8Ayd0JYPTVrwaG4cdMxGqTWnCDtgoFOMuPlo jbfl8iuEZFH6T0rEUdNXpWE2Nf9uRQ51+xve+tj/Y+nRwSHau+DLx/iG7ORcx0cJpJmk KoXn9Tt4gurS62pypsrO4zxywlPZVl+6FD6leNAPNqYrfdVwxi0f7WtbtgU73BfGftEA KA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 31wxrndng3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:43:26 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621glFh050725; Thu, 2 Jul 2020 01:43:25 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 31xg17stfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:25 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0621hPVZ022102; Thu, 2 Jul 2020 01:43:25 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:25 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 4/7] target: fix iscsi transport id parsing Date: Wed, 1 Jul 2020 20:43:20 -0500 Message-Id: <1593654203-12442-5-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020010 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org The length passed in the ADDITIONAL LENGTH field includes padding and the terminating NULL for the last field (name or isid depending on the format), so we should not also try to calculate that and then double add that to the returned length. Signed-off-by: Mike Christie --- drivers/target/target_core_fabric_lib.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index 1e031d8..81bc8ec 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -265,9 +265,7 @@ static char *iscsi_parse_pr_out_transport_id( char **port_nexus_ptr) { char *p; - u32 tid_len, padding; int i; - u16 add_len; u8 format_code = (buf[0] & 0xc0); /* * Check for FORMAT CODE 00b or 01b from spc4r17, section 7.5.4.6: @@ -293,23 +291,11 @@ static char *iscsi_parse_pr_out_transport_id( */ if (out_tid_len) { /* The shift works thanks to integer promotion rules */ - add_len = get_unaligned_be16(&buf[2]); - - tid_len = strlen(&buf[4]); - tid_len += 4; /* Add four bytes for iSCSI Transport ID header */ - tid_len += 1; /* Add one byte for NULL terminator */ - padding = ((-tid_len) & 3); - if (padding != 0) - tid_len += padding; - - if ((add_len + 4) != tid_len) { - pr_debug("LIO-Target Extracted add_len: %hu " - "does not match calculated tid_len: %u," - " using tid_len instead\n", add_len+4, tid_len); - *out_tid_len = tid_len; - } else - *out_tid_len = (add_len + 4); + *out_tid_len = get_unaligned_be16(&buf[2]); + /* Add four bytes for iSCSI Transport ID header */ + *out_tid_len += 4; } + /* * Check for ',i,0x' separator between iSCSI Name and iSCSI Initiator * Session ID as defined in Table 390 - iSCSI initiator port TransportID From patchwork Thu Jul 2 01:43:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637675 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 720B913B4 for ; Thu, 2 Jul 2020 01:43:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55CA9207D4 for ; Thu, 2 Jul 2020 01:43:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NoVZYboF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbgGBBnc (ORCPT ); Wed, 1 Jul 2020 21:43:32 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:33712 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728051AbgGBBna (ORCPT ); Wed, 1 Jul 2020 21:43:30 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621bSg6037913; Thu, 2 Jul 2020 01:43:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=WEtz0vycwnjLRrbztQ5Azf9829l7tpkmZQIWHv3V/BY=; b=NoVZYboFXgHyKnhrdmMGD2o0KGH5fI871oGT0SjZEcNn647A9u64eUN8JBtGW0tXmr85 /J0INtWscx9ccnJurVpEsKugQl22glP3fhCjfPUBIYNIe1bS2wOBkqy6TrJYjHn3ESAI CRic2oF+FQtR1IRuwy1Erq+hvOXck5QIV50SPfNf8uFFWUAAhtPYVwGKd6UZCeZHVnal IrN+QQOpLUrGlt6QejYXtbxBpwDFUtuGXbUbsIOUNv4Kftr5zM+9DpIAj22eFuab7Ths lpB1ewLYxLM0eDPqfhIPT34v+eaI4tbALx9158TthQ5yi/dEV61i7skZZBlqjgx+zbJ/ 9Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 31ywrbuwb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:43:27 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621gfVD145889; Thu, 2 Jul 2020 01:43:26 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 31xfvus3fv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:26 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0621hPrL022105; Thu, 2 Jul 2020 01:43:25 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:25 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 5/7] target: fix iscsi transport id buffer setup Date: Wed, 1 Jul 2020 20:43:21 -0500 Message-Id: <1593654203-12442-6-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020010 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 cotscore=-2147483648 priorityscore=1501 lowpriorityscore=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org This fixes the following bugs with the transport id setup for iscsi: 1. Incorrectly adding NULL after initiator name for TPID format 1. 2. For TPID format 1 buffer setup we are doing off+len, off++ and then also len+=some_value. This results in the isid going past buffer boundaries when we then do buf[off+len] 3. The pr_reg_isid is the isid in string format which is 12 bytes, but we are only copying 6 bytes. Signed-off-by: Mike Christie --- V2: - Drop chunk that dropped format code. drivers/target/target_core_fabric_lib.c | 72 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index 81bc8ec..428e5a1 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -136,29 +136,22 @@ static int iscsi_get_pr_transport_id( spin_lock_irq(&se_nacl->nacl_sess_lock); /* - * From spc4r17 Section 7.5.4.6: TransportID for initiator - * ports using SCSI over iSCSI. + * Only null terminate the last field. * - * The null-terminated, null-padded (see 4.4.2) ISCSI NAME field - * shall contain the iSCSI name of an iSCSI initiator node (see - * RFC 3720). The first ISCSI NAME field byte containing an ASCII - * null character terminates the ISCSI NAME field without regard for - * the specified length of the iSCSI TransportID or the contents of - * the ADDITIONAL LENGTH field. - */ - len = sprintf(&buf[off], "%s", se_nacl->initiatorname); - /* - * Add Extra byte for NULL terminator - */ - len++; - /* - * If there is ISID present with the registration and *format code == 1 - * 1, use iSCSI Initiator port TransportID format. + * From spc4r37 section 7.6.4.6: TransportID for initiator ports using + * SCSI over iSCSI. * - * Otherwise use iSCSI Initiator device TransportID format that - * does not contain the ASCII encoded iSCSI Initiator iSID value - * provied by the iSCSi Initiator during the iSCSI login process. + * Table 507 TPID=0 Initiator device TransportID + * + * The null-terminated, null-padded (see 4.3.2) ISCSI NAME field shall + * contain the iSCSI name of an iSCSI initiator node (see RFC 7143). + * The first ISCSI NAME field byte containing an ASCII null character + * terminates the ISCSI NAME field without regard for the specified + * length of the iSCSI TransportID or the contents of the ADDITIONAL + * LENGTH field. */ + len = sprintf(&buf[off], "%s", se_nacl->initiatorname); + off += len; if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) { /* * Set FORMAT CODE 01b for iSCSI Initiator port TransportID @@ -166,8 +159,12 @@ static int iscsi_get_pr_transport_id( */ buf[0] |= 0x40; /* - * From spc4r17 Section 7.5.4.6: TransportID for initiator - * ports using SCSI over iSCSI. Table 390 + * From spc4r37 Section 7.6.4.6 + * + * Table 508 TPID=1 Initiator port TransportID. + * + * The ISCSI NAME field shall not be null-terminated + * (see 4.3.2) and shall not be padded. * * The SEPARATOR field shall contain the five ASCII * characters ",i,0x". @@ -177,23 +174,24 @@ static int iscsi_get_pr_transport_id( * (see RFC 3720) in the form of ASCII characters that are the * hexadecimal digits converted from the binary iSCSI initiator * session identifier value. The first ISCSI INITIATOR SESSION - * ID field byte containing an ASCII null character + * ID field byte containing an ASCII null character terminates + * the ISCSI INITIATOR SESSION ID field without regard for the + * specified length of the iSCSI TransportID or the contents + * of the ADDITIONAL LENGTH field. */ - buf[off+len] = 0x2c; off++; /* ASCII Character: "," */ - buf[off+len] = 0x69; off++; /* ASCII Character: "i" */ - buf[off+len] = 0x2c; off++; /* ASCII Character: "," */ - buf[off+len] = 0x30; off++; /* ASCII Character: "0" */ - buf[off+len] = 0x78; off++; /* ASCII Character: "x" */ - len += 5; - buf[off+len] = pr_reg->pr_reg_isid[0]; off++; - buf[off+len] = pr_reg->pr_reg_isid[1]; off++; - buf[off+len] = pr_reg->pr_reg_isid[2]; off++; - buf[off+len] = pr_reg->pr_reg_isid[3]; off++; - buf[off+len] = pr_reg->pr_reg_isid[4]; off++; - buf[off+len] = pr_reg->pr_reg_isid[5]; off++; - buf[off+len] = '\0'; off++; - len += 7; + buf[off++] = 0x2c; /* ASCII Character: "," */ + buf[off++] = 0x69; /* ASCII Character: "i" */ + buf[off++] = 0x2c; /* ASCII Character: "," */ + buf[off++] = 0x30; /* ASCII Character: "0" */ + buf[off++] = 0x78; /* ASCII Character: "x" */ + + memcpy(buf + off, pr_reg->pr_reg_isid, 12); + off += 12; + + len += 17; } + buf[off] = '\0'; + len += 1; spin_unlock_irq(&se_nacl->nacl_sess_lock); /* * The ADDITIONAL LENGTH field specifies the number of bytes that follow From patchwork Thu Jul 2 01:43:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB5B513B4 for ; Thu, 2 Jul 2020 01:43:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90B02207D4 for ; Thu, 2 Jul 2020 01:43:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="OPxGddzl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728226AbgGBBnd (ORCPT ); Wed, 1 Jul 2020 21:43:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51526 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726982AbgGBBna (ORCPT ); Wed, 1 Jul 2020 21:43:30 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621cE1I153722; Thu, 2 Jul 2020 01:43:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=DWAIxulAH+tb9paAnCtFhRyJYCxj9IZByO0kan0Qh5c=; b=OPxGddzleqanBu12q7nSsP3Tzyo/hy1hUrbbngGvCdMU+b29UPMF6c6GqF+aCCIogEFI lmfJ9RTAy1JgLhzNBClatJXGPUtkKwoA2zaXzkYuNV9pjPC19UFT0c+PGz3eWeWaYHDY 4wooiRNKYo8VS17obzY8X5TMhk7SOcXk93ZfSPeVk667ddt2ZjfWbbqYMtqxQmqfCVy4 iEFrAS/ehTttsZb3jBSFVIHIO3tkO+b+iCafEwvz6b5RUetF46rMIuN8+XtTNCyWZONc UJpyhp4hxvBn9vtXuieVl8PoJBiNXpAmbdQBjqKQP93S0ZKRUMiDPZBgTFcec/q08e5F DA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 31wxrndng5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:43:27 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621bvvP181672; Thu, 2 Jul 2020 01:43:26 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 31xg204ty2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:26 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0621hQTJ030548; Thu, 2 Jul 2020 01:43:26 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:25 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 6/7] target: fix iscsi transport id buf len calculation Date: Wed, 1 Jul 2020 20:43:22 -0500 Message-Id: <1593654203-12442-7-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org The isid returned to the initiator is in string format which is 12 bytes. We also only add 1 terminating NULL and not one after the initiator name and another one after the isid. Signed-off-by: Mike Christie --- drivers/target/target_core_fabric_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index 428e5a1..1d2762a 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -234,7 +234,7 @@ static int iscsi_get_pr_transport_id_len( */ if (pr_reg->isid_present_at_reg) { len += 5; /* For ",i,0x" ASCII separator */ - len += 7; /* For iSCSI Initiator Session ID + Null terminator */ + len += 12; /* For iSCSI Initiator Session ID */ *format_code = 1; } else *format_code = 0; From patchwork Thu Jul 2 01:43:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11637681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CAC113B4 for ; Thu, 2 Jul 2020 01:43:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 424FE207D4 for ; Thu, 2 Jul 2020 01:43:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="D8GaqqeU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728213AbgGBBnk (ORCPT ); Wed, 1 Jul 2020 21:43:40 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:33912 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726135AbgGBBna (ORCPT ); Wed, 1 Jul 2020 21:43:30 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621cwbn155834; Thu, 2 Jul 2020 01:43:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=fK14tJ8EapNLd8Lo5gCESUlnZUEqFu1GK84uDjIBzWU=; b=D8GaqqeUQLYO1GfS/Ow25clYWVzgneGlXlDNoIweVSyCGwZsb2r8vS0ON5XPsQRdwsml XGH2Mw22iRMLTDSEAlI1xQjyARofW+XvNV32Vhdp7E6wZUYGXGVS3Mz/Rh16v+vUwblA UE/cW7h4/cAQ7Z6/MKR2IEQS12MPoLsjzf+r6d1ZyvAkqXWr6ZhYOlrsMZjjHvl1vLgQ cK/bXEr8iENAC0uMgGMv3kbuXRKB4Yzm9B/Q0tvhPAUDv/Qyw5vfEpVq9KUTnXGj79Ao TgjooIYqsTX6gOD/suAV99FIpouq5W1A9fVFEAyxwsLASfEQzdOZrHh98G9s0Kz3LlPd TQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 31xx1e2hur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 02 Jul 2020 01:43:28 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0621bqLd181516; Thu, 2 Jul 2020 01:43:27 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 31xg204ty9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jul 2020 01:43:27 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0621hQpD017167; Thu, 2 Jul 2020 01:43:26 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jul 2020 01:43:26 +0000 From: Mike Christie To: martin.petersen@oracle.com, bstroesser@ts.fujitsu.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 7/7] target: handle short iSIDs Date: Wed, 1 Jul 2020 20:43:23 -0500 Message-Id: <1593654203-12442-8-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> References: <1593654203-12442-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9669 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=0 mlxlogscore=999 cotscore=-2147483648 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020009 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org SPC4 has: The first ISCSI INITIATOR SESSION ID field byte containing an ASCII null character terminates the ISCSI INITIATOR SESSION ID field without regard for the specified length of the iSCSI TransportID or the contents of the ADDITIONAL LENGTH field. ---------------------------------------- which sounds like we can get an iSID shorter than 12 chars. SPC and the iSCSI RFC do not say how to handle that case other than just cutting off the iSID. This patch just makes sure that if we get an iSID like that, we only copy/send that string. There is no OS that does this right now, so there was no test case. I did test with sg utils to check it works as expected and nothing breaks. Signed-off-by: Mike Christie --- drivers/target/target_core_fabric_lib.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index 1d2762a..6600ae4 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -132,6 +132,7 @@ static int iscsi_get_pr_transport_id( unsigned char *buf) { u32 off = 4, padding = 0; + int isid_len; u16 len = 0; spin_lock_irq(&se_nacl->nacl_sess_lock); @@ -184,11 +185,11 @@ static int iscsi_get_pr_transport_id( buf[off++] = 0x2c; /* ASCII Character: "," */ buf[off++] = 0x30; /* ASCII Character: "0" */ buf[off++] = 0x78; /* ASCII Character: "x" */ + len += 5; - memcpy(buf + off, pr_reg->pr_reg_isid, 12); - off += 12; - - len += 17; + isid_len = sprintf(buf + off, "%s", pr_reg->pr_reg_isid); + off += isid_len; + len += isid_len; } buf[off] = '\0'; len += 1; @@ -234,7 +235,7 @@ static int iscsi_get_pr_transport_id_len( */ if (pr_reg->isid_present_at_reg) { len += 5; /* For ",i,0x" ASCII separator */ - len += 12; /* For iSCSI Initiator Session ID */ + len += strlen(pr_reg->pr_reg_isid); *format_code = 1; } else *format_code = 0; @@ -318,6 +319,16 @@ static char *iscsi_parse_pr_out_transport_id( * iscsi_target.c:lio_sess_get_initiator_sid() */ for (i = 0; i < 12; i++) { + /* + * The first ISCSI INITIATOR SESSION ID field byte + * containing an ASCII null character terminates the + * ISCSI INITIATOR SESSION ID field without regard for + * the specified length of the iSCSI TransportID or the + * contents of the ADDITIONAL LENGTH field. + */ + if (*p == '\0') + break; + if (isdigit(*p)) { p++; continue;