From: Hui Peng <benquike@gmail.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org,
john.ogness@linutronix.de
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] serial: fix 8250 hash_mutex race and uart_get_baud_rate() divide-by-zero
Date: Sat, 19 Sep 2026 22:26:27 +0000 [thread overview]
Message-ID: <20260919222627.3797854-1-benquike@gmail.com> (raw)
Fix two bugs in the serial subsystem:
1. In serial8250_Label / serial_link_irq_chain() and
serial_unlink_irq_chain() (drivers/tty/serial/8250/8250_core.c), hold
hash_mutex across the entire IRQ list manipulation and
request_irq()/free_irq() sequence to prevent racing IRQ chain
insertions/removals.
2. In uart_get_baud_rate() and uart_set_info()
(drivers/tty/serial/serial_core.c), avoid unsigned overflow in
port->uartclk = new_info->baud_base * 16 and ensure the fallback
retry in uart_get_baud_rate() terminates cleanly when no baud rate
lies in [min, max].
Fixes: ab4382d27412 ("tty: move drivers/serial/ to drivers/tty/serial/")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index b875d394796f..0bc810f285a4 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -134,8 +134,6 @@ static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_por
{
struct irq_info *i;
- guard(mutex)(&hash_mutex);
-
hash_for_each_possible(irq_lists, i, node, up->port.irq)
if (i->irq == up->port.irq)
return i;
@@ -156,6 +154,8 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
struct irq_info *i;
int ret;
+ guard(mutex)(&hash_mutex);
+
i = serial_get_or_create_irq_info(up);
if (IS_ERR(i))
return PTR_ERR(i);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 95774b0f1484..4cd4fb0f7ee3 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -501,7 +501,7 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
break;
}
- for (try = 0; try < 2; try++) {
+ for (try = 0; try < 3; try++) {
baud = tty_termios_baud_rate(termios);
/*
@@ -965,7 +965,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
}
if ((new_info->irq >= irq_get_nr_irqs()) || (new_info->irq < 0) ||
- (new_info->baud_base < 9600))
+ (new_info->baud_base < 9600) || (new_info->baud_base > UINT_MAX / 16))
return -EINVAL;
if (change_port || change_irq) {
next reply other threads:[~2026-09-19 22:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 22:26 Hui Peng [this message]
2026-09-20 5:17 ` Greg KH
[not found] ` <CAKpmkkV+Gk11x0wCbT1dK8FDraaCb0q=ALS+Tnj0wM+EcMt-SA@mail.gmail.com>
2026-09-20 5:31 ` Greg KH
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=20260919222627.3797854-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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®