]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
HID: hiddev: fix potential use-after-free
authorJiri Kosina <jkosina@suse.cz>
Tue, 24 May 2011 09:43:18 +0000 (11:43 +0200)
committerJiri Kosina <jkosina@suse.cz>
Tue, 24 May 2011 09:43:18 +0000 (11:43 +0200)
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>
drivers/hid/usbhid/hiddev.c

index ff3c644888b1ba8b0bf14e2426313b66db3688c0..4985f485932fb5e3582601c14918411c38a1d14d 100644 (file)
@@ -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);
 }