All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet-fc: fix issues with targetport assoc_list list walking
@ 2019-02-05 17:38 James Smart
  2019-02-06 13:44 ` Ewan D. Milne
  2019-03-12 19:30 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: James Smart @ 2019-02-05 17:38 UTC (permalink / raw)


There are two changes:

1) The logic in the __nvmet_fc_free_assoc() routine is bad. It uses
"safe" routines assuming pointers will come back valid. However,
the intervening next structure being linked can be removed from the
list and the resulting safe pointers are bad, resulting in NULL ptrs
being hit.

Correct by scheduling a work element to perform the association
delete, which can be done while under lock.

2) Prior patch that added the work element scheduling left a
possible reference on the object if the work element couldn't
be scheduled

Correct by doing the put on a failing schedule_work() call.

Signed-off-by: Nigel Kirkland <nigel.kirkland at broadcom.com>
Signed-off-by: James Smart <jsmart2021 at gmail.com>
---
 drivers/nvme/target/fc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index f98f5c5bea26..9d065850cda4 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1155,10 +1155,8 @@ __nvmet_fc_free_assocs(struct nvmet_fc_tgtport *tgtport)
 				&tgtport->assoc_list, a_list) {
 		if (!nvmet_fc_tgt_a_get(assoc))
 			continue;
-		spin_unlock_irqrestore(&tgtport->lock, flags);
-		nvmet_fc_delete_target_assoc(assoc);
-		nvmet_fc_tgt_a_put(assoc);
-		spin_lock_irqsave(&tgtport->lock, flags);
+		if (!schedule_work(&assoc->del_work))
+			nvmet_fc_tgt_a_put(assoc);
 	}
 	spin_unlock_irqrestore(&tgtport->lock, flags);
 }
@@ -1197,7 +1195,8 @@ nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl)
 		nvmet_fc_tgtport_put(tgtport);
 
 		if (found_ctrl) {
-			schedule_work(&assoc->del_work);
+			if (schedule_work(&assoc->del_work))
+				nvmet_fc_tgt_a_put(assoc);
 			return;
 		}
 
-- 
2.13.7

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] nvmet-fc: fix issues with targetport assoc_list list walking
  2019-02-05 17:38 [PATCH] nvmet-fc: fix issues with targetport assoc_list list walking James Smart
@ 2019-02-06 13:44 ` Ewan D. Milne
  2019-03-12 19:30 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Ewan D. Milne @ 2019-02-06 13:44 UTC (permalink / raw)


On Tue, 2019-02-05@09:38 -0800, James Smart wrote:
> There are two changes:
> 
> 1) The logic in the __nvmet_fc_free_assoc() routine is bad. It uses
> "safe" routines assuming pointers will come back valid. However,
> the intervening next structure being linked can be removed from the
> list and the resulting safe pointers are bad, resulting in NULL ptrs
> being hit.
> 
> Correct by scheduling a work element to perform the association
> delete, which can be done while under lock.
> 
> 2) Prior patch that added the work element scheduling left a
> possible reference on the object if the work element couldn't
> be scheduled
> 
> Correct by doing the put on a failing schedule_work() call.
> 
> Signed-off-by: Nigel Kirkland <nigel.kirkland at broadcom.com>
> Signed-off-by: James Smart <jsmart2021 at gmail.com>
> ---
>  drivers/nvme/target/fc.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index f98f5c5bea26..9d065850cda4 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -1155,10 +1155,8 @@ __nvmet_fc_free_assocs(struct nvmet_fc_tgtport *tgtport)
>  				&tgtport->assoc_list, a_list) {
>  		if (!nvmet_fc_tgt_a_get(assoc))
>  			continue;
> -		spin_unlock_irqrestore(&tgtport->lock, flags);
> -		nvmet_fc_delete_target_assoc(assoc);
> -		nvmet_fc_tgt_a_put(assoc);
> -		spin_lock_irqsave(&tgtport->lock, flags);
> +		if (!schedule_work(&assoc->del_work))
> +			nvmet_fc_tgt_a_put(assoc);
>  	}
>  	spin_unlock_irqrestore(&tgtport->lock, flags);
>  }
> @@ -1197,7 +1195,8 @@ nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl)
>  		nvmet_fc_tgtport_put(tgtport);
>  
>  		if (found_ctrl) {
> -			schedule_work(&assoc->del_work);
> +			if (schedule_work(&assoc->del_work))
> +				nvmet_fc_tgt_a_put(assoc);
>  			return;
>  		}
>  

Reviewed-by: Ewan D. Milne <emilne at redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] nvmet-fc: fix issues with targetport assoc_list list walking
  2019-02-05 17:38 [PATCH] nvmet-fc: fix issues with targetport assoc_list list walking James Smart
  2019-02-06 13:44 ` Ewan D. Milne
@ 2019-03-12 19:30 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2019-03-12 19:30 UTC (permalink / raw)


Thanks,

applied to nvme-5.1.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-12 19:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-05 17:38 [PATCH] nvmet-fc: fix issues with targetport assoc_list list walking James Smart
2019-02-06 13:44 ` Ewan D. Milne
2019-03-12 19:30 ` Christoph Hellwig

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.