linux-stable/drivers/firmware
Andre Przywara ead445dd3d firmware: arm_scmi: Fix double free in SMC transport cleanup path
[ Upstream commit f1d71576d2 ]

When the generic SCMI code tears down a channel, it calls the chan_free
callback function, defined by each transport. Since multiple protocols
might share the same transport_info member, chan_free() might want to
clean up the same member multiple times within the given SCMI transport
implementation. In this case, it is SMC transport. This will lead to a NULL
pointer dereference at the second time:

    | scmi_protocol scmi_dev.1: Enabled polling mode TX channel - prot_id:16
    | arm-scmi firmware:scmi: SCMI Notifications - Core Enabled.
    | arm-scmi firmware:scmi: unable to communicate with SCMI
    | Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
    | Mem abort info:
    |   ESR = 0x0000000096000004
    |   EC = 0x25: DABT (current EL), IL = 32 bits
    |   SET = 0, FnV = 0
    |   EA = 0, S1PTW = 0
    |   FSC = 0x04: level 0 translation fault
    | Data abort info:
    |   ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
    |   CM = 0, WnR = 0, TnD = 0, TagAccess = 0
    |   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
    | user pgtable: 4k pages, 48-bit VAs, pgdp=0000000881ef8000
    | [0000000000000000] pgd=0000000000000000, p4d=0000000000000000
    | Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
    | Modules linked in:
    | CPU: 4 PID: 1 Comm: swapper/0 Not tainted 6.7.0-rc2-00124-g455ef3d016c9-dirty #793
    | Hardware name: FVP Base RevC (DT)
    | pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
    | pc : smc_chan_free+0x3c/0x6c
    | lr : smc_chan_free+0x3c/0x6c
    | Call trace:
    |  smc_chan_free+0x3c/0x6c
    |  idr_for_each+0x68/0xf8
    |  scmi_cleanup_channels.isra.0+0x2c/0x58
    |  scmi_probe+0x434/0x734
    |  platform_probe+0x68/0xd8
    |  really_probe+0x110/0x27c
    |  __driver_probe_device+0x78/0x12c
    |  driver_probe_device+0x3c/0x118
    |  __driver_attach+0x74/0x128
    |  bus_for_each_dev+0x78/0xe0
    |  driver_attach+0x24/0x30
    |  bus_add_driver+0xe4/0x1e8
    |  driver_register+0x60/0x128
    |  __platform_driver_register+0x28/0x34
    |  scmi_driver_init+0x84/0xc0
    |  do_one_initcall+0x78/0x33c
    |  kernel_init_freeable+0x2b8/0x51c
    |  kernel_init+0x24/0x130
    |  ret_from_fork+0x10/0x20
    | Code: f0004701 910a0021 aa1403e5 97b91c70 (b9400280)
    | ---[ end trace 0000000000000000 ]---

Simply check for the struct pointer being NULL before trying to access
its members, to avoid this situation.

This was found when a transport doesn't really work (for instance no SMC
service), the probe routines then tries to clean up, and triggers a crash.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Fixes: 1dc6558062 ("firmware: arm_scmi: Add smc/hvc transport")
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20240126122325.2039669-1-andre.przywara@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-03-26 18:16:46 -04:00
..
arm_ffa firmware: arm_ffa: Handle partitions setup failures 2024-01-22 10:07:12 +00:00
arm_scmi firmware: arm_scmi: Fix double free in SMC transport cleanup path 2024-03-26 18:16:46 -04:00
broadcom MIPS: BCM47XX: remove MODULE_LICENSE in non-modules 2023-04-13 13:13:51 -07:00
cirrus firmware: cirrus: cs_dsp: Only log list of algorithms in debug build 2023-09-13 18:50:32 +01:00
efi efi/capsule-loader: fix incorrect allocation size 2024-02-13 16:30:07 +01:00
google firmware: coreboot_table: Convert to platform remove callback returning void 2024-01-04 17:01:14 +01:00
imx firmware: imx-dsp: Convert to platform remove callback returning void 2024-01-04 17:01:14 +01:00
meson firmware: meson-sm: unmap out_base shmem in error path 2023-11-27 09:17:51 +01:00
microchip RISC-V firmware drivers for v6.9 2024-03-06 07:42:08 +01:00
psci firmware/psci: demote suspend-mode warning to info level 2023-04-14 13:48:56 +02:00
qcom firmware: qcom: qseecom: fix memory leaks in error paths 2023-12-18 21:14:58 -06:00
smccc firmware: smccc: Fix use of uninitialised results structure 2023-07-18 10:08:05 +01:00
tegra SoC driver updates for 6.7 2023-11-01 14:46:51 -10:00
xilinx firmware: xilinx: Export function to use in other module 2024-01-04 17:02:49 +01:00
Kconfig Core: 2024-01-12 13:54:25 -08:00
Makefile Core: 2024-01-12 13:54:25 -08:00
arm_scpi.c firmware: arm_scpi: Convert to platform remove callback returning void 2024-01-04 17:01:14 +01:00
arm_sdei.c arm64: sdei: abort running SDEI handlers during crash 2023-08-04 17:35:33 +01:00
dmi-id.c driver core: make struct class.dev_uevent() take a const * 2022-11-24 17:12:15 +01:00
dmi-sysfs.c firmware: dmi-sysfs: handle HAS_IOPORT=n 2023-05-31 19:17:29 +01:00
dmi_scan.c firmware: dmi: Fortify entry point length checks 2022-09-23 14:53:14 +02:00
edd.c edd: make kobj_type structure constant 2023-03-09 18:07:33 +01:00
iscsi_ibft.c
iscsi_ibft_find.c iscsi_ibft: Fix finding the iBFT under Xen Dom 0 2023-06-26 07:47:11 +02:00
memmap.c
mtk-adsp-ipc.c firmware: mtk-adsp-ipc: Convert to platform remove callback returning void 2024-01-04 17:01:14 +01:00
qemu_fw_cfg.c firmware: qemu_fw_cfg: Convert to platform remove callback returning void 2024-01-04 17:01:15 +01:00
raspberrypi.c firmware: raspberrypi: Convert to platform remove callback returning void 2024-01-04 17:01:15 +01:00
stratix10-rsu.c firmware: stratix10-rsu: Convert to platform remove callback returning void 2024-01-04 17:01:15 +01:00
stratix10-svc.c firmware: stratix10-svc: Convert to platform remove callback returning void 2024-01-04 17:01:15 +01:00
sysfb.c Revert "drivers/firmware: Move sysfb_init() from device_initcall to subsys_initcall_sync" 2024-01-24 17:03:44 +01:00
sysfb_simplefb.c firmware/sysfb: Fix VESA format selection 2023-04-21 14:27:31 +02:00
ti_sci.c firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create() 2023-11-24 12:49:08 -06:00
ti_sci.h
trusted_foundations.c
turris-mox-rwtm.c firmware: turris-mox-rwtm: Convert to platform remove callback returning void 2024-01-04 17:01:15 +01:00