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>
This commit is contained in:
parent
a1a73e42a4
commit
014f0b6109
|
@ -790,6 +790,15 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
|
||||||
goto out;
|
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) {
|
if (idev->info->mmap) {
|
||||||
ret = idev->info->mmap(idev->info, vma);
|
ret = idev->info->mmap(idev->info, vma);
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -31,6 +31,7 @@ struct uio_map;
|
||||||
* @offs: offset of device memory within the page
|
* @offs: offset of device memory within the page
|
||||||
* @size: size of IO (multiple of page size)
|
* @size: size of IO (multiple of page size)
|
||||||
* @memtype: type of memory addr points to
|
* @memtype: type of memory addr points to
|
||||||
|
* @readonly: true of region is read-only
|
||||||
* @internal_addr: ioremap-ped version of addr, for driver internal use
|
* @internal_addr: ioremap-ped version of addr, for driver internal use
|
||||||
* @map: for use by the UIO core only.
|
* @map: for use by the UIO core only.
|
||||||
*/
|
*/
|
||||||
|
@ -40,6 +41,7 @@ struct uio_mem {
|
||||||
unsigned long offs;
|
unsigned long offs;
|
||||||
resource_size_t size;
|
resource_size_t size;
|
||||||
int memtype;
|
int memtype;
|
||||||
|
bool readonly;
|
||||||
void __iomem *internal_addr;
|
void __iomem *internal_addr;
|
||||||
struct uio_map *map;
|
struct uio_map *map;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue