Skip to contentSkip to conversation

doubts concerning locking and signals in input_register_device()

DISCUSSION Oliver Neukum 2 participants 3 messages Jun 20, 2022 – Jul 6, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Hi Oliver,

Quoted 17 lines · Oliver Neukum

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.

Quoted 6 lines

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.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 1 line · Dmitry Torokhov

Hi Oliver,

Hi,

Quoted 7 lines

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