linux/drivers
Mårten Lindahl d2bef2cbd3 driver core: Free DMA range map when device is released
commit d8f7a5484f upstream.

When unbinding/binding a driver with DMA mapped memory, the DMA map is
not freed before the driver is reloaded. This leads to a memory leak
when the DMA map is overwritten when reprobing the driver.

This can be reproduced with a platform driver having a dma-range:

dummy {
	...
	#address-cells = <0x2>;
	#size-cells = <0x2>;
	ranges;
	dma-ranges = <...>;
	...
};

and then unbinding/binding it:

~# echo soc:dummy >/sys/bus/platform/drivers/<driver>/unbind

DMA map object 0xffffff800b0ae540 still being held by &pdev->dev

~# echo soc:dummy >/sys/bus/platform/drivers/<driver>/bind
~# echo scan > /sys/kernel/debug/kmemleak
~# cat /sys/kernel/debug/kmemleak
unreferenced object 0xffffff800b0ae540 (size 64):
  comm "sh", pid 833, jiffies 4295174550 (age 2535.352s)
  hex dump (first 32 bytes):
    00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 80 00 00 00 00 00 00 00 80 00 00 00 00  ................
  backtrace:
    [<ffffffefd1694708>] create_object.isra.0+0x108/0x344
    [<ffffffefd1d1a850>] kmemleak_alloc+0x8c/0xd0
    [<ffffffefd167e2d0>] __kmalloc+0x440/0x6f0
    [<ffffffefd1a960a4>] of_dma_get_range+0x124/0x220
    [<ffffffefd1a8ce90>] of_dma_configure_id+0x40/0x2d0
    [<ffffffefd198b68c>] platform_dma_configure+0x5c/0xa4
    [<ffffffefd198846c>] really_probe+0x8c/0x514
    [<ffffffefd1988990>] __driver_probe_device+0x9c/0x19c
    [<ffffffefd1988cd8>] device_driver_attach+0x54/0xbc
    [<ffffffefd1986634>] bind_store+0xc4/0x120
    [<ffffffefd19856e0>] drv_attr_store+0x30/0x44
    [<ffffffefd173c9b0>] sysfs_kf_write+0x50/0x60
    [<ffffffefd173c1c4>] kernfs_fop_write_iter+0x124/0x1b4
    [<ffffffefd16a013c>] new_sync_write+0xdc/0x160
    [<ffffffefd16a256c>] vfs_write+0x23c/0x2a0
    [<ffffffefd16a2758>] ksys_write+0x64/0xec

To prevent this we should free the dma_range_map when the device is
released.

