* [PATCH] rapidio: mport_cdev: fix sequential UAF in dma_req_free()
@ 2026-02-20 4:08 James Kim
2026-02-20 6:04 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: James Kim @ 2026-02-20 4:08 UTC (permalink / raw)
To: linux-kernel; +Cc: mporter, alex.bou9, stable, gregkh, James Kim
Hi,
Resending this patch to the proper list(s). No changes since the original submission.
dma_req_free() drops the mapping reference under buf_mutex 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 sequential (non-racy) use-after-free.
Fix this by caching map and md before kref_put() and using the cached
md for mutex unlocking.
Fixes: 4b0986a36 ("rapidio: add mport character device support")
Cc: stable@vger.kernel.org
Signed-off-by: James Kim <james010kim@gmail.com>
---
drivers/rapidio/devices/rio_mport_cdev.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 7df466e22282..5fb6ec439028 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -582,9 +582,14 @@ static void dma_req_free(struct kref *ref)
}
if (req->map) {
- mutex_lock(&req->map->md->buf_mutex);
- kref_put(&req->map->ref, mport_release_mapping);
- mutex_unlock(&req->map->md->buf_mutex);
+ struct rio_mport_mapping *map = req->map;
+ struct mport_dev *md = map->md;
+
+ mutex_lock(&md->buf_mutex);
+ kref_put(&map->ref, mport_release_mapping);
+ mutex_unlock(&md->buf_mutex);
+
+ req->map = NULL;
}
kref_put(&priv->dma_ref, mport_release_dma);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rapidio: mport_cdev: fix sequential UAF in dma_req_free()
2026-02-20 4:08 [PATCH] rapidio: mport_cdev: fix sequential UAF in dma_req_free() James Kim
@ 2026-02-20 6:04 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-02-20 6:04 UTC (permalink / raw)
To: James Kim; +Cc: linux-kernel, mporter, alex.bou9, stable
On Fri, Feb 20, 2026 at 01:08:22PM +0900, James Kim wrote:
> Hi,
>
> Resending this patch to the proper list(s). No changes since the original submission.
This goes below the --- line, otherwise it will end up in the changelog
:(
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] rapidio: mport_cdev: fix sequential UAF in dma_req_free()
@ 2026-02-20 8:36 James Kim
0 siblings, 0 replies; 3+ messages in thread
From: James Kim @ 2026-02-20 8:36 UTC (permalink / raw)
To: linux-kernel; +Cc: mporter, alex.bou9, stable, gregkh, James Kim
dma_req_free() drops the mapping reference under buf_mutex 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 sequential (non-racy) use-after-free.
Fix this by caching map and md before kref_put() and using the cached
md for mutex unlocking.
Fixes: 4b0986a36 ("rapidio: add mport character device support")
Cc: stable@vger.kernel.org
Signed-off-by: James Kim <james010kim@gmail.com>
---
drivers/rapidio/devices/rio_mport_cdev.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
Resending to the proper list(s), no changes since the original submission.
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 7df466e22282..5fb6ec439028 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -582,9 +582,14 @@ static void dma_req_free(struct kref *ref)
}
if (req->map) {
- mutex_lock(&req->map->md->buf_mutex);
- kref_put(&req->map->ref, mport_release_mapping);
- mutex_unlock(&req->map->md->buf_mutex);
+ struct rio_mport_mapping *map = req->map;
+ struct mport_dev *md = map->md;
+
+ mutex_lock(&md->buf_mutex);
+ kref_put(&map->ref, mport_release_mapping);
+ mutex_unlock(&md->buf_mutex);
+
+ req->map = NULL;
}
kref_put(&priv->dma_ref, mport_release_dma);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-20 8:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-20 4:08 [PATCH] rapidio: mport_cdev: fix sequential UAF in dma_req_free() James Kim
2026-02-20 6:04 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2026-02-20 8:36 James Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox