1
0
Fork 0
alistair23-linux/drivers/bus
John Garry 29c25e6949 bus: hisi_lpc: Fixup IO ports addresses to avoid use-after-free in host removal
[ Upstream commit a6dd255bdd ]

Some released ACPI FW for Huawei boards describes incorrect the port IO
address range for child devices, in that it tells us the IO port max range
is 0x3fff for each child device, which is not correct. The address range
should be [e4:e8) or similar. With this incorrect upper range, the child
device IO port resources overlap.

As such, the kernel thinks that the LPC host serial device is a child of
the IPMI device:

root@(none)$ more /proc/ioports
[...]
00ffc0e3-00ffffff : hisi-lpc-ipmi.0.auto
  00ffc0e3-00ffc0e3 : ipmi_si
  00ffc0e4-00ffc0e4 : ipmi_si
  00ffc0e5-00ffc0e5 : ipmi_si
  00ffc2f7-00ffffff : serial8250.1.auto
    00ffc2f7-00ffc2fe : serial
root@(none)$

They should both be siblings. Note that these are logical PIO addresses,
which have a direct mapping from the FW IO port ranges.

This shows up as a real issue when we enable CONFIG_KASAN and
CONFIG_DEBUG_TEST_DRIVER_REMOVE - we see use-after-free warnings in the
host removal path:

==================================================================
BUG: KASAN: use-after-free in release_resource+0x38/0xc8
Read of size 8 at addr ffff0026accdbc38 by task swapper/0/1

CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.5.0-rc6-00001-g68e186e77b5c-dirty #1593
Hardware name: Huawei Taishan 2180 /D03, BIOS Hisilicon D03 IT20 Nemo 2.0 RC0 03/30/2018
Call trace:
dump_backtrace+0x0/0x290
show_stack+0x14/0x20
dump_stack+0xf0/0x14c
print_address_description.isra.9+0x6c/0x3b8
__kasan_report+0x12c/0x23c
kasan_report+0xc/0x18
__asan_load8+0x94/0xb8
release_resource+0x38/0xc8
platform_device_del.part.10+0x80/0xe0
platform_device_unregister+0x20/0x38
hisi_lpc_acpi_remove_subdev+0x10/0x20
device_for_each_child+0xc8/0x128
hisi_lpc_acpi_remove+0x4c/0xa8
hisi_lpc_remove+0xbc/0xc0
platform_drv_remove+0x3c/0x68
really_probe+0x174/0x548
driver_probe_device+0x7c/0x148
device_driver_attach+0x94/0xa0
__driver_attach+0xa4/0x110
bus_for_each_dev+0xe8/0x158
driver_attach+0x30/0x40
bus_add_driver+0x234/0x2f0
driver_register+0xbc/0x1d0
__platform_driver_register+0x7c/0x88
hisi_lpc_driver_init+0x18/0x20
do_one_initcall+0xb4/0x258
kernel_init_freeable+0x248/0x2c0
kernel_init+0x10/0x118
ret_from_fork+0x10/0x1c

...

The issue here is that the kernel created an incorrect parent-child
resource dependency between two devices, and references the false parent
node when deleting the second child device, when it had been deleted
already.

Fix up the child device resources from FW to create proper IO port
resource relationships for broken FW.

With this, the IO port layout looks more healthy:

root@(none)$ more /proc/ioports
[...]
00ffc0e3-00ffc0e7 : hisi-lpc-ipmi.0.auto
  00ffc0e3-00ffc0e3 : ipmi_si
  00ffc0e4-00ffc0e4 : ipmi_si
  00ffc0e5-00ffc0e5 : ipmi_si
00ffc2f7-00ffc2ff : serial8250.1.auto
  00ffc2f7-00ffc2fe : serial

Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-10-01 13:17:37 +02:00
..
fsl-mc bus: fsl-mc: remove explicit device_link_del 2019-08-16 14:17:35 -05:00
Kconfig bus: tegra-aconnect: Remove PM_CLK dependency 2020-03-05 16:43:51 +01:00
Makefile bus: Add support for Moxtet bus 2019-08-14 15:30:35 +02:00
arm-cci.c bus: arm-cci: remove unnecessary unreachable() 2018-05-14 01:22:49 -07:00
brcmstb_gisb.c This pull request contains Broadcom ARM/ARM64/MIPS SoCs drivers changes 2019-06-17 04:52:52 -07:00
da8xx-mstpri.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
hisi_lpc.c bus: hisi_lpc: Fixup IO ports addresses to avoid use-after-free in host removal 2020-10-01 13:17:37 +02:00
imx-weim.c bus: imx-weim: remove incorrect __init annotations 2019-09-04 17:59:32 +02:00
mips_cdmm.c MIPS/BUS/CDMM: Convert to hotplug state machine 2016-09-06 18:30:25 +02:00
moxtet.c bus: moxtet: fix potential stack buffer overflow 2020-02-19 19:53:04 +01:00
mvebu-mbus.c bus: mvebu-mbus: Convert to using %pOFn instead of device_node.name 2018-09-28 16:41:57 -05:00
omap-ocp2scp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
omap_l3_noc.c bus: omap: add MODULE_LICENSE tags 2018-01-11 18:02:56 -08:00
omap_l3_noc.h bus: omap_l3_noc: Fix master id address decoding for OMAP5 2015-05-04 10:21:01 -07:00
omap_l3_smx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
omap_l3_smx.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
qcom-ebi2.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
simple-pm-bus.c drivers: bus: Add Simple Power-Managed Bus Driver 2015-02-24 06:36:18 +09:00
sun50i-de2.c bus: add bus driver for accessing Allwinner A64 DE2 2018-06-28 10:20:19 +02:00
sunxi-rsb.c bus: sunxi-rsb: Return correct data when mixing 16-bit and 8-bit reads 2020-04-17 10:49:56 +02:00
tegra-aconnect.c bus: tegra-aconnect: add system sleep callbacks 2019-03-28 17:26:14 +01:00
tegra-gmi.c bus: Add support for Tegra Generic Memory Interface 2016-11-15 17:27:53 +01:00
ti-sysc.c bus: ti-sysc: Add missing quirk flags for usb_host_hs 2020-08-19 08:16:00 +02:00
ts-nbus.c gpiolib: Pass array info to get/set array functions 2018-09-13 11:16:54 +02:00
uniphier-system-bus.c bus: uniphier-system-bus: use devm_platform_ioremap_resource() 2019-09-05 17:57:18 +02:00
vexpress-config.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00