summaryrefslogtreecommitdiff
path: root/drivers/misc
diff options
context:
space:
mode:
authorZhangfei Gao <zhangfei.gao@linaro.org>2023-05-11 12:59:20 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-05-31 21:00:26 +0300
commitdf1b056d489d98c7c45fa89627102dd34b44496f (patch)
treebf3562a5bff1da63e8e5c9b3479c47cc0bef37b3 /drivers/misc
parent24ee010bdabb15c601ab6ce2007ad32f4ef4a880 (diff)
downloadlinux-df1b056d489d98c7c45fa89627102dd34b44496f.tar.xz
uacce: use q->mapping to replace inode->i_mapping
The inode can be different in a container, for example, a docker and host both open the same uacce parent device, which uses the same uacce struct but different inode, so uacce->inode is not enough. What's worse, when docker stops, the inode will be destroyed as well, causing use-after-free in uacce_remove. So use q->mapping to replace uacce->inode->i_mapping. Signed-off-by: Weili Qian <qianweili@huawei.com> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org> Link: https://lore.kernel.org/r/20230511095921.9331-2-zhangfei.gao@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/uacce/uacce.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index 346bd7cf2e94..338b59ef5493 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -166,8 +166,8 @@ static int uacce_fops_open(struct inode *inode, struct file *filep)
init_waitqueue_head(&q->wait);
filep->private_data = q;
- uacce->inode = inode;
q->state = UACCE_Q_INIT;
+ q->mapping = filep->f_mapping;
mutex_init(&q->mutex);
list_add(&q->list, &uacce->queues);
mutex_unlock(&uacce->mutex);
@@ -574,12 +574,6 @@ void uacce_remove(struct uacce_device *uacce)
if (!uacce)
return;
- /*
- * unmap remaining mapping from user space, preventing user still
- * access the mmaped area while parent device is already removed
- */
- if (uacce->inode)
- unmap_mapping_range(uacce->inode->i_mapping, 0, 0, 1);
/*
* uacce_fops_open() may be running concurrently, even after we remove
@@ -597,6 +591,12 @@ void uacce_remove(struct uacce_device *uacce)
uacce_put_queue(q);
mutex_unlock(&q->mutex);
uacce_unbind_queue(q);
+
+ /*
+ * unmap remaining mapping from user space, preventing user still
+ * access the mmaped area while parent device is already removed
+ */
+ unmap_mapping_range(q->mapping, 0, 0, 1);
}
/* disable sva now since no opened queues */