Fixes: e0d072782c ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
Cc: stable <stable@vger.kernel.org>
Suggested-by: Rob Herring <robh@kernel.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
Link: https://lore.kernel.org/r/20220216094128.4025861-1-marten.lindahl@axis.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-03-02 11:48:07 +01:00
..
accessibility speakup-dectlk: Restore pitch setting 2022-02-16 12:56:37 +01:00
acpi ACPI: PM: Revert "Only mark EC GPE for wakeup on Intel systems" 2022-02-23 12:03:18 +01:00
amba ARM: 9120/1: Revert "amba: make use of -1 IRQs warn" 2021-11-06 14:13:31 +01:00
android binder: avoid potential data leakage when copying txn 2022-01-27 11:04:09 +01:00
ata ata: pata_hpt37x: disable primary channel on HPT371 2022-03-02 11:48:04 +01:00
atm
auxdisplay auxdisplay: charlcd: checking for pointer reference before dereferencing 2022-01-11 15:35:17 +01:00
base driver core: Free DMA range map when device is released 2022-03-02 11:48:07 +01:00
bcma
block block: fix surprise removal for drivers calling blk_set_queue_dying 2022-02-23 12:03:15 +01:00
bluetooth Bluetooth: btusb: Return error code when getting patch status failed 2022-01-27 11:05:22 +01:00
bus bus: mhi: pci_generic: Add mru_default for Cinterion MV31-W 2022-02-16 12:56:39 +01:00
cdrom
char random: wake up /dev/random writers after zap 2022-02-23 12:03:07 +01:00
clk clk: jz4725b: fix mmc0 clock gating 2022-03-02 11:47:48 +01:00
clocksource ARM: dts: Fix timer regression for beagleboard revision c 2022-02-16 12:56:21 +01:00
comedi comedi: vmk80xx: fix bulk and interrupt message timeouts 2021-11-12 15:05:51 +01:00
connector
counter
cpufreq cpufreq: Fix initialization of min and max frequency QoS requests 2022-01-27 11:04:44 +01:00
cpuidle cpuidle: Fix kobject memory leaks in error paths 2021-11-18 19:16:29 +01:00
crypto crypto: octeontx2 - uninitialized variable in kvf_limits_store() 2022-01-27 11:05:30 +01:00
cxl cxl/pmem: Fix reference counting for delayed work 2022-01-27 11:02:58 +01:00
dax
dca
devfreq
dio
dma dmaengine: ptdma: Fix the error handling path in pt_core_init() 2022-02-23 12:03:21 +01:00
dma-buf dma-buf: heaps: Fix potential spectre v1 gadget 2022-02-08 18:34:06 +01:00
edac EDAC: Fix calculation of returned address and next offset in edac_align_ptr() 2022-02-23 12:03:20 +01:00
eisa
extcon
firewire
firmware efi/libstub: arm64: Fix image check alignment at entry 2022-02-01 17:27:11 +01:00
fpga
fsi
gnss
gpio gpio: rockchip: Reset int_bothedge when changing trigger 2022-03-02 11:48:01 +01:00
gpu drm/i915/dg2: Print PHY name properly on calibration error 2022-03-02 11:47:57 +01:00
greybus
hid HID: elo: fix memory leak in elo_probe 2022-02-23 12:03:16 +01:00
hsi HSI: core: Fix return freed object in hsi_new_client 2022-01-27 11:04:31 +01:00
hv Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj 2022-02-23 12:03:16 +01:00
hwmon hwmon: Handle failure to register sensor with thermal zone correctly 2022-03-02 11:47:54 +01:00
hwspinlock
hwtracing coresight: trbe: Defer the probe on offline CPUs 2021-11-18 19:16:06 +01:00
i2c i2c: brcmstb: fix support for DSL and CM variants 2022-02-23 12:03:22 +01:00
i3c
idle
iio iio: Fix error handling for PM 2022-03-02 11:48:04 +01:00
infiniband RDMA/ib_srp: Fix a deadlock 2022-03-02 11:48:02 +01:00
input Input: zinitix - make sure the IRQ is allocated before it gets enabled 2022-01-11 15:35:19 +01:00
interconnect interconnect: qcom: rpm: Prevent integer overflow in rate 2022-01-27 11:05:00 +01:00
iommu iommu: Fix potential use-after-free during probe 2022-02-16 12:56:41 +01:00
ipack
irqchip irqchip/sifive-plic: Add missing thead,c900-plic match string 2022-02-23 12:03:17 +01:00
isdn mISDN: change function names to avoid conflicts 2022-01-11 15:35:18 +01:00
leds leds: lp55xx: initialise output direction from dts 2022-01-27 11:04:21 +01:00
macintosh
mailbox mailbox: change mailbox-mpfs compatible string 2022-01-27 11:05:05 +01:00
mcb
md block: fix surprise removal for drivers calling blk_set_queue_dying 2022-02-23 12:03:15 +01:00
media media: correct MEDIA_TEST_SUPPORT help text 2022-01-27 11:05:20 +01:00
memory memory: renesas-rpc-if: Return error in case devm_ioremap_resource() fails 2022-01-27 11:03:11 +01:00
memstick memstick: jmb38x_ms: use appropriate free function in jmb38x_ms_alloc_host() 2021-11-18 19:16:32 +01:00
message
mfd mfd: tps65910: Set PWR_OFF bit during driver probe 2022-01-27 11:05:07 +01:00
misc eeprom: ee1004: limit i2c reads to I2C_SMBUS_BLOCK_MAX 2022-02-16 12:56:33 +01:00
mmc mmc: block: fix read single on recovery logic 2022-02-23 12:03:03 +01:00
most most: fix control-message timeouts 2021-11-18 19:16:08 +01:00
mtd mtd: core: Fix a conflict between MTD and NVMEM on wp-gpios property 2022-03-02 11:48:07 +01:00
mux
net bnxt_en: Increase firmware message response DMA wait time 2022-03-02 11:48:02 +01:00
nfc NFC: st21nfca: Fix memory leak in device probe and remove 2022-01-05 12:42:36 +01:00
ntb
nubus
nvdimm nvdimm/pmem: cleanup the disk if pmem_release_disk() is yet assigned 2021-11-18 19:17:07 +01:00
nvme nvme: also mark passthrough-only namespaces ready in nvme_update_ns_info 2022-03-02 11:47:56 +01:00
nvmem nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios property 2022-03-02 11:48:06 +01:00
of of: base: Improve argument length mismatch error 2022-01-27 11:05:19 +01:00
opp opp: Fix return in _opp_add_static_v2() 2021-11-18 19:17:00 +01:00
parisc parisc: Fix sglist access in ccio-dma.c 2022-02-23 12:03:03 +01:00
parport
pci PCI: hv: Fix NUMA node assignment when kernel boots with custom NUMA topology 2022-02-23 12:03:04 +01:00
pcmcia pcmcia: fix setting of kthread task states 2022-01-27 11:04:02 +01:00
perf perf/arm-cmn: Fix CPU hotplug unregistration 2022-01-27 11:03:36 +01:00
phy phy: phy-mtk-tphy: Fix duplicated argument in phy-mtk-tphy 2022-02-23 12:03:17 +01:00
pinctrl pinctrl: bcm63xx: fix unmet dependency on REGMAP for GPIO_REGMAP 2022-02-23 12:03:05 +01:00
platform surface: surface3_power: Fix battery readings on batteries without a serial number 2022-03-02 11:47:59 +01:00
pnp
power power: reset: mt6397: Check for null res pointer 2022-01-27 11:03:49 +01:00
powercap
pps
ps3
ptp net: fix SOF_TIMESTAMPING_BIND_PHC to work with multiple sockets 2022-01-27 11:03:52 +01:00
pwm
rapidio
ras
regulator regulator: qcom_smd: Align probe function with rpmh-regulator 2022-01-27 11:04:54 +01:00
remoteproc remoteproc: imx_rproc: Fix a resource leak in the remove function 2022-01-27 11:05:10 +01:00
reset reset: renesas: Fix Runtime PM usage 2022-01-11 15:35:16 +01:00
rpmsg rpmsg: char: Fix race between the release of rpmsg_eptdev and cdev 2022-02-01 17:27:07 +01:00
rtc rtc: cmos: Evaluate century appropriate 2022-02-08 18:34:12 +01:00
s390 s390/cio: verify the driver availability for path_event call 2022-02-16 12:56:38 +01:00
sbus
scsi scsi: qedi: Fix ABBA deadlock in qedi_process_tmf_resp() and qedi_process_cmd_cleanup_resp() 2022-02-23 12:03:22 +01:00
sh maple: fix wrong return value of maple_bus_init(). 2021-11-25 09:48:31 +01:00
siox
slimbus
soc soc: aspeed: lpc-ctrl: Block error printing on probe defer cases 2022-02-23 12:03:19 +01:00
soundwire soundwire: bus: stop dereferencing invalid slave pointer 2021-11-18 19:16:54 +01:00
spi spi: spi-zynq-qspi: Fix a NULL pointer dereference in zynq_qspi_exec_mem_op() 2022-03-02 11:48:01 +01:00
spmi
ssb
staging staging: vc04_services: Fix RCU dereference check 2022-02-23 12:03:17 +01:00
target scsi: target: iscsi: Make sure the np under each tpg is unique 2022-02-16 12:56:12 +01:00
tc
tee optee: use driver internal tee_context for some rpc 2022-03-02 11:47:51 +01:00
thermal thermal/drivers/int340x: Fix RFIM mailbox write commands 2022-02-16 12:56:07 +01:00
thunderbolt thunderbolt: Runtime PM activate both ends of the device link 2022-01-27 11:04:36 +01:00
tty sc16is7xx: Fix for incorrect data being transmitted 2022-03-02 11:48:04 +01:00
uio
usb xhci: Prevent futile URB re-submissions due to incorrect return value. 2022-03-02 11:48:06 +01:00
vdpa vdpa/mlx5: Restore cur_num_vqs in case of failure in change_num_qps() 2022-01-27 11:05:36 +01:00
vfio
vhost vhost/vsock: don't check owner in vhost_vsock_stop() while releasing 2022-03-02 11:47:48 +01:00
video fbcon: Avoid 'cap' set but not used warning 2022-02-16 12:56:27 +01:00
virt nitro_enclaves: Use get_user_pages_unlocked() call to handle mmap assert 2022-01-05 12:42:39 +01:00
virtio virtio_ring: mark ring unused on error 2022-01-27 11:05:35 +01:00
visorbus
vlynq
vme
w1 w1: Misuse of get_user()/put_user() reported by sparse 2022-01-27 11:04:59 +01:00
watchdog ar7: fix kernel builds for compiler test 2021-11-18 19:17:03 +01:00
xen xen/gntdev: fix unmap notification order 2022-01-27 11:05:08 +01:00
zorro
Kconfig firmware: include drivers/firmware/Kconfig unconditionally 2021-10-07 16:51:26 +02:00
Makefile virtio: always enter drivers/virtio/ 2021-12-22 09:32:39 +01:00