linux/drivers/soc/qcom
Bjorn Andersson 1efdbf5323 soc: qcom: pmic_glink: Fix race during initialization
commit 3568affcdd upstream.

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 '1ebcde047c
("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2024-09-04 13:28:28 +02:00
..
apr.c driver core: make struct bus_type.uevent() take a const * 2023-01-27 13:45:52 +01:00
cmd-db.c soc: qcom: cmd-db: Map shared memory as WC, not WB 2024-09-04 13:28:28 +02:00
icc-bwmon.c soc: qcom: icc-bwmon: Fix refcount imbalance seen during bwmon_remove 2024-08-03 08:53:28 +02:00
ice.c soc: qcom: Explicitly include correct DT includes 2023-07-14 14:05:06 -07:00
Kconfig soc: qcom: Add RPM processor/subsystem driver 2023-07-13 22:18:57 -07:00
kryo-l2-accessors.c soc: qcom: kryo-l2-accessors: Fix misnaming of 'val' 2020-11-10 23:23:02 -06:00
llcc-qcom.c soc: qcom: llcc: Check return value on Broadcast_OR reg read 2024-03-26 18:19:29 -04:00
Makefile Merge branch 'genpd_create_dir' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/linux-pm into drivers-for-6.6 2023-08-03 09:27:23 -07:00
mdt_loader.c soc: qcom: mdt_loader: Fix split image detection 2023-06-13 10:13:01 -07:00
ocmem.c soc: qcom: ocmem: add missing clk_disable_unprepare() in ocmem_dev_probe() 2023-08-03 08:04:30 -07:00
pdr_interface.c soc: qcom: pdr: fix parsing of domains lists 2024-08-03 08:53:28 +02:00
pdr_internal.h soc: qcom: pdr: Make QMI message rules const 2022-10-17 13:19:40 -05:00
pmic_glink.c soc: qcom: pmic_glink: Fix race during initialization 2024-09-04 13:28:28 +02:00
pmic_glink_altmode.c soc: qcom: pmic_glink: Fix race during initialization 2024-09-04 13:28:28 +02:00
qcom-geni-se.c ARM: SoC drivers for 6.5 2023-06-29 15:22:19 -07:00
qcom_aoss.c soc: qcom: aoss: Tidy up qmp_send() callers 2023-08-13 19:27:32 -07:00
qcom_gsbi.c soc: qcom: use devm_clk_get_enabled() in gsbi_probe() 2023-07-21 20:06:34 -07:00
qcom_stats.c soc: qcom: stats: Populate all subsystem debugfs files 2023-02-06 12:13:30 -08:00
qmi_encdec.c soc: qcom: qmi_encdec: Restrict string length in decode 2023-08-03 08:08:07 -07:00
qmi_interface.c soc: qcom: qmi: Use alloc_ordered_workqueue() to create ordered workqueues 2023-05-24 20:03:19 -07:00
ramp_controller.c ARM: SoC drivers for 6.5 2023-06-29 15:22:19 -07:00
rmtfs_mem.c soc: qcom: rmtfs: Fix error code in probe() 2023-05-24 20:05:08 -07:00
rpm-proc.c soc: qcom: Add RPM processor/subsystem driver 2023-07-13 22:18:57 -07:00
rpm_master_stats.c soc: qcom: Fix a IS_ERR() vs NULL bug in probe 2023-06-13 11:57:26 -07:00
rpmh-internal.h soc: qcom: rpmh-rsc: Avoid unnecessary checks on irq-done response 2022-12-05 15:12:17 -06:00
rpmh-rsc.c soc: qcom: rpmh-rsc: Ensure irqs aren't disabled by rpmh_rsc_send_data() callers 2024-08-03 08:53:25 +02:00
rpmh.c soc: qcom: rpmh-rsc: Ensure irqs aren't disabled by rpmh_rsc_send_data() callers 2024-08-03 08:53:25 +02:00
smd-rpm.c This pull request is full of clk driver changes. In fact, there aren't any 2023-08-30 19:53:39 -07:00
smem.c soc: qcom: smem: Fix incompatible types in comparison 2023-08-03 08:07:20 -07:00
smem_state.c soc: qcom: smem_state: Add refcounting for the 'state->of_node' 2022-08-18 14:13:46 -05:00
smp2p.c soc: qcom: move from strlcpy with unused retval to strscpy 2022-10-17 13:19:39 -05:00
smsm.c soc: qcom: smsm: Use dev_err_probe() 2023-03-24 05:59:07 -07:00
socinfo.c soc: qcom: socinfo: rename PM2250 to PM4125 2024-03-26 18:19:23 -04:00
spm.c soc: qcom: Explicitly include correct DT includes 2023-07-14 14:05:06 -07:00
trace-rpmh.h soc: qcom: rpmh-rsc: Include state in trace event 2023-07-09 21:18:35 -07:00
wcnss_ctrl.c soc: qcom: Explicitly include correct DT includes 2023-07-14 14:05:06 -07:00