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, Samuel Ortiz <sameo@linux.intel.com>,
	Johan Hovold <johan@kernel.org>
Subject: [PATCH 4.4 07/83] NFC: fix broken device allocation
Date: Tue, 25 Jul 2017 12:18:31 -0700	[thread overview]
Message-ID: <20170725191709.515284558@linuxfoundation.org> (raw)
In-Reply-To: <20170725191708.449126292@linuxfoundation.org>

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

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

From: Johan Hovold <johan@kernel.org>

commit 20777bc57c346b6994f465e0d8261a7fbf213a09 upstream.

Commit 7eda8b8e9677 ("NFC: Use IDR library to assing NFC devices IDs")
moved device-id allocation and struct-device initialisation from
nfc_allocate_device() to nfc_register_device().

This broke just about every nfc-device-registration error path, which
continue to call nfc_free_device() that tries to put the device
reference of the now uninitialised (but zeroed) struct device:

kobject: '(null)' (ce316420): is not initialized, yet kobject_put() is being called.

The late struct-device initialisation also meant that various work
queues whose names are derived from the nfc device name were also
misnamed:

  421 root         0 SW<  [(null)_nci_cmd_]
  422 root         0 SW<  [(null)_nci_rx_w]
  423 root         0 SW<  [(null)_nci_tx_w]

Move the id-allocation and struct-device initialisation back to
nfc_allocate_device() and fix up the single call site which did not use
nfc_free_device() in its error path.

Fixes: 7eda8b8e9677 ("NFC: Use IDR library to assing NFC devices IDs")
Cc: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 net/nfc/core.c     |   31 ++++++++++++++++++-------------
 net/nfc/nci/core.c |    3 +--
 2 files changed, 19 insertions(+), 15 deletions(-)

--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -969,6 +969,8 @@ static void nfc_release(struct device *d
 			kfree(se);
 	}
 
+	ida_simple_remove(&nfc_index_ida, dev->idx);
+
 	kfree(dev);
 }
 
@@ -1043,6 +1045,7 @@ struct nfc_dev *nfc_allocate_device(stru
 				    int tx_headroom, int tx_tailroom)
 {
 	struct nfc_dev *dev;
+	int rc;
 
 	if (!ops->start_poll || !ops->stop_poll || !ops->activate_target ||
 	    !ops->deactivate_target || !ops->im_transceive)
@@ -1055,6 +1058,15 @@ struct nfc_dev *nfc_allocate_device(stru
 	if (!dev)
 		return NULL;
 
+	rc = ida_simple_get(&nfc_index_ida, 0, 0, GFP_KERNEL);
+	if (rc < 0)
+		goto err_free_dev;
+	dev->idx = rc;
+
+	dev->dev.class = &nfc_class;
+	dev_set_name(&dev->dev, "nfc%d", dev->idx);
+	device_initialize(&dev->dev);
+
 	dev->ops = ops;
 	dev->supported_protocols = supported_protocols;
 	dev->tx_headroom = tx_headroom;
@@ -1077,6 +1089,11 @@ struct nfc_dev *nfc_allocate_device(stru
 	}
 
 	return dev;
+
+err_free_dev:
+	kfree(dev);
+
+	return ERR_PTR(rc);
 }
 EXPORT_SYMBOL(nfc_allocate_device);
 
@@ -1091,14 +1108,6 @@ int nfc_register_device(struct nfc_dev *
 
 	pr_debug("dev_name=%s\n", dev_name(&dev->dev));
 
-	dev->idx = ida_simple_get(&nfc_index_ida, 0, 0, GFP_KERNEL);
-	if (dev->idx < 0)
-		return dev->idx;
-
-	dev->dev.class = &nfc_class;
-	dev_set_name(&dev->dev, "nfc%d", dev->idx);
-	device_initialize(&dev->dev);
-
 	mutex_lock(&nfc_devlist_mutex);
 	nfc_devlist_generation++;
 	rc = device_add(&dev->dev);
@@ -1136,12 +1145,10 @@ EXPORT_SYMBOL(nfc_register_device);
  */
 void nfc_unregister_device(struct nfc_dev *dev)
 {
-	int rc, id;
+	int rc;
 
 	pr_debug("dev_name=%s\n", dev_name(&dev->dev));
 
-	id = dev->idx;
-
 	if (dev->rfkill) {
 		rfkill_unregister(dev->rfkill);
 		rfkill_destroy(dev->rfkill);
@@ -1166,8 +1173,6 @@ void nfc_unregister_device(struct nfc_de
 	nfc_devlist_generation++;
 	device_del(&dev->dev);
 	mutex_unlock(&nfc_devlist_mutex);
-
-	ida_simple_remove(&nfc_index_ida, id);
 }
 EXPORT_SYMBOL(nfc_unregister_device);
 
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -1084,8 +1084,7 @@ struct nci_dev *nci_allocate_device(stru
 	return ndev;
 
 free_nfc:
-	kfree(ndev->nfc_dev);
-
+	nfc_free_device(ndev->nfc_dev);
 free_nci:
 	kfree(ndev);
 	return NULL;

  parent reply	other threads:[~2017-07-25 19:19 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 19:18 [PATCH 4.4 00/83] 4.4.79-stable review Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 01/83] disable new gcc-7.1.1 warnings for now Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 02/83] [media] ir-core: fix gcc-7 warning on bool arithmetic Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 03/83] [media] s5p-jpeg: dont return a random width/height Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 04/83] thermal: cpu_cooling: Avoid accessing potentially freed structures Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 05/83] ath9k: fix tx99 use after free Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 06/83] ath9k: fix tx99 bus error Greg Kroah-Hartman
