From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 12/12] usb: apple-mfi-fastcharge: Simplify match and property_is_writeable
Date: Sun, 06 Dec 2026 03:06:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-252105@kernel.org> (raw)
In-Reply-To: <7be74b3b899167a181d41b1c32da6099602c02b4.1796524906.git.rosenp@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: apple-mfi-fastcharge: NULL deref in mfi_fc_resume() during
probe
- [Medium] usb: apple-mfi-fastcharge: UAF in mfi_fc_resume() during
unbind
--
commit 69d314052e91b1c0b04c5d6cf67281bfa7bec29d
Author: Rosen Penev <rosenp@gmail.com>
usb: apple-mfi-fastcharge: Simplify match and property_is_writeable
This commit simplifies mfi_fc_match() to check the 0x12nn product ID range
with a u16 mask and reduces apple_mfi_fc_property_is_writeable() to a single
comparison, concluding the apple-mfi-fastcharge cleanup and runtime PM
series.
> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
> index 02adec28d9e69..41eb0d56f9e01 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c
[ ... ]
> mfi->udev = udev;
> +
> + psy = devm_power_supply_register(&udev->dev, psy_desc, &psy_cfg);
> + if (IS_ERR(psy))
> + return PTR_ERR(psy);
> +
> dev_set_drvdata(&udev->dev, mfi);
> + usb_enable_autosuspend(udev);
>
> return 0;
> -
> -err_free_name:
> - kfree(battery_name);
> -err_free_mfi:
> - kfree(mfi);
> - return err;
> }
>
> -static void mfi_fc_disconnect(struct usb_device *udev)
> +static int mfi_fc_resume(struct usb_device *udev, pm_message_t message)
> {
> - struct mfi_device *mfi;
> + struct mfi_device *mfi = dev_get_drvdata(&udev->dev);
>
> - mfi = dev_get_drvdata(&udev->dev);
> - if (mfi->battery)
> - power_supply_unregister(mfi->battery);
> - kfree(mfi->battery_desc.name);
> - dev_set_drvdata(&udev->dev, NULL);
> - kfree(mfi);
> + guard(mutex)(&mfi->lock);
[Severity: High]
Can mfi_fc_resume() dereference a NULL mfi pointer during probe?
Earlier in this series, commits "usb: apple-mfi-fastcharge: Restore charge
current on resume", "usb: apple-mfi-fastcharge: Serialize charge_type access
with a mutex", and "usb: apple-mfi-fastcharge: Configure runtime PM
autosuspend" added mfi_fc_resume() with guard(mutex)(&mfi->lock) and enabled
autosuspend.
When binding to a runtime-suspended device (for instance on rebind after an
unbind leaves autosuspend enabled), really_probe() sets dev->driver before
usb_probe_device() runs usb_generic_driver_probe() ->
usb_set_configuration() -> usb_autoresume_device() -> usb_resume_device().
Because udev->dev.driver is already set while drvdata is still NULL,
usb_resume_device() calls mfi_fc_resume() before mfi_fc_probe(), causing a
NULL pointer dereference on &mfi->lock.
In addition, mfi_fc_probe() registers the power_supply device before calling
dev_set_drvdata(&udev->dev, mfi), so a concurrent write to charge_type can
also trigger pm_runtime_resume_and_get() -> mfi_fc_resume() while drvdata is
still NULL.
Returning 0 when mfi is NULL in mfi_fc_resume() and calling dev_set_drvdata()
before devm_power_supply_register() would close both windows.
[ ... ]
> static struct usb_device_driver mfi_fc_driver = {
> .name = "apple-mfi-fastcharge",
> .probe = mfi_fc_probe,
> - .disconnect = mfi_fc_disconnect,
> + .resume = mfi_fc_resume,
> .id_table = mfi_fc_id_table,
> .match = mfi_fc_match,
> .generic_subclass = 1,
> + .supports_autosuspend = 1,
> };
[Severity: Medium]
Without a .disconnect callback, can mfi_fc_resume() race with devm teardown
during unbind and trigger a use-after-free on mfi?
Earlier in this series, commit "usb: apple-mfi-fastcharge: Convert to devm
resources" removed mfi_fc_disconnect() and moved mfi and mfi->lock to devm.
During unbind, usb_generic_driver_disconnect() calls
usb_set_configuration(udev, -1) -> usb_autosuspend_device(udev), allowing
udev and its port to runtime-suspend while dev->driver is still set.
Because usb_port_runtime_resume() and usb_runtime_resume() do not hold
device_lock(&udev->dev), an asynchronous runtime resume can run after
devres_release_all() frees mfi and destroys mfi->lock, but before
device_unbind_cleanup() clears dev->driver and drvdata:
CPU0 CPU1
__device_release_driver()
usb_unbind_device()
usb_set_configuration(..., -1)
usb_autosuspend_device()
usb_port_runtime_resume()
pm_request_resume(&udev->dev)
device_unbind_cleanup()
devres_release_all()
mutex_destroy(&mfi->lock)
kfree(mfi)
usb_runtime_resume()
usb_resume_device()
mfi_fc_resume()
guard(mutex)(&mfi->lock)
<-- use-after-free
device_set_driver(dev, NULL)
dev_set_drvdata(dev, NULL)
mfi_fc_resume() then locks a destroyed mutex in freed memory (or hits a NULL
pointer dereference if drvdata was just cleared), risking memory corruption
or an Oops on unbind or module removal. Adding a .disconnect callback that
disables autosuspend, synchronizes runtime PM, and clears drvdata before
devm teardown would prevent this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796524906.git.rosenp@gmail.com?part=12
next prev parent reply other threads:[~2026-12-06 3:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 2:44 [PATCH 00/12] usb: apple-mfi-fastcharge: Fixes and cleanups Rosen Penev
2026-12-06 2:44 ` [PATCH 01/12] usb: apple-mfi-fastcharge: Convert to devm resources Rosen Penev
2026-12-06 3:00 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 02/12] usb: apple-mfi-fastcharge: Use pm_runtime_resume_and_get() Rosen Penev
2026-12-06 2:44 ` [PATCH 03/12] usb: apple-mfi-fastcharge: Fix usb_control_msg() return check and timeout Rosen Penev
2026-12-06 2:44 ` [PATCH 04/12] usb: apple-mfi-fastcharge: Use POWER_SUPPLY_TYPE_USB instead of BATTERY Rosen Penev
2026-12-06 3:04 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 05/12] usb: apple-mfi-fastcharge: Constify power_supply_property array Rosen Penev
2026-12-06 2:44 ` [PATCH 06/12] usb: apple-mfi-fastcharge: Use topology-based device name Rosen Penev
2026-12-06 2:44 ` [PATCH 07/12] usb: apple-mfi-fastcharge: Restore charge current on resume Rosen Penev
2026-12-06 3:05 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 08/12] usb: apple-mfi-fastcharge: Serialize charge_type access with a mutex Rosen Penev
2026-12-06 3:07 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 09/12] usb: apple-mfi-fastcharge: Configure runtime PM autosuspend Rosen Penev
2026-12-06 3:05 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 10/12] usb: apple-mfi-fastcharge: Name the vendor power request Rosen Penev
2026-12-06 2:44 ` [PATCH 11/12] usb: apple-mfi-fastcharge: Rename battery variables to psy Rosen Penev
2026-12-06 2:58 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 12/12] usb: apple-mfi-fastcharge: Simplify match and property_is_writeable Rosen Penev
2026-12-06 3:06 ` sashiko-bot [this message]
2026-12-06 3:07 ` [PATCH 00/12] usb: apple-mfi-fastcharge: Fixes and cleanups sashiko-bot
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=sashiko-outbox-252105@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rosenp@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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