All of lore.kernel.org
 help / color / mirror / Atom feed
From: Valentine Barshak <vbarshak@mvista.com>
To: Jiri Kosina <jkosina@suse.cz>
Cc: linux-usb@vger.kernel.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] USB: HID: Fix race between disconnect and hiddev_ioctl
Date: Tue, 07 Dec 2010 18:02:46 +0300	[thread overview]
Message-ID: <4CFE4C96.4000702@mvista.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1012071546040.14806@pobox.suse.cz>

Jiri Kosina wrote:
> 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.
>   
Thanks!
> (BTW your patches didn't reach mail mailbox, I had to dig them out from 
> mailinglist -- did you receive bounces by any chance?).
>   
Yes, they did bounce.
Thanks,
Val.
> Thanks,
>
>   

  reply	other threads:[~2010-12-07 15:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-06 14:45 [PATCH 0/2] USB: HID: Fix race between disconnect and hiddev_ioctl Valentine Barshak
2010-12-06 14:51 ` [PATCH 1/2] " Valentine Barshak
2010-12-07 14:47   ` Jiri Kosina
2010-12-07 15:02     ` Valentine Barshak [this message]
     [not found] ` <20101206144519.GA8438-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2010-12-06 15:16   ` [PATCH 2/2] USB: HID: Consolidate device existence checks in hiddev_ioctl Valentine Barshak
2010-12-06 15:16     ` Valentine Barshak

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=4CFE4C96.4000702@mvista.com \
    --to=vbarshak@mvista.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.