From: Zongmin Zhou <min_halo@163.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org, pjw@kernel.org,
samuel.holland@sifive.com
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
linux-riscv@lists.infradead.org,
Zongmin Zhou <zhouzongmin@kylinos.cn>
Subject: [PATCH] serial: sifive: fix off-by-one in console port bounds check
Date: Thu, 27 Aug 2026 09:45:24 +0800 [thread overview]
Message-ID: <20260827014524.19375-1-min_halo@163.com> (raw)
From: Zongmin Zhou <zhouzongmin@kylinos.cn>
sifive_serial_console_ports[] is sized SIFIVE_SERIAL_MAX_PORTS (8), so
valid indices are 0..7. The bounds check in sifive_serial_probe() uses
"id > SIFIVE_SERIAL_MAX_PORTS", which lets id == 8 pass and causes an
out-of-bounds write in __ssp_add_console_port() through
sifive_serial_console_ports[ssp->port.line].
Fix the check to use >= instead, matching the check already used in
sifive_serial_console_setup().
Fixes: 45c054d0815b ("tty: serial: add driver for the SiFive UART")
Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
---
drivers/tty/serial/sifive.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c
index 110d676..5d76f04 100644
--- a/drivers/tty/serial/sifive.c
+++ b/drivers/tty/serial/sifive.c
@@ -999,7 +999,7 @@ static int sifive_serial_probe(struct platform_device *pdev)
}
#ifdef CONFIG_SERIAL_SIFIVE_CONSOLE
- if (id > SIFIVE_SERIAL_MAX_PORTS) {
+ if (id >= SIFIVE_SERIAL_MAX_PORTS) {
dev_err(&pdev->dev, "too many UARTs (%d)\n", id);
return -EINVAL;
}
--
2.34.1
No virus found
Checked by Hillstone Network AntiVirus
next reply other threads:[~2026-08-27 1:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 1:45 Zongmin Zhou [this message]
2026-08-27 1:57 ` [PATCH] serial: sifive: fix off-by-one in console port bounds check 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=20260827014524.19375-1-min_halo@163.com \
--to=min_halo@163.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-serial@vger.kernel.org \
--cc=pjw@kernel.org \
--cc=samuel.holland@sifive.com \
--cc=zhouzongmin@kylinos.cn \
/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