qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memory: Revert "memory: accept mismatching sizes in memory_region_access_valid"
@ 2020-06-10 13:47 Michael S. Tsirkin
  2020-06-10 13:54 ` Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Michael S. Tsirkin @ 2020-06-10 13:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, qemu-stable, Richard Henderson

Memory API documentation documents valid .min_access_size and .max_access_size
fields and explains that any access outside these boundaries is blocked.

This is what devices seem to assume.

However this is not what the implementation does: it simply
ignores the boundaries unless there's an "accepts" callback.

Naturally, this breaks a bunch of devices.

Revert to the documented behaviour.

Devices that want to allow any access can just drop the valid field,
or add the impl field to have accesses converted to appropriate
length.

Cc: qemu-stable@nongnu.org
Reviewed-by: Richard Henderson <rth@twiddle.net>
Fixes: CVE-2020-13754
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1842363
Fixes: a014ed07bd5a ("memory: accept mismatching sizes in memory_region_access_valid")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 memory.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/memory.c b/memory.c
index 91ceaf9fcf..3e9388fb74 100644
--- a/memory.c
+++ b/memory.c
@@ -1352,35 +1352,24 @@ bool memory_region_access_valid(MemoryRegion *mr,
                                 bool is_write,
                                 MemTxAttrs attrs)
 {
-    int access_size_min, access_size_max;
-    int access_size, i;
+    if (mr->ops->valid.accepts
+        && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs)) {
+        return false;
+    }
 
     if (!mr->ops->valid.unaligned && (addr & (size - 1))) {
         return false;
     }
 
-    if (!mr->ops->valid.accepts) {
+    /* Treat zero as compatibility all valid */
+    if (!mr->ops->valid.max_access_size) {
         return true;
     }
 
-    access_size_min = mr->ops->valid.min_access_size;
-    if (!mr->ops->valid.min_access_size) {
-        access_size_min = 1;
+    if (size > mr->ops->valid.max_access_size
+        || size < mr->ops->valid.min_access_size) {
+        return false;
     }
-
-    access_size_max = mr->ops->valid.max_access_size;
-    if (!mr->ops->valid.max_access_size) {
-        access_size_max = 4;
-    }
-
-    access_size = MAX(MIN(size, access_size_max), access_size_min);
-    for (i = 0; i < size; i += access_size) {
-        if (!mr->ops->valid.accepts(mr->opaque, addr + i, access_size,
-                                    is_write, attrs)) {
-            return false;
-        }
-    }
-
     return true;
 }
 
-- 
MST



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

end of thread, other threads:[~2020-08-31 16:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-10 13:47 [PATCH] memory: Revert "memory: accept mismatching sizes in memory_region_access_valid" Michael S. Tsirkin
2020-06-10 13:54 ` Michael S. Tsirkin
2020-06-12 16:51 ` Paolo Bonzini
     [not found] ` <20200827053216.GA1515751@ubuntu-n2-xlarge-x86>
2020-08-27 15:53   ` Alistair Francis
2020-08-27 16:40     ` Nathan Chancellor
2020-08-30  6:20   ` Michael S. Tsirkin
2020-08-30  6:49     ` Nathan Chancellor
2020-08-30  7:24       ` Mark Cave-Ayland
2020-08-30  7:43         ` Nathan Chancellor
2020-08-30  9:21           ` Mark Cave-Ayland
2020-08-31 16:17           ` Alistair Francis
2020-08-31 16:08         ` Alistair Francis
2020-08-30 21:02   ` Michael S. Tsirkin

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