Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v4 2/4] tty: serdev: Export functions to pause receive_buf callback calls
Date: Fri, 16 Oct 2026 18:13:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-174756@kernel.org> (raw)
In-Reply-To: <20261016-rust_serdev_probe_refactor-v4-2-46832e034757@posteo.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] tty: NULL pointer dereference / UAF in ttyport_pause_rx and ttyport_resume_rx due to TOCTOU
--

commit 7862c81055f41fa0e8cc37f91200a9bcccf35960
Author: Markus Probst <markus.probst@posteo.de>

tty: serdev: Export functions to pause receive_buf callback calls

These functions will be used to simply the serdev rust abstraction. It
also contributes to the fixing of 2 race conditions in the serdev rust
abstraction.

> diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
> index 125a17a0bea50..e164ee7edc121 100644
> --- a/drivers/tty/serdev/serdev-ttyport.c
> +++ b/drivers/tty/serdev/serdev-ttyport.c

[ ... ]

> @@ -185,6 +190,37 @@ static bool ttyport_close(struct serdev_controller *ctrl)
>  	return true;
>  }
>  
> +static void ttyport_pause_rx(struct serdev_controller *ctrl)
> +{
> +	struct serport *serport = serdev_controller_get_drvdata(ctrl);
> +	struct tty_struct *tty = serport->tty;
> +
> +	guard(mutex)(&serport->lock);

[Severity: High]
Does this code have a race condition since the local pointer tty is assigned
from serport->tty before the serport->lock is acquired?

This lock protects the lifecycle of the tty structure and the SERPORT_ACTIVE
flag, which are modified concurrently by ttyport_open() and ttyport_close().

If a concurrent thread calls ttyport_open() or if the port transitions states
asynchronously, it will allocate a new tty_struct, set serport->tty, and set
SERPORT_ACTIVE to true.

> +
> +	scoped_guard(mutex, &serport->receive_lock)
> +		set_bit(SERPORT_PAUSE_RX, &serport->flags);
> +
> +	if (test_bit(SERPORT_ACTIVE, &serport->flags))
> +		tty_buffer_cancel_work(tty->port);

Because tty was captured outside the lock, could it remain NULL if previously
closed or point to a freed structure?

If the ttyport_pause_rx() thread then acquires the lock and sees that
SERPORT_ACTIVE is true, will this result in an immediate NULL pointer
dereference or use-after-free when accessing tty->port?

Should the assignment of the tty pointer be moved inside the critical section?

> +}
> +
> +static void ttyport_resume_rx(struct serdev_controller *ctrl)
> +{
> +	struct serport *serport = serdev_controller_get_drvdata(ctrl);
> +	struct tty_struct *tty = serport->tty;
> +
> +	guard(mutex)(&serport->lock);

[Severity: High]
Does the identical vulnerability exist in the resume path where tty is
captured outside the lock?

> +
> +	if (!test_bit(SERPORT_PAUSE_RX, &serport->flags))
> +		return;
> +
> +	scoped_guard(mutex, &serport->receive_lock)
> +		clear_bit(SERPORT_PAUSE_RX, &serport->flags);
> +
> +	if (test_bit(SERPORT_ACTIVE, &serport->flags))
> +		tty_buffer_restart_work(tty->port);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016-rust_serdev_probe_refactor-v4-0-46832e034757@posteo.de?part=2

  reply	other threads:[~2026-10-16 18:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 18:00 [PATCH v4 0/4] rust: serdev: Refactor Markus Probst
2026-10-16 18:00 ` [PATCH v4 1/4] tty: serdev: Add mutex lock Markus Probst
2026-10-16 18:15   ` sashiko-bot
2026-10-16 18:00 ` [PATCH v4 2/4] tty: serdev: Export functions to pause receive_buf callback calls Markus Probst
2026-10-16 18:13   ` sashiko-bot [this message]
2026-10-16 18:00 ` [PATCH v4 3/4] rust: serdev: Replace `active` mutex with receive pause Markus Probst
2026-10-16 18:11   ` sashiko-bot
2026-10-16 18:00 ` [PATCH v4 4/4] rust: serdev: Simplify callbacks Markus Probst
2026-10-16 18:17   ` sashiko-bot

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=sashiko-outbox-174756@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-serial@vger.kernel.org \
    --cc=markus.probst@posteo.de \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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