Skip to content

Commit 97418e9

Browse files
justin-heMarc Zyngier
authored andcommitted
KVM: arm/arm64: Remove excessive permission check in kvm_arch_prepare_memory_region
In kvm_arch_prepare_memory_region, arm kvm regards the memory region as writable if the flag has no KVM_MEM_READONLY, and the vm is readonly if !VM_WRITE. But there is common usage for setting kvm memory region as follows: e.g. qemu side (see the PROT_NONE flag) 1. mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); memory_region_init_ram_ptr() 2. re mmap the above area with read/write authority. Such example is used in virtio-fs qemu codes which hasn't been upstreamed [1]. But seems we can't forbid this example. Without this patch, it will cause an EPERM during kvm_set_memory_region() and cause qemu boot crash. As told by Ard, "the underlying assumption is incorrect, i.e., that the value of vm_flags at this point in time defines how the VMA is used during its lifetime. There may be other cases where a VMA is created with VM_READ vm_flags that are changed to VM_READ|VM_WRITE later, and we are currently rejecting this use case as well." [1] https://gitlab.com/virtio-fs/qemu/blob/5a356e/hw/virtio/vhost-user-fs.c#L488 Suggested-by: Ard Biesheuvel <[email protected]> Signed-off-by: Jia He <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Christoffer Dall <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 54ad68b commit 97418e9

File tree

1 file changed

+0
-9
lines changed

1 file changed

+0
-9
lines changed

virt/kvm/arm/mmu.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,15 +2301,6 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
23012301
if (!vma || vma->vm_start >= reg_end)
23022302
break;
23032303

2304-
/*
2305-
* Mapping a read-only VMA is only allowed if the
2306-
* memory region is configured as read-only.
2307-
*/
2308-
if (writable && !(vma->vm_flags & VM_WRITE)) {
2309-
ret = -EPERM;
2310-
break;
2311-
}
2312-
23132304
/*
23142305
* Take the intersection of this VMA with the memory region
23152306
*/

0 commit comments

Comments
 (0)