All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Gurtovoy <maxg@mellanox.com>
To: Leon Romanovsky <leon@kernel.org>, Doug Ledford <dledford@redhat.com>
Cc: linux-rdma@vger.kernel.org,
	Vladimir Neyelov <vladimirn@mellanox.com>,
	stable@vger.kernel.org, sagig <sagi@grimberg.me>
Subject: Re: [PATCH rdma-next] IB/iser: Fix connection teardown race condition
Date: Thu, 25 May 2017 18:24:59 +0300	[thread overview]
Message-ID: <98334f53-a7ff-d465-989f-a5ee7add2291@mellanox.com> (raw)
In-Reply-To: <20170521161731.22223-1-leon@kernel.org>

Hi Sagi,

what do you think on this approach ?
we must somehow defend on the NULL deref in case dd_data in iscsi_conn 
(the iser_conn) already NULL due to conn_stop call.


>
> diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
> index 5a887efb4bdf..9ba649836d86 100644
> --- a/drivers/infiniband/ulp/iser/iscsi_iser.c
> +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
> @@ -83,6 +83,7 @@ static struct scsi_host_template iscsi_iser_sht;
>  static struct iscsi_transport iscsi_iser_transport;
>  static struct scsi_transport_template *iscsi_iser_scsi_transport;
>  static struct workqueue_struct *release_wq;
> +static DEFINE_MUTEX(unbind_iser_conn_mutex);
>  struct iser_global ig;
>
>  int iser_debug_level = 0;
> @@ -550,12 +551,14 @@ iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
>  	 */
>  	if (iser_conn) {
>  		mutex_lock(&iser_conn->state_mutex);
> +		mutex_lock(&unbind_iser_conn_mutex);
>  		iser_conn_terminate(iser_conn);
>  		iscsi_conn_stop(cls_conn, flag);
>
>  		/* unbind */
>  		iser_conn->iscsi_conn = NULL;
>  		conn->dd_data = NULL;
> +		mutex_unlock(&unbind_iser_conn_mutex);
>
>  		complete(&iser_conn->stop_completion);
>  		mutex_unlock(&iser_conn->state_mutex);
> @@ -977,13 +980,21 @@ static int iscsi_iser_slave_alloc(struct scsi_device *sdev)
>  	struct iser_conn *iser_conn;
>  	struct ib_device *ib_dev;
>
> +	mutex_lock(&unbind_iser_conn_mutex);
> +
>  	session = starget_to_session(scsi_target(sdev))->dd_data;
>  	iser_conn = session->leadconn->dd_data;
> +	if (!iser_conn) {
> +		mutex_unlock(&unbind_iser_conn_mutex);
> +		return -ENOTCONN;
> +	}
>  	ib_dev = iser_conn->ib_conn.device->ib_device;
>
>  	if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG))
>  		blk_queue_virt_boundary(sdev->request_queue, ~MASK_4K);
>
> +	mutex_unlock(&unbind_iser_conn_mutex);
> +
>  	return 0;
>  }
>
> --
> 2.12.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

WARNING: multiple messages have this Message-ID (diff)
From: Max Gurtovoy <maxg@mellanox.com>
To: Leon Romanovsky <leon@kernel.org>, Doug Ledford <dledford@redhat.com>
Cc: <linux-rdma@vger.kernel.org>,
	Vladimir Neyelov <vladimirn@mellanox.com>,
	<stable@vger.kernel.org>, sagig <sagi@grimberg.me>
Subject: Re: [PATCH rdma-next] IB/iser: Fix connection teardown race condition
Date: Thu, 25 May 2017 18:24:59 +0300	[thread overview]
Message-ID: <98334f53-a7ff-d465-989f-a5ee7add2291@mellanox.com> (raw)
In-Reply-To: <20170521161731.22223-1-leon@kernel.org>

Hi Sagi,

what do you think on this approach ?
we must somehow defend on the NULL deref in case dd_data in iscsi_conn 
(the iser_conn) already NULL due to conn_stop call.


>
> diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
> index 5a887efb4bdf..9ba649836d86 100644
> --- a/drivers/infiniband/ulp/iser/iscsi_iser.c
> +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
> @@ -83,6 +83,7 @@ static struct scsi_host_template iscsi_iser_sht;
>  static struct iscsi_transport iscsi_iser_transport;
>  static struct scsi_transport_template *iscsi_iser_scsi_transport;
>  static struct workqueue_struct *release_wq;
> +static DEFINE_MUTEX(unbind_iser_conn_mutex);
>  struct iser_global ig;
>
>  int iser_debug_level = 0;
> @@ -550,12 +551,14 @@ iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
>  	 */
>  	if (iser_conn) {
>  		mutex_lock(&iser_conn->state_mutex);
> +		mutex_lock(&unbind_iser_conn_mutex);
>  		iser_conn_terminate(iser_conn);
>  		iscsi_conn_stop(cls_conn, flag);
>
>  		/* unbind */
>  		iser_conn->iscsi_conn = NULL;
>  		conn->dd_data = NULL;
> +		mutex_unlock(&unbind_iser_conn_mutex);
>
>  		complete(&iser_conn->stop_completion);
>  		mutex_unlock(&iser_conn->state_mutex);
> @@ -977,13 +980,21 @@ static int iscsi_iser_slave_alloc(struct scsi_device *sdev)
>  	struct iser_conn *iser_conn;
>  	struct ib_device *ib_dev;
>
> +	mutex_lock(&unbind_iser_conn_mutex);
> +
>  	session = starget_to_session(scsi_target(sdev))->dd_data;
>  	iser_conn = session->leadconn->dd_data;
> +	if (!iser_conn) {
> +		mutex_unlock(&unbind_iser_conn_mutex);
> +		return -ENOTCONN;
> +	}
>  	ib_dev = iser_conn->ib_conn.device->ib_device;
>
>  	if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG))
>  		blk_queue_virt_boundary(sdev->request_queue, ~MASK_4K);
>
> +	mutex_unlock(&unbind_iser_conn_mutex);
> +
>  	return 0;
>  }
>
> --
> 2.12.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

  reply	other threads:[~2017-05-25 15:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-21 16:17 [PATCH rdma-next] IB/iser: Fix connection teardown race condition Leon Romanovsky
2017-05-21 16:17 ` Leon Romanovsky
2017-05-25 15:24 ` Max Gurtovoy [this message]
2017-05-25 15:24   ` Max Gurtovoy
2017-05-30 11:50   ` Sagi Grimberg
     [not found]     ` <fa976fe5-be25-1c6a-5997-8fa7524e89d8-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
2017-07-22 17:17       ` Doug Ledford
2017-07-22 17:17         ` Doug Ledford

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=98334f53-a7ff-d465-989f-a5ee7add2291@mellanox.com \
    --to=maxg@mellanox.com \
    --cc=dledford@redhat.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sagi@grimberg.me \
    --cc=stable@vger.kernel.org \
    --cc=vladimirn@mellanox.com \
    /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.