All of lore.kernel.org
 help / color / mirror / Atom feed
* doubts concerning locking and signals in input_register_device()
@ 2022-06-20 12:48 Oliver Neukum
  2022-06-24  0:46 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Neukum @ 2022-06-20 12:48 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: jkosina, linux-input, Alan Stern, USB list

Hi,

I am looking at this code in input_register_device():

        error = mutex_lock_interruptible(&input_mutex);
        if (error)
                goto err_device_del;

The problem is not the scope of the locking, but how the
lock is taken.
AFAICT this code will be called in the context of an
ordinary task when you set a configuration through usbfs.
usb_set_configuration() has to probe all interfaces
of a device under its new configuration and does not
handle -EINTR, which input_register_device() will
return when a signal interrupts taking the mutex.

Hence there is a window for a race during which a
mistimed harmless signal will cause a failure of probe()

Now, as this is fairly core code I'd rather ask what
you think before I make the simple fix of taking
the mutex with uninterruptible sleep. What is to be done?

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: doubts concerning locking and signals in input_register_device()
  2022-06-20 12:48 doubts concerning locking and signals in input_register_device() Oliver Neukum
@ 2022-06-24  0:46 ` Dmitry Torokhov
  2022-07-06  8:54   ` Oliver Neukum
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2022-06-24  0:46 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: jkosina, linux-input, Alan Stern, USB list

Hi Oliver,

On Mon, Jun 20, 2022 at 02:48:01PM +0200, Oliver Neukum wrote:
> Hi,
> 
> I am looking at this code in input_register_device():
> 
>         error = mutex_lock_interruptible(&input_mutex);
>         if (error)
>                 goto err_device_del;
> 
> The problem is not the scope of the locking, but how the
> lock is taken.
> AFAICT this code will be called in the context of an
> ordinary task when you set a configuration through usbfs.
> usb_set_configuration() has to probe all interfaces
> of a device under its new configuration and does not
> handle -EINTR, which input_register_device() will
> return when a signal interrupts taking the mutex.
> 
> Hence there is a window for a race during which a
> mistimed harmless signal will cause a failure of probe()
> 
> Now, as this is fairly core code I'd rather ask what
> you think before I make the simple fix of taking
> the mutex with uninterruptible sleep. What is to be done?

The reason I believe we should be using interruptible or killable
versions of locking is to give a chance to bail (with Ctrl-C or kill or
whatever) in case the system is wedged for some reason.

Where would this mistimed harmless signal come from unless user actually
tries to interrupt module loading/driver binding/sysfs access?

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: doubts concerning locking and signals in input_register_device()
  2022-06-24  0:46 ` Dmitry Torokhov
@ 2022-07-06  8:54   ` Oliver Neukum
  0 siblings, 0 replies; 3+ messages in thread
From: Oliver Neukum @ 2022-07-06  8:54 UTC (permalink / raw)
  To: Dmitry Torokhov, Oliver Neukum; +Cc: jkosina, linux-input, Alan Stern, USB list



On 24.06.22 02:46, Dmitry Torokhov wrote:
> Hi Oliver,

Hi,

> 
> The reason I believe we should be using interruptible or killable
> versions of locking is to give a chance to bail (with Ctrl-C or kill or
> whatever) in case the system is wedged for some reason.
> 
> Where would this mistimed harmless signal come from unless user actually
> tries to interrupt module loading/driver binding/sysfs access?

timers, window size, ....

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-06  8:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20 12:48 doubts concerning locking and signals in input_register_device() Oliver Neukum
2022-06-24  0:46 ` Dmitry Torokhov
2022-07-06  8:54   ` Oliver Neukum

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.