All of lore.kernel.org
 help / color / mirror / Atom feed
From: Valentine Barshak <vbarshak@mvista.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Oliver Neukum <oliver@neukum.org>, Jiri Kosina <jkosina@suse.cz>,
	linux-usb@vger.kernel.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] USB: USBHID: Fix race between disconnect and hiddev_ioctl
Date: Mon, 06 Dec 2010 17:03:03 +0300	[thread overview]
Message-ID: <4CFCED17.9060702@mvista.com> (raw)
In-Reply-To: <20101204203750.GA7326@core.coreip.homeip.net>

Dmitry Torokhov wrote:
> On Sat, Dec 04, 2010 at 09:22:23PM +0100, Oliver Neukum wrote:
>   
>> Am Samstag, 4. Dezember 2010, 00:16:12 schrieb Dmitry Torokhov:
>>     
>>>> 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.
>>>>         
>>> Why didn't you take the lock and check hiddev->exist at the beginning of
>>> ioctl handler instead of pushing it down into individual command
>>> handlers? I guess it would slow down HIDIOCGVERSION but I think we could
>>> pay this price for code that is more clear ;)
>>>       
>> Strictly speaking you'd change the semantics. Right now you can execute
>> the ioctl even if you know you are holding an fd to a disconnected device
>> open.
>>     
>
> No, I do not think I would. I do not believe that the availability for
> HIDIOCGVERSION on disconnected device is spelled out in API/ABI spec. We
> only know that ioctl will either succeed or appropriate error code is
> returned. The fact that right now HIDIOCGVERSION is available on
> disconnected devices is just an implementation detail subject to change.
>
>   
It's not just HIDIOCGVERSION. A couple of other commands 
(HIDIOCGFLAG/HIDIOCSFLAG) didn't check device existence in the first 
place either.
Current implementation depends on when the device is actually removed.
If it has been removed before the hiddev_ioctl(), hiddev_ioctl() returns 
-EIO.
If the device is removed while hiddev_ioctl() is in progress, we either 
do not notice that and handle HIDIOCGVERSION and HIDIOCGFLAG/HIDIOCSFLAG
just fine, or return -ENODEV.
I'll submit a patch in a bit that applies on top of the "[PATCH] USB: 
USBHID: Fix race between disconnect and hiddev_ioctl" and makes the 
hiddev_ioctl() check
device existence before processing the command and always return -ENODEV 
in case the device has been removed.
Thanks,
Val.


  reply	other threads:[~2010-12-06 13:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03 17:27 [PATCH] USB: USBHID: Fix race between disconnect and hiddev_ioctl Valentine Barshak
2010-12-03 23:16 ` Dmitry Torokhov
     [not found]   ` <20101203231611.GB22969-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2010-12-03 23:31     ` Valentine Barshak
2010-12-03 23:31       ` Valentine Barshak
2010-12-04 20:22   ` Oliver Neukum
     [not found]     ` <201012042122.23852.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2010-12-04 20:37       ` Dmitry Torokhov
2010-12-04 20:37         ` Dmitry Torokhov
2010-12-06 14:03         ` Valentine Barshak [this message]
2010-12-06 15:25           ` Valentine Barshak
  -- strict thread matches above, loose matches on Subject: below --
2010-12-03 17:52 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=4CFCED17.9060702@mvista.com \
    --to=vbarshak@mvista.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oliver@neukum.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.