From: Sagi Grimberg <sagig@dev.mellanox.co.il>
To: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Cc: "Nicholas A. Bellinger" <nab@daterainc.com>,
target-devel <target-devel@vger.kernel.org>,
linux-scsi <linux-scsi@vger.kernel.org>,
Sagi Grimberg <sagig@mellanox.com>,
Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>
Subject: Re: [PATCH] target: Fix target_sense_desc_format NULL pointer dereference
Date: Thu, 17 Sep 2015 09:53:27 +0300 [thread overview]
Message-ID: <55FA6367.7020105@dev.mellanox.co.il> (raw)
In-Reply-To: <1442462652.23132.25.camel@haakon3.risingtidesystems.com>
> How about the following to fix up TCM_WRITE_PROTECT + D_SENSE..?
>
> diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
> index abf2076..ba102c5 100644
> --- a/drivers/target/target_core_device.c
> +++ b/drivers/target/target_core_device.c
> @@ -62,22 +62,13 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
> struct se_session *se_sess = se_cmd->se_sess;
> struct se_node_acl *nacl = se_sess->se_node_acl;
> struct se_dev_entry *deve;
> + sense_reason_t ret = TCM_NO_SENSE;
>
> rcu_read_lock();
> deve = target_nacl_find_deve(nacl, unpacked_lun);
> if (deve) {
> atomic_long_inc(&deve->total_cmds);
>
> - if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
> - (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) {
> - pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
> - " Access for 0x%08llx\n",
> - se_cmd->se_tfo->get_fabric_name(),
> - unpacked_lun);
> - rcu_read_unlock();
> - return TCM_WRITE_PROTECTED;
> - }
> -
> if (se_cmd->data_direction == DMA_TO_DEVICE)
> atomic_long_add(se_cmd->data_length,
> &deve->write_bytes);
> @@ -93,6 +84,17 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
>
> percpu_ref_get(&se_lun->lun_ref);
> se_cmd->lun_ref_active = true;
> +
> + if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
> + (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) {
> + pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
> + " Access for 0x%08llx\n",
> + se_cmd->se_tfo->get_fabric_name(),
> + unpacked_lun);
> + rcu_read_unlock();
> + ret = TCM_WRITE_PROTECTED;
> + goto ref_dev;
> + }
> }
> rcu_read_unlock();
>
> @@ -109,12 +111,6 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
> unpacked_lun);
> return TCM_NON_EXISTENT_LUN;
> }
> - /*
> - * Force WRITE PROTECT for virtual LUN 0
> - */
> - if ((se_cmd->data_direction != DMA_FROM_DEVICE) &&
> - (se_cmd->data_direction != DMA_NONE))
> - return TCM_WRITE_PROTECTED;
>
> se_lun = se_sess->se_tpg->tpg_virt_lun0;
> se_cmd->se_lun = se_sess->se_tpg->tpg_virt_lun0;
> @@ -123,6 +119,15 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
>
> percpu_ref_get(&se_lun->lun_ref);
> se_cmd->lun_ref_active = true;
> +
> + /*
> + * Force WRITE PROTECT for virtual LUN 0
> + */
> + if ((se_cmd->data_direction != DMA_FROM_DEVICE) &&
> + (se_cmd->data_direction != DMA_NONE)) {
> + ret = TCM_WRITE_PROTECTED;
> + goto ref_dev;
> + }
> }
> /*
> * RCU reference protected by percpu se_lun->lun_ref taken above that
> @@ -130,6 +135,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
> * pointer can be kfree_rcu() by the final se_lun->lun_group put via
> * target_core_fabric_configfs.c:target_fabric_port_release
> */
> +ref_dev:
> se_cmd->se_dev = rcu_dereference_raw(se_lun->lun_se_dev);
> atomic_long_inc(&se_cmd->se_dev->num_cmds);
So transport_lookup_cmd_lun() will always assign se_dev. Looks fine.
You can add when resubmitting:
Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
Thanks Nic.
prev parent reply other threads:[~2015-09-17 6:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 6:31 [PATCH] target: Fix target_sense_desc_format NULL pointer dereference Nicholas A. Bellinger
2015-09-16 12:08 ` Sagi Grimberg
2015-09-17 4:04 ` Nicholas A. Bellinger
2015-09-17 6:53 ` Sagi Grimberg [this message]
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=55FA6367.7020105@dev.mellanox.co.il \
--to=sagig@dev.mellanox.co.il \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@daterainc.com \
--cc=nab@linux-iscsi.org \
--cc=sagig@mellanox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.