summaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorJiri Kosina2011-05-24 11:43:18 +0200
committerJiri Kosina2011-05-24 11:43:18 +0200
commit7f77897ef2b6a5ee4eb8bc24fe8b1f3eab254328 (patch)
tree024098e2025c2fbbd3b0a2edf70711ffef76f9b8 /drivers/hid
parentMerge branch 'sh-latest' of git://git.kernel.org/pub/scm/linux/kernel/git/let... (diff)
downloadkernel-qcow2-linux-7f77897ef2b6a5ee4eb8bc24fe8b1f3eab254328.tar.gz
kernel-qcow2-linux-7f77897ef2b6a5ee4eb8bc24fe8b1f3eab254328.tar.xz
kernel-qcow2-linux-7f77897ef2b6a5ee4eb8bc24fe8b1f3eab254328.zip
HID: hiddev: fix potential use-after-free
Commit 6cb4b040795 ("HID: hiddev: fix race between hiddev_disconnect and hiddev_release") made it possible to access hiddev (for unlocking the existance mutex) once hiddev has been kfreed. Change the order so that this can not happen (always unlock the mutex first, it is needed only to protect access to ->exist and ->open). Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/usbhid/hiddev.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index ff3c644888b1..4985f485932f 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -923,10 +923,11 @@ void hiddev_disconnect(struct hid_device *hid)
usb_deregister_dev(usbhid->intf, &hiddev_class);
if (hiddev->open) {
+ mutex_unlock(&hiddev->existancelock);
usbhid_close(hiddev->hid);
wake_up_interruptible(&hiddev->wait);
} else {
+ mutex_unlock(&hiddev->existancelock);
kfree(hiddev);
}
- mutex_unlock(&hiddev->existancelock);
}