public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: synclink_gt: Fix potential deadlock on &info->lock
@ 2023-07-28 12:39 Chengfeng Ye
  2023-07-31  5:40 ` Jiri Slaby
       [not found] ` <a95e699c-c507-931e-92b0-7f63a5e3a9e1@web.de>
  0 siblings, 2 replies; 3+ messages in thread
From: Chengfeng Ye @ 2023-07-28 12:39 UTC (permalink / raw)
  To: gregkh, jirislaby, ilpo.jarvinen, bhelgaas, russell.h.weight
  Cc: linux-kernel, Chengfeng Ye

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@gmail.com>
---
 drivers/tty/synclink_gt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index 16e469e581ec..e86bb6228e0f 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -1088,12 +1088,13 @@ static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *us
 static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params)
 {
 	struct MGSL_PARAMS32 tmp_params;
+	unsigned long flags;
 
 	DBGINFO(("%s set_params32\n", info->device_name));
 	if (copy_from_user(&tmp_params, new_params, sizeof(struct MGSL_PARAMS32)))
 		return -EFAULT;
 
-	spin_lock(&info->lock);
+	spin_lock_irqsave(&info->lock, flags);
 	if (tmp_params.mode == MGSL_MODE_BASE_CLOCK) {
 		info->base_clock = tmp_params.clock_speed;
 	} else {
@@ -1111,7 +1112,7 @@ static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *ne
 		info->params.stop_bits       = tmp_params.stop_bits;
 		info->params.parity          = tmp_params.parity;
 	}
-	spin_unlock(&info->lock);
+	spin_unlock_irqrestore(&info->lock, flags);
 
 	program_hw(info);
 
-- 
2.17.1


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

* Re: [PATCH] tty: synclink_gt: Fix potential deadlock on &info->lock
  2023-07-28 12:39 [PATCH] tty: synclink_gt: Fix potential deadlock on &info->lock Chengfeng Ye
@ 2023-07-31  5:40 ` Jiri Slaby
       [not found] ` <a95e699c-c507-931e-92b0-7f63a5e3a9e1@web.de>
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2023-07-31  5:40 UTC (permalink / raw)
  To: Chengfeng Ye, gregkh, ilpo.jarvinen, bhelgaas, russell.h.weight
  Cc: linux-kernel

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@gmail.com>

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

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

thanks,
-- 
js
suse labs


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

* Re: [PATCH] tty: synclink_gt: Fix potential deadlock on &info->lock
       [not found] ` <a95e699c-c507-931e-92b0-7f63a5e3a9e1@web.de>
@ 2023-07-31 13:22   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-07-31 13:22 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Chengfeng Ye, kernel-janitors, Bjorn Helgaas, Ilpo Järvinen,
	Jiri Slaby, Russ Weight, LKML

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless
review comment to a patch submission on a Linux kernel developer mailing
list.  I strongly suggest that you not do this anymore.  Please do not
bother developers who are actively working to produce patches and
features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to
follow it at all.  The person/bot/AI that sent it is being ignored by
almost all Linux kernel maintainers for having a persistent pattern of
behavior of producing distracting and pointless commentary, and
inability to adapt to feedback.  Please feel free to also ignore emails
from them.

thanks,

greg k-h's patch email bot

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

end of thread, other threads:[~2023-07-31 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-28 12:39 [PATCH] tty: synclink_gt: Fix potential deadlock on &info->lock Chengfeng Ye
2023-07-31  5:40 ` Jiri Slaby
     [not found] ` <a95e699c-c507-931e-92b0-7f63a5e3a9e1@web.de>
2023-07-31 13:22   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox