Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] tty: vt: protect tty lifetime in keyboard path
@ 2026-11-19  2:42 Haoli Zhang
  2026-11-19  2:52 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Haoli Zhang @ 2026-11-19  2:42 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, linux-kernel, linux-serial,
	syzbot+2932e8970a6398db95c3, 25031212117, byu, Haoli Zhang

I apologize for the v1 patch. It included a NULL check inside the
conditional tty_port_tty guard, even though the guard skips its body when
no tty is associated. That check was redundant and made the guard usage
unclear. I have removed it in this version.

fn_hold() reads vc->port.tty and calls start_tty() or stop_tty() without
holding a tty reference. kbd_event_lock serializes keyboard event
processing, but it does not protect the tty lifetime against
con_shutdown() clearing the port association.

Use the tty_port_tty guard in fn_hold() to obtain a reference and keep it
until start_tty() or stop_tty() returns. Use tty_port_tty_set() when
installing and clearing the association, so tty lookup and association
updates are serialized by the port lock. fn_hold() keeps the tty
reference until the start/stop operation completes.

Reported-by: syzbot+2932e8970a6398db95c3@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=2932e8970a6398db95c3
Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn>
---
Changes in v2:
- Remove the redundant NULL check inside the conditional tty_port_tty guard.

 drivers/tty/vt/keyboard.c | 26 ++++++++++++++------------
 drivers/tty/vt/vt.c       |  4 ++--
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -510,17 +510,19 @@
 static void fn_hold(struct vc_data *vc)
 {
-	struct tty_struct *tty = vc->port.tty;
-
-	if (rep || !tty)
+	if (rep)
 		return;
 
-	/*
-	 * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);
-	 * these routines are also activated by ^S/^Q.
-	 * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)
-	 */
-	if (tty->flow.stopped)
-		start_tty(tty);
-	else
-		stop_tty(tty);
+	scoped_guard(tty_port_tty, &vc->port) {
+		struct tty_struct *tty = scoped_tty();
+
+		/*
+		 * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);
+		 * these routines are also activated by ^S/^Q.
+		 * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)
+		 */
+		if (tty->flow.stopped)
+			start_tty(tty);
+		else
+			stop_tty(tty);
+	}
 }
 
 static void fn_num(struct vc_data *vc)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3759,7 +3759,7 @@
 		return ret;
 
 	tty->driver_data = vc;
-	vc->port.tty = tty;
+	tty_port_tty_set(&vc->port, tty);
 	tty_port_get(&vc->port);
 
 	if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
@@ -3792,7 +3792,7 @@
 	BUG_ON(vc == NULL);
 
 	guard(console_lock)();
-	vc->port.tty = NULL;
+	tty_port_tty_set(&vc->port, NULL);
 }
 
 static void con_cleanup(struct tty_struct *tty)


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

* Re: [PATCH v2] tty: vt: protect tty lifetime in keyboard path
  2026-11-19  2:42 [PATCH v2] tty: vt: protect tty lifetime in keyboard path Haoli Zhang
@ 2026-11-19  2:52 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19  2:52 UTC (permalink / raw)
  To: Haoli Zhang; +Cc: linux-serial

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] tty: vt: patch revision commentary and apology in commit message
  body
--

commit 07a0cb83e09876e569aba67b5389fa9413ff391d
Author: Haoli Zhang <26031212468@stu.xidian.edu.cn>

tty: vt: protect tty lifetime in keyboard path

This commit uses the tty_port_tty guard in fn_hold() and tty_port_tty_set()
in con_install() and con_shutdown() to protect the tty lifetime against
concurrent port dissociation.

> I apologize for the v1 patch. It included a NULL check inside the
> conditional tty_port_tty guard, even though the guard skips its body when
> no tty is associated. That check was redundant and made the guard usage
> unclear. I have removed it in this version.

[Severity: Low]
This isn't a bug, but v1-to-v2 revision commentary and notes to reviewers
belong below the "---" tearline so they do not become part of the permanent
git commit log.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119024207.4075962-1-26031212468@stu.xidian.edu.cn?part=1

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

end of thread, other threads:[~2026-11-19  2:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  2:42 [PATCH v2] tty: vt: protect tty lifetime in keyboard path Haoli Zhang
2026-11-19  2:52 ` sashiko-bot

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