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=1796526437; b=qzwqcrjMEFgOPgArLH811EFIyabzI/Xg1NaGtpfMQQVeFuZuEYB7wvgipMiOmzQDtvkc X7Z86JZ5ZFnB9X3jkXvmDCDJf/ARBSxbNvO786FDp16WlNM7K2xy+E1AfogYu6d7s5rom I7tLol6liL1hFkGJsAbBiqbBmnU4BiaweQIoo/zmX4gBXS7nUJCzyIaSgG5xC0kO7cTLE FIqaSPM6xaXEi/8GBoyd2iHTax87PQCcikjSxmuax9vYR6tUDdfY8okRbMcuJP3CWDenV w3PRCe8Lgt++lO8G0dwWjJrGQQUY470R5q8L8j+bDXnzriOVkQxJJuxXalMPXAVJFkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796526437; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=eHDFelf0Zg1BXSVonGfh+PuhpDQZDzqTDHzaPPGhg6I=; b=H5GVpb20JQvpiwW/jHKN0HgOWZ+avHjELLhU65TRmauaqTK2hbTEIzgCmHiPUvl50tS5 NHewhi+DDC5UlHJasUW0Xy2waLlkrP+3eyp9YRkD8LFPHdfcmbL7ZBYOLFCULD7tRnl04 sL1UJfAaiOjy3BT44BT/OYwQPs/54HcEIg2Wy+AQCbKzPmnBnK+Rl94s+KpM4yqRtk49q U6iP/iFlnc00z4bOA/C+eaVgml8LRQO4I6Qj2CI5L1wYNiqpp5sL8LTxWFihLLcqX2s33 HwCiovV1wFokjqxoeKv4THrVvKcbXD+EooHxKwW5w/8LIK/jO7WvO2qdAeAHeG2MGyQ== 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=M89bNkY+; 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 0832B606A31F for ; Sun, 6 Dec 2026 03:07:16 +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=M89bNkY+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DD721F00A10; Sun, 6 Dec 2026 03:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796526436; bh=eHDFelf0Zg1BXSVonGfh+PuhpDQZDzqTDHzaPPGhg6I=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=M89bNkY+29UW0s8+ai3WQEieVf9x/6JKReHNLpong1URaejeFVIy+bLmEufubJz9g hItA1BFnjIyA8guGMrcKs0pYN+KGI2qwTjrA1fMoiX1gPV92uzsPx47kGQnFHJOxMr MKF24WVovwG+odQTMWStI7AsZm9siHpRKqmZQvpt7UpvrFZnP3XjDDtMdwLQbNRz6G 9HaPUdFdlSLyzGoQEClvioGy2JESig3eZacHzt+e5/6vb3/3K3kw1ioi0CxQ7QZSih DWzgAYJf5PgZxCFlh5XExb1X4ZxRZEjmOgHc71hUHrUh7YTlJA0uPPnkXwTLGSdRnH W/gnopPInDRHQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 08/12] usb: apple-mfi-fastcharge: Serialize charge_type access with a mutex Reply-To: sashiko-reviews@lists.linux.dev To: "Rosen Penev" Cc: linux-usb@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 03:07:15 +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 3 potential issues to consider: - [High] usb: apple-mfi-fastcharge: NULL dereference in mfi_fc_resume() during probe - [Medium] usb: apple-mfi-fastcharge: unbind races mfi_fc_resume() via devm cleanup - [Low] usb: apple-mfi-fastcharge: missing Fixes tag for charge_type race fix -- commit b8bcac8cd75839545033e3e164816c2f61377563 Author: Rosen Penev > usb: apple-mfi-fastcharge: Serialize charge_type access with a mutex > > Concurrent writes to charge_type from userspace can race: both > threads may read the old value, send their USB command, and write > the software state, leaving the cached charge_type mismatched with > the actual hardware state. > > Add a per-device mutex and hold it across the USB control transfer > in set_charge_type, so the cached value always matches the last > current sent to the device. Update the cache only after the transfer > succeeds, which removes the need to roll it back on error. Take the > same lock in get_property and in the resume path. Initialize it with > devm_mutex_init() and use guard(mutex) for scoped locking. > > Signed-off-by: Rosen Penev [Severity: Low] This fixes a concurrency bug on mfi->charge_type that has been present since the driver was added. Should this include: Fixes: 249fa8217b84 ("USB: Add driver to control USB fast charge for iOS = devices") > diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/a= pple-mfi-fastcharge.c > index 85cf970e5f5eb..fb4b975a62e94 100644 > --- a/drivers/usb/misc/apple-mfi-fastcharge.c > +++ b/drivers/usb/misc/apple-mfi-fastcharge.c [ ... ] > @@ -176,11 +179,16 @@ static int mfi_fc_probe(struct usb_device *udev) > struct power_supply_desc *battery_desc; > struct power_supply *battery; > struct mfi_device *mfi; > + int ret; > =20 > mfi =3D devm_kzalloc_obj(&udev->dev, *mfi); > if (!mfi) > return -ENOMEM; > =20 > + ret =3D devm_mutex_init(&udev->dev, &mfi->lock); > + if (ret) > + return ret; [Severity: Medium] Can driver unbind race with mfi_fc_resume() and trigger a use-after-free on mfi->lock? During unbind while the device remains attached (such as sysfs unbind or rmmod), usb_unbind_device() drops the runtime PM usage count so udev can runtime-suspend while udev->dev.driver is still set. A concurrent lockless runtime resume, such as writing a negative delay to power/autosuspend, can then observe udev->dev.driver before device_unbind_cleanup() clears it: CPU0 (unbind) CPU1 (autosuspend_store) __device_release_driver() usb_unbind_device() usb_autosuspend_device() ... -> usb_runtime_suspend() pm_runtime_set_autosuspend_delay() rpm_resume() -> usb_resume_device() reads udev->dev.driver usb_generic_driver_resume() device_unbind_cleanup() devres_release_all() mutex_destroy(&mfi->lock) kfree(mfi) mfi_fc_resume() guard(mutex)(&mfi->lock) <-- use-after-free device_set_driver(dev, NULL) dev_set_drvdata(dev, NULL) Because devres_release_all() destroys mfi->lock and frees mfi before dev->driver and drvdata are cleared and without a pm_runtime_barrier(), mfi_fc_resume() can lock freed memory, dereference a NULL mfi, or have mfi->lock destroyed while sleeping in usb_control_msg(). [ ... ] > @@ -212,6 +220,8 @@ static int mfi_fc_resume(struct usb_device *udev, pm_= message_t message) > { > struct mfi_device *mfi =3D dev_get_drvdata(&udev->dev); > =20 > + guard(mutex)(&mfi->lock); [Severity: High] Will guard(mutex)(&mfi->lock) dereference a NULL mfi when probing a runtime-suspended device? really_probe() binds udev->dev.driver via device_set_driver() before calling usb_probe_device(), which calls usb_autoresume_device() (both directly and via usb_generic_driver_probe() -> usb_set_configuration()) before mfi_fc_probe() runs. If the device is runtime-suspended at probe time, usb_resume_device() invokes mfi_fc_resume() while dev_get_drvdata(&udev->dev) is still NULL, causing a NULL pointer dereference in mutex_lock(). Returning 0 early when !mfi avoids the crash. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796524906.gi= t.rosenp@gmail.com?part=3D8