* [PATCH v2] uacce: unmap remaining mmapping from user space
@ 2020-02-26 7:12 Zhangfei Gao
2020-03-06 1:51 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Zhangfei Gao @ 2020-02-26 7:12 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arnd Bergmann, Herbert Xu, jonathan.cameron,
dave.jiang, grant.likely, jean-philippe, Jerome Glisse,
ilias.apalodimas, francois.ozog, kenneth-lee-2012, Wangzhou,
haojian . zhuang, guodong.xu
Cc: linux-accelerators, linux-kernel, linux-crypto, iommu, Zhangfei Gao
When uacce parent device module is removed, user app may
still keep the mmaped area, which can be accessed unsafely.
When rmmod, Parent device driver will call uacce_remove,
which unmap all remaining mapping from user space for safety.
VM_FAULT_SIGBUS is also reported to user space accordingly.
Suggested-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
v2: Unmap before put_queue, where memory is freed, commented from Zaibo.
drivers/misc/uacce/uacce.c | 16 ++++++++++++++++
include/linux/uacce.h | 2 ++
2 files changed, 18 insertions(+)
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index ffced4d..d39307f 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -224,6 +224,7 @@ 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;
return 0;
@@ -253,6 +254,14 @@ static int uacce_fops_release(struct inode *inode, struct file *filep)
return 0;
}
+static vm_fault_t uacce_vma_fault(struct vm_fault *vmf)
+{
+ if (vmf->flags & (FAULT_FLAG_MKWRITE | FAULT_FLAG_WRITE))
+ return VM_FAULT_SIGBUS;
+
+ return 0;
+}
+
static void uacce_vma_close(struct vm_area_struct *vma)
{
struct uacce_queue *q = vma->vm_private_data;
@@ -265,6 +274,7 @@ static void uacce_vma_close(struct vm_area_struct *vma)
}
static const struct vm_operations_struct uacce_vm_ops = {
+ .fault = uacce_vma_fault,
.close = uacce_vma_close,
};
@@ -556,6 +566,12 @@ 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);
/* ensure no open queue remains */
mutex_lock(&uacce->mm_lock);
diff --git a/include/linux/uacce.h b/include/linux/uacce.h
index 904a461..0e215e6 100644
--- a/include/linux/uacce.h
+++ b/include/linux/uacce.h
@@ -98,6 +98,7 @@ struct uacce_queue {
* @priv: private pointer of the uacce
* @mm_list: list head of uacce_mm->list
* @mm_lock: lock for mm_list
+ * @inode: core vfs
*/
struct uacce_device {
const char *algs;
@@ -113,6 +114,7 @@ struct uacce_device {
void *priv;
struct list_head mm_list;
struct mutex mm_lock;
+ struct inode *inode;
};
/**
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] uacce: unmap remaining mmapping from user space
2020-02-26 7:12 [PATCH v2] uacce: unmap remaining mmapping from user space Zhangfei Gao
@ 2020-03-06 1:51 ` Herbert Xu
2020-03-06 2:36 ` zhangfei
0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2020-03-06 1:51 UTC (permalink / raw)
To: Zhangfei Gao
Cc: Greg Kroah-Hartman, Arnd Bergmann, jonathan.cameron, dave.jiang,
grant.likely, jean-philippe, Jerome Glisse, ilias.apalodimas,
francois.ozog, kenneth-lee-2012, Wangzhou, haojian . zhuang,
guodong.xu, linux-accelerators, linux-kernel, linux-crypto,
iommu
On Wed, Feb 26, 2020 at 03:12:06PM +0800, Zhangfei Gao wrote:
> When uacce parent device module is removed, user app may
> still keep the mmaped area, which can be accessed unsafely.
> When rmmod, Parent device driver will call uacce_remove,
> which unmap all remaining mapping from user space for safety.
> VM_FAULT_SIGBUS is also reported to user space accordingly.
>
> Suggested-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
> ---
> v2: Unmap before put_queue, where memory is freed, commented from Zaibo.
>
> drivers/misc/uacce/uacce.c | 16 ++++++++++++++++
> include/linux/uacce.h | 2 ++
> 2 files changed, 18 insertions(+)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] uacce: unmap remaining mmapping from user space
2020-03-06 1:51 ` Herbert Xu
@ 2020-03-06 2:36 ` zhangfei
0 siblings, 0 replies; 3+ messages in thread
From: zhangfei @ 2020-03-06 2:36 UTC (permalink / raw)
To: Herbert Xu
Cc: Greg Kroah-Hartman, Arnd Bergmann, jonathan.cameron, dave.jiang,
grant.likely, jean-philippe, Jerome Glisse, ilias.apalodimas,
francois.ozog, kenneth-lee-2012, Wangzhou, haojian . zhuang,
guodong.xu, linux-accelerators, linux-kernel, linux-crypto,
iommu
On 2020/3/6 上午9:51, Herbert Xu wrote:
> On Wed, Feb 26, 2020 at 03:12:06PM +0800, Zhangfei Gao wrote:
>> When uacce parent device module is removed, user app may
>> still keep the mmaped area, which can be accessed unsafely.
>> When rmmod, Parent device driver will call uacce_remove,
>> which unmap all remaining mapping from user space for safety.
>> VM_FAULT_SIGBUS is also reported to user space accordingly.
>>
>> Suggested-by: Dave Jiang <dave.jiang@intel.com>
>> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
>> ---
>> v2: Unmap before put_queue, where memory is freed, commented from Zaibo.
>>
>> drivers/misc/uacce/uacce.c | 16 ++++++++++++++++
>> include/linux/uacce.h | 2 ++
>> 2 files changed, 18 insertions(+)
> Patch applied. Thanks.
Thanks Herbert for the help.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-06 2:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 7:12 [PATCH v2] uacce: unmap remaining mmapping from user space Zhangfei Gao
2020-03-06 1:51 ` Herbert Xu
2020-03-06 2:36 ` zhangfei
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).