2017-07-25 19:18 ` Greg Kroah-Hartman [this message]
2017-08-01 18:15   ` [PATCH 4.4 07/83] NFC: fix broken device allocation Ben Hutchings
2017-08-01 19:16     ` Johan Hovold
2017-07-25 19:18 ` [PATCH 4.4 08/83] NFC: nfcmrvl_uart: add missing tty-device sanity check Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 09/83] NFC: nfcmrvl: do not use device-managed resources Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 10/83] NFC: nfcmrvl: use nfc-device for firmware download Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 11/83] NFC: nfcmrvl: fix firmware-management initialisation Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 12/83] nfc: Ensure presence of required attributes in the activate_target handler Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 13/83] nfc: Fix the sockaddr length sanitization in llcp_sock_connect Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 14/83] NFC: Add sockaddr length checks before accessing sa_family in bind handlers Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 15/83] perf intel-pt: Move decoder error setting into one condition Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 16/83] perf intel-pt: Improve sample timestamp Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 17/83] perf intel-pt: Fix missing stack clear Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 18/83] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 19/83] perf intel-pt: Clear FUP flag on error Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 20/83] Bluetooth: use constant time memory comparison for secret values Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 21/83] wlcore: fix 64K page support Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 22/83] ASoC: compress: Derive substream from stream based on direction Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 23/83] PM / Domains: Fix unsafe iteration over modified list of device links Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 24/83] PM / Domains: Fix unsafe iteration over modified list of domain providers Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 25/83] scsi: ses: do not add a device to an enclosure if enclosure_add_links() fails Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 26/83] iscsi-target: Add login_keys_workaround attribute for non RFC initiators Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 27/83] powerpc/64: Fix atomic64_inc_not_zero() to return an int Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 28/83] powerpc: Fix emulation of mcrf in emulate_step() Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 29/83] powerpc: Fix emulation of mfocrf " Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 30/83] powerpc/asm: Mark cr0 as clobbered in mftb() Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 31/83] af_key: Fix sadb_x_ipsecrequest parsing Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 32/83] PCI/PM: Restore the status of PCI devices across hibernation Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 33/83] ipvs: SNAT packet replies only for NATed connections Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 34/83] xhci: fix 20000ms port resume timeout Greg Kroah-Hartman
2017-07-25 19:18 ` [PATCH 4.4 35/83] xhci: Fix NULL pointer dereference when cleaning up streams for removed host Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 36/83] usb: storage: return on error to avoid a null pointer dereference Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 37/83] USB: cdc-acm: add device-id for quirky printer Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 38/83] usb: renesas_usbhs: fix usbhsc_resume() for !USBHSF_RUNTIME_PWCTRL Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 39/83] usb: renesas_usbhs: gadget: disable all eps when the driver stops Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 40/83] md: dont use flush_signals in userspace processes Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 42/83] [media] cx88: Fix regression in initial video standard setting Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 43/83] Raid5 should update rdev->sectors after reshape Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 44/83] s390/syscalls: Fix out of bounds arguments access Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 48/83] ipmi: use rcu lock around call to intf->handlers->sender() Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 49/83] ipmi:ssif: Add missing unlock in error branch Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 50/83] f2fs: Dont clear SGID when inheriting ACLs Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 51/83] vfio: Fix group release deadlock Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 52/83] vfio: New external user group/file match Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 53/83] ftrace: Fix uninitialized variable in match_records() Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 54/83] MIPS: Fix mips_atomic_set() retry condition Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 55/83] MIPS: Fix mips_atomic_set() with EVA Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 56/83] MIPS: Negate error syscall return in trace Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 57/83] x86/acpi: Prevent out of bound access caused by broken ACPI tables Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 58/83] x86/ioapic: Pass the correct data to unmask_ioapic_irq() Greg Kroah-Hartman
2017-08-03 20:24   ` Ben Hutchings
2017-07-25 19:19 ` [PATCH 4.4 59/83] MIPS: Fix MIPS I ISA /proc/cpuinfo reporting Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 60/83] MIPS: Save static registers before sysmips Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 61/83] MIPS: Actually decode JALX in `__compute_return_epc_for_insn Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 62/83] MIPS: Fix unaligned PC interpretation in `compute_return_epc Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 63/83] MIPS: math-emu: Prevent wrong ISA mode instruction emulation Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 64/83] MIPS: Send SIGILL for BPOSGE32 in `__compute_return_epc_for_insn Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 65/83] MIPS: Rename `sigill_r6 to `sigill_r2r6 " Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 66/83] MIPS: Send SIGILL for linked branches " Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 67/83] MIPS: Fix a typo: s/preset/present/ in r2-to-r6 emulation error message Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 68/83] Input: i8042 - fix crash at boot time Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 69/83] NFS: only invalidate dentrys that are clearly invalid Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 70/83] udf: Fix deadlock between writeback and udf_setsize() Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 71/83] target: Fix COMPARE_AND_WRITE caw_sem leak during se_cmd quiesce Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 73/83] Revert "perf/core: Drop kernel samples even though :u is specified" Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 74/83] staging: rtl8188eu: add TL-WN722N v2 support Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 75/83] ceph: fix race in concurrent readdir Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 76/83] RDMA/core: Initialize port_num in qp_attr Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 77/83] drm/mst: Fix error handling during MST sideband message reception Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 78/83] drm/mst: Avoid dereferencing a NULL mstb in drm_dp_mst_handle_up_req() Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 79/83] drm/mst: Avoid processing partially received up/down message transactions Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 80/83] of: device: Export of_device_{get_modalias, uvent_modalias} to modules Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 81/83] spmi: Include OF based modalias in device uevent Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 82/83] tracing: Fix kmemleak in instance_rmdir Greg Kroah-Hartman
2017-07-25 19:19 ` [PATCH 4.4 83/83] alarmtimer: dont rate limit one-shot timers Greg Kroah-Hartman
2017-07-26  2:54 ` [PATCH 4.4 00/83] 4.4.79-stable review Guenter Roeck
2017-07-26 14:24 ` 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=20170725191709.515284558@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sameo@linux.intel.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).