From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Sagi Grimberg <sagig@mellanox.com>,
Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>,
Andy Grover <agrover@redhat.com>,
Mike Christie <michaelc@cs.wisc.edu>,
Nicholas Bellinger <nab@linux-iscsi.org>
Subject: [PATCH 4.4 52/91] target: Obtain se_node_acl->acl_kref during get_initiator_node_acl
Date: Fri, 10 Mar 2017 10:08:51 +0100 [thread overview]
Message-ID: <20170310083903.371869983@linuxfoundation.org> (raw)
In-Reply-To: <20170310083900.730556986@linuxfoundation.org>
4.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Bellinger <nab@linux-iscsi.org>
commit 21aaa23b0ebbd19334fa461370c03cbb076b3295 upstream.
This patch addresses a long standing race where obtaining
se_node_acl->acl_kref in __transport_register_session()
happens a bit too late, and leaves open the potential
for core_tpg_del_initiator_node_acl() to hit a NULL
pointer dereference.
Instead, take ->acl_kref in core_tpg_get_initiator_node_acl()
while se_portal_group->acl_node_mutex is held, and move the
final target_put_nacl() from transport_deregister_session()
into transport_free_session() so that fabric driver login
failure handling using the modern method to still work
as expected.
Also, update core_tpg_get_initiator_node_acl() to take
an extra reference for dynamically generated acls for
demo-mode, before returning to fabric caller. Also
update iscsi-target sendtargets special case handling
to use target_tpg_has_node_acl() when checking if
demo_mode_discovery == true during discovery lookup.
Note the existing wait_for_completion(&acl->acl_free_comp)
in core_tpg_del_initiator_node_acl() does not change.
Cc: Sagi Grimberg <sagig@mellanox.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Andy Grover <agrover@redhat.com>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/target/iscsi/iscsi_target.c | 2 -
drivers/target/target_core_tpg.c | 42 ++++++++++++++++++++++++++++++++-
drivers/target/target_core_transport.c | 19 ++++++++++----
include/target/target_core_fabric.h | 2 +
4 files changed, 57 insertions(+), 8 deletions(-)
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -3436,7 +3436,7 @@ iscsit_build_sendtargets_response(struct
if ((tpg->tpg_attrib.generate_node_acls == 0) &&
(tpg->tpg_attrib.demo_mode_discovery == 0) &&
- (!core_tpg_get_initiator_node_acl(&tpg->tpg_se_tpg,
+ (!target_tpg_has_node_acl(&tpg->tpg_se_tpg,
cmd->conn->sess->sess_ops->InitiatorName))) {
continue;
}
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -75,9 +75,21 @@ struct se_node_acl *core_tpg_get_initiat
unsigned char *initiatorname)
{
struct se_node_acl *acl;
-
+ /*
+ * Obtain se_node_acl->acl_kref using fabric driver provided
+ * initiatorname[] during node acl endpoint lookup driven by
+ * new se_session login.
+ *
+ * The reference is held until se_session shutdown -> release
+ * occurs via fabric driver invoked transport_deregister_session()
+ * or transport_free_session() code.
+ */
mutex_lock(&tpg->acl_node_mutex);
acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname);
+ if (acl) {
+ if (!kref_get_unless_zero(&acl->acl_kref))
+ acl = NULL;
+ }
mutex_unlock(&tpg->acl_node_mutex);
return acl;
@@ -232,6 +244,25 @@ static void target_add_node_acl(struct s
acl->initiatorname);
}
+bool target_tpg_has_node_acl(struct se_portal_group *tpg,
+ const char *initiatorname)
+{
+ struct se_node_acl *acl;
+ bool found = false;
+
+ mutex_lock(&tpg->acl_node_mutex);
+ list_for_each_entry(acl, &tpg->acl_node_list, acl_list) {
+ if (!strcmp(acl->initiatorname, initiatorname)) {
+ found = true;
+ break;
+ }
+ }
+ mutex_unlock(&tpg->acl_node_mutex);
+
+ return found;
+}
+EXPORT_SYMBOL(target_tpg_has_node_acl);
+
struct se_node_acl *core_tpg_check_initiator_node_acl(
struct se_portal_group *tpg,
unsigned char *initiatorname)
@@ -248,6 +279,15 @@ struct se_node_acl *core_tpg_check_initi
acl = target_alloc_node_acl(tpg, initiatorname);
if (!acl)
return NULL;
+ /*
+ * When allocating a dynamically generated node_acl, go ahead
+ * and take the extra kref now before returning to the fabric
+ * driver caller.
+ *
+ * Note this reference will be released at session shutdown
+ * time within transport_free_session() code.
+ */
+ kref_get(&acl->acl_kref);
acl->dynamic_node_acl = 1;
/*
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -341,7 +341,6 @@ void __transport_register_session(
&buf[0], PR_REG_ISID_LEN);
se_sess->sess_bin_isid = get_unaligned_be64(&buf[0]);
}
- kref_get(&se_nacl->acl_kref);
spin_lock_irq(&se_nacl->nacl_sess_lock);
/*
@@ -432,6 +431,7 @@ void target_put_nacl(struct se_node_acl
{
kref_put(&nacl->acl_kref, target_complete_nacl);
}
+EXPORT_SYMBOL(target_put_nacl);
void transport_deregister_session_configfs(struct se_session *se_sess)
{
@@ -464,6 +464,15 @@ EXPORT_SYMBOL(transport_deregister_sessi
void transport_free_session(struct se_session *se_sess)
{
+ struct se_node_acl *se_nacl = se_sess->se_node_acl;
+ /*
+ * Drop the se_node_acl->nacl_kref obtained from within
+ * core_tpg_get_initiator_node_acl().
+ */
+ if (se_nacl) {
+ se_sess->se_node_acl = NULL;
+ target_put_nacl(se_nacl);
+ }
if (se_sess->sess_cmd_map) {
percpu_ida_destroy(&se_sess->sess_tag_pool);
kvfree(se_sess->sess_cmd_map);
@@ -478,7 +487,7 @@ void transport_deregister_session(struct
const struct target_core_fabric_ops *se_tfo;
struct se_node_acl *se_nacl;
unsigned long flags;
- bool comp_nacl = true, drop_nacl = false;
+ bool drop_nacl = false;
if (!se_tpg) {
transport_free_session(se_sess);
@@ -511,18 +520,16 @@ void transport_deregister_session(struct
if (drop_nacl) {
core_tpg_wait_for_nacl_pr_ref(se_nacl);
core_free_device_list_for_node(se_nacl, se_tpg);
+ se_sess->se_node_acl = NULL;
kfree(se_nacl);
- comp_nacl = false;
}
pr_debug("TARGET_CORE[%s]: Deregistered fabric_sess\n",
se_tpg->se_tpg_tfo->get_fabric_name());
/*
* If last kref is dropping now for an explicit NodeACL, awake sleeping
* ->acl_free_comp caller to wakeup configfs se_node_acl->acl_group
- * removal context.
+ * removal context from within transport_free_session() code.
*/
- if (se_nacl && comp_nacl)
- target_put_nacl(se_nacl);
transport_free_session(se_sess);
}
--- a/include/target/target_core_fabric.h
+++ b/include/target/target_core_fabric.h
@@ -168,6 +168,8 @@ void core_allocate_nexus_loss_ua(struct
struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
unsigned char *);
+bool target_tpg_has_node_acl(struct se_portal_group *tpg,
+ const char *);
struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *,
unsigned char *);
int core_tpg_set_initiator_node_queue_depth(struct se_portal_group *,
next prev parent reply other threads:[~2017-03-10 9:08 UTC|newest]
Thread overview: 101+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-10 9:07 [PATCH 4.4 00/91] 4.4.53-stable review Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 01/91] MIPS: Fix special case in 64 bit IP checksumming Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 03/91] MIPS: OCTEON: Fix copy_from_user fault handling for large buffers Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 04/91] MIPS: Lantiq: Keep ethernet enabled during boot Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 05/91] MIPS: Clear ISA bit correctly in get_frame_info() Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 06/91] MIPS: Prevent unaligned accesses during stack unwinding Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 07/91] MIPS: Fix get_frame_info() handling of microMIPS function size Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 08/91] MIPS: Fix is_jump_ins() handling of 16b microMIPS instructions Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 09/91] MIPS: Calculate microMIPS ra properly when unwinding the stack Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 10/91] MIPS: Handle microMIPS jumps in the same way as MIPS32/MIPS64 jumps Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 11/91] [media] am437x-vpfe: always assign bpp variable Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 12/91] [media] uvcvideo: Fix a wrong macro Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 13/91] [media] media: fix dm1105.c build error Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 14/91] ARM: at91: define LPDDR types Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 15/91] ARM: dts: at91: Enable DMA on sama5d4_xplained console Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 16/91] ARM: dts: at91: Enable DMA on sama5d2_xplained console Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 17/91] ALSA: hda/realtek - Cannot adjust speakers volume on a Dell AIO Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 18/91] ALSA: hda - fix Lewisburg audio issue Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 19/91] ALSA: timer: Reject user params with too small ticks Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 20/91] ALSA: ctxfi: Fallback DMA mask to 32bit Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 21/91] ALSA: seq: Fix link corruption by event error handling Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 22/91] ALSA: hda - Add subwoofer support for Dell Inspiron 17 7000 Gaming Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 23/91] ALSA: hda - Fix micmute hotkey problem for a lenovo AIO machine Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 24/91] staging: rtl: fix possible NULL pointer dereference Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 25/91] regulator: Fix regulator_summary for deviceless consumers Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 26/91] iommu/vt-d: Fix some macros that are incorrectly specified in intel-iommu Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 27/91] iommu/vt-d: Tylersburg isoch identity map check is done too late Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 28/91] mm/page_alloc: fix nodes for reclaim in fast path Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 29/91] mm: vmpressure: fix sending wrong events on underflow Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 30/91] mm: do not access page->mapping directly on page_endio Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 31/91] ipc/shm: Fix shmat mmap nil-page protection Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 32/91] dm cache: fix corruption seen when using cache > 2TB Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 33/91] dm stats: fix a leaked s->histogram_boundaries array Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 34/91] scsi: storvsc: use tagged SRB requests if supported by the device Greg Kroah-Hartman
2017-03-10 14:56 ` Ben Hutchings
2017-03-10 15:21 ` Greg Kroah-Hartman
2017-03-10 15:29 ` KY Srinivasan
2017-03-10 9:08 ` [PATCH 4.4 35/91] scsi: storvsc: properly handle SRB_ERROR when sense message is present Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 36/91] scsi: storvsc: properly set residual data length on errors Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 37/91] scsi: aacraid: Reorder Adapter status check Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 38/91] scsi: use scsi_device_from_queue() for scsi_dh Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 39/91] sd: get disk reference in sd_check_events() Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 40/91] Fix: Disable sys_membarrier when nohz_full is enabled Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 41/91] jbd2: dont leak modified metadata buffers on an aborted journal Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 42/91] block/loop: fix race between I/O and set_status Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 43/91] loop: fix LO_FLAGS_PARTSCAN hang Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 44/91] ext4: Include forgotten start block on fallocate insert range Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 45/91] ext4: do not polute the extents cache while shifting extents Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 46/91] ext4: trim allocation requests to group size Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 47/91] ext4: fix data corruption in data=journal mode Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 48/91] ext4: fix inline data error paths Greg Kroah-Hartman
2017-03-10 16:48 ` Ben Hutchings
2017-03-12 5:22 ` Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 49/91] ext4: preserve the needs_recovery flag when the journal is aborted Greg Kroah-Hartman
2017-03-10 16:58 ` Ben Hutchings
2017-03-10 20:14 ` Theodore Ts'o
2017-03-11 5:27 ` Ben Hutchings
2017-03-10 9:08 ` [PATCH 4.4 50/91] ext4: return EROFS if device is r/o and journal replay is needed Greg Kroah-Hartman
2017-03-10 9:08 ` Greg Kroah-Hartman [this message]
2017-03-10 9:08 ` [PATCH 4.4 53/91] target: Fix multi-session dynamic se_node_acl double free OOPs Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 54/91] ath5k: drop bogus warning on drv_set_key with unsupported cipher Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 55/91] ath9k: fix race condition in enabling/disabling IRQs Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 56/91] ath9k: use correct OTP register offsets for the AR9340 and AR9550 Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 57/91] crypto: testmgr - Pad aes_ccm_enc_tv_template vector Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 58/91] fuse: add missing FR_FORCE Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 59/91] arm/arm64: KVM: Enforce unconditional flush to PoC when mapping to stage-2 Greg Kroah-Hartman
2017-03-10 9:08 ` [PATCH 4.4 60/91] iio: pressure: mpl115: do not rely on structure field ordering Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 61/91] iio: pressure: mpl3115: " Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 62/91] can: usb_8dev: Fix memory leak of priv->cmd_msg_buffer Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 63/91] w1: dont leak refcount on slave attach failure in w1_attach_slave_device() Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 64/91] w1: ds2490: USB transfer buffers need to be DMAable Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 65/91] usb: musb: da8xx: Remove CPPI 3.0 quirk and methods Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 66/91] usb: host: xhci: plat: check hcc_params after add hcd Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 67/91] usb: gadget: udc: fsl: Add missing complete function Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 68/91] hv: allocate synic pages for all present CPUs Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 69/91] hv: init percpu_list in hv_synic_alloc() Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 70/91] Drivers: hv: util: kvp: Fix a rescind processing issue Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 71/91] Drivers: hv: util: Fcopy: " Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 72/91] Drivers: hv: util: Backup: " Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 73/91] RDMA/core: Fix incorrect structure packing for booleans Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 74/91] rdma_cm: fail iwarp accepts w/o connection params Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 75/91] gfs2: Add missing rcu locking for glock lookup Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 76/91] rtlwifi: Fix alignment issues Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 77/91] rtlwifi: rtl8192c-common: Fix "BUG: KASAN: Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 78/91] nfsd: minor nfsd_setattr cleanup Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 79/91] nfsd: special case truncates some more Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 80/91] NFSv4: Fix memory and state leak in _nfs4_open_and_get_state Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 81/91] NFSv4: fix getacl head length estimation Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 82/91] NFSv4: fix getacl ERANGE for some ACL buffer sizes Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 83/91] rtc: sun6i: Add some locking Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 84/91] rtc: sun6i: Switch to the external oscillator Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 85/91] md linear: fix a race between linear_add() and linear_congested() Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 87/91] dmaengine: ipu: Make sure the interrupt routine checks all interrupts Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 88/91] powerpc/xmon: Fix data-breakpoint Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 89/91] MIPS: IP22: Reformat inline assembler code to modern standards Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 90/91] MIPS: IP22: Fix build error due to binutils 2.25 uselessnes Greg Kroah-Hartman
2017-03-10 9:09 ` [PATCH 4.4 91/91] scsi: lpfc: Correct WQ creation for pagesize Greg Kroah-Hartman
2017-03-10 18:35 ` [PATCH 4.4 00/91] 4.4.53-stable review Guenter Roeck
2017-03-10 19:15 ` Shuah Khan
[not found] ` <58c2d01c.cdd8190a.421eb.b1d4@mx.google.com>
[not found] ` <m2pohoes9u.fsf@baylibre.com>
2017-03-13 8:56 ` Thomas Petazzoni
2017-03-14 17:08 ` Kevin Hilman
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=20170310083903.371869983@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=agrover@redhat.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=michaelc@cs.wisc.edu \
--cc=nab@linux-iscsi.org \
--cc=sagig@mellanox.com \
--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).