From patchwork Sun Jul 15 23:16:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 10525289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 08F5F60545 for ; Sun, 15 Jul 2018 23:16:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE08E288A6 for ; Sun, 15 Jul 2018 23:16:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E207C28958; Sun, 15 Jul 2018 23:16:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 729AF2894D for ; Sun, 15 Jul 2018 23:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727296AbeGOXlQ (ORCPT ); Sun, 15 Jul 2018 19:41:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41716 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727125AbeGOXlP (ORCPT ); Sun, 15 Jul 2018 19:41:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C0564001868; Sun, 15 Jul 2018 23:16:42 +0000 (UTC) Received: from rh2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3BC276EA; Sun, 15 Jul 2018 23:16:41 +0000 (UTC) From: Mike Christie To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, nab@linux-iscsi.org Cc: Mike Christie Subject: [PATCH 02/15] target: fix isid copying and comparision Date: Sun, 15 Jul 2018 18:16:18 -0500 Message-Id: <1531696591-8558-3-git-send-email-mchristi@redhat.com> In-Reply-To: <1531696591-8558-1-git-send-email-mchristi@redhat.com> References: <1531696591-8558-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 15 Jul 2018 23:16:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 15 Jul 2018 23:16:42 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mchristi@redhat.com' RCPT:'' Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The isid is 48 bits, and in hex string format it's 12 bytes. We are currently copying the 12 byte hex string to a u64 so we can easily compare it, but this has the problem that only 8 bytes of the 12 bytes are copied. The next patches will want to print se_session sess_bin_isid so this has us use hex2bin to when converting from the hex sting to the bin value. Signed-off-by: Mike Christie --- drivers/target/target_core_pr.c | 20 ++++++++++++++++---- drivers/target/target_core_transport.c | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 01ac306..65e5253 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -662,8 +662,7 @@ static struct t10_pr_registration *__core_scsi3_do_alloc_registration( rcu_read_unlock(); pr_err("Unable to locate PR deve %s mapped_lun: %llu\n", nacl->initiatorname, mapped_lun); - kmem_cache_free(t10_pr_reg_cache, pr_reg); - return NULL; + goto free_reg; } kref_get(&pr_reg->pr_reg_deve->pr_kref); rcu_read_unlock(); @@ -679,12 +678,20 @@ static struct t10_pr_registration *__core_scsi3_do_alloc_registration( * save it to the registration now. */ if (isid != NULL) { - pr_reg->pr_reg_bin_isid = get_unaligned_be64(isid); + if (hex2bin((u8 *)&pr_reg->pr_reg_bin_isid, isid, 6)) { + pr_err("Invalid isid %s\n", isid); + goto free_reg; + } + snprintf(pr_reg->pr_reg_isid, PR_REG_ISID_LEN, "%s", isid); pr_reg->isid_present_at_reg = 1; } return pr_reg; + +free_reg: + kmem_cache_free(t10_pr_reg_cache, pr_reg); + return NULL; } static int core_scsi3_lunacl_depend_item(struct se_dev_entry *); @@ -873,7 +880,12 @@ int core_scsi3_alloc_aptpl_registration( * SCSI Initiator Port, restore it now. */ if (isid != NULL) { - pr_reg->pr_reg_bin_isid = get_unaligned_be64(isid); + if (hex2bin((u8 *)&pr_reg->pr_reg_bin_isid, isid, 6)) { + pr_err("Invalid isid %s\n", isid); + kmem_cache_free(t10_pr_reg_cache, pr_reg); + return -EINVAL; + } + snprintf(pr_reg->pr_reg_isid, PR_REG_ISID_LEN, "%s", isid); pr_reg->isid_present_at_reg = 1; } diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7261561..6324743 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -380,7 +380,8 @@ void __transport_register_session( memset(&buf[0], 0, PR_REG_ISID_LEN); se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, &buf[0], PR_REG_ISID_LEN); - se_sess->sess_bin_isid = get_unaligned_be64(&buf[0]); + + WARN_ON(hex2bin((u8 *)&se_sess->sess_bin_isid, buf, 6)); } spin_lock_irq(&se_nacl->nacl_sess_lock);