From: Mike Christie <mchristi@redhat.com>
To: target-devel@vger.kernel.org
Subject: [PATCH 02/15] target: fix isid copying and comparision
Date: Sun, 15 Jul 2018 23:16:18 +0000 [thread overview]
Message-ID: <1531696591-8558-3-git-send-email-mchristi@redhat.com> (raw)
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 <mchristi@redhat.com>
---
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);
--
2.7.2
next reply other threads:[~2018-07-15 23:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-15 23:16 Mike Christie [this message]
2018-07-18 22:09 ` [PATCH 02/15] target: fix isid copying and comparision Bart Van Assche
2018-07-19 0:03 ` Mike Christie
2018-07-19 1:02 ` Mike Christie
2018-07-19 15:15 ` Bart Van Assche
2018-07-19 16:13 ` Mike Christie
2018-07-20 21:08 ` Mike Christie
2018-07-20 21:15 ` Mike Christie
2018-07-20 22:24 ` Bart Van Assche
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=1531696591-8558-3-git-send-email-mchristi@redhat.com \
--to=mchristi@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).