lkml.org 
[lkml]   [2010]   [Dec]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] USB: HID: Fix race between disconnect and hiddev_ioctl
On Mon, 6 Dec 2010, Valentine Barshak wrote:

> A USB HID device can be disconnected at any time.
> If this happens right before or while hiddev_ioctl is in progress,
> the hiddev_ioctl tries to access invalid hiddev->hid pointer.
> When the hid device is disconnected, the hiddev_disconnect()
> ends up with a call to hid_device_release() which frees
> hid_device, but doesn't set the hiddev->hid pointer to NULL.
> If the deallocated memory region has been re-used by the kernel,
> this can cause a crash or memory corruption.
>
> Since disconnect can happen at any time, we can't initialize
> struct hid_device *hid = hiddev->hid at the beginning of ioctl
> and then use it.
>
> This change checks hiddev->exist flag while holding
> the existancelock and uses hid_device only if it exists.

The code duplication isn't really particularly nice, but I don't see any
way around it that wouldn't complicate things even more.

I will be applying the patches, thanks.

(BTW your patches didn't reach mail mailbox, I had to dig them out from
mailinglist -- did you receive bounces by any chance?).

Thanks,

--
Jiri Kosina
SUSE Labs, Novell Inc.


\
 
 \ /
  Last update: 2010-12-07 15:49    [W:0.047 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site