Skip to contentSkip to conversation

IB/isert: Don't share drop_cmd_list across concurrent connection teardowns

PATCH Applied lirongqing 3 participants 3 messages Sep 21 – Sep 28

Subsystems (3)
lore
Share & tools
lore

lirongqing

author
#0 lore raw

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().

Fixes 3e03c4b01da3 ("iser-target: Put the reference on commands waiting for unsol data")
---
 drivers/infiniband/ulp/isert/ib_isert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/isert/ib_isert.c +1 -1
index e69db43..efa8d7b 100644
@@ -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
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

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.

Quoted 5 lines

Make drop_cmd_list a stack-local list, matching the pattern already used in isert_free_np().

Fixes 3e03c4b01da3 ("iser-target: Put the reference on commands waiting for unsol data")

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
#2 lore raw
In reply to lirongqing
Quoted 6 lines · lirongqing

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.

Quoted 7 lines

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.

[...]

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]>