From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Jiri Slaby <jirislaby@kernel.org>
Cc: sparclinux@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Joshua Rogers <linux@joshua.hu>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
stable <stable@kernel.org>
Subject: Re: [PATCH 2/2] tty: vcc: hold port lock when clearing tty pointer in vcc_cleanup
Date: Mon, 3 Aug 2026 16:09:05 +0200 [thread overview]
Message-ID: <2026080338-imperfect-plant-ef79@gregkh> (raw)
In-Reply-To: <f3b571b3-86b3-480b-bde3-dd2e7bead7fb@kernel.org>
On Fri, Jul 31, 2026 at 10:32:36AM +0200, Jiri Slaby wrote:
> On 31. 07. 26, 10:15, Greg Kroah-Hartman wrote:
> > From: Joshua Rogers <linux@joshua.hu>
> >
> > 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 <stable@kernel.org>
> > Signed-off-by: Joshua Rogers <linux@joshua.hu>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> > drivers/tty/vcc.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
> > index 3947bd2b75ac..03ed8c692acd 100644
> > --- a/drivers/tty/vcc.c
> > +++ b/drivers/tty/vcc.c
> > @@ -983,10 +983,13 @@ static int vcc_install(struct tty_driver *driver, struct tty_struct *tty)
> > static void vcc_cleanup(struct tty_struct *tty)
> > {
> > struct vcc_port *port;
> > + unsigned long flags;
> > port = vcc_get(tty->index, true);
> > if (port) {
> > + spin_lock_irqsave(&port->lock, flags);
> > port->tty = NULL;
> > + spin_unlock_irqrestore(&port->lock, flags);
>
> For these, I like
>
> scope_guard(spinlock_irqsave, &port->lock)
> port->tty = NULL;
Fair enough, that's much cleaner, LLMs really do not know about that
pattern yet :)
thanks,
greg k-h
prev parent reply other threads:[~2026-08-03 14:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:15 [PATCH 0/2] tty: vcc: Some small vcc bugfixes found by code scans Greg Kroah-Hartman
2026-07-31 8:15 ` [PATCH 1/2] tty: vcc: zero-initialize control packet in vcc_send_ctl() Greg Kroah-Hartman
2026-07-31 8:29 ` Jiri Slaby
2026-07-31 8:32 ` Greg Kroah-Hartman
2026-07-31 9:16 ` Jiri Slaby
2026-07-31 12:02 ` Greg Kroah-Hartman
2026-07-31 8:15 ` [PATCH 2/2] tty: vcc: hold port lock when clearing tty pointer in vcc_cleanup Greg Kroah-Hartman
2026-07-31 8:32 ` Jiri Slaby
2026-08-03 14:09 ` Greg Kroah-Hartman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2026080338-imperfect-plant-ef79@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=davem@davemloft.net \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@joshua.hu \
--cc=sparclinux@vger.kernel.org \
--cc=stable@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox