All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v6 5/9] serial: max310x: wait for TX to drain before powering down in shutdown
Date: Sun, 04 Oct 2026 12:28:35 +0000	[thread overview]
Message-ID: <20261004122835.92E741F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004-max310x-rs485-sw-delay-v6-5-3a0ef13ed9e3@vaisala.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serial: max310x: DoS via uninterruptible sleep in max310x_shutdown()
--

commit 418c89d1dd7ac6d2979824452f69b97e06892699
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>

serial: max310x: wait for TX to drain before powering down in shutdown

This patch waits for the TX FIFO to drain before powering down the port
in max310x_shutdown(), calculating the per-character sleep duration
based on the configured baud rate.

> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index 2456a2af891f5..9dcc817b97945 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c

[ ... ]

> @@ -1124,10 +1126,13 @@ static void max310x_set_termios(struct uart_port *port,
>  	uart_update_timeout(port, termios->c_cflag, baud);
>  
>  	/*
> -	 * Cache the new baud rate and reprogram the RS485 RTS delays, whose
> -	 * millisecond-to-bit-time conversion depends on it.
> +	 * Cache the new baud rate and the time it takes to clock out one
> +	 * character before reprogramming the RS485 RTS delays: the
> +	 * millisecond-to-bit-time conversion divides by the baud rate.
>  	 */
>  	to_max310x_port(port)->baud = baud;
> +	to_max310x_port(port)->char_time_us =
> +		DIV_ROUND_UP(USEC_PER_SEC * frame_bits, baud);

[Severity: High]
Does this calculation create a dangerously large sleep duration at extremely
low baud rates?

If a user configures a very low baud rate (e.g., 50 baud or even 1 baud), this
value becomes extremely large since it scales inversely with the baud rate.

>  	max310x_set_rts_ctl_params(to_max310x_port(port));
>  }
>  
> @@ -1223,6 +1228,22 @@ static int max310x_startup(struct uart_port *port)
>  
>  static void max310x_shutdown(struct uart_port *port)
>  {
> +	struct max310x_one *one = to_max310x_port(port);
> +	unsigned int tries = port->fifosize + 1;
> +
> +	/*
> +	 * The tty layer's wait-until-sent is bounded by closing_wait, which
> +	 * can be configured to none, and a hangup reaches here with no wait
> +	 * at all, so the FIFO may still hold anything up to its full size.
> +	 * tx_empty() also only reflects the chip TX FIFO - the last character
> +	 * may still be in the transmit shift register. Let the FIFO drain and
> +	 * the final character clock out before the port is powered down,
> +	 * otherwise the transfer is truncated on the wire.
> +	 */
> +	while (!max310x_tx_empty(port) && tries-- > 0)
> +		fsleep(one->char_time_us);
> +	fsleep(one->char_time_us);

[Severity: High]
Can this loop be used to cause a local Denial of Service via an extended
D-state hang or Hung Task Panic?

If a user opens the TTY, configures a very low baud rate (e.g., speed 1-50),
disables CTS flow control (preventing the TX FIFO from draining), and closes
the device, max310x_shutdown() could call fsleep() up to 129 times in
TASK_UNINTERRUPTIBLE.

At 50 baud, char_time_us is 200,000, causing a 25.8 second uninterruptible
sleep per close(). At 1 baud, this sleep duration exceeds 20 minutes, which
would trigger the kernel's hung_task_panic. Even without a panic, the
extended D-state sleep holds the TTY port mutex, blocking system services
like udev or other users from accessing the port.

> +
>  	/* Disable all interrupts */
>  	max310x_port_write(port, MAX310X_IRQEN_REG, 0);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261004-max310x-rs485-sw-delay-v6-0-3a0ef13ed9e3@vaisala.com?part=5

  reply	other threads:[~2026-10-04 12:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 12:16 [PATCH v6 0/9] serial: max310x: RS485 delay and RTS fixes, software-timed delays Tapio Reijonen
2026-10-04 12:16 ` [PATCH v6 1/9] serial: max310x: don't clobber the TX break bit in set_termios Tapio Reijonen
2026-10-04 12:23   ` sashiko-bot
2026-10-05 15:45   ` Hugo Villeneuve
2026-10-04 12:16 ` [PATCH v6 2/9] serial: max310x: assert the transceiver during a break Tapio Reijonen
2026-10-04 12:33   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 3/9] serial: max310x: centralize the RS485 transceiver programming Tapio Reijonen
2026-10-04 12:24   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 4/9] serial: max310x: convert RS485 delays from milliseconds to bit-times Tapio Reijonen
2026-10-04 12:30   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 5/9] serial: max310x: wait for TX to drain before powering down in shutdown Tapio Reijonen
2026-10-04 12:28   ` sashiko-bot [this message]
2026-10-05 10:12   ` Maarten Brock
2026-10-05 10:51     ` Tapio Reijonen
2026-10-04 12:16 ` [PATCH v6 6/9] serial: max310x: support active-low RTS on the hardware path Tapio Reijonen
2026-10-04 12:25   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 7/9] serial: max310x: schedule tx_work directly from the IRQ handler Tapio Reijonen
2026-10-04 12:24   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 8/9] serial: max310x: drive RTS in software when hardware delays are too short Tapio Reijonen
2026-10-04 12:31   ` sashiko-bot
2026-10-04 12:16 ` [PATCH v6 9/9] serial: max310x: don't transmit while an RS485 reconfigure is pending Tapio Reijonen
2026-10-04 12:31   ` 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=20261004122835.92E741F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tapio.reijonen@vaisala.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.