Skip to content

Commit 417c20a

Browse files
author
Nicholas Bellinger
committed
iscsi-target: Fix use-after-free during TPG session shutdown
This patch fixes a use-after-free bug in iscsit_release_sessions_for_tpg() where se_portal_group->session_lock was incorrectly released/re-acquired while walking the active se_portal_group->tpg_sess_list. The can result in a NULL pointer dereference when iscsit_close_session() shutdown happens in the normal path asynchronously to this code, causing a bogus dereference of an already freed list entry to occur. To address this bug, walk the session list checking for the same state as before, but move entries to a local list to avoid dropping the lock while walking the active list. As before, signal using iscsi_session->session_restatement=1 for those list entries to be released locally by iscsit_free_session() code. Reported-by: Sunilkumar Nadumuttlu <sjn@datera.io> Cc: Sunilkumar Nadumuttlu <sjn@datera.io> Cc: <stable@vger.kernel.org> # v3.1+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 7359df2 commit 417c20a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/target/iscsi/iscsi_target.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,6 +4765,7 @@ int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *tpg, int force)
47654765
struct iscsi_session *sess;
47664766
struct se_portal_group *se_tpg = &tpg->tpg_se_tpg;
47674767
struct se_session *se_sess, *se_sess_tmp;
4768+
LIST_HEAD(free_list);
47684769
int session_count = 0;
47694770

47704771
spin_lock_bh(&se_tpg->session_lock);
@@ -4786,14 +4787,17 @@ int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *tpg, int force)
47864787
}
47874788
atomic_set(&sess->session_reinstatement, 1);
47884789
spin_unlock(&sess->conn_lock);
4789-
spin_unlock_bh(&se_tpg->session_lock);
47904790

4791-
iscsit_free_session(sess);
4792-
spin_lock_bh(&se_tpg->session_lock);
4791+
list_move_tail(&se_sess->sess_list, &free_list);
4792+
}
4793+
spin_unlock_bh(&se_tpg->session_lock);
47934794

4795+
list_for_each_entry_safe(se_sess, se_sess_tmp, &free_list, sess_list) {
4796+
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
4797+
4798+
iscsit_free_session(sess);
47944799
session_count++;
47954800
}
4796-
spin_unlock_bh(&se_tpg->session_lock);
47974801

47984802
pr_debug("Released %d iSCSI Session(s) from Target Portal"
47994803
" Group: %hu\n", session_count, tpg->tpgt);

0 commit comments

Comments
 (0)