stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Sunilkumar Nadumuttlu <sjn@datera.io>,
	Nicholas Bellinger <nab@linux-iscsi.org>
Subject: [PATCH 3.14 27/29] iscsi-target: Fix use-after-free during TPG session shutdown
Date: Sat,  8 Aug 2015 15:07:50 -0700	[thread overview]
Message-ID: <20150808220719.312225568@linuxfoundation.org> (raw)
In-Reply-To: <20150808220718.247950412@linuxfoundation.org>

3.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Nicholas Bellinger <nab@linux-iscsi.org>

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 |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -4709,6 +4709,7 @@ int iscsit_release_sessions_for_tpg(stru
 	struct iscsi_session *sess;
 	struct se_portal_group *se_tpg = &tpg->tpg_se_tpg;
 	struct se_session *se_sess, *se_sess_tmp;
+	LIST_HEAD(free_list);
 	int session_count = 0;
 
 	spin_lock_bh(&se_tpg->session_lock);
@@ -4730,14 +4731,17 @@ int iscsit_release_sessions_for_tpg(stru
 		}
 		atomic_set(&sess->session_reinstatement, 1);
 		spin_unlock(&sess->conn_lock);
-		spin_unlock_bh(&se_tpg->session_lock);
 
-		iscsit_free_session(sess);
-		spin_lock_bh(&se_tpg->session_lock);
+		list_move_tail(&se_sess->sess_list, &free_list);
+	}
+	spin_unlock_bh(&se_tpg->session_lock);
 
+	list_for_each_entry_safe(se_sess, se_sess_tmp, &free_list, sess_list) {
+		sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
+
+		iscsit_free_session(sess);
 		session_count++;
 	}
-	spin_unlock_bh(&se_tpg->session_lock);
 
 	pr_debug("Released %d iSCSI Session(s) from Target Portal"
 			" Group: %hu\n", session_count, tpg->tpgt);



  parent reply	other threads:[~2015-08-08 22:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-08 22:07 [PATCH 3.14 00/29] 3.14.50-stable review Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 01/29] mm: avoid setting up anonymous pages into file mapping Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 02/29] freeing unlinked file indefinitely delayed Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 03/29] s390/sclp: clear upper register halves in _sclp_print_early Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 04/29] ARC: make sure instruction_pointer() returns unsigned value Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 07/29] ALSA: usb-audio: add dB range mapping for some devices Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 08/29] ALSA: hda - Fix MacBook Pro 5,2 quirk Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 10/29] mac80211: clear subdir_stations when removing debugfs Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 11/29] mmc: sdhci-esdhc: Make 8BIT bus work Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 12/29] mmc: sdhci-pxav3: fix platform_data is not initialized Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 13/29] md/raid1: fix test for was read error from last working device Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 14/29] tile: use free_bootmem_late() for initrd Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 15/29] Input: usbtouchscreen - avoid unresponsive TSC-30 touch screen Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 16/29] blkcg: fix gendisk reference leak in blkg_conf_prep() Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 17/29] ata: pmp: add quirk for Marvell 4140 SATA PMP Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 18/29] usb-storage: ignore ZTE MF 823 card reader in mode 0x1225 Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 19/29] xhci: Calculate old endpoints correctly on device reset Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 20/29] xhci: report U3 when link is in resume state Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 21/29] xhci: prevent bus_suspend if SS port resuming in phase 1 Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 22/29] xhci: do not report PLC when link is in internal resume state Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 23/29] x86/efi: Use all 64 bit of efi_memmap in setup_e820() Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 24/29] rds: rds_ib_device.refcount overflow Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 26/29] avr32: handle NULL as a valid clock object Greg Kroah-Hartman
2015-08-08 22:07 ` Greg Kroah-Hartman [this message]
2015-08-08 22:07 ` [PATCH 3.14 28/29] iscsi-target: Fix iser explicit logout TX kthread leak Greg Kroah-Hartman
2015-08-08 22:07 ` [PATCH 3.14 29/29] efi: fix 32bit kernel boot failed problem using efi Greg Kroah-Hartman
2015-08-09  3:16 ` [PATCH 3.14 00/29] 3.14.50-stable review Guenter Roeck
2015-08-10 19:10   ` Greg Kroah-Hartman
2015-08-10  5:03 ` Sudip Mukherjee
2015-08-10 18:13 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150808220719.312225568@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=sjn@datera.io \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).