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=1795960899; b=iJWEgi1nYmKQsmtiVIbHPIm4P4d8IazJGzwDtM0jp61gJNU0npkf8V8oaLi/7wKjw63N qC2ZTg3mDuSrdqSFc9OUiYFVQDYuo1wtzceXFWGmgGH4U5gxMuUhsVfDLLLfvIOOlXVvO k284xs4Ya0NdXd4ZoJ/dM0G4Zo3lMZU+4sNkqiC06ba5Src5ogAycHeS79FNDDQkZ8E7/ RvBRhH89WG+z9OIERzbktDRKc7CdFNeD+3ATZhQ+PDFNJHTzOV2ISRp+Y4d1fq1CgWHUg iFGtR4ve78c4za5X3oplPOCU1Q24sEZQJROGKApAyxrFSSE2NitzxBnh8bATBtJHIxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795960899; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=pw7hta/jsUTWOLV8VQmbWJXXNyT8GZHpL6cItYFjT2M=; b=IFkdA0wby8tVKNb00O4fbvqOTH7y3GhE7szQIsT2DWu1Fq/nEecYiaV34YXaC3Iv0HPr 4eMusuHNnLmGB4NT2Rbc2dZw3DVSJBCdvlSJIDdzLOpp95gKOSS27sAQjnBlvg5POBOyv bNTuoE1OEvVUz4Vg8NoRFTH6NzJ3Ys2qBIK0IpNjlUCQPhiMNCr99/HeAymNcWcMCBFit QqbSHV0WSIMkrRI93NJXbzUW0OLo/XbBSOGktdk+wdJYkJsK3ScjoMscmhpmJNUydMejQ 3IuFIAeDlgDnYjWkL/ZYToc4VPbz6897MC9yurzojrmBboJxyF4S7YkQEEGzroiM3Yg== 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=HKPwCI4K; 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 7A9B9606A31C for ; Sun, 29 Nov 2026 14:01:39 +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=HKPwCI4K Received: by smtp.kernel.org (Postfix) with ESMTPSA id F27841F00897; Sun, 29 Nov 2026 14:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795960899; bh=pw7hta/jsUTWOLV8VQmbWJXXNyT8GZHpL6cItYFjT2M=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HKPwCI4K9C9deQNLcuNrq+fWWlE2fHSrtjCFQ70k0hP5C6gT90Zn1LkAK2XPrA8HO 41w310GPWGSBS23TpYcKo71hbx10c/1U3vN9zyTEtRjm/If5eglB333CnlvPmm6SHw zxKFsybYayuovj0Rp+ZAVwrVewT88frqbDgOXOzQpmsPGjI96YIM94qnORog5BIka9 73WTvhsGQkbeWhW9nijq0+wIqdVW4LuuRfhaECw9LhHQ9uXSLI9s54vR4vpb4e/TPd TjAHZpmOWqm3DhqgMyXV+M/L9sBwaZxf0H1Bb62f/MMLr05cYR8TfhpXEW079WBYEo VEq1U15alAc1w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 1/5] usb: typec: ucsi: glink: Handle a restart of the remote before the work runs Reply-To: sashiko-reviews@lists.linux.dev To: "Vladyslav Tymoshchuk" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261129134442.579-2-tvlad744@gmail.com> References: <20261129134442.579-1-tvlad744@gmail.com> <20261129134442.579-2-tvlad744@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 14:01:38 +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: typec: ucsi: glink: use-after-free on UCSI re-registration - [Medium] usb: typec: ucsi: glink: stale pd_running used in pmic_glink_ucsi_register() - [Low] usb: typec: ucsi: glink: wrong Fixes commit in changelog -- commit a32a3e07eca3f17ff775eaeede6e3c77bdeacb36 Author: Vladyslav Tymoshchuk > usb: typec: ucsi: glink: Handle a restart of the remote before the work r= uns > > When the remote service goes down and comes back up before the register > work runs, the work finds the service running and UCSI registered, and > does nothing. The restarted firmware is then never initialized, and no > longer reports connector changes. > > Remember that the service went down, and register UCSI anew. > > Fixes: 62b5412b1f4a ("usb: typec: ucsi: add PMIC Glink UCSI driver") > Signed-off-by: Vladyslav Tymoshchuk [Severity: Low] Should the Fixes tag reference 11bb2ffb6793 ("usb: typec: ucsi: Move unregister out of atomic section") instead? In 62b5412b1f4a ("usb: typec: ucsi: add PMIC Glink UCSI driver"), pmic_glink_ucsi_pdr_notify() called ucsi_unregister() directly when the service went down. 11bb2ffb6793 ("usb: typec: ucsi: Move unregister out of atomic section") deferred unregistration to pmic_glink_ucsi_register() and introduced the pd_running and ucsi_registered checks. > diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi= /ucsi_glink.c > index 2696e0b978f66..0535710271822 100644 > --- a/drivers/usb/typec/ucsi/ucsi_glink.c > +++ b/drivers/usb/typec/ucsi/ucsi_glink.c [ ... ] > @@ -314,18 +315,22 @@ static void pmic_glink_ucsi_register(struct work_st= ruct *work) > { > struct pmic_glink_ucsi *ucsi =3D container_of(work, struct pmic_glink_u= csi, register_work); > unsigned long flags; > - bool pd_running; > + bool pd_running, pd_restarted; > =20 > spin_lock_irqsave(&ucsi->state_lock, flags); > pd_running =3D ucsi->pd_running; > + pd_restarted =3D ucsi->pd_restarted; > + ucsi->pd_restarted =3D false; > spin_unlock_irqrestore(&ucsi->state_lock, flags); > =20 > + if (ucsi->ucsi_registered && (pd_restarted || !pd_running)) { > + ucsi_unregister(ucsi->ucsi); > + ucsi->ucsi_registered =3D false; > + } [Severity: Medium] Can pd_running become stale while ucsi_unregister() sleeps? ucsi_unregister() sleeps while cancelling work and waiting on GLINK command= s. If the remote service goes down during that window, pmic_glink_ucsi_registe= r() continues with the earlier pd_running =3D=3D true snapshot, calls ucsi_regi= ster() against the down service, and sets ucsi->ucsi_registered =3D true. > + > if (!ucsi->ucsi_registered && pd_running) { > ucsi_register(ucsi->ucsi); > ucsi->ucsi_registered =3D true; > - } else if (ucsi->ucsi_registered && !pd_running) { > - ucsi_unregister(ucsi->ucsi); > - ucsi->ucsi_registered =3D false; > } > } [Severity: High] Can re-registering the same ucsi->ucsi instance after ucsi_unregister() cause a use-after-free or double free on ucsi->connector? ucsi_unregister() frees ucsi->connector without clearing the pointer, ucsi->ntfy, or EVENT_PENDING in ucsi->flags: drivers/usb/typec/ucsi/ucsi.c:ucsi_unregister() { ... for (i =3D 0; i < ucsi->cap.num_connectors; i++) { cancel_work_sync(&ucsi->connector[i].work); ucsi_unregister_port(&ucsi->connector[i]); lockdep_unregister_key(&ucsi->connector[i].lock_key); } kfree(ucsi->connector); } Because ucsi_register() queues ucsi->work asynchronously, ucsi->connector remains a dangling pointer and ucsi->ntfy retains UCSI_ENABLE_NTFY_CONNECTOR_CHANGE until ucsi_init() assigns a new connector array: kworker (register_work / ucsi->work) kworker (notify_work) pmic_glink_ucsi_register() ucsi_unregister(ucsi->ucsi) kfree(ucsi->connector) ucsi_register(ucsi->ucsi) queue_delayed_work(..., &ucsi->work, 0) pmic_glink_ucsi_notify() ucsi_notify_common() ucsi_connector_change() con =3D &ucsi->connector[num -= 1]; schedule_work(&con->work) <-- use-after-free In addition, if ucsi_register() fails (its return value is not checked), if ucsi_init() fails before reallocating ucsi->connector, or if another ucsi_unregister() runs before ucsi_init() finishes, the next ucsi_unregister() sees the non-NULL ucsi->connector pointer, dereferences the freed array, and calls kfree(ucsi->connector) a second time. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129134442.579-= 1-tvlad744@gmail.com?part=3D1