mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yingjie Wang <1075151112@qq.com>
To: gregkh@linuxfoundation.org
Cc: jirislaby@kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] serial: 8250: Disallow runtime changes to nr_uarts
Date: Sun, 25 Oct 2026 10:06:09 +0800	[thread overview]
Message-ID: <tencent_23BFCCE74C508AD599E72011EAE5E409C006@qq.com> (raw)

nr_uarts is clamped to UART_NR while the initial 8250 ports are
initialized, but it is also used as the iteration bound by the remove
path. serial8250_get_port() assumes that the index is within the
serial8250_ports array.

Allowing nr_uarts to be changed through sysfs can therefore make the
remove path access beyond the end of serial8250_ports. The value also
describes the number of initialized or dynamically registered ports, so
changing it after setup is not safe even when the new value is within the
array limit.

Make the nr_uarts module parameter read-only through sysfs. Boot-time and
module-load parameter parsing remain supported and still go through the
existing clamp.

Tested on x86-64 with CONFIG_KASAN=y under QEMU:
- 8250.nr_uarts=5 is honored at boot.
- Writes to /sys/module/8250/parameters/nr_uarts are rejected.

Signed-off-by: Yingjie Wang <1075151112@qq.com>
---
 drivers/tty/serial/8250/8250_platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
index 9d9dba4e0439a..2b07337407fd1 100644
--- a/drivers/tty/serial/8250/8250_platform.c
+++ b/drivers/tty/serial/8250/8250_platform.c
@@ -385,7 +385,7 @@ MODULE_DESCRIPTION("Generic 8250/16x50 serial platform driver");
 module_param_hw(share_irqs, bool, other, 0644);
 MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices (unsafe)");
 
-module_param(nr_uarts, uint, 0644);
+module_param(nr_uarts, uint, 0444);
 MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
 
 MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);

base-commit: 1184f87e2790e8af9be3116f608d2e86b4792d7d
-- 
2.43.0


                 reply	other threads:[~2026-10-25  2:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=tencent_23BFCCE74C508AD599E72011EAE5E409C006@qq.com \
    --to=1075151112@qq.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --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®