From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Hui Peng <benquike@gmail.com>
Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org,
john.ogness@linutronix.de, ilpo.jarvinen@linux.intel.com,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v4 2/3] serial: core: allow third iteration in uart_get_baud_rate() fallback
Date: Thu, 24 Sep 2026 15:29:56 +0300 [thread overview]
Message-ID: <arUXxEZo2374oRpO@ashevche-desk.local> (raw)
In-Reply-To: <20260924060511.2364717-3-benquike@gmail.com>
On Thu, Sep 24, 2026 at 06:04:45AM +0000, Hui Peng wrote:
> In uart_get_baud_rate(), when the requested baud rate is out of range
> (try == 0) and old is non-NULL, the function copies the old termios baud
> rate into termios, sets old = NULL, and continues to try == 1. If the
> old baud rate is also out of range (for instance, after uport->uartclk
> was lowered via TIOCSSERIAL so max = uport->uartclk / 16 is smaller than
> both the old and new baud rates), try == 1 clips baud to [min + 1,
> max - 1] and encodes it into termios via tty_termios_encode_baud_rate().
>
> However, because the loop bound is for (try = 0; try < 2; try++), the
> loop terminates immediately after try == 1 without re-evaluating
> baud = tty_termios_baud_rate(termios) for the clipped rate, hitting
> WARN_ON(1) and returning 0, which then triggers a fatal divide-by-zero
> (Oops: divide error) in uart_get_divisor():
> WARNING: drivers/tty/serial/serial_core.c:548 at uart_get_baud_rate+0x136/0x260, CPU#1: init/1
> ...
> Oops: divide error: 0000 [#1] SMP KASAN PTI
> CPU: 1 UID: 0 PID: 1 Comm: init Tainted: G W N 7.3.0-rc3-g5dd1818b15d9 #1 PREEMPT(lazy)
> RIP: 0010:uart_get_divisor+0x5b/0x100
> Call Trace:
> <TASK>
> serial8250_get_divisor+0x123/0x1a0
> serial8250_do_set_termios+0x21e/0x1610
> serial8250_set_termios+0x77/0x90
> uart_change_line_settings+0xf6/0x720
> uart_set_termios+0x1c1/0x5b0
> tty_set_termios+0x5f7/0x920
> set_termios+0x533/0x7d0
> tty_mode_ioctl+0x8e4/0xd10
> n_tty_ioctl_helper+0x3c/0x270
> n_tty_ioctl+0x4e/0x2c0
> tty_ioctl+0x1028/0x1480
> __x64_sys_ioctl+0x184/0x1d0
> do_syscall_64+0xda/0x4b0
Submitting Patches suggests to leave only ~3-5 *significant (or important)
lines of traceback. At very brief look the last 7 do not add any valuable
information.
> Increase the loop limit to try < 3 so that the clipped baud rate encoded
> on try == 1 is evaluated and returned on try == 2.
>
> Tested in QEMU against Linux 7.3.0-rc3 by setting /dev/ttyS1 to B115200,
> lowering baud_base to 9600 (max = 9600) via TIOCSSERIAL, and calling
> tcsetattr() with B57600 (old = B115200), reproducing the WARNING and
> Oops: divide error in uart_get_divisor() on the unfixed kernel and
> verifying clean execution with 0 warnings/faults with the fix applied.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-09-24 12:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 6:04 [PATCH v4 0/3] serial: fix IRQ chain race, baud fallback, and uartclk overflow Hui Peng
2026-09-24 6:04 ` [PATCH v4 1/3] serial: 8250: hold hash_mutex across IRQ chain linking in serial_link_irq_chain() Hui Peng
2026-09-24 6:04 ` [PATCH v4 2/3] serial: core: allow third iteration in uart_get_baud_rate() fallback Hui Peng
2026-09-24 12:29 ` Andy Shevchenko [this message]
2026-09-24 6:42 ` [PATCH v4 0/3] serial: fix IRQ chain race, baud fallback, and uartclk overflow Greg KH
2026-09-24 6:54 ` [PATCH v4 3/3] serial: core: reject baud_base values that overflow port->uartclk in uart_set_info() Hui Peng
2026-09-24 11:40 ` Ilpo Järvinen
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=arUXxEZo2374oRpO@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=benquike@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=stable@vger.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
all inboxes | Powered by JetHome®