linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: n_gsm: add missing tty_kref_put
@ 2021-11-09 10:39 Pavel Skripkin
  2021-11-09 17:33 ` Jiri Slaby
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Skripkin @ 2021-11-09 10:39 UTC (permalink / raw)
  To: gregkh, jirislaby, hdanton; +Cc: linux-kernel, Pavel Skripkin

My local syzbot instance hit memory leak in gsmld_attach_gsm(). The
reproducer injects allocation failure in tty_register_device(). After
this error only previous tty_register_device() calls unwinded, but not
tty_kref_get().

It leads to tty_struct leak, because ->close() won't be called in case
of ->open() failure and nothing puts tty reference.

Fixes: 0a360e8b65d6 ("tty: n_gsm: check error while registering tty devices")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 drivers/tty/n_gsm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 1d92d2a84889..1cc3aec17d2d 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2394,6 +2394,8 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
 				for (i--; i >= 1; i--)
 					tty_unregister_device(gsm_tty_driver,
 								base + i);
+
+				tty_kref_put(gsm->tty);
 				return PTR_ERR(dev);
 			}
 		}
-- 
2.33.1


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

* Re: [PATCH] tty: n_gsm: add missing tty_kref_put
  2021-11-09 10:39 [PATCH] tty: n_gsm: add missing tty_kref_put Pavel Skripkin
@ 2021-11-09 17:33 ` Jiri Slaby
  2021-11-09 19:10   ` Pavel Skripkin
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Slaby @ 2021-11-09 17:33 UTC (permalink / raw)
  To: Pavel Skripkin, gregkh, hdanton; +Cc: linux-kernel

On 09. 11. 21, 11:39, Pavel Skripkin wrote:
> My local syzbot instance hit memory leak in gsmld_attach_gsm(). The
> reproducer injects allocation failure in tty_register_device(). After
> this error only previous tty_register_device() calls unwinded, but not
> tty_kref_get().
> 
> It leads to tty_struct leak, because ->close() won't be called in case
> of ->open() failure and nothing puts tty reference.

I don't have time to check the n_gsm case now (like: are you talking 
about tty->open/close or file_ops->open/close -- they behave 
differently), but tty definitely calls close even if open fails.

> Fixes: 0a360e8b65d6 ("tty: n_gsm: check error while registering tty devices")
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> ---
>   drivers/tty/n_gsm.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index 1d92d2a84889..1cc3aec17d2d 100644
> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
> @@ -2394,6 +2394,8 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
>   				for (i--; i >= 1; i--)
>   					tty_unregister_device(gsm_tty_driver,
>   								base + i);
> +
> +				tty_kref_put(gsm->tty);
>   				return PTR_ERR(dev);
>   			}
>   		}
> 


-- 
js
suse labs

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

* Re: [PATCH] tty: n_gsm: add missing tty_kref_put
  2021-11-09 17:33 ` Jiri Slaby
@ 2021-11-09 19:10   ` Pavel Skripkin
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Skripkin @ 2021-11-09 19:10 UTC (permalink / raw)
  To: Jiri Slaby, gregkh, hdanton; +Cc: linux-kernel

On 11/9/21 20:33, Jiri Slaby wrote:
> On 09. 11. 21, 11:39, Pavel Skripkin wrote:
>> My local syzbot instance hit memory leak in gsmld_attach_gsm(). The
>> reproducer injects allocation failure in tty_register_device(). After
>> this error only previous tty_register_device() calls unwinded, but not
>> tty_kref_get().
>> 
>> It leads to tty_struct leak, because ->close() won't be called in case
>> of ->open() failure and nothing puts tty reference.
> 
> I don't have time to check the n_gsm case now (like: are you talking
> about tty->open/close or file_ops->open/close -- they behave
> differently), but tty definitely calls close even if open fails.
> 

Oh, I see now. I wasn't aware about this difference. Will do more 
detailed analysis of reported leak. Thank you for pointing it out!




With regards,
Pavel Skripkin

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

end of thread, other threads:[~2021-11-09 19:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 10:39 [PATCH] tty: n_gsm: add missing tty_kref_put Pavel Skripkin
2021-11-09 17:33 ` Jiri Slaby
2021-11-09 19:10   ` Pavel Skripkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).