Linux USB
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Guoming Chen" <chenguoming88s@gmail.com>,
	"Peter Chen" <peter.chen@kernel.org>,
	"Pawel Laszczak" <pawell@cadence.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: "Roger Quadros" <rogerq@kernel.org>, <linux-usb@vger.kernel.org>
Subject: Re: [PATCH v5] usb: cdns3: fix NULL dereference in cdns_host_resume()
Date: Wed, 25 Nov 2026 11:20:45 +0100	[thread overview]
Message-ID: <DN47SW6B9HLS.337QKFJFOFOLJ@bootlin.com> (raw)
In-Reply-To: <20261125090115.2993-1-chenguoming88s@gmail.com>

Hello Guoming,

On Wed Nov 25, 2026 at 10:01 AM CET, Guoming Chen wrote:
> cdns_host_resume() dereferences the xhci-hcd child's drvdata without
> checking it, and both the child and its drvdata can be NULL:
>
> - cdns->host_dev: cdns_role_start() sets cdns->role before calling the
>   role's start callback and keeps it on failure, so the next resume
>   still calls cdns_host_resume() after a failed host start.

That explanation is much clearer. But the fix here isn't to patch resume
to support being called if the role wasn't started. The fix is to never
call resume if the role wasn't started successfully.

Two ways to do this (there might be more):
 - either we unset cdns->role if role->start() failed
 - or we don't call role->resume() if state == INACTIVE

Please provide the platform name + full kernel panic, this was asked for
in my last email... Or you say that you have never seen that bug in
practice.

> - the child's drvdata: __cdns_host_init() creates the child, but
>   xhci-plat sets the drvdata only in its probe.  The parent is resumed
>   before that, by __driver_probe_device() when the child is first
>   probed and by a system resume in between.

Here again if the role isn't all setup, then its resume should never get
called. Wouldn't the check for state==ACTIVE before calling
role->resume() be enough?

In any case, again, having a resume callback be called when a
device/role isn't ready isn't correct and *that* should be fixed.

Again, for this bug here. You were asked to provide the platform used
and full kernel panics (two because you are fixing two bugs here). What
is found below in your commit is not a full panic log, it is a tiny
hand(?)-crafted snippet. Or you say that you have never seen that bug
in practice.

> Commit 87e4b043b98a ("usb: cdns3: fix role switching during resume")
> only covers a role change during resume.

Funny you mention this commit; it does the proper thing of NOT calling
resume when it would be broken to do so.

> Check both and return early; the child's probe initializes the
> controller from scratch, so power_lost has nothing to act on yet.
> Publish cdns->host_dev only after platform_device_add() succeeds, so
> the error paths leave it NULL instead of pointing at a freed device.
>
> The resume-before-probe case oopses as:
>
>   pc : usb_hcd_is_primary_hcd+0x0/0x1c
>   lr : cdns_host_resume+0x24/0x44
>   Call trace:
>    usb_hcd_is_primary_hcd+0x0/0x1c
>    cdns_resume+0x50/0xdc
>    cdnsp_controller_resume.isra.0+0x14c/0x198
>    cdnsp_plat_runtime_resume+0x20/0x10c
>    ...
>    __pm_runtime_resume+0x4c/0x90
>    __driver_probe_device+0x64/0x1a0
>    xhci_plat_init+0x44/0x50
>
> Fixes: 3a85c1011540 ("usb: host: cdns3: forward lost power information to xhci")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guoming Chen <chenguoming88s@gmail.com>
> ---
> Changes in v5:
>  - Rewrite the commit message around the two NULL checks and their
>    exact causes; add the oops call trace.  No functional changes.

From v4 to v5 you dropped the Cc to lkml and stable mailing lists. Why?

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


      parent reply	other threads:[~2026-11-25 10:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  4:43 [PATCH v3] usb: cdns3: fix NULL dereference in cdns_host_resume() Guomin chen
2026-11-23  4:56 ` sashiko-bot
2026-11-23  7:51 ` [PATCH v4] " Guomin chen
2026-11-23  8:05   ` sashiko-bot
2026-11-23 11:07   ` Théo Lebrun
2026-11-24 14:20     ` guoming chen
2026-11-25  9:01   ` [PATCH v5] " Guoming Chen
2026-11-25  9:11     ` sashiko-bot
2026-11-25 10:20     ` Théo Lebrun [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=DN47SW6B9HLS.337QKFJFOFOLJ@bootlin.com \
    --to=theo.lebrun@bootlin.com \
    --cc=chenguoming88s@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=pawell@cadence.com \
    --cc=peter.chen@kernel.org \
    --cc=rogerq@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox