All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Bertrand Jacquin <bertrand@jacquin.bzh>
Cc: gregkh@linuxfoundation.org, venkat.jayaraman@intel.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] usb: typec: ucsi: Fix NULL pointer dereference in power level debugfs
Date: Mon, 26 Oct 2026 12:40:13 +0100	[thread overview]
Message-ID: <at88HU4YlGSAJGoE@black.igk.intel.com> (raw)
In-Reply-To: <20261010120357.4937-1-bertrand@jacquin.bzh>

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

      parent reply	other threads:[~2026-10-26 11:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=at88HU4YlGSAJGoE@black.igk.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=bertrand@jacquin.bzh \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=venkat.jayaraman@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.