Skip to content

Commit 9411a89

Browse files
maurizio-lombardimartinkpetersen
authored andcommitted
scsi: target: iscsi: Fix use-after-free in iscsit_dec_conn_usage_count()
In iscsit_dec_conn_usage_count(), the function calls complete() while holding the conn->conn_usage_lock. As soon as complete() is invoked, the waiter (such as iscsit_close_connection()) may wake up and proceed to free the iscsit_conn structure. If the waiter frees the memory before the current thread reaches spin_unlock_bh(), it results in a KASAN slab-use-after-free as the function attempts to release a lock within the already-freed connection structure. Fix this by releasing the spinlock before calling complete(). Signed-off-by: Maurizio Lombardi <mlombard@redhat.com> Reported-by: Zhaojuan Guo <zguo@redhat.com> Reviewed-by: Mike Christie <michael.christie@oracle.com> Link: https://patch.msgid.link/20260112165352.138606-2-mlombard@redhat.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent fe2f8ad commit 9411a89

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/target/iscsi/iscsi_target_util.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,11 @@ void iscsit_dec_conn_usage_count(struct iscsit_conn *conn)
810810
spin_lock_bh(&conn->conn_usage_lock);
811811
conn->conn_usage_count--;
812812

813-
if (!conn->conn_usage_count && conn->conn_waiting_on_uc)
813+
if (!conn->conn_usage_count && conn->conn_waiting_on_uc) {
814+
spin_unlock_bh(&conn->conn_usage_lock);
814815
complete(&conn->conn_waiting_on_uc_comp);
816+
return;
817+
}
815818

816819
spin_unlock_bh(&conn->conn_usage_lock);
817820
}

0 commit comments

Comments
 (0)