Skip to content

Commit

Permalink
scsi: target: Fix cmd_count ref leak
Browse files Browse the repository at this point in the history
percpu_ref_init sets the refcount to 1 and percpu_ref_kill drops it.
Drivers like iSCSI and loop do not call target_sess_cmd_list_set_waiting
during session shutdown, though, so they have been calling percpu_ref_exit
with a refcount still taken and leaking the cmd_counts memory.

Link: https://lore.kernel.org/r/1604257174-4524-3-git-send-email-michael.christie@oracle.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Mike Christie authored and Martin K. Petersen committed Nov 5, 2020
1 parent a2b5d6f commit 02dd491
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/target/target_core_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ EXPORT_SYMBOL(transport_init_session);

void transport_uninit_session(struct se_session *se_sess)
{
/*
* Drivers like iscsi and loop do not call
* target_sess_cmd_list_set_waiting during session shutdown so we
* have to drop the ref taken at init time here.
*/
if (!se_sess->sess_tearing_down)
percpu_ref_put(&se_sess->cmd_count);

percpu_ref_exit(&se_sess->cmd_count);
}

Expand Down

0 comments on commit 02dd491

Please sign in to comment.