The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Yingjie Wang <1075151112@qq.com>
Cc: jirislaby@kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] serial: 8250: Disallow runtime changes to nr_uarts
Date: Fri, 4 Dec 2026 17:50:10 +0900	[thread overview]
Message-ID: <2026120435-emphatic-renovate-e3bd@gregkh> (raw)
In-Reply-To: <tencent_23BFCCE74C508AD599E72011EAE5E409C006@qq.com>

On Sun, Oct 25, 2026 at 10:06:09AM +0800, Yingjie Wang wrote:
> 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
> 

You are breaking an existing userspace api for no good reason other than
"root did something that broke the system", right?

Why not properly fix the issue instead of papering over it this way?

thanks.

greg k-h

      reply	other threads:[~2026-12-04  9:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25  2:06 [PATCH] serial: 8250: Disallow runtime changes to nr_uarts Yingjie Wang
2026-12-04  8:50 ` Greg KH [this message]

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=2026120435-emphatic-renovate-e3bd@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=1075151112@qq.com \
    --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