* [PATCH] rapidio: Fix a use after free in mport_mm_close
@ 2021-03-23 2:06 Lv Yunlong
0 siblings, 0 replies; only message in thread
From: Lv Yunlong @ 2021-03-23 2:06 UTC (permalink / raw)
To: mporter, alex.bou9; +Cc: linux-kernel, Lv Yunlong
In mport_mm_close, map is freed by kref_put(&map->ref,).
But mutex_unlock(&map->md->buf_mutex) uses map later.
Other thread could allocate the freed chunk and cause
an unexpected result.
My patch adds a variable buf_mutex to store the mutex before
map is freed.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
drivers/rapidio/devices/rio_mport_cdev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 94331d999d27..836bcb4ab50a 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -2179,9 +2179,11 @@ static void mport_mm_close(struct vm_area_struct *vma)
struct rio_mport_mapping *map = vma->vm_private_data;
rmcd_debug(MMAP, "%pad", &map->phys_addr);
- mutex_lock(&map->md->buf_mutex);
+ struct mutex buf_mutex = map->md->buf_mutex;
+
+ mutex_lock(&buf_mutex);
kref_put(&map->ref, mport_release_mapping);
- mutex_unlock(&map->md->buf_mutex);
+ mutex_unlock(&buf_mutex);
}
static const struct vm_operations_struct vm_ops = {
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-03-23 2:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 2:06 [PATCH] rapidio: Fix a use after free in mport_mm_close Lv Yunlong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).