On Fri, 6 Jul 2012, Hans de Goede wrote:

> > In theory we could prevent this problem by adding pre- and post-reset
> > handlers to usbfs.  The difficulty is: What should such handlers do?
> > There's no way to inform client programs about the reset.
> 
> Right, so I see one option here:
> 
> 1) Have devio.c: proc_resetdevice check it all interfaces are claimed by the 
> caller
>     (I've not yet looked how hard this is.

There's a bit array (ps->ifclaimed), so it's not too hard.  However the
ps structure is shared among duplicated file handles.  For example, if
a program opens a usbfs file and claims an interface, and then forks,
both the parent and the child processes will appear to own the
interface.

> 2) If all interfaces are claimed set a "self inflicted reset" flag.
> 3) In pre-reset check-n-clear the "self inflicted reset" if it was set, return
>     success, if it was not set return failure which will make the reset 
> behave as if
>     there is no pre-reset

Maybe all the checking could be done in pre_reset.  All you'd need to
do in proc_resetdevice is set and then clear a "reset pending" flag in
the ps structure.

> Then we will only get the no unbind/rebind behavior on "self inflicted" 
> resets,
> in which case we can assume userspace knows about the reset ...
> 
> This would require adding a capability to signal to libusb the kernel now 
> does things
> this way, and for libusb to be thought about this new capability, to check it 
> has
> all interfaces claimed, and to then and only then not release / re-claim over 
> a reset.
> 
> This sounds like a lot of complications on both sides with little gain ...

True.  And it doesn't help in situations where usbfs doesn't own all of
the interfaces.

> > Repeat the unbind and try again if the reclaim fails.  Two iterations
> > should be sufficient.
> 
> Oh, smart! Yes that will work, so unless we decide to add pre_reset to usbfs
> I guess I'll respin this patch to include this change.

That seems best for now.

Alan Stern


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to