[PATCH v2 2/2] tty: vcc: hold port lock when clearing tty pointer in vcc_cleanup
Greg Kroah-Hartman <[email protected]> Mon, 03 Aug 2026 16:10:55 +0200
| Newsgroups | org.kernel.vger.sparclinux,org.kernel.vger.linux-kernel,org.kernel.vger.linux-serial |
|---|---|
| Message-ID | <[email protected]> |
From: Joshua Rogers <[email protected]> vcc_cleanup() sets port->tty to NULL without holding port->lock, racing with vcc_event() LDC callbacks that read port->tty under port->lock and then use tty->port. This can cause a use-after-free when the callback dereferences tty->port after cleanup has already destroyed and freed it. Assisted-by: AISLE:Snapshot Cc: stable <[email protected]> Signed-off-by: Joshua Rogers <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> --- drivers/tty/vcc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c index 3947bd2b75ac..9adb533f7034 100644 --- a/drivers/tty/vcc.c +++ b/drivers/tty/vcc.c @@ -986,7 +986,8 @@ static void vcc_cleanup(struct tty_struct *tty) port = vcc_get(tty->index, true); if (port) { - port->tty = NULL; + scoped_guard(spinlock_irqsave, &port->lock) + port->tty = NULL; if (port->removed) { vcc_table_remove(tty->index); -- 2.55.0