qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix subtle integer overflow bug in memory API
@ 2011-09-14  7:02 David Gibson
  2011-09-14  8:23 ` Avi Kivity
  0 siblings, 1 reply; 9+ messages in thread
From: David Gibson @ 2011-09-14  7:02 UTC (permalink / raw)
  To: avi; +Cc: agraf, qemu-devel

It is quite common to have a MemoryRegion with size of INT64_MAX.
When processing alias regions in render_memory_region() it's quite
easy to find a case where it will construct a temporary AddrRange with
a non-zero start, and size still of INT64_MAX.  When means attempting
to compute the end of such a range as start + size will result in
signed integer overflow.

This integer overflow means that addrrange_intersects() can
incorrectly report regions as not intersecting when they do.  For
example consider the case of address ranges {0x10000000000,
0x7fffffffffffffff} and {0x10010000000, 0x10000000} where the second
is in fact included completely in the first.

This patch rearranges addrrange_intersects() to avoid the integer
overflow, correcting this behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 memory.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index 57f0fa4..101b67c 100644
--- a/memory.c
+++ b/memory.c
@@ -55,8 +55,8 @@ static AddrRange addrrange_shift(AddrRange range, int64_t delta)
 
 static bool addrrange_intersects(AddrRange r1, AddrRange r2)
 {
-    return (r1.start >= r2.start && r1.start < r2.start + r2.size)
-        || (r2.start >= r1.start && r2.start < r1.start + r1.size);
+    return (r1.start >= r2.start && (r1.start - r2.start) < r2.size)
+        || (r2.start >= r1.start && (r2.start - r1.start) < r1.size);
 }
 
 static AddrRange addrrange_intersection(AddrRange r1, AddrRange r2)
-- 
1.7.5.4

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

end of thread, other threads:[~2011-09-16  3:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-14  7:02 [Qemu-devel] [PATCH] Fix subtle integer overflow bug in memory API David Gibson
2011-09-14  8:23 ` Avi Kivity
2011-09-14  8:38   ` Avi Kivity
2011-09-15  2:34   ` David Gibson
2011-09-15  2:58     ` David Gibson
2011-09-15  7:28       ` Avi Kivity
2011-09-16  3:16         ` David Gibson
2011-09-15  7:38     ` Paolo Bonzini
2011-09-15  7:43       ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).