linux/drivers/usb
Bjorn Andersson 3568affcdd soc: qcom: pmic_glink: Fix race during initialization
As pointed out by Stephen Boyd it is possible that during initialization
of the pmic_glink child drivers, the protection-domain notifiers fires,
and the associated work is scheduled, before the client registration
returns and as a result the local "client" pointer has been initialized.

The outcome of this is a NULL pointer dereference as the "client"
pointer is blindly dereferenced.

Timeline provided by Stephen:
 CPU0                               CPU1
 ----                               ----
 ucsi->client = NULL;
 devm_pmic_glink_register_client()
  client->pdr_notify(client->priv, pg->client_state)
   pmic_glink_ucsi_pdr_notify()
    schedule_work(&ucsi->register_work)
    <schedule away>
                                    pmic_glink_ucsi_register()
                                     ucsi_register()
                                      pmic_glink_ucsi_read_version()
                                       pmic_glink_ucsi_read()
                                        pmic_glink_ucsi_read()
                                         pmic_glink_send(ucsi->client)
                                         <client is NULL BAD>
 ucsi->client = client // Too late!

This code is identical across the altmode, battery manager and usci
child drivers.

Resolve this by splitting the allocation of the "client" object and the
registration thereof into two operations.

This only happens if the protection domain registry is populated at the
time of registration, which by the introduction of commit '1ebcde047c54
("soc: qcom: add pd-mapper implementation")' became much more likely.

Reported-by: Amit Pundir <amit.pundir@linaro.org>
Closes: https://lore.kernel.org/all/CAMi1Hd2_a7TjA7J9ShrAbNOd_CoZ3D87twmO5t+nZxC9sX18tA@mail.gmail.com/
Reported-by: Johan Hovold <johan@kernel.org>
Closes: https://lore.kernel.org/all/ZqiyLvP0gkBnuekL@hovoldconsulting.com/
Reported-by: Stephen Boyd <swboyd@chromium.org>
Closes: https://lore.kernel.org/all/CAE-0n52JgfCBWiFQyQWPji8cq_rCsviBpW-m72YitgNfdaEhQg@mail.gmail.com/
Fixes: 58ef4ece1e ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Cc: stable@vger.kernel.org
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Tested-by: Amit Pundir <amit.pundir@linaro.org>
Reviewed-by: Johan Hovold <johan+linaro@kernel.org>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
Link: https://lore.kernel.org/r/20240820-pmic-glink-v6-11-races-v3-1-eec53c750a04@quicinc.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
2024-08-21 08:37:30 -05:00
..
atm usb: atm: cxacru: fix endpoint checking in cxacru_bind() 2024-06-20 19:34:51 +02:00
c67x00 USB: c67x00: Remove unused declaration c67x00_hcd_msg_received() 2023-10-02 16:42:33 +02:00
cdns3 pci-v6.11-changes 2024-07-19 19:03:18 -07:00
chipidea usb: chipidea: ci_hdrc_tegra: Switch to RUNTIME_PM_OPS() 2024-06-27 16:07:01 +02:00
class usb: add missing MODULE_DESCRIPTION() macros 2024-06-20 19:18:52 +02:00
common Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
core Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
dwc2 usb: dwc2: add support for other Lantiq SoCs 2024-07-10 13:56:32 +02:00
dwc3 USB/Thunderbolt updates for 6.11-rc1 2024-07-19 15:37:48 -07:00
early
fotg210 usb: fotg210: Add missing kernel doc description 2024-05-11 08:42:03 +01:00
gadget Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
host USB/Thunderbolt updates for 6.11-rc1 2024-07-19 15:37:48 -07:00
image scsi: core: Add a dma_alignment field to the host and host template 2024-04-11 21:37:48 -04:00
isp1760 mm, slab: remove last vestiges of SLAB_MEM_SPREAD 2024-03-12 20:32:19 -07:00
misc of: remove internal arguments from of_property_for_each_u32() 2024-07-25 06:53:47 -05:00
mon usb: add missing MODULE_DESCRIPTION() macros 2024-06-20 19:18:52 +02:00
mtu3 tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
musb Merge 6.10-rc6 into usb-next 2024-07-01 13:59:29 +02:00
phy usb: phy: add missing MODULE_DESCRIPTION() macros 2024-06-20 19:18:32 +02:00
renesas_usbhs usb: renesas_usbhs: Remove renesas_usbhs_get_info() wrapper 2024-04-18 16:47:49 +02:00
roles Merge v6.8-rc6 into usb-next 2024-02-26 06:53:50 +01:00
serial Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
storage USB: uas: Implement the new shutdown callback 2024-07-10 13:58:24 +02:00
typec soc: qcom: pmic_glink: Fix race during initialization 2024-08-21 08:37:30 -05:00
usbip usbip: Don't submit special requests twice 2024-06-04 15:40:56 +02:00
Kconfig usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk 2023-10-02 16:19:12 +02:00
Makefile USB: xen-hcd: Traverse host/ when CONFIG_USB_XEN_HCD is selected 2024-06-04 15:33:38 +02:00
usb-skeleton.c