iscsi-target: Fix use-after-free during TPG session shutdown
authorNicholas Bellinger <nab@linux-iscsi.org>
Wed, 22 Jul 2015 07:24:09 +0000 (00:24 -0700)
committerDanny Wood <danwood76@gmail.com>
Tue, 29 Jan 2019 13:09:39 +0000 (13:09 +0000)
commit5319d0b176ecb5b225f14cc64da196542679bf07
treea89f87a15fbfa192360c03786337c41cd3db881d
parent520daff2a8df36f133ca8f3ee84f473b47ab7d53
iscsi-target: Fix use-after-free during TPG session shutdown

commit 417c20a9bdd1e876384127cf096d8ae8b559066c upstream.

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>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/target/iscsi/iscsi_target.c