Re: [PATCH] serial: digicolor: fix use-after-free on driver unbind
From: Junrui Luo <hidden>
Date: 2025-12-25 04:23:06
Also in:
linux-serial, lkml
On Mon, Dec 22, 2025 at 07:22:14AM +0100, Greg Kroah-Hartman wrote:
On Mon, Dec 22, 2025 at 12:55:02PM +0800, Junrui Luo wrote:quoted
The digicolor_uart_console_write() function accesses the global digicolor_ports[] array to retrieve the uart port pointer, which can lead to a use-after-free if the console write occurs after the port has been removed via unbind. digicolor_uart_remove() leaves a dangling pointer in the array. Fix by clearing the array entry in digicolor_uart_remove() and adding a NULL check in digicolor_uart_console_write(). Reported-by: Yuhao Jiang <redacted> Reported-by: Junrui Luo <redacted> Fixes: 5930cb3511df ("serial: driver for Conexant Digicolor USART") Signed-off-by: Junrui Luo <redacted> --- drivers/tty/serial/digicolor-usart.c | 4 ++++ 1 file changed, 4 insertions(+)diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c index d2482df5cb9b..5861be2072c4 100644 --- a/drivers/tty/serial/digicolor-usart.c +++ b/drivers/tty/serial/digicolor-usart.c@@ -397,6 +397,9 @@ static void digicolor_uart_console_write(struct console *co, const char *c, unsigned long flags; int locked = 1; + if (!port) + return; +What prevents port from changing right after you tested this?
Thanks for the review. You're right that there's a potentially race window between the NULL check and port usage. I found that several drivers handle this the same way: - meson_uart: has NULL check in console_write, clears array in remove - sprd_serial: Fixed similar issue in commit 99038fe75afa This check does not fully eliminate the race window, and adding stronger synchronization in the console_write() path may have non-trivial cost. I am willing to adopt an alternative if one is preferred.
And who is calling unbind on a port? Why? That's a debuggging thing that a developer could do, it should not be part of any normal system operation.
Although this may most commonly occur in development or testing environments, it is still a legitimate bug that should be fixed. In addition, unbind may also occur in: - Some embedded systems using runtime device tree overlays - Certain virtualization scenarios with device passthrough Though these are uncommon. thanks, Junrui Luo