Skip to contentSkip to conversation

KVM: make checks stricter in coalesced_mmio_in_range()

PATCH In review Dan Carpenter 2 participants 2 messages Oct 19, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

virt/kvm/coalesced_mmio.c +9 -3
index a6ec206..88b2fe3 100644
@@ -28,9 +28,15 @@ static int coalesced_mmio_in_range(struct kvm_coalesced_mmio_dev *dev,
 	 * (addr,len) is fully included in
 	 * (zone->addr, zone->size)
 	 */
-
-	return (dev->zone.addr <= addr &&
-		addr + len <= dev->zone.addr + dev->zone.size);
+	if (len < 0)
+		return 0;
+	if (addr + len < addr)
+		return 0;
+	if (addr < dev->zone.addr)
+		return 0;
+	if (addr + len > dev->zone.addr + dev->zone.size)
+		return 0;
+	return 1;
 }
 
 static int coalesced_mmio_has_room(struct kvm_coalesced_mmio_dev *dev)
#1 lore raw
Quoted 8 lines · Dan Carpenter

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.

There are no negative implications, if variables wrap unregistration fails. Applied, thanks.