Skip to contentSkip to conversation

nvmet-fc: Tear down the association when the admin queue allocation fails

PATCH Applied Guixin Liu 3 participants 3 messages Oct 26

Subsystems (3)
lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH 1/1 nvmet-fc: Tear down the association when the admin queue allocation fails

When the initial admin queue allocation fails after a new association was created, nvmet_fc_ls_create_association() only drops the association reference, which frees the association. By then the association is already on the target port's assoc_list, though, and removal from that list only happens in nvmet_fc_delete_target_assoc(), which this error path never calls. The freed association stays on the list, where later lookups and the port teardown can access it, and the target port reference taken at allocation time leaks.

A remote host can trigger this reliably with a Create Association LS requesting a queue too large to allocate.

Schedule the regular association teardown instead of dropping the reference directly. The teardown removes the association from the list and releases the target port reference before the final reference drop frees it.

Fixes 0cab4404874f ("nvme-fc: fix a missing queue put in nvmet_fc_ls_create_association")
---
 drivers/nvme/target/fc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/fc.c +1 -1
index 1b557775e033..2d68a355cf79 100644
@@ -1705,7 +1705,7 @@ nvmet_fc_ls_create_association(struct nvmet_fc_tgtport *tgtport,
 					be16_to_cpu(rqst->assoc_cmd.sqsize));
 			if (!queue) {
 				ret = VERR_QUEUE_ALLOC_FAIL;
-				nvmet_fc_tgt_a_put(iod->assoc);
+				nvmet_fc_schedule_delete_assoc(iod->assoc);
 			}
 		}
 	}
Signature · 1 line
2.43.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Guixin Liu

When the initial admin queue allocation fails after a new association was created, nvmet_fc_ls_create_association() only drops the association reference, which frees the association. By then the association is already on the target port's assoc_list, though, and removal from that list only happens in nvmet_fc_delete_target_assoc(), which this error path never calls. The freed association stays on the list, where later lookups and the port teardown can access it, and the target port reference taken at allocation time leaks.

A remote host can trigger this reliably with a Create Association LS requesting a queue too large to allocate.

Quoted 8 lines

Schedule the regular association teardown instead of dropping the reference directly. The teardown removes the association from the list and releases the target port reference before the final reference drop frees it.

Fixes 0cab4404874f ("nvme-fc: fix a missing queue put in nvmet_fc_ls_create_association")

Looks good to me.

maintainer Applied
#2 lore raw
In reply to Guixin Liu
Quoted 9 lines · Guixin Liu

When the initial admin queue allocation fails after a new association was created, nvmet_fc_ls_create_association() only drops the association reference, which frees the association. By then the association is already on the target port's assoc_list, though, and removal from that list only happens in nvmet_fc_delete_target_assoc(), which this error path never calls. The freed association stays on the list, where later lookups and the port teardown can access it, and the target port reference taken at allocation time leaks.

Quoted 7 lines

A remote host can trigger this reliably with a Create Association LS requesting a queue too large to allocate.

Schedule the regular association teardown instead of dropping the reference directly. The teardown removes the association from the list and releases the target port reference before the final reference drop frees it.

Thanks, applied to nvme-7.4.