mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Manoj Chourasia <mchourasia@nvidia.com>,
	Jiri Kosina <jkosina@suse.cz>,
	Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 05/93] HID: hidraw: correctly deallocate memory on device disconnect
Date: Fri, 20 Sep 2013 13:08:00 -0700	[thread overview]
Message-ID: <1379707768-1804-6-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1379707768-1804-1-git-send-email-kamal@canonical.com>

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

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

From: Manoj Chourasia <mchourasia@nvidia.com>

commit 212a871a3934beccf43431608c27ed2e05a476ec upstream.

This changes puts the commit 4fe9f8e203f back in place
with the fixes for slab corruption because of the commit.

When a device is unplugged, wait for all processes that
have opened the device to close before deallocating the device.

This commit was solving kernel crash because of the corruption in
rb tree of vmalloc. The rootcause was the device data pointer was
geting excessed after the memory associated with hidraw was freed.

The commit 4fe9f8e203f was buggy as it was also freeing the hidraw
first and then calling delete operation on the list associated with
that hidraw leading to slab corruption.

Signed-off-by: Manoj Chourasia <mchourasia@nvidia.com>
Tested-by: Peter Wu <lekensteyn@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 drivers/hid/hidraw.c | 60 ++++++++++++++++++++++------------------------------
 1 file changed, 25 insertions(+), 35 deletions(-)

diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 413a731..cfe5288 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -113,7 +113,7 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer,
 	__u8 *buf;
 	int ret = 0;
 
-	if (!hidraw_table[minor]) {
+	if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
 		ret = -ENODEV;
 		goto out;
 	}
@@ -261,7 +261,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
 	}
 
 	mutex_lock(&minors_lock);
-	if (!hidraw_table[minor]) {
+	if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
 		err = -ENODEV;
 		goto out_unlock;
 	}
@@ -302,39 +302,38 @@ static int hidraw_fasync(int fd, struct file *file, int on)
 	return fasync_helper(fd, file, on, &list->fasync);
 }
 
+static void drop_ref(struct hidraw *hidraw, int exists_bit)
+{
+	if (exists_bit) {
+		hid_hw_close(hidraw->hid);
+		hidraw->exist = 0;
+		if (hidraw->open)
+			wake_up_interruptible(&hidraw->wait);
+	} else {
+		--hidraw->open;
+	}
+
+	if (!hidraw->open && !hidraw->exist) {
+		device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
+		hidraw_table[hidraw->minor] = NULL;
+		kfree(hidraw);
+	}
+}
+
 static int hidraw_release(struct inode * inode, struct file * file)
 {
 	unsigned int minor = iminor(inode);
-	struct hidraw *dev;
 	struct hidraw_list *list = file->private_data;
-	int ret;
-	int i;
 
 	mutex_lock(&minors_lock);
-	if (!hidraw_table[minor]) {
-		ret = -ENODEV;
-		goto unlock;
-	}
 
 	list_del(&list->node);
-	dev = hidraw_table[minor];
-	if (!--dev->open) {
-		if (list->hidraw->exist) {
-			hid_hw_power(dev->hid, PM_HINT_NORMAL);
-			hid_hw_close(dev->hid);
-		} else {
-			kfree(list->hidraw);
-		}
-	}
-
-	for (i = 0; i < HIDRAW_BUFFER_SIZE; ++i)
-		kfree(list->buffer[i].value);
 	kfree(list);
-	ret = 0;
-unlock:
-	mutex_unlock(&minors_lock);
 
-	return ret;
+	drop_ref(hidraw_table[minor], 0);
+
+	mutex_unlock(&minors_lock);
+	return 0;
 }
 
 static long hidraw_ioctl(struct file *file, unsigned int cmd,
@@ -539,18 +538,9 @@ void hidraw_disconnect(struct hid_device *hid)
 	struct hidraw *hidraw = hid->hidraw;
 
 	mutex_lock(&minors_lock);
-	hidraw->exist = 0;
-
-	device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
 
-	hidraw_table[hidraw->minor] = NULL;
+	drop_ref(hidraw, 1);
 
-	if (hidraw->open) {
-		hid_hw_close(hid);
-		wake_up_interruptible(&hidraw->wait);
-	} else {
-		kfree(hidraw);
-	}
 	mutex_unlock(&minors_lock);
 }
 EXPORT_SYMBOL_GPL(hidraw_disconnect);
