public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] KVM: make checks stricter in coalesced_mmio_in_range()
@ 2011-10-19  6:15 Dan Carpenter
  2011-10-19 17:26 ` Marcelo Tosatti
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2011-10-19  6:15 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, kvm, kernel-janitors

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 <dan.carpenter@oracle.com>

diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index a6ec206..88b2fe3 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -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)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] KVM: make checks stricter in coalesced_mmio_in_range()
  2011-10-19  6:15 [patch] KVM: make checks stricter in coalesced_mmio_in_range() Dan Carpenter
@ 2011-10-19 17:26 ` Marcelo Tosatti
  0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2011-10-19 17:26 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Avi Kivity, kvm, kernel-janitors

On Wed, Oct 19, 2011 at 09:15:10AM +0300, Dan Carpenter wrote:
> 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-10-19 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-19  6:15 [patch] KVM: make checks stricter in coalesced_mmio_in_range() Dan Carpenter
2011-10-19 17:26 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox