diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2019-06-04 14:40:09 +0200 |
---|---|---|
committer | Peng Fan <peng.fan@nxp.com> | 2020-04-29 15:03:04 +0800 |
commit | 014f0b6109adb117e4473f3e8f69000b05d050cc (patch) | |
tree | 246b12d1cb62f3cb5bfd7d3615f5fabf487dc62b /drivers/uio | |
parent | a1a73e42a47a7794bf2cbed5eb0825f23d2ffeaa (diff) |
uio: Enable read-only mappings
This allows to tag memory regions read-only, denying userspace to map
them writable. Default remains read/write.
Acked-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Diffstat (limited to 'drivers/uio')
-rw-r--r-- | drivers/uio/uio.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index a57698985f9c..ac18542ee4fe 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -790,6 +790,15 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma) goto out; } + if (idev->info->mem[mi].readonly) { + if (vma->vm_flags & VM_WRITE) { + ret = -EINVAL; + goto out; + } + + vma->vm_flags &= ~VM_MAYWRITE; + } + if (idev->info->mmap) { ret = idev->info->mmap(idev->info, vma); goto out; |