nvmet-fc: fix issues with targetport assoc_list list walking
Subsystems (3)
PATCH 1/1 nvmet-fc: fix issues with targetport assoc_list list walking
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.
--- drivers/nvme/target/fc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/nvme/target/fc.c +4 -5
@@ -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 ; }
Signature · 1 line
2.13.7
PATCH 1/1 nvmet-fc: fix issues with targetport assoc_list list walking
Quoted 41 lines · James Smart
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(-)drivers/nvme/target/fc.c +2
-4@@ -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); }
drivers/nvme/target/fc.c nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl) · line 1202
Quoted 9 lines
drivers/nvme/target/fc.c +2
-1@@ -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 ; }
Christoph Hellwig
AppliedPATCH 1/1 nvmet-fc: fix issues with targetport assoc_list list walking
In reply to James SmartThanks,
applied to nvme-5.1.