From: Jiri Slaby <jirislaby@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Markus Probst <markus.probst@posteo.de>,
linux-serial@vger.kernel.org
Cc: Rob Herring <robh@kernel.org>,
linux-kernel@vger.kernel.org, Joshua Rogers <linux@joshua.hu>,
stable <stable@kernel.org>
Subject: Re: [PATCH 2/2] serdev: use tty_port_tty_get() in ttyport_write_buf() to prevent UAF
Date: Fri, 31 Jul 2026 10:24:02 +0200 [thread overview]
Message-ID: <d6d96f15-03f5-4213-9d7c-145b5a8c3f79@kernel.org> (raw)
In-Reply-To: <20260731-aisle-tty-serdev-v1-2-2401a3189327@linuxfoundation.org>
On 31. 07. 26, 10:06, Greg Kroah-Hartman wrote:
> From: Joshua Rogers <linux@joshua.hu>
>
> ttyport_write_buf() snapshots serport->tty as a raw pointer without
> taking a reference, while ttyport_close() can concurrently release the
> tty via tty_release_struct(), leading to a use-after-free. Use
> tty_port_tty_get() to obtain a reference-counted tty pointer, matching
> the pattern already used by ttyport_write_wakeup().
>
> 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/serdev/serdev-ttyport.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
> index 48ce5b3f8308..4d37c8130dd7 100644
> --- a/drivers/tty/serdev/serdev-ttyport.c
> +++ b/drivers/tty/serdev/serdev-ttyport.c
> @@ -85,13 +85,21 @@ static const struct tty_port_client_operations client_ops = {
> static ssize_t ttyport_write_buf(struct serdev_controller *ctrl, const u8 *data, size_t len)
> {
> struct serport *serport = serdev_controller_get_drvdata(ctrl);
> - struct tty_struct *tty = serport->tty;
> + struct tty_struct *tty;
> + ssize_t ret;
>
> if (!test_bit(SERPORT_ACTIVE, &serport->flags))
> return 0;
>
> + tty = tty_port_tty_get(serport->port);
> + if (!tty)
> + return 0;
> +
> set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
> - return tty->ops->write(serport->tty, data, len);
> + ret = tty->ops->write(tty, data, len);
> + tty_kref_put(tty);
Here,
scope_guard(tty_port_tty, serport->port) {
struct tty_struct *tty = scoped_tty();
set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
return tty->ops->write(serport->tty, data, len);
}
return 0;
appears to be cleaner.
thanks,
--
js
suse labs
next prev parent reply other threads:[~2026-07-31 8:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:06 [PATCH 0/2] serdev: Some small serdev bugfixes found by code scans Greg Kroah-Hartman
2026-07-31 8:06 ` [PATCH 1/2] serdev: fix race between tty-port unregister and in-flight callbacks Greg Kroah-Hartman
2026-07-31 11:30 ` Markus Probst
2026-07-31 12:01 ` Greg Kroah-Hartman
2026-07-31 12:43 ` Markus Probst
2026-07-31 8:06 ` [PATCH 2/2] serdev: use tty_port_tty_get() in ttyport_write_buf() to prevent UAF Greg Kroah-Hartman
2026-07-31 8:24 ` Jiri Slaby [this message]
2026-07-31 8:28 ` Greg Kroah-Hartman
2026-07-31 13:00 ` Markus Probst
2026-07-31 13:22 ` Greg Kroah-Hartman
2026-07-31 13:30 ` Markus Probst
2026-07-31 8:14 ` [PATCH 0/2] serdev: Some small serdev bugfixes found by code scans Greg Kroah-Hartman
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=d6d96f15-03f5-4213-9d7c-145b5a8c3f79@kernel.org \
--to=jirislaby@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@joshua.hu \
--cc=markus.probst@posteo.de \
--cc=robh@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