Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] kgdboc: Fix tty driver reference leak in configure_kgdboc()
@ 2026-09-17 15:55 Wentao Liang
  2026-09-17 16:00 ` sashiko-bot
  2026-09-17 21:59 ` Doug Anderson
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-09-17 15:55 UTC (permalink / raw)
  To: alan
  Cc: danielt, dianders, gregkh, jason.wessel, jirislaby,
	kgdb-bugreport, linux-kernel, linux-serial, Wentao Liang, stable

tty_find_polling_driver() returns the tty driver with an extra
reference taken by tty_driver_kref_get(). configure_kgdboc() stores it
in kgdb_tty_driver but the reference is never dropped: it is leaked when
kgdb_register_io_module() fails, when the configuration is cleared, and
on every reconfigure.

Release the reference both when unconfiguring and on the error path.

Fixes: 7d7b93c1452f ("tty: kref the tty driver object")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/tty/serial/kgdboc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index 5a955c80a853..e2c8e5ec688c 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -188,6 +188,11 @@ static void cleanup_kgdboc(void)
 
 	kgdboc_unregister_kbd();
 	kgdb_unregister_io_module(&kgdboc_io_ops);
+
+	if (kgdb_tty_driver) {
+		tty_driver_kref_put(kgdb_tty_driver);
+		kgdb_tty_driver = NULL;
+	}
 }
 
 static int configure_kgdboc(void)
@@ -254,6 +259,10 @@ static int configure_kgdboc(void)
 
 noconfig:
 	kgdboc_unregister_kbd();
+	if (kgdb_tty_driver) {
+		tty_driver_kref_put(kgdb_tty_driver);
+		kgdb_tty_driver = NULL;
+	}
 	configured = 0;
 
 	return err;
-- 
2.34.1


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

* Re: [PATCH] kgdboc: Fix tty driver reference leak in configure_kgdboc()
  2026-09-17 15:55 [PATCH] kgdboc: Fix tty driver reference leak in configure_kgdboc() Wentao Liang
@ 2026-09-17 16:00 ` sashiko-bot
  2026-09-17 21:59 ` Doug Anderson
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-17 16:00 UTC (permalink / raw)
  To: Wentao Liang; +Cc: linux-serial

> tty_find_polling_driver() returns the tty driver with an extra
> reference taken by tty_driver_kref_get(). configure_kgdboc() stores it
> in kgdb_tty_driver but the reference is never dropped: it is leaked when
> kgdb_register_io_module() fails, when the configuration is cleared, and
> on every reconfigure.
> 
> Release the reference both when unconfiguring and on the error path.
> 
> Fixes: 7d7b93c1452f ("tty: kref the tty driver object")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260917155523.2161202-1-vulab@iscas.ac.cn?part=1


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

* Re: [PATCH] kgdboc: Fix tty driver reference leak in configure_kgdboc()
  2026-09-17 15:55 [PATCH] kgdboc: Fix tty driver reference leak in configure_kgdboc() Wentao Liang
  2026-09-17 16:00 ` sashiko-bot
@ 2026-09-17 21:59 ` Doug Anderson
  1 sibling, 0 replies; 3+ messages in thread
From: Doug Anderson @ 2026-09-17 21:59 UTC (permalink / raw)
  To: Wentao Liang
  Cc: alan, danielt, gregkh, jason.wessel, jirislaby, kgdb-bugreport,
	linux-kernel, linux-serial, stable

Hi,

On Thu, Sep 17, 2026 at 8:55 AM Wentao Liang <vulab@iscas.ac.cn> wrote:
>
> tty_find_polling_driver() returns the tty driver with an extra
> reference taken by tty_driver_kref_get(). configure_kgdboc() stores it
> in kgdb_tty_driver but the reference is never dropped: it is leaked when
> kgdb_register_io_module() fails, when the configuration is cleared, and
> on every reconfigure.
>
> Release the reference both when unconfiguring and on the error path.
>
> Fixes: 7d7b93c1452f ("tty: kref the tty driver object")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/tty/serial/kgdboc.c | 9 +++++++++
>  1 file changed, 9 insertions(+)

Looks right to me. Even the "Fixes" looks right since the tty change
landed after kgdb was added to the mainline kernel (by a ~6 months).

Reviewed-by: Douglas Anderson <dianders@chromium.org>

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

end of thread, other threads:[~2026-09-17 21:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 15:55 [PATCH] kgdboc: Fix tty driver reference leak in configure_kgdboc() Wentao Liang
2026-09-17 16:00 ` sashiko-bot
2026-09-17 21:59 ` Doug Anderson

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