From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH 1/3] serial: max310x: do not advance the TX fifo past a flush
Date: Mon, 16 Nov 2026 10:18:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-216707@kernel.org> (raw)
In-Reply-To: <20261116-max310x-tx-fixes-v1-1-61c01f180911@vaisala.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] serial: max310x: out-of-bounds write in max310x_handle_rx()
[1]
--
commit 12622456e1b4a71d597213ac90888e9dce7b8d1e
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>
serial: max310x: do not advance the TX fifo past a flush
This commit copies outgoing bytes into a per-port buffer under the port
lock before transmitting over SPI and skips advancing the TX kfifo if
uart_flush_buffer() ran during the transfer.
> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index a0ed70185555e..e6a740295b966 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
> @@ -317,11 +317,13 @@ struct max310x_one {
> bool sw_rts_during_tx;
> bool cancel_tx_delay_tmr;
> bool tx_teardown; /* envelope being torn down */
> + bool tx_flushed; /* fifo reset under a transfer */
> bool rs485_pending; /* rs_work not yet applied */
> bool tx_break; /* break_ctl() owns the transceiver */
> enum max310x_tx_state tx_state;
>
> u8 rx_buf[MAX310X_FIFO_SIZE];
> + u8 tx_buf[MAX310X_FIFO_SIZE];
> };
> #define to_max310x_port(_port) \
> container_of(_port, struct max310x_one, port)
[ ... ]
> @@ -931,23 +934,41 @@ static void max310x_handle_tx(struct uart_port *port)
> return;
> }
>
> - /*
> - * It's a circ buffer -- wrap around.
> - * We could do that in one SPI transaction, but meh.
> - */
> while (!kfifo_is_empty(&tport->xmit_fifo)) {
> unsigned int txlen, to_send;
> - unsigned char *tail;
> + unsigned long flags;
>
> /* Limit to space available in TX FIFO */
> txlen = max310x_port_read(port, MAX310X_TXFIFOLVL_REG);
> txlen = port->fifosize - txlen;
> + txlen = min(txlen, sizeof(one->tx_buf));
[Severity: Critical]
This problem wasn't introduced by this patch, but can max310x_handle_rx()
overflow one->rx_buf in the batched read path [1]?
drivers/tty/serial/max310x.c:max310x_handle_rx() {
...
if (port->read_status_mask == MAX310X_LSR_RXOVR_BIT) {
...
sts = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG);
max310x_batch_read(port, one->rx_buf, rxlen);
...
} else {
if (unlikely(rxlen >= port->fifosize)) {
dev_warn_ratelimited(port->dev, "Possible RX FIFO overrun\n");
port->icount.buf_overrun++;
/* Ensure sanity of RX level */
rxlen = port->fifosize;
}
...
}
Unlike the non-batched branch (and the new txlen clamp above), the batched
branch passes rxlen read from MAX310X_RXFIFOLVL_REG straight to
max310x_batch_read() without clamping it to sizeof(one->rx_buf). If the
chip reports a length larger than MAX310X_FIFO_SIZE (128 bytes),
regmap_noinc_read() writes past the end of one->rx_buf and corrupts the
enclosing struct max310x_port allocation.
[1] https://sashiko.dev/#/bug/linux-faf2b0a9-9b3f-4e76-a18b-7e85a4d79395
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-max310x-tx-fixes-v1-0-61c01f180911@vaisala.com?part=1
next prev parent reply other threads:[~2026-11-16 10:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 9:57 [PATCH 0/3] serial: max310x: transmit path fixes Tapio Reijonen
2026-11-16 9:57 ` [PATCH 1/3] serial: max310x: do not advance the TX fifo past a flush Tapio Reijonen
2026-11-16 10:18 ` sashiko-bot [this message]
2026-11-16 9:57 ` [PATCH 2/3] serial: max310x: re-check the TX queue before the after-send hold Tapio Reijonen
2026-11-16 10:12 ` sashiko-bot
2026-11-16 9:57 ` [PATCH 3/3] serial: max310x: hold TX data until the software RTS send phase Tapio Reijonen
2026-11-16 10:34 ` 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-216707@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox