Skip to content

Commit 5c02c44

Browse files
dan.carpenter@oracle.comJiri Kosina
authored andcommitted
HID: hiddev: Fix race in in hiddev_disconnect()
Syzbot reports that "hiddev" is used after it's free in hiddev_disconnect(). The hiddev_disconnect() function sets "hiddev->exist = 0;" so hiddev_release() can free it as soon as we drop the "existancelock" lock. This patch moves the mutex_unlock(&hiddev->existancelock) until after we have finished using it. Reported-by: [email protected] Fixes: 7f77897 ("HID: hiddev: fix potential use-after-free") Suggested-by: Alan Stern <[email protected]> Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 84a4062 commit 5c02c44

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/hid/usbhid/hiddev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,9 @@ void hiddev_disconnect(struct hid_device *hid)
932932
hiddev->exist = 0;
933933

934934
if (hiddev->open) {
935-
mutex_unlock(&hiddev->existancelock);
936935
hid_hw_close(hiddev->hid);
937936
wake_up_interruptible(&hiddev->wait);
937+
mutex_unlock(&hiddev->existancelock);
938938
} else {
939939
mutex_unlock(&hiddev->existancelock);
940940
kfree(hiddev);

0 commit comments

Comments
 (0)