IB/isert: Don't share drop_cmd_list across concurrent connection teardowns
Subsystems (3)
PATCH 1/1 IB/isert: Don't share drop_cmd_list across concurrent connection teardowns
From: Li RongQing <[email protected]>
isert_put_unsol_pending_cmds() declares drop_cmd_list as a static LIST_HEAD, so the list is shared across all invocations of the function. It is called from isert_wait_conn(), the per-connection .iscsit_wait_conn transport callback, which runs independently for each connection during teardown.
conn->cmd_lock only protects each connection's own conn_cmd_list, not the shared drop_cmd_list. If two connections tear down at the same time, both threads list_move_tail() commands into the same drop_cmd_list without any mutual exclusion, and then both iterate and list_del/put it concurrently. This corrupts the linked list and can double-free iscsit_cmd structures.
Make drop_cmd_list a stack-local list, matching the pattern already used in isert_free_np().
--- drivers/infiniband/ulp/isert/ib_isert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/isert/ib_isert.c +1 -1
@@ -2583,7 +2583,7 @@ static void isert_put_unsol_pending_cmds(struct iscsit_conn *conn) {struct iscsit_cmd *cmd, *tmp; -static LIST_HEAD (drop_cmd_list); +LIST_HEAD (drop_cmd_list);spin_lock_bh (&conn->cmd_lock);list_for_each_entry_safe (cmd, tmp, &conn->conn_cmd_list, i_conn_node) {
Signature · 1 line
2.9.4
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines
From: Li RongQing <[email protected]>
isert_put_unsol_pending_cmds()declaresdrop_cmd_listas a staticLIST_HEAD, so the list is shared across all invocations of the function. It is called fromisert_wait_conn(), the per-connection .iscsit_wait_conn transport callback, which runs independently for each connection during teardown.
conn->cmd_lockonly protects each connection's ownconn_cmd_list, not the shareddrop_cmd_list. If two connections tear down at the same time, both threadslist_move_tail()commands into the samedrop_cmd_listwithout any mutual exclusion, and then both iterate and list_del/put it concurrently. This corrupts the linked list and can double-freeiscsit_cmdstructures.
Quoted 5 lines
Make
drop_cmd_lista stack-local list, matching the pattern already used inisert_free_np().Fixes 3e03c4b01da3 ("iser-target: Put the reference on commands waiting for unsol data")Signed-off-by Li RongQing <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Leon Romanovsky
AppliedQuoted 6 lines · lirongqing
isert_put_unsol_pending_cmds()declaresdrop_cmd_listas a staticLIST_HEAD, so the list is shared across all invocations of the function. It is called fromisert_wait_conn(), the per-connection .iscsit_wait_conn transport callback, which runs independently for each connection during teardown.
Quoted 7 lines
conn->cmd_lockonly protects each connection's ownconn_cmd_list, not the shareddrop_cmd_list. If two connections tear down at the same time, both threadslist_move_tail()commands into the samedrop_cmd_listwithout any mutual exclusion, and then both iterate and list_del/put it concurrently. This corrupts the linked list and can double-freeiscsit_cmdstructures.[...]
Applied, thanks!
[1/1] IB/isert: Don't share drop_cmd_list across concurrent connection teardowns
https://git.kernel.org/rdma/rdma/c/d30e9b1bc47bd9
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>