2024-04-18 17:31:48

by Jeongjun Park

[permalink] [raw]
Subject: [PATCH] hams: Fix deadlock caused by unsafe-irq lock in sp_get()


read_lock() present in sp_get() is interrupt-vulnerable, so the function needs to be modified.


Reported-by: [email protected]
Signed-off-by: Jeongjun Park <[email protected]>
---
drivers/net/hamradio/6pack.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 6ed38a3cdd73..f882682ff0c8 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -372,12 +372,13 @@ static DEFINE_RWLOCK(disc_data_lock);
static struct sixpack *sp_get(struct tty_struct *tty)
{
struct sixpack *sp;
+ unsigned long flags;

- read_lock(&disc_data_lock);
+ flags = read_lock_irqsave(&disc_data_lock);
sp = tty->disc_data;
if (sp)
refcount_inc(&sp->refcnt);
- read_unlock(&disc_data_lock);
+ read_unlock_irqrestore(&disc_data_lock, flags);

return sp;
}
--
2.34.1


2024-04-22 12:49:37

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] hams: Fix deadlock caused by unsafe-irq lock in sp_get()

On Fri, Apr 19, 2024 at 02:30:37AM +0900, Jeongjun Park wrote:
>
> read_lock() present in sp_get() is interrupt-vulnerable, so the function needs to be modified.
>
>
> Reported-by: [email protected]
> Signed-off-by: Jeongjun Park <[email protected]>
> ---
> drivers/net/hamradio/6pack.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
> index 6ed38a3cdd73..f882682ff0c8 100644
> --- a/drivers/net/hamradio/6pack.c
> +++ b/drivers/net/hamradio/6pack.c
> @@ -372,12 +372,13 @@ static DEFINE_RWLOCK(disc_data_lock);
> static struct sixpack *sp_get(struct tty_struct *tty)
> {
> struct sixpack *sp;
> + unsigned long flags;
>
> - read_lock(&disc_data_lock);
> + flags = read_lock_irqsave(&disc_data_lock);

This doesn't compile. At least build test your patches.

regards,
dan carpenter