Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] tty: serial: core: fix NULL pointer deref in uart_resume_port()
@ 2026-06-08 16:52 Weiming Shi
  2026-06-12 10:01 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Weiming Shi @ 2026-06-08 16:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-kernel, linux-serial, Xiang Mei

uart_resume_port() looks up the tty device child with device_find_child()
and passes the result straight to device_may_wakeup(). device_find_child()
returns NULL when the port has no matching tty device child, and
device_may_wakeup() dereferences dev->power.can_wakeup, so a NULL tty_dev
faults. uart_suspend_port() already guards the same call with
"tty_dev && device_may_wakeup(tty_dev)"; the resume path does not.

 Oops: general protection fault, probably for non-canonical address
 KASAN: null-ptr-deref in range [0x148-0x14f]
 RIP: 0010:uart_resume_port (pm_wakeup.h:84 serial_core.c:2477)
  serial_pnp_resume (8250/8250_pnp.c:522)
  pnp_bus_resume (drivers/pnp/driver.c:234)

Mirror the NULL guard from uart_suspend_port(). put_device(tty_dev)
already tolerates a NULL argument, so only the device_may_wakeup() call
needs the check; the non-NULL path is unchanged.

Fixes: b3b708fa2780 ("wake up from a serial port")
Reported-by: Xiang Mei <xmei5@asu.edu>
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 89cebdd278410..7dd3ec3dea438 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2373,7 +2373,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
 	guard(mutex)(&port->mutex);
 
 	tty_dev = device_find_child(&uport->port_dev->dev, &match, serial_match_port);
-	if (!uport->suspended && device_may_wakeup(tty_dev)) {
+	if (!uport->suspended && tty_dev && device_may_wakeup(tty_dev)) {
 		if (irqd_is_wakeup_set(irq_get_irq_data((uport->irq))))
 			disable_irq_wake(uport->irq);
 		put_device(tty_dev);
-- 
2.43.0


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

* Re: [PATCH] tty: serial: core: fix NULL pointer deref in uart_resume_port()
  2026-06-08 16:52 [PATCH] tty: serial: core: fix NULL pointer deref in uart_resume_port() Weiming Shi
@ 2026-06-12 10:01 ` Greg Kroah-Hartman
  2026-06-13  5:37   ` Weiming Shi
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-06-12 10:01 UTC (permalink / raw)
  To: Weiming Shi; +Cc: Jiri Slaby, linux-kernel, linux-serial, Xiang Mei

On Mon, Jun 08, 2026 at 09:52:17AM -0700, Weiming Shi wrote:
> uart_resume_port() looks up the tty device child with device_find_child()
> and passes the result straight to device_may_wakeup(). device_find_child()
> returns NULL when the port has no matching tty device child,

How can that happen in a real system?  Have you triggered this before,
if so, what hardware does it?

> and
> device_may_wakeup() dereferences dev->power.can_wakeup, so a NULL tty_dev
> faults. uart_suspend_port() already guards the same call with
> "tty_dev && device_may_wakeup(tty_dev)"; the resume path does not.
> 
>  Oops: general protection fault, probably for non-canonical address
>  KASAN: null-ptr-deref in range [0x148-0x14f]
>  RIP: 0010:uart_resume_port (pm_wakeup.h:84 serial_core.c:2477)
>   serial_pnp_resume (8250/8250_pnp.c:522)
>   pnp_bus_resume (drivers/pnp/driver.c:234)

Is this a real oops, or a made up one?

> Mirror the NULL guard from uart_suspend_port(). put_device(tty_dev)
> already tolerates a NULL argument, so only the device_may_wakeup() call
> needs the check; the non-NULL path is unchanged.
> 
> Fixes: b3b708fa2780 ("wake up from a serial port")
> Reported-by: Xiang Mei <xmei5@asu.edu>

Where was this reported?

Why isn't this cc: stable?  And why hasn't anyone tripped over it in the
past 19 years?

thanks,

greg k-h

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

* Re: [PATCH] tty: serial: core: fix NULL pointer deref in uart_resume_port()
  2026-06-12 10:01 ` Greg Kroah-Hartman
@ 2026-06-13  5:37   ` Weiming Shi
  0 siblings, 0 replies; 3+ messages in thread
From: Weiming Shi @ 2026-06-13  5:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Weiming Shi
  Cc: Jiri Slaby, linux-kernel, linux-serial, Xiang Mei

On Fri Jun 12, 2026 at 6:01 PM CST, Greg Kroah-Hartman wrote:
> On Mon, Jun 08, 2026 at 09:52:17AM -0700, Weiming Shi wrote:
>> uart_resume_port() looks up the tty device child with device_find_child()
>> and passes the result straight to device_may_wakeup(). device_find_child()
>> returns NULL when the port has no matching tty device child,
>
> How can that happen in a real system?  Have you triggered this before,
> if so, what hardware does it?
>
>> and
>> device_may_wakeup() dereferences dev->power.can_wakeup, so a NULL tty_dev
>> faults. uart_suspend_port() already guards the same call with
>> "tty_dev && device_may_wakeup(tty_dev)"; the resume path does not.
>> 
>>  Oops: general protection fault, probably for non-canonical address
>>  KASAN: null-ptr-deref in range [0x148-0x14f]
>>  RIP: 0010:uart_resume_port (pm_wakeup.h:84 serial_core.c:2477)
>>   serial_pnp_resume (8250/8250_pnp.c:522)
>>   pnp_bus_resume (drivers/pnp/driver.c:234)
>
> Is this a real oops, or a made up one?
>
>> Mirror the NULL guard from uart_suspend_port(). put_device(tty_dev)
>> already tolerates a NULL argument, so only the device_may_wakeup() call
>> needs the check; the non-NULL path is unchanged.
>> 
>> Fixes: b3b708fa2780 ("wake up from a serial port")
>> Reported-by: Xiang Mei <xmei5@asu.edu>
>
> Where was this reported?
>
> Why isn't this cc: stable?  And why hasn't anyone tripped over it in the
> past 19 years?
>
> thanks,
>
> greg k-h


Hi greg,

This is a false positive, please drop it.
Sorry for wasting your time. I'll check reachability before sending anything next time.

Best,
Weiming Shi

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

end of thread, other threads:[~2026-06-13  5:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 16:52 [PATCH] tty: serial: core: fix NULL pointer deref in uart_resume_port() Weiming Shi
2026-06-12 10:01 ` Greg Kroah-Hartman
2026-06-13  5:37   ` Weiming Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox