xen-gntdev: Avoid double-mapping memory
If an already-mapped area of the device was mapped into userspace a second time, a hypercall was incorrectly made to remap the memory again. Avoid the hypercall on later mmap calls, and fail the mmap call if a writable mapping is attempted on a read-only range. Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
committed by
Konrad Rzeszutek Wilk
parent
b57c18694e
commit
12996fc38a
@ -258,6 +258,9 @@ static int map_grant_pages(struct grant_map *map)
|
|||||||
phys_addr_t addr;
|
phys_addr_t addr;
|
||||||
|
|
||||||
if (!use_ptemod) {
|
if (!use_ptemod) {
|
||||||
|
/* Note: it could already be mapped */
|
||||||
|
if (map->map_ops[0].handle)
|
||||||
|
return 0;
|
||||||
for (i = 0; i < map->count; i++) {
|
for (i = 0; i < map->count; i++) {
|
||||||
addr = (phys_addr_t)
|
addr = (phys_addr_t)
|
||||||
pfn_to_kaddr(page_to_pfn(map->pages[i]));
|
pfn_to_kaddr(page_to_pfn(map->pages[i]));
|
||||||
@ -668,9 +671,15 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
|
|||||||
if (use_ptemod)
|
if (use_ptemod)
|
||||||
map->vma = vma;
|
map->vma = vma;
|
||||||
|
|
||||||
map->flags = GNTMAP_host_map;
|
if (map->flags) {
|
||||||
if (!(vma->vm_flags & VM_WRITE))
|
if ((vma->vm_flags & VM_WRITE) &&
|
||||||
map->flags |= GNTMAP_readonly;
|
(map->flags & GNTMAP_readonly))
|
||||||
|
return -EINVAL;
|
||||||
|
} else {
|
||||||
|
map->flags = GNTMAP_host_map;
|
||||||
|
if (!(vma->vm_flags & VM_WRITE))
|
||||||
|
map->flags |= GNTMAP_readonly;
|
||||||
|
}
|
||||||
|
|
||||||
spin_unlock(&priv->lock);
|
spin_unlock(&priv->lock);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user