From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796544704; b=1eJPodyYohyaxQbXujy+3NJx11E+kKjmQmpqeQPO2cGFhgBrNPkHShb/ym2v/gS86BdR Y/gnqr7otNB9nwzvlVmQsqOnRI10auw4AXRBzZayiOuMaTPhdO0xmWzBW/v1NfGJm+C7C SsSTLZRHvRqS+JRgmiK2ARoQBZLTq5GFfJhR2GBduBWKtAwzCYITG8yzW/Srmfmz/MeUm z1a6JidDsS4y0hw+5OuUtj3OdK0ySSUegV1QGgRYdq2VaeTId4oJ9WLXl5UTFYzZcr5JM oTMkDRwOIhVdhFCBgPk32A90CfQ6k0TktiUIkq4SsAq2eEkgKJvcEB+Fiu9y36RaoOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796544704; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=iWI/0One0SbfKCnHck2cERgm3dBBGKqr5TfmVZjZgLQ=; b=4KrCN+/IfKPUKGFhnCnRpBrHDDFiIdMNphltIlID2WNuq/s6hKnV2GCXzjmanl0pYXuR 5WKZSK2BNSJCjbLbiV6RJRX7Ziu88nmgek6bu4atnU3qM3ItZ6x1ibus16zpcA11vbwgJ NQ7qBudNQtwDUUB5yTpiwLHG0xiUhlaWXypEjPgdwQWv0eIImiYWt7gGcBus5eEHPFP2u EZjGoH5LkB2HdYi+njWdkgtTHCRud5WK2S/YcAVuJEZ3dAu0OYZoO8tJSc0hqgQikY6Xb QCkLFHyR/1PUV2OFSr9AJH+M32IptPH4g5gpSx+YNdcdjS3/EYzqiSI5I37J+A228kw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cCdsanTB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 124B2606A330 for ; Sun, 6 Dec 2026 08:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cCdsanTB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C4FB1F0092B; Sun, 6 Dec 2026 08:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796544703; bh=iWI/0One0SbfKCnHck2cERgm3dBBGKqr5TfmVZjZgLQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cCdsanTB9e/UenEnWZMaVIF1UWy5BTeYyAeBMbVEVtcYy39NneLYuMlTvQ+NYbPaj dyha7e+voq4+qR00NOm453Yb956peDciw/8tlMlsHxC2Si5r5UvLEGMgduewTO8ZgX 9uheeXt2A/LH0PNEjx3TRpCC0jznqVOUJwz7Mu3hlP+JXoeCXcI08EoWp9znDmcn5L BZMjyd8QMDKSp5S+ZTA6F/oqx+Y+FQMX+ZhmFnJ3lEFL7wE0sETd3a2sjoSfGL3bT4 +sDMWmnAEA7DnB420EyaLp3Al78qKyH8dUFxJN8dFw+MxCArsgYFDUkohu8UVuDLVP JpR9ltwShQRsQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] serial: 8250: Keep the nr_uarts parameter separate from the port count Reply-To: sashiko-reviews@lists.linux.dev To: "Yingjie Wang" <1075151112@qq.com> Cc: linux-serial@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 08:11:43 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] serial: 8250: missing Fixes trailer for nr_uarts sysfs bug fix - [Low] serial: 8250: unsynchronized nr_uarts_param access in serial8250_init() -- commit c2dc0eff28b8be5787216dd942c3e3a4a656669f Author: Yingjie Wang <1075151112@qq.com> > serial: 8250: Keep the nr_uarts parameter separate from the port count > > nr_uarts is the nr_uarts module parameter, and since commit 9d86719f8769 > ("serial: 8250: Allow using ports higher than SERIAL_8250_RUNTIME_UARTS") > it is also the number of serial8250_ports[] entries that have been set > up: registering a port when none of them is free sets up the next entry > and increments nr_uarts. The parameter is writable through sysfs, so a > write changes that count behind the driver's back. > > A value above UART_NR makes the loops over the ports index past the end > of serial8250_ports[]. With KASAN, writing 33 to > /sys/module/8250/parameters/nr_uarts and unbinding the serial8250 > platform device reports a global-out-of-bounds read in > serial8250_remove(). A smaller value makes serial8250_remove() skip > ports that are still registered, and the next registration that finds > no free entry sets up an entry that is in use again: after writing 1, > rebinding a PCI serial port in a QEMU guest made it take over ttyS1 > from 8250_pnp, with an "ida_free called for id=3D1 which is not > allocated" warning. A larger value lets a registration use an entry > that was never set up. > > Keep the parameter in a variable of its own and only use it when the > initial ports are set up, where it is still clamped to UART_NR. > nr_uarts then only counts the entries that have been set up. > The parameter can still be written, but that no longer affects the > ports, and reading it returns the configured value instead of the > current number of entries, as it did before the commit above. > > Signed-off-by: Yingjie Wang <1075151112@qq.com> [Severity: Low] This fixes a KASAN global-out-of-bounds read and port-tracking corruption when /sys/module/8250/parameters/nr_uarts is written. Should it include: Fixes: a61c2d78ce61 ("[SERIAL] Make the number of UARTs registered config= urable.") Fixes: 9d86719f8769 ("serial: 8250: Allow using ports higher than SERIAL_= 8250_RUNTIME_UARTS") [ ... ] > diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial= /8250/8250_platform.c > index 1a41a4ac25f88..1457652816761 100644 > --- a/drivers/tty/serial/8250/8250_platform.c > +++ b/drivers/tty/serial/8250/8250_platform.c [ ... ] > @@ -62,8 +68,10 @@ static void __init __serial8250_isa_init_ports(void) > { > int i; > =20 > + nr_uarts =3D nr_uarts_param; > if (nr_uarts > UART_NR) > nr_uarts =3D UART_NR; > + nr_uarts_param =3D nr_uarts; [Severity: Low] Can this access to nr_uarts_param race with sysfs reads or writes when the driver is built as a module? load_module() exposes /sys/module/8250/parameters/nr_uarts in mod_sysfs_setup() before do_init_module() runs serial8250_init(). Sysfs accesses serialize on kernel_param_lock(), while serial8250_init() and __serial8250_isa_init_ports() touch nr_uarts_param without it: CPU0 (modprobe) CPU1 (sysfs) load_module() mod_sysfs_setup() do_init_module() serial8250_init() if (nr_uarts_param =3D=3D 0) serial8250_isa_init_ports() DO_ONCE(...) nr_uarts =3D nr_uarts_param; param_attr_store() kernel_param_lock() param_set_uint() <-- data race kernel_param_unlock() nr_uarts_param =3D nr_uarts; <-- clobbers write The new unconditional store to nr_uarts_param introduces a KCSAN data race against concurrent sysfs reads or writes and can clobber a sysfs write even when the initial value did not exceed UART_NR. A concurrent write of 0 between the check in serial8250_init() and __serial8250_isa_init_ports() also bypasses the -ENODEV return and loads the driver with nr_uarts set to 0. Since DO_ONCE() holds once_lock with interrupts disabled, kernel_param_lock(THIS_MODULE) cannot be taken in __serial8250_isa_init_ports(). Snapshotting and clamping nr_uarts_param under kernel_param_lock(THIS_MODULE) in serial8250_init() avoids the race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_E59F5D41E55= 6C99EC4443B971E2734FFCA08@qq.com?part=3D1