linux/drivers/rapidio
James Kim 5cbef379a9 rapidio: mport_cdev: fix use-after-free in dma_req_free()
dma_req_free() acquires buf_mutex through req->map, drops the mapping
reference with kref_put(), and then dereferences req->map again to unlock
the mutex.

If kref_put() drops the last reference, mport_release_mapping() frees the
mapping, and the subsequent mutex_unlock() dereferences a freed object. 
This is a use-after-free.

Fix this by caching map and md before kref_put(), clearing req->map while
holding buf_mutex, and using the cached md for mutex unlocking.

The bug is reachable from userspace via the RapidIO mport character device
interface.

Link: https://lore.kernel.org/20260723235220.588424-1-james010kim@gmail.com
Fixes: e8de370188 ("rapidio: add mport char device driver")
Signed-off-by: James Kim <james010kim@gmail.com>
Reviewed-by: Dan Carpenter <error27@gmail.com>
Cc: Alexandre Bounine <alex.bou9@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-08-05 11:20:14 -07:00
..
devices rapidio: mport_cdev: fix use-after-free in dma_req_free() 2026-08-05 11:20:14 -07:00
switches rapidio: remove not used code about RIO_VID_TUNDRA 2021-12-21 10:22:19 +01:00
Kconfig rapidio: remove choice for enumeration 2024-05-14 23:36:19 +09:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rio_cm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
rio-access.c drivers/rapidio/rio-access.c: fix missing include of <linux/rio_drv.h> 2019-12-04 19:44:13 -08:00
rio-driver.c drivers: rapidio: make rio_bus_type const 2025-10-22 07:55:02 +02:00
rio-scan.c rapidio: clear mport->net when rio_add_net() fails 2026-08-03 21:10:13 -07:00
rio-sysfs.c sysfs: treewide: switch back to attribute_group::bin_attrs 2025-06-17 10:44:15 +02:00
rio.c rapidio: rio: add WQ_PERCPU to alloc_workqueue users 2026-05-07 11:30:04 -10:00
rio.h rapidio: remove unused functions 2025-05-11 17:54:09 -07:00