From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796526401; b=d5zHdxL5r+bEtGPKxWOh7H8Id+nWPRfZMbd7T1/VlDwPG0uK73dd80+SQifuqTUuyV6x JLShNVfaKW9TJ2Sz+ejxBL8zy+LMfaIPKz/FlW8fgjdTIP7Er6h5JlSVXpkeIjsLOhNNA n1RU7kUeLy0KDRlPvqYrVazLHglOzu9pgpc1tlxVe/5uaONZt5yHYbgoW2OxxWGwiWRsq 5ysU2mb8HDTTuRPAvs8S0OWWxHT51MKoK3DBkvyPtbLn/ABYZHT6Co3kJDXXgxIj2LfVa KvftclYFdcqcMwdsJRh+GqwMk9+hT827pYbpCDYXZ8hHi8K5v6YCHU8XM9GRbTLtpCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796526401; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vQda9yhtULomDRrlA2V3Cxsh1t+Lm33CJMUFoA3ieKs=; b=pTrmtCaJC9FeGAGS0/rAUviVtH0Hw2J2xZEqHJwd1toqOBb1wGU3Ob9vBrhO3x5IP+Sm FZ0mnD3SijOBiY/Uz2an1YuDsGqCO/DjvgMQacGsEeja8MeGSEa9z5KeGr6R6VseeJZvr zPBC8Yjx+9WBRorPes501TAPK3DZzWQg+g9WGModRf0f3MRbRVwWCWTEA9hDj8rtA8NT+ I9MtC6b5Jqi6di00E6ZfMAyB19y5YNU3kD2ubNxir018HcbMVxa1Hfy4I7uSKA5v7cyAk 1PlPYAkIliofb2qHmZoGMnSYmb50NewxKyunWzCxqU8jQyZDM3ocn40ul9lPBIDeDHQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oaiuu5aq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1081B606A31F for ; Sun, 6 Dec 2026 03:06:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oaiuu5aq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8134C1F0092B; Sun, 6 Dec 2026 03:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796526400; bh=vQda9yhtULomDRrlA2V3Cxsh1t+Lm33CJMUFoA3ieKs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oaiuu5aqfUf71xh6Re5FolYdlPKjzji3VV8cht0xJ2cM8/EF+QbxSzm8FPo2uQSvx G73HTxaawcTEv5kFZ+k1Lqs7Hbz9ifyjpxZlY1oL0HDbcG8kTL9phoNEfMqU+P7tOL OIBasCtpl1Vu5bZu4uUTdEipvJD6mWrmMCv8fanER+kRjavovpj7r/B9VD6FAOqc5U /M7mGNFhfGWaFR+wx4XQpgEYBCfqmubxfByP2YaFrk2BFhQ5RGd1uoUP0yGSZTWeFX u7A7GRAYvyN2eA+E3thfR7pVmzDWFbPr4Q3wNz3DS2RXigFykg0oTEk9gt1mEY6YAx a52DTwZG56dmg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 12/12] usb: apple-mfi-fastcharge: Simplify match and property_is_writeable Reply-To: sashiko-reviews@lists.linux.dev To: "Rosen Penev" Cc: linux-usb@vger.kernel.org In-Reply-To: <7be74b3b899167a181d41b1c32da6099602c02b4.1796524906.git.rosenp@gmail.com> References: <7be74b3b899167a181d41b1c32da6099602c02b4.1796524906.git.rosenp@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 03:06:40 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/a= pple-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 =3D udev; > + > + psy =3D 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); > =20 > return 0; > - > -err_free_name: > - kfree(battery_name); > -err_free_mfi: > - kfree(mfi); > - return err; > } > =20 > -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 =3D dev_get_drvdata(&udev->dev); > =20 > - mfi =3D 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 =3D { > .name =3D "apple-mfi-fastcharge", > .probe =3D mfi_fc_probe, > - .disconnect =3D mfi_fc_disconnect, > + .resume =3D mfi_fc_resume, > .id_table =3D mfi_fc_id_table, > .match =3D mfi_fc_match, > .generic_subclass =3D 1, > + .supports_autosuspend =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796524906.gi= t.rosenp@gmail.com?part=3D12