FAILED: patch "[PATCH] serial: core: fix NULL pointer dereference in" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 499485a67fbacf4d9afbdb43522388c64f853428
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100502-chute-cranial-b5eb@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 499485a67fbacf4d9afbdb43522388c64f853428 Mon Sep 17 00:00:00 2001
From: Ruslan Valiyev <[email protected]>
Date: Wed, 26 Aug 2026 10:46:54 +0200
Subject: [PATCH] serial: core: fix NULL pointer dereference in
serial_core_unregister_port()
port->port_dev is NULL when no port device is installed: it is cleared on teardown, and never set if registration failed before serial_core_port_device_add(). serial_core_unregister_port() passes it straight to serial_core_get_ctrl_dev(), which dereferences it:
KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047] RIP: serial_core_unregister_port Call Trace: serial8250_unregister_port serial8250_remove unbind_store
Return early when there is no port device, and read port->port_dev under port_mutex.
Also clear port->port_dev on the serial_core_register_port() error path, where the port device has already been removed.
drivers/tty/serial/serial_core.c +15 -2
@@ -3381,6 +3381,7 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) err_unregister_port_dev:serial_base_port_device_remove (port->port_dev); + port->port_dev =NULL ; err_unregister_ctrl_dev:serial_base_ctrl_device_remove (new_ctrl_dev);
@@ -3395,12 +3396,24 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)void serial_core_unregister_port (struct uart_driver *drv,struct uart_port *port) {struct device *phys_dev = port->dev; -struct serial_port_device *port_dev = port->port_dev; -struct serial_ctrl_device *ctrl_dev =serial_core_get_ctrl_dev (port_dev); +struct serial_port_device *port_dev; +struct serial_ctrl_device *ctrl_dev;int ctrl_id = port->ctrl_id;guard (mutex)(&port_mutex); +/* +* A NULL port device means there is no registered port device to +* remove: serial_core_remove_one_port() clears port_dev on +* teardown, and it is never set if registration failed before +* serial_core_port_device_add(). +*/ + port_dev = port->port_dev; +if (!port_dev) +return ; + + ctrl_dev =serial_core_get_ctrl_dev (port_dev); + port->flags |=UPF_DEAD ;serial_core_remove_one_port (drv, port);