Linux USB
 help / color / mirror / Atom feed
* Re: [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
  2026-10-10 12:03 [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs Bertrand Jacquin
@ 2026-10-10 11:17 ` sashiko-bot
  2026-10-12  3:16 ` Huang Wei
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-10-10 11:17 UTC (permalink / raw)
  To: Bertrand Jacquin; +Cc: linux-usb

> ucsi_register() creates the debugfs entries right away, but
> ucsi->connector is only set by ucsi_init(), which runs later from
> ucsi->work and only publishes the connectors once the PPM has been
> reset and all ports are registered. Until then, or for good if init
> fails, ucsi->connector is NULL, yet the peak_current, avg_current and
> vbus_voltage show callbacks dereference it unconditionally.
> 
> On an Intel NUC13ANKi5 whose PPM never answers when CONFIG_ACPI_EC=n,
> reading those files after the failed init oopses:
> 
>   ucsi_acpi USBC000:00: error -ETIMEDOUT: PPM init failed
>   BUG: kernel NULL pointer dereference, address: 000000000000045c
>   #PF: supervisor read access in kernel mode
>   RIP: 0010:ucsi_debugfs_register+0x291/0x420 [typec_ucsi]
>   Call Trace:
>    <TASK>
>    seq_read_iter+0x1e4/0x4c0
>    seq_read+0x12b/0x160
>    full_proxy_read+0x9a/0x1f0
>    vfs_read+0xba/0x320
>    ksys_read+0x74/0x110
>    do_syscall_64+0x79/0x240
>    entry_SYSCALL_64_after_hwframe+0x71/0x79
> 
> Return -ENODEV from those callbacks while no connector is available.
> 
> Fixes: c851b71fd6cd ("usb: typec: ucsi: Add support for READ_POWER_LEVEL command")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bertrand Jacquin <bertrand@jacquin.bzh>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261010120357.4937-1-bertrand@jacquin.bzh?part=1


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

* [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
@ 2026-10-10 12:03 Bertrand Jacquin
  2026-10-10 11:17 ` sashiko-bot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Bertrand Jacquin @ 2026-10-10 12:03 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: venkat.jayaraman, linux-usb, linux-kernel, stable

ucsi_register() creates the debugfs entries right away, but
ucsi->connector is only set by ucsi_init(), which runs later from
ucsi->work and only publishes the connectors once the PPM has been
reset and all ports are registered. Until then, or for good if init
fails, ucsi->connector is NULL, yet the peak_current, avg_current and
vbus_voltage show callbacks dereference it unconditionally.

On an Intel NUC13ANKi5 whose PPM never answers when CONFIG_ACPI_EC=n,
reading those files after the failed init oopses:

  ucsi_acpi USBC000:00: error -ETIMEDOUT: PPM init failed
  BUG: kernel NULL pointer dereference, address: 000000000000045c
  #PF: supervisor read access in kernel mode
  RIP: 0010:ucsi_debugfs_register+0x291/0x420 [typec_ucsi]
  Call Trace:
   <TASK>
   seq_read_iter+0x1e4/0x4c0
   seq_read+0x12b/0x160
   full_proxy_read+0x9a/0x1f0
   vfs_read+0xba/0x320
   ksys_read+0x74/0x110
   do_syscall_64+0x79/0x240
   entry_SYSCALL_64_after_hwframe+0x71/0x79

Return -ENODEV from those callbacks while no connector is available.

Fixes: c851b71fd6cd ("usb: typec: ucsi: Add support for READ_POWER_LEVEL command")
Cc: stable@vger.kernel.org
Signed-off-by: Bertrand Jacquin <bertrand@jacquin.bzh>
---
 drivers/usb/typec/ucsi/debugfs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
index 77a0dd75edd3..911a151ac16a 100644
--- a/drivers/usb/typec/ucsi/debugfs.c
+++ b/drivers/usb/typec/ucsi/debugfs.c
@@ -92,6 +92,9 @@ static int ucsi_peak_curr_show(struct seq_file *m, void *v)
 {
 	struct ucsi *ucsi = m->private;
 
+	if (!ucsi->connector)
+		return -ENODEV;
+
 	seq_printf(m, "%u mA\n", ucsi->connector->peak_current);
 	return 0;
 }
@@ -101,6 +104,9 @@ static int ucsi_avg_curr_show(struct seq_file *m, void *v)
 {
 	struct ucsi *ucsi = m->private;
 
+	if (!ucsi->connector)
+		return -ENODEV;
+
 	seq_printf(m, "%u mA\n", ucsi->connector->avg_current);
 	return 0;
 }
@@ -110,6 +116,9 @@ static int ucsi_vbus_volt_show(struct seq_file *m, void *v)
 {
 	struct ucsi *ucsi = m->private;
 
+	if (!ucsi->connector)
+		return -ENODEV;
+
 	seq_printf(m, "%u mV\n", ucsi->connector->vbus_voltage);
 	return 0;
 }

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

* Re: [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
  2026-10-10 12:03 [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs Bertrand Jacquin
  2026-10-10 11:17 ` sashiko-bot
@ 2026-10-12  3:16 ` Huang Wei
  2026-10-26 11:40 ` Heikki Krogerus
  2026-11-20 12:29 ` Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Huang Wei @ 2026-10-12  3:16 UTC (permalink / raw)
  To: Bertrand Jacquin
  Cc: Heikki Krogerus, Greg Kroah-Hartman, Venkat Jayaraman, linux-usb,
	linux-kernel, stable, huangwei

Hi Bertrand,

I checked this over. The window is real - ucsi_register() creates the
debugfs entries right away while ucsi->connector is only assigned at
the end of ucsi_init(), so on the PPM-init-failed path those three
files stay reachable with a NULL connector.

I also grepped debugfs.c for other ucsi->connector dereferences - the
three show functions the patch guards are the only ones (ucsi_resp
and the command interface go through ucsi->debugfs), so the fix is
complete.

One thing I'd note in favour of guarding rather than moving
ucsi_debugfs_register() after connector assignment: the command and
response files are exactly what you want available when the PPM is
misbehaving, so keeping the early registration and just making the
power-level reads fail cleanly looks like the better shape to me.

Reviewed-by: Huang Wei <huangwei@kylinos.cn>

Thanks,
Huang Wei

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

* Re: [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
  2026-10-10 12:03 [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs Bertrand Jacquin
  2026-10-10 11:17 ` sashiko-bot
  2026-10-12  3:16 ` Huang Wei
@ 2026-10-26 11:40 ` Heikki Krogerus
  2026-11-20 12:29 ` Greg KH
  3 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2026-10-26 11:40 UTC (permalink / raw)
  To: Bertrand Jacquin
  Cc: gregkh, venkat.jayaraman, linux-usb, linux-kernel, stable

On Sat, Oct 10, 2026 at 01:03:57PM +0100, Bertrand Jacquin wrote:
> ucsi_register() creates the debugfs entries right away, but
> ucsi->connector is only set by ucsi_init(), which runs later from
> ucsi->work and only publishes the connectors once the PPM has been
> reset and all ports are registered. Until then, or for good if init
> fails, ucsi->connector is NULL, yet the peak_current, avg_current and
> vbus_voltage show callbacks dereference it unconditionally.
> 
> On an Intel NUC13ANKi5 whose PPM never answers when CONFIG_ACPI_EC=n,
> reading those files after the failed init oopses:
> 
>   ucsi_acpi USBC000:00: error -ETIMEDOUT: PPM init failed
>   BUG: kernel NULL pointer dereference, address: 000000000000045c
>   #PF: supervisor read access in kernel mode
>   RIP: 0010:ucsi_debugfs_register+0x291/0x420 [typec_ucsi]
>   Call Trace:
>    <TASK>
>    seq_read_iter+0x1e4/0x4c0
>    seq_read+0x12b/0x160
>    full_proxy_read+0x9a/0x1f0
>    vfs_read+0xba/0x320
>    ksys_read+0x74/0x110
>    do_syscall_64+0x79/0x240
>    entry_SYSCALL_64_after_hwframe+0x71/0x79
> 
> Return -ENODEV from those callbacks while no connector is available.
> 
> Fixes: c851b71fd6cd ("usb: typec: ucsi: Add support for READ_POWER_LEVEL command")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bertrand Jacquin <bertrand@jacquin.bzh>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/debugfs.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
> index 77a0dd75edd3..911a151ac16a 100644
> --- a/drivers/usb/typec/ucsi/debugfs.c
> +++ b/drivers/usb/typec/ucsi/debugfs.c
> @@ -92,6 +92,9 @@ static int ucsi_peak_curr_show(struct seq_file *m, void *v)
>  {
>  	struct ucsi *ucsi = m->private;
>  
> +	if (!ucsi->connector)
> +		return -ENODEV;
> +
>  	seq_printf(m, "%u mA\n", ucsi->connector->peak_current);
>  	return 0;
>  }
> @@ -101,6 +104,9 @@ static int ucsi_avg_curr_show(struct seq_file *m, void *v)
>  {
>  	struct ucsi *ucsi = m->private;
>  
> +	if (!ucsi->connector)
> +		return -ENODEV;
> +
>  	seq_printf(m, "%u mA\n", ucsi->connector->avg_current);
>  	return 0;
>  }
> @@ -110,6 +116,9 @@ static int ucsi_vbus_volt_show(struct seq_file *m, void *v)
>  {
>  	struct ucsi *ucsi = m->private;
>  
> +	if (!ucsi->connector)
> +		return -ENODEV;
> +
>  	seq_printf(m, "%u mV\n", ucsi->connector->vbus_voltage);
>  	return 0;
>  }

-- 
heikki

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

* Re: [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
  2026-10-10 12:03 [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs Bertrand Jacquin
                   ` (2 preceding siblings ...)
  2026-10-26 11:40 ` Heikki Krogerus
@ 2026-11-20 12:29 ` Greg KH
  2026-11-21 16:08   ` Bertrand Jacquin
  3 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2026-11-20 12:29 UTC (permalink / raw)
  To: Bertrand Jacquin
  Cc: heikki.krogerus, venkat.jayaraman, linux-usb, linux-kernel,
	stable

On Sat, Oct 10, 2026 at 01:03:57PM +0100, Bertrand Jacquin wrote:
> ucsi_register() creates the debugfs entries right away, but
> ucsi->connector is only set by ucsi_init(), which runs later from
> ucsi->work and only publishes the connectors once the PPM has been
> reset and all ports are registered. Until then, or for good if init
> fails, ucsi->connector is NULL, yet the peak_current, avg_current and
> vbus_voltage show callbacks dereference it unconditionally.
> 
> On an Intel NUC13ANKi5 whose PPM never answers when CONFIG_ACPI_EC=n,
> reading those files after the failed init oopses:
> 
>   ucsi_acpi USBC000:00: error -ETIMEDOUT: PPM init failed
>   BUG: kernel NULL pointer dereference, address: 000000000000045c
>   #PF: supervisor read access in kernel mode
>   RIP: 0010:ucsi_debugfs_register+0x291/0x420 [typec_ucsi]
>   Call Trace:
>    <TASK>
>    seq_read_iter+0x1e4/0x4c0
>    seq_read+0x12b/0x160
>    full_proxy_read+0x9a/0x1f0
>    vfs_read+0xba/0x320
>    ksys_read+0x74/0x110
>    do_syscall_64+0x79/0x240
>    entry_SYSCALL_64_after_hwframe+0x71/0x79
> 
> Return -ENODEV from those callbacks while no connector is available.
> 
> Fixes: c851b71fd6cd ("usb: typec: ucsi: Add support for READ_POWER_LEVEL command")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bertrand Jacquin <bertrand@jacquin.bzh>
> ---
>  drivers/usb/typec/ucsi/debugfs.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
> index 77a0dd75edd3..911a151ac16a 100644
> --- a/drivers/usb/typec/ucsi/debugfs.c
> +++ b/drivers/usb/typec/ucsi/debugfs.c
> @@ -92,6 +92,9 @@ static int ucsi_peak_curr_show(struct seq_file *m, void *v)
>  {
>  	struct ucsi *ucsi = m->private;
>  
> +	if (!ucsi->connector)
> +		return -ENODEV;

What keeps connector from changing to NULL right after you read from it?


> +
>  	seq_printf(m, "%u mA\n", ucsi->connector->peak_current);
>  	return 0;
>  }
> @@ -101,6 +104,9 @@ static int ucsi_avg_curr_show(struct seq_file *m, void *v)
>  {
>  	struct ucsi *ucsi = m->private;
>  
> +	if (!ucsi->connector)
> +		return -ENODEV;

Same here.

thanks,

greg k-h

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

* Re: [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
  2026-11-20 12:29 ` Greg KH
@ 2026-11-21 16:08   ` Bertrand Jacquin
  0 siblings, 0 replies; 6+ messages in thread
From: Bertrand Jacquin @ 2026-11-21 16:08 UTC (permalink / raw)
  To: Greg KH; +Cc: heikki.krogerus, venkat.jayaraman, linux-usb, linux-kernel,
	stable

[-- Attachment #1: Type: text/plain, Size: 2925 bytes --]

Hi Greg,

On Friday, November 20 2026 at 13:29:13 +0100, Greg KH wrote:
> On Sat, Oct 10, 2026 at 01:03:57PM +0100, Bertrand Jacquin wrote:
> > ucsi_register() creates the debugfs entries right away, but
> > ucsi->connector is only set by ucsi_init(), which runs later from
> > ucsi->work and only publishes the connectors once the PPM has been
> > reset and all ports are registered. Until then, or for good if init
> > fails, ucsi->connector is NULL, yet the peak_current, avg_current and
> > vbus_voltage show callbacks dereference it unconditionally.
> >
> > On an Intel NUC13ANKi5 whose PPM never answers when CONFIG_ACPI_EC=n,
> > reading those files after the failed init oopses:
> >
> >   ucsi_acpi USBC000:00: error -ETIMEDOUT: PPM init failed
> >   BUG: kernel NULL pointer dereference, address: 000000000000045c
> >   #PF: supervisor read access in kernel mode
> >   RIP: 0010:ucsi_debugfs_register+0x291/0x420 [typec_ucsi]
> >   Call Trace:
> >    <TASK>
> >    seq_read_iter+0x1e4/0x4c0
> >    seq_read+0x12b/0x160
> >    full_proxy_read+0x9a/0x1f0
> >    vfs_read+0xba/0x320
> >    ksys_read+0x74/0x110
> >    do_syscall_64+0x79/0x240
> >    entry_SYSCALL_64_after_hwframe+0x71/0x79
> >
> > Return -ENODEV from those callbacks while no connector is available.
> >
> > Fixes: c851b71fd6cd ("usb: typec: ucsi: Add support for READ_POWER_LEVEL command")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Bertrand Jacquin <bertrand@jacquin.bzh>
> > ---
> >  drivers/usb/typec/ucsi/debugfs.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c
> > index 77a0dd75edd3..911a151ac16a 100644
> > --- a/drivers/usb/typec/ucsi/debugfs.c
> > +++ b/drivers/usb/typec/ucsi/debugfs.c
> > @@ -92,6 +92,9 @@ static int ucsi_peak_curr_show(struct seq_file *m, void *v)
> >  {
> >  	struct ucsi *ucsi = m->private;
> >
> > +	if (!ucsi->connector)
> > +		return -ENODEV;
> 
> What keeps connector from changing to NULL right after you read from it?

ucsi->connector never transitions back to NULL. only ucsi_init() writes to it
through ucsi->work where it's assigned only once, after all ports are
registered. Every failure path before that assignment leaves it NULL and never
cleared afterwards.

The only end of its lifetime is ucsi_unregister(), which calls
ucsi_debugfs_unregister() before kfree(ucsi->connector).
debugfs_remove_recursive() waits for in-flight readers to drain (the
full_proxy fops hold a debugfs_file_get() reference and
__debugfs_file_removed() waits on active_users_drained). Any read
after that fails with -EIO. So no show callback can run once the
array is freed.

A reader can therefore only see NULL (init still pending, or failed
for good, as in the reported oops) or a valid array, and the check
handles the NULL case.

Cheers,

-- 
Bertrand

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]

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

end of thread, other threads:[~2026-11-21 16:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-10 12:03 [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs Bertrand Jacquin
2026-10-10 11:17 ` sashiko-bot
2026-10-12  3:16 ` Huang Wei
2026-10-26 11:40 ` Heikki Krogerus
2026-11-20 12:29 ` Greg KH
2026-11-21 16:08   ` Bertrand Jacquin

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