Re: [PATCH] tty: synclink_gt: Fix potential deadlock on &info->lock

From: Jiri Slaby
Date: Mon Jul 31 2023 - 01:40:58 EST


On 28. 07. 23, 14:39, Chengfeng Ye wrote:
As &info->lock is acquired by slgt_interrupt() under irq context, other
process context code acquiring the lock should disable irq, otherwise
deadlock could happen if the irq preempt the execution while the
lock is held in process context on the same CPU.

Lock acquisition inside set_params32() does not disable irq, and this
function is called by slgt_compat_ioctl() from process context.

Possible deadlock scenario:
slgt_compat_ioctl()
-> set_params32()
-> spin_lock(&info->lock)
<irq>
-> slgt_interrupt()
-> spin_lock(&info->lock); (deadlock here)

This flaw was found by an experimental static analysis tool I am developing
for irq-related deadlock. x86_64 allmodconfig using gcc shows no new
warning.

The patch fixes the potential deadlock by spin_lock_irqsave() like other
lock acquisition sites.

Signed-off-by: Chengfeng Ye <dg573847474@xxxxxxxxx>

Oh well, this driver deserves to die (or a massive rewrite).

Reviewed-by: Jiri Slaby <jirislaby@xxxxxxxxxx>

thanks,
--
js
suse labs