qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4] exec: Fix non-power-of-2 sized accesses
@ 2013-08-16 21:58 Alex Williamson
  2013-08-17  6:33 ` Paolo Bonzini
  2013-08-17  8:23 ` Laszlo Ersek
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Williamson @ 2013-08-16 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: lersek, qemu-stable, rth

Since commit 23326164 we align access sizes to match the alignment of
the address, but we don't align the access size itself.  This means we
let illegal access sizes (ex. 3) slip through if the address is
sufficiently aligned (ex. 4).  This results in an abort which would be
easy for a guest to trigger.  Account for aligning the access size.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Cc: qemu-stable@nongnu.org
---

v4: KISS
v3: Highest power of 2, not lowest
v2: Remove unnecessary loop condition

 exec.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/exec.c b/exec.c
index 3ca9381..67a822c 100644
--- a/exec.c
+++ b/exec.c
@@ -1924,12 +1924,20 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
         }
     }
 
-    /* Don't attempt accesses larger than the maximum.  */
-    if (l > access_size_max) {
-        l = access_size_max;
+    /* Don't attempt accesses larger than the maximum or unsupported sizes.  */
+    if (l >= access_size_max) {
+        return access_size_max;
+    } else {
+        if (l >= 8) {
+            return 8;
+        } else if (l >= 4) {
+            return 4;
+        } else if (l >= 2) {
+            return 2;
+        } else {
+            return 1;
+        }
     }
-
-    return l;
 }
 
 bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,

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

end of thread, other threads:[~2013-08-17 18:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-16 21:58 [Qemu-devel] [PATCH v4] exec: Fix non-power-of-2 sized accesses Alex Williamson
2013-08-17  6:33 ` Paolo Bonzini
2013-08-17 15:19   ` Alex Williamson
2013-08-17  8:23 ` Laszlo Ersek
2013-08-17  9:16   ` Laszlo Ersek
2013-08-17 15:14   ` Alex Williamson
2013-08-17 17:58   ` Paolo Bonzini

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).