Skip to content

Commit 1a21424

Browse files
Dan Carpenteravikivity
Dan Carpenter
authored andcommitted
KVM: make checks stricter in coalesced_mmio_in_range()
My testing version of Smatch complains that addr and len come from the user and they can wrap. The path is: -> kvm_vm_ioctl() -> kvm_vm_ioctl_unregister_coalesced_mmio() -> coalesced_mmio_in_range() I don't know what the implications are of wrapping here, but we may as well fix it, if only to silence the warning. Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Marcelo Tosatti <[email protected]>
1 parent 3f2e526 commit 1a21424

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

virt/kvm/coalesced_mmio.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ static int coalesced_mmio_in_range(struct kvm_coalesced_mmio_dev *dev,
2828
* (addr,len) is fully included in
2929
* (zone->addr, zone->size)
3030
*/
31-
32-
return (dev->zone.addr <= addr &&
33-
addr + len <= dev->zone.addr + dev->zone.size);
31+
if (len < 0)
32+
return 0;
33+
if (addr + len < addr)
34+
return 0;
35+
if (addr < dev->zone.addr)
36+
return 0;
37+
if (addr + len > dev->zone.addr + dev->zone.size)
38+
return 0;
39+
return 1;
3440
}
3541

3642
static int coalesced_mmio_has_room(struct kvm_coalesced_mmio_dev *dev)

0 commit comments

Comments
 (0)