-- 
1.8.1.2


  parent reply	other threads:[~2013-09-20 20:32 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20 20:07 [ 3.8.y.z extended stable ] Linux 3.8.13.10 stable review Kamal Mostafa
2013-09-20 20:07 ` [PATCH 01/93] Revert "net/core/sock.c: add missing VSOCK string in af_family_*_key_strings" Kamal Mostafa
2013-09-20 20:07 ` [PATCH 02/93] Revert "zram: use zram->lock to protect zram_free_page() in swap free notify path" Kamal Mostafa
2013-09-20 20:07 ` [PATCH 03/93] zram: allow request end to coincide with disksize Kamal Mostafa
2013-09-20 20:07 ` [PATCH 04/93] mtd: nand: fix NAND_BUSWIDTH_AUTO for x16 devices Kamal Mostafa
2013-09-20 20:08 ` Kamal Mostafa [this message]
2013-09-20 20:08 ` [PATCH 06/93] xen-gnt: prevent adding duplicate gnt callbacks Kamal Mostafa
2013-09-20 20:08 ` [PATCH 07/93] ath9k: always clear ps filter bit on new assoc Kamal Mostafa
2013-09-20 20:08 ` [PATCH 08/93] ceph: Don't forget the 'up_read(&osdc->map_sem)' if met error Kamal Mostafa
2013-09-20 20:08 ` [PATCH 09/93] libceph: unregister request in __map_request failed and nofail == false Kamal Mostafa
2013-09-20 20:08 ` [PATCH 10/93] usb: config->desc.bLength may not exceed amount of data returned by the device Kamal Mostafa
2013-09-20 20:08 ` [PATCH 11/93] USB: cdc-wdm: fix race between interrupt handler and tasklet Kamal Mostafa
2013-09-20 20:08 ` [PATCH 12/93] powerpc: Handle unaligned ldbrx/stdbrx Kamal Mostafa
2013-09-20 20:08 ` [PATCH 13/93] intel-iommu: Fix leaks in pagetable freeing Kamal Mostafa
2013-09-20 20:08 ` [PATCH 14/93] drivers/misc/hpilo: Correct panic when an AUX iLO is detected Kamal Mostafa
2013-09-20 20:08 ` [PATCH 15/93] USB: handle LPM errors during device suspend correctly Kamal Mostafa
2013-09-20 20:08 ` [PATCH 16/93] xhci-plat: Don't enable legacy PCI interrupts Kamal Mostafa
2013-09-20 20:08 ` [PATCH 17/93] ath9k: fix rx descriptor related race condition Kamal Mostafa
2013-09-20 20:08 ` [PATCH 18/93] ath9k: avoid accessing MRC registers on single-chain devices Kamal Mostafa
2013-09-20 20:08 ` [PATCH 19/93] brcmsmac: Fix WARNING caused by lack of calls to dma_mapping_error() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 20/93] ext4: simplify truncation code in ext4_setattr() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 21/93] ext4: fix lost truncate due to race with writeback Kamal Mostafa
2013-09-20 20:08 ` [PATCH 22/93] ASoC: wm8960: Fix PLL register writes Kamal Mostafa
2013-09-20 20:08 ` [PATCH 23/93] rculist: list_first_or_null_rcu() should use list_entry_rcu() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 24/93] USB: mos7720: use GFP_ATOMIC under spinlock Kamal Mostafa
2013-09-20 20:08 ` [PATCH 25/93] USB: mos7720: fix big-endian control requests Kamal Mostafa
2013-09-20 20:08 ` [PATCH 26/93] arm64: perf: fix group validation when using enable_on_exec Kamal Mostafa
2013-09-20 20:08 ` [PATCH 27/93] arm64: perf: fix ARMv8 EVTYPE_MASK to include NSH bit Kamal Mostafa
2013-09-20 20:08 ` [PATCH 28/93] staging: comedi: dt282x: dt282x_ai_insn_read() always fails Kamal Mostafa
2013-09-20 20:08 ` [PATCH 29/93] usb: ehci-mxc: check for pdata before dereferencing Kamal Mostafa
2013-09-20 20:08 ` [PATCH 30/93] mmc: tmio_mmc_dma: fix PIO fallback on SDHI Kamal Mostafa
2013-09-20 20:08 ` [PATCH 31/93] proc: Restrict mounting the proc filesystem Kamal Mostafa
2013-09-20 20:08 ` [PATCH 32/93] usb: xhci: Disable runtime PM suspend for quirky controllers Kamal Mostafa
2013-09-20 20:08 ` [PATCH 33/93] USB: OHCI: Allow runtime PM without system sleep Kamal Mostafa
2013-09-20 20:08 ` [PATCH 34/93] pinctrl: at91: fix get_pullup/down function return Kamal Mostafa
2013-09-20 20:08 ` [PATCH 35/93] ACPI / EC: Add HP Folio 13 to ec_dmi_table in order to skip DSDT scan Kamal Mostafa
2013-09-20 20:08 ` [PATCH 36/93] ACPI / EC: Add ASUSTEK L4R to quirk list in order to validate ECDT Kamal Mostafa
2013-09-20 20:08 ` [PATCH 37/93] HID: validate HID report id size Kamal Mostafa
2013-09-20 20:08 ` [PATCH 38/93] cpuidle: coupled: abort idle if pokes are pending Kamal Mostafa
2013-09-20 20:08 ` [PATCH 39/93] cpuidle: coupled: disable interrupts after entering safe state Kamal Mostafa
2013-09-20 20:08 ` [PATCH 40/93] cpuidle: coupled: fix race condition between pokes and " Kamal Mostafa
2013-09-20 20:08 ` [PATCH 41/93] of: Fix missing memory initialization on FDT unflattening Kamal Mostafa
2013-09-20 20:08 ` [PATCH 42/93] leds: wm831x-status: Request a REG resource Kamal Mostafa
2013-09-20 20:08 ` [PATCH 43/93] USB: fix build error when CONFIG_PM_SLEEP isn't enabled Kamal Mostafa
2013-09-20 20:08 ` [PATCH 44/93] clk: wm831x: Initialise wm831x pointer on init Kamal Mostafa
2013-09-20 20:08 ` [PATCH 45/93] drm/edid: add quirk for Medion MD30217PG Kamal Mostafa
2013-09-20 20:08 ` [PATCH 46/93] drm/radeon: fix endian bugs in hw i2c atom routines Kamal Mostafa
2013-09-20 20:08 ` [PATCH 47/93] drm/radeon: update line buffer allocation for dce4.1/5 Kamal Mostafa
2013-09-20 20:08 ` [PATCH 48/93] drm/radeon: update line buffer allocation for dce6 Kamal Mostafa
2013-09-20 20:08 ` [PATCH 49/93] drm/radeon: fix LCD record parsing Kamal Mostafa
2013-09-20 20:08 ` [PATCH 50/93] drm/radeon: fix resume on some rs4xx boards (v2) Kamal Mostafa
2013-09-20 20:08 ` [PATCH 51/93] drm/radeon: fix handling of variable sized arrays for router objects Kamal Mostafa
2013-09-20 20:08 ` [PATCH 52/93] radeon kms: fix uninitialised hotplug work usage in r100_irq_process() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 53/93] pidns: Fix hang in zap_pid_ns_processes by sending a potentially extra wakeup Kamal Mostafa
2013-09-20 20:08 ` [PATCH 54/93] x86, smap: Handle csum_partial_copy_*_user() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 55/93] Introduce [compat_]save_altstack_ex() to unbreak x86 SMAP Kamal Mostafa
2013-09-20 20:08 ` [PATCH 56/93] drm: fix DRM_IOCTL_MODE_GETFB handle-leak Kamal Mostafa
2013-09-20 20:08 ` [PATCH 57/93] HID: picolcd: Prevent NULL pointer dereference on _remove() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 58/93] HID: battery: don't do DMA from stack Kamal Mostafa
2013-09-20 20:08 ` [PATCH 59/93] ALSA: hda - hdmi: Fallback to ALSA allocation when selecting CA Kamal Mostafa
2013-09-20 20:08 ` [PATCH 60/93] fuse: postpone end_page_writeback() in fuse_writepage_locked() Kamal Mostafa
2013-09-20 20:08 ` [PATCH 61/93] fuse: invalidate inode attributes on xattr modification Kamal Mostafa
2013-09-20 20:08 ` [PATCH 62/93] [media] media: coda: Fix DT driver data pointer for i.MX27 Kamal Mostafa
2013-09-20 20:08 ` [PATCH 63/93] [media] s5p-g2d: Fix registration failure Kamal Mostafa
2013-09-20 20:08 ` [PATCH 64/93] [media] DocBook: upgrade media_api DocBook version to 4.2 Kamal Mostafa
2013-09-20 20:09 ` [PATCH 65/93] [media] v4l2: added missing mutex.h include to v4l2-ctrls.h Kamal Mostafa
2013-09-20 20:09 ` [PATCH 66/93] [media] hdpvr: fix iteration over uninitialized lists in hdpvr_probe() Kamal Mostafa
2013-09-20 20:09 ` [PATCH 67/93] [media] exynos-gsc: Register v4l2 device Kamal Mostafa
2013-09-20 20:09 ` [PATCH 68/93] fuse: readdir: check for slash in names Kamal Mostafa
2013-09-20 20:09 ` [PATCH 69/93] MIPS: ath79: Fix ar933x watchdog clock Kamal Mostafa
2013-09-20 20:09 ` [PATCH 70/93] libceph: use pg_num_mask instead of pgp_num_mask for pg.seed calc Kamal Mostafa
2013-09-20 20:09 ` [PATCH 71/93] HID: pantherlord: validate output report details Kamal Mostafa
2013-09-20 20:09 ` [PATCH 72/93] HID: ntrig: validate feature " Kamal Mostafa
2013-09-20 20:09 ` [PATCH 73/93] HID: sensor-hub: " Kamal Mostafa
2013-09-20 20:09 ` [PATCH 74/93] HID: picolcd_core: validate output " Kamal Mostafa
2013-09-20 20:09 ` [PATCH 75/93] HID: check for NULL field when setting values Kamal Mostafa
2013-09-20 20:09 ` [PATCH 76/93] ARM: PCI: versatile: Fix map_irq function to match hardware Kamal Mostafa
2013-09-20 20:09 ` [PATCH 77/93] ARM: PCI: versatile: Fix PCI I/O Kamal Mostafa
2013-09-20 20:09 ` [PATCH 78/93] ARM: PCI: versatile: Fix SMAP register offsets Kamal Mostafa
2013-09-20 20:09 ` [PATCH 79/93] net: mvneta: properly disable HW PHY polling and ensure adjust_link() works Kamal Mostafa
2013-09-20 20:09 ` [PATCH 80/93] drm/i915: try not to lose backlight CBLV precision Kamal Mostafa
2013-09-20 20:09 ` [PATCH 81/93] crypto: api - Fix race condition in larval lookup Kamal Mostafa
2013-09-20 20:09 ` [PATCH 82/93] cifs: ensure that srv_mutex is held when dealing with ssocket pointer Kamal Mostafa
2013-09-20 20:09 ` [PATCH 83/93] CIFS: Fix a memory leak when a lease break comes Kamal Mostafa
2013-09-20 20:09 ` [PATCH 84/93] ALSA: hda - Add Toshiba Satellite C870 to MSI blacklist Kamal Mostafa
2013-09-20 20:09 ` [PATCH 85/93] lguest: Point to the right directory for the lguest launcher Kamal Mostafa
2013-09-20 20:09 ` [PATCH 86/93] powerpc: Default arch idle could cede processor on pseries Kamal Mostafa
2013-09-20 20:09 ` [PATCH 87/93] ASoC: mc13783: add spi errata fix Kamal Mostafa
2013-09-20 20:09 ` [PATCH 88/93] [SCSI] sd: Fix potential out-of-bounds access Kamal Mostafa
2013-09-20 20:09 ` [PATCH 89/93] pidns: fix vfork() after unshare(CLONE_NEWPID) Kamal Mostafa
2013-09-20 20:09 ` [PATCH 90/93] ocfs2: fix the end cluster offset of FIEMAP Kamal Mostafa
2013-09-20 20:09 ` [PATCH 91/93] mm/huge_memory.c: fix potential NULL pointer dereference Kamal Mostafa
2013-09-20 20:09 ` [PATCH 92/93] mm: fix aio performance regression for database caused by THP Kamal Mostafa
2013-09-20 20:09 ` [PATCH 93/93] memcg: fix multiple large threshold notifications Kamal Mostafa

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=1379707768-1804-6-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=jkosina@suse.cz \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchourasia@nvidia.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

all inboxes | Powered by JetHome®