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=1796349182; b=G4HFGR66u2uomM2XGXPzR/9o5sR3PaOQeP0vf5GUDfXcoAclri5knhTasziGMwx58A5v yj5ftkdny7NEcRdbXq+HGshUUvFj1p3Ucq4QF5UTS8Ur9yaQ1kZE8Rd8o3pOQ2onETF/F RRpaL0kfJqRdXgYrv+xovVw6qhxvvWUzqhv85wrVz5U1u/w2J7XdzIubGY+pK2L+DknNU h3PG2G47vCKV3nUOul23j4PmjzWyP+TACAqSEk4+9m4e/KaQpyy/UKMbJy1gl2Iw7xb4I h5f7nXg1rACuKwKx4Ulrhr9W9IytctJG0R27UjcuVpZzIsn5hoqC3W8GP4vrHZ0Virw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796349182; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=cLZkRMj/ZcGGcAdA/utZ1SzRRhzEcyNsEqGrC/FQftU=; b=zKEXS3P/64pG8I1R5UVb2a4+BStSvG4lADxP8fQujkHS9TRJIe4SVUju5sJ+tpxOg9SG fBdQxu4h+ZrYsCJjLKRPhVDM1Aqfek/bzD2NmdCGfsNpmiUr6MV/ozvatsG2gJxhhWTCn LcSnr2LJMNKglR8MiOfi8wu4b9hYp23G6HgAp7G5ssedJLD2BKys9iYe12cUeIthQnEA4 1fHoGSX7PcymVIYYhD5pCpaGEXE77irD32O0vltsHkA3PTp+U9lh6A4Ru73tZUoenWTAl VJDS2xIbncHjtzS36R4zrsoPRNWcdiu5t2VCFre3cG/OIfACvtPVXRhBi9A/sTT6Dbg== 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=SsghNkmp; 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 5EC3B606A32F for ; Fri, 4 Dec 2026 01:53:02 +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=SsghNkmp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28CF41F000CE; Fri, 4 Dec 2026 01:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796349182; bh=cLZkRMj/ZcGGcAdA/utZ1SzRRhzEcyNsEqGrC/FQftU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=SsghNkmpxhiwUBcP0WPXV8R7vrclVD2joWeKgYQn1ldnM9WzBGflpibnCBsWBie8s DCJypQHuPdKYHZqOksNIlO6F8XyUElCbKiQMmOHBISD+x1RD7LOI1PjKoI3nWWbNTM UTv9N2OAXikGxQKRBmdMmnBpnXDtTBOlXFDgjiMnanpkk+ewiLTfECKiCcN7dD9j6U PMowDdZFGziGP6wAIvJh7j5qDwClchuL6xoJDltc+3MSHQNiAyX7ISGe9ECDAMbokW s/39N6T9+CVs/sR9NeBwJqkoHa+gYgbMXFsq5KWmRughnPVXKcvhq8QtLwDRzU2q/a V0p74OYVlXCbw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] usb: typec: ucsi: Enable notifications before registering connectors Reply-To: sashiko-reviews@lists.linux.dev To: "Jameson Thies" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261204012637.2469388-1-jthies@google.com> References: <20261204012637.2469388-1-jthies@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 01:53:01 +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: UAF in ucsi_connector_change() on re-registration - [Medium] usb: typec: ucsi: 2s EC IRQ stalls in gaokun_ucsi_notify() during init - [Low] usb: typec: ucsi: missing smp_mb() between connector publish and read_cci() -- commit 0cdc70b936d7ce3ae2f45a36f06d4808bd20f8c0 Author: Jameson Thies usb: typec: ucsi: Enable notifications before registering connectors This commit enables UCSI notifications before registering connectors in ucsi_init(), deferring the publication of ucsi->connector with smp_store_release() until registration finishes and gating early events in ucsi_connector_change() on ucsi->connector being NULL. > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c > index 9e453d216c169..3c51d1da256ef 100644 > --- a/drivers/usb/typec/ucsi/ucsi.c > +++ b/drivers/usb/typec/ucsi/ucsi.c > @@ -1561,7 +1561,9 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 nu= m) > { > struct ucsi_connector *con; > =20 > - if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) { > + /* Pairs with smp_store_release() in ucsi_init() */ > + con =3D smp_load_acquire(&ucsi->connector); > + if (!con) { > dev_dbg(ucsi->dev, "Early connector change event\n"); > return; > } > @@ -1573,7 +1575,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 nu= m) > return; > } > =20 > - con =3D &ucsi->connector[num - 1]; > + con =3D &con[num - 1]; > =20 > if (!test_and_set_bit(EVENT_PENDING, &ucsi->flags)) > schedule_work(&con->work); [Severity: High] Can this trigger a use-after-free on ucsi->connector when a UCSI device is re-registered? ucsi_unregister() frees ucsi->connector with kfree(ucsi->connector) without setting it to NULL. Drivers such as pmic_glink_ucsi_register() reuse the same struct ucsi across ucsi_unregister() and ucsi_register() during PDR recovery. Because ucsi_init() now enables connector change notifications before registering connectors and updating ucsi->connector, a connector change arriving during ucsi_register_port() loads the dangling pointer and calls schedule_work(&con->work) on freed memory. Clearing ucsi->connector to NULL in ucsi_unregister() before freeing it would close this. > @@ -2126,22 +2128,6 @@ static int ucsi_init(struct ucsi *ucsi) [ ... ] > /* Enable all supported notifications */ > ntfy =3D ucsi_get_supported_notifications(ucsi); > command =3D UCSI_SET_NOTIFICATION_ENABLE | ntfy; > @@ -2151,6 +2137,17 @@ static int ucsi_init(struct ucsi *ucsi) > =20 > ucsi->ntfy =3D ntfy; > =20 > + /* Register all connectors */ > + for (i =3D 0; i < ucsi->cap.num_connectors; i++) { > + connector[i].num =3D i + 1; > + ret =3D ucsi_register_port(ucsi, &connector[i]); > + if (ret) > + goto err_unregister; > + } [Severity: Medium] Does keeping UCSI_CCI_CONNECTOR(cci) latched during ucsi_register_port() cause repeated 2-second EC IRQ stalls on Huawei Gaokun hardware? Because ucsi_connector_change() drops early events without acknowledging them while ucsi->connector is NULL, UCSI_CCI_CONNECTOR(cci) stays non-zero across every command and ACK in ucsi_register_port(). In drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c, gaokun_ucsi_notify() runs inside the IRQF_ONESHOT EC IRQ thread and calls gaokun_ucsi_handle_no_usb_event() whenever UCSI_CCI_CONNECTOR(cci) is set. That waits in wait_for_completion_timeout(&port->usb_ack, 2 * HZ), masking EC_EVENT_USB and UCSI completions. On timeout, gaokun_ucsi_usb_notify_ind() sees !uec->ucsi->connector and returns early without completing port->usb_ack, so every remaining command and ACK stalls the EC IRQ for 2s. > + > + /* Pairs with smp_load_acquire() in ucsi_connector_change() */ > + smp_store_release(&ucsi->connector, connector); > + > mutex_lock(&ucsi->ppm_lock); > ret =3D ucsi->ops->read_cci(ucsi, &cci); > mutex_unlock(&ucsi->ppm_lock); [Severity: Low] Could a connector change event still be lost between publishing ucsi->connector and reading CCI on weakly-ordered ACPI systems? An uncontended mutex_lock() fastpath only provides acquire semantics, so the release store to ucsi->connector does not prevent a later load from reordering before it. In ucsi_acpi, ucsi_acpi_read_cci() does a plain memcpy() from cacheable RAM and ucsi_acpi_notify() does not take ppm_lock: CPU0 (ucsi_init) CPU1 (ucsi_acpi_notify) smp_store_release(&ucsi->connector, connector) mutex_lock(&ucsi->ppm_lock) /* acquire only; no smp_mb() */ /* EC updates UCSI_CCI */ ucsi_acpi_read_cci() ucsi_acpi_read_cci() -> sees change /* reordered before store, ucsi_connector_change() reads 0 */ smp_load_acquire(&ucsi->connector) /* sees NULL */ <-- event lost On RISC-V 64 (where arch_cmpxchg_acquire() emits only fence r, rw), this reordering leaves the port in a stale state with the unacknowledged change latched in CCI. Adding smp_mb() between smp_store_release() and read_cci() would prevent this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204012637.2469= 388-1-jthies@google.com?part=3D1