All of lore.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] serial: core: fix NULL pointer dereference in" failed to apply to 6.18-stable tree
@ 2026-10-05 10:15 gregkh
  2026-12-05 13:55   ` Dickson Wu via B4 Relay
  0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2026-10-05 10:15 UTC (permalink / raw)
  To: linuxoid, gregkh, tony.lindgren; +Cc: stable


The patch below does not apply to the 6.18-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 <stable@vger.kernel.org>.

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.18.y
git checkout FETCH_HEAD
git cherry-pick -x 499485a67fbacf4d9afbdb43522388c64f853428
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026100500-unmoral-shrunk-9a8e@gregkh' --subject-prefix 'PATCH 6.18.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 <linuxoid@gmail.com>
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.

Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Reported-by: syzbot+9f57c1b2792029198fcf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
Cc: stable@kernel.org
Assisted-by: Claude:claude-opus-5
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
Link: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
Link: https://lore.kernel.org/all/20260826073237.1377668-1-linuxoid@gmail.com/
Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
Link: https://patch.msgid.link/20260826084654.1392851-1-linuxoid@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 33c8f3b6ac81..6332ed545c89 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -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);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 6.18.y] serial: core: fix NULL pointer dereference in serial_core_unregister_port()
  2026-10-05 10:15 FAILED: patch "[PATCH] serial: core: fix NULL pointer dereference in" failed to apply to 6.18-stable tree gregkh
@ 2026-12-05 13:55   ` Dickson Wu via B4 Relay
  0 siblings, 0 replies; 4+ messages in thread
From: Dickson Wu @ 2026-12-05 13:55 UTC (permalink / raw)
  To: stable
  Cc: Greg Kroah-Hartman, Jiri Slaby, Tony Lindgren, Andy Shevchenko,
	Hugo Villeneuve, John Ogness, Lukas Wunner, Gerhard Engleder,
	linux-serial, linux-kernel, syzkaller-bugs, Ruslan Valiyev,
	syzbot+9f57c1b2792029198fcf

From: Ruslan Valiyev <linuxoid@gmail.com>

commit 499485a67fbacf4d9afbdb43522388c64f853428 upstream.

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.

Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Reported-by: syzbot+9f57c1b2792029198fcf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
Cc: stable@kernel.org
Assisted-by: Claude:claude-opus-5
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
Link: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
Link: https://lore.kernel.org/all/20260826073237.1377668-1-linuxoid@gmail.com/
Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
Link: https://patch.msgid.link/20260826084654.1392851-1-linuxoid@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ adapted to 6.18.y: release the explicit port_mutex on early return ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
6.18.y takes port_mutex with mutex_lock() rather than guard(mutex),
so the new early return unlocks it explicitly.

Tested on v6.18.66:
- x86_64 W=1 build of drivers/tty/serial/serial_core.o, base vs
  patched, no new warnings
- booted base and patched kernels under QEMU/KVM with a PCI 8250
  port: unbind and rebind of the port and the tty_tstamp_update
  selftest pass on both. The syzbot NULL port_dev path and the
  registration failure path were not exercised at runtime.

The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
 drivers/tty/serial/serial_core.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index ae42a067f20d..8847ebdcca2c 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3380,6 +3380,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);
@@ -3394,12 +3395,26 @@ 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;
 
 	mutex_lock(&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) {
+		mutex_unlock(&port_mutex);
+		return;
+	}
+
+	ctrl_dev = serial_core_get_ctrl_dev(port_dev);
+
 	port->flags |= UPF_DEAD;
 
 	serial_core_remove_one_port(drv, port);

---
base-commit: 2c7bb1d0212c23234a9f85123eb7a36eecc76776
change-id: 20261205-serial-618-e3d7596a366d

Best regards,
--  
Dickson Wu <dickson.wu@certik.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 6.18.y] serial: core: fix NULL pointer dereference in serial_core_unregister_port()
@ 2026-12-05 13:55   ` Dickson Wu via B4 Relay
  0 siblings, 0 replies; 4+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-12-05 13:55 UTC (permalink / raw)
  To: stable
  Cc: Greg Kroah-Hartman, Jiri Slaby, Tony Lindgren, Andy Shevchenko,
	Hugo Villeneuve, John Ogness, Lukas Wunner, Gerhard Engleder,
	linux-serial, linux-kernel, syzkaller-bugs, Ruslan Valiyev,
	syzbot+9f57c1b2792029198fcf

From: Ruslan Valiyev <linuxoid@gmail.com>

commit 499485a67fbacf4d9afbdb43522388c64f853428 upstream.

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.

Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Reported-by: syzbot+9f57c1b2792029198fcf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
Cc: stable@kernel.org
Assisted-by: Claude:claude-opus-5
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
Link: https://syzkaller.appspot.com/bug?extid=9f57c1b2792029198fcf
Link: https://lore.kernel.org/all/20260826073237.1377668-1-linuxoid@gmail.com/
Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
Link: https://patch.msgid.link/20260826084654.1392851-1-linuxoid@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ adapted to 6.18.y: release the explicit port_mutex on early return ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
6.18.y takes port_mutex with mutex_lock() rather than guard(mutex),
so the new early return unlocks it explicitly.

Tested on v6.18.66:
- x86_64 W=1 build of drivers/tty/serial/serial_core.o, base vs
  patched, no new warnings
- booted base and patched kernels under QEMU/KVM with a PCI 8250
  port: unbind and rebind of the port and the tty_tstamp_update
  selftest pass on both. The syzbot NULL port_dev path and the
  registration failure path were not exercised at runtime.

The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
 drivers/tty/serial/serial_core.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index ae42a067f20d..8847ebdcca2c 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3380,6 +3380,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);
@@ -3394,12 +3395,26 @@ 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;
 
 	mutex_lock(&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) {
+		mutex_unlock(&port_mutex);
+		return;
+	}
+
+	ctrl_dev = serial_core_get_ctrl_dev(port_dev);
+
 	port->flags |= UPF_DEAD;
 
 	serial_core_remove_one_port(drv, port);

---
base-commit: 2c7bb1d0212c23234a9f85123eb7a36eecc76776
change-id: 20261205-serial-618-e3d7596a366d

Best regards,
--  
Dickson Wu <dickson.wu@certik.com>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.18.y] serial: core: fix NULL pointer dereference in serial_core_unregister_port()
  2026-12-05 13:55   ` Dickson Wu via B4 Relay
  (?)
@ 2026-12-05 14:05   ` sashiko-bot
  -1 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-05 14:05 UTC (permalink / raw)
  To: Dickson Wu; +Cc: linux-serial

> From: Ruslan Valiyev <linuxoid@gmail.com>
> 
> commit 499485a67fbacf4d9afbdb43522388c64f853428 upstream.
> 
> 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
> [ ... ]
> Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
> Link: https://patch.msgid.link/20260826084654.1392851-1-linuxoid@gmail.com
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> [ adapted to 6.18.y: release the explicit port_mutex on early return ]
> Signed-off-by: Dickson Wu <dickson.wu@certik.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-serial-618-v1-1-ed1f370c3295@certik.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-05 14:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-05 10:15 FAILED: patch "[PATCH] serial: core: fix NULL pointer dereference in" failed to apply to 6.18-stable tree gregkh
2026-12-05 13:55 ` [PATCH 6.18.y] serial: core: fix NULL pointer dereference in serial_core_unregister_port() Dickson Wu
2026-12-05 13:55   ` Dickson Wu via B4 Relay
2026-12-05 14:05   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.