Blame 0015-ssd0323-fix-buffer-overun-on-invalid-state-load.patch

70114f
From 0cbd8c5754d6f56b53717e92353772777a799b87 Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:52:05 +0300
70114f
Subject: [PATCH] ssd0323: fix buffer overun on invalid state load
70114f
70114f
CVE-2013-4538
70114f
70114f
s->cmd_len used as index in ssd0323_transfer() to store 32-bit field.
70114f
Possible this field might then be supplied by guest to overwrite a
70114f
return addr somewhere. Same for row/col fields, which are indicies into
70114f
framebuffer array.
70114f
70114f
To fix validate after load.
70114f
70114f
Additionally, validate that the row/col_start/end are within bounds;
70114f
otherwise the guest can provoke an overrun by either setting the _end
70114f
field so large that the row++ increments just walk off the end of the
70114f
array, or by setting the _start value to something bogus and then
70114f
letting the "we hit end of row" logic reset row to row_start.
70114f
70114f
For completeness, validate mode as well.
70114f
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit ead7a57df37d2187813a121308213f41591bd811)
70114f
---
70114f
 hw/display/ssd0323.c | 24 ++++++++++++++++++++++++
70114f
 1 file changed, 24 insertions(+)
70114f
70114f
diff --git a/hw/display/ssd0323.c b/hw/display/ssd0323.c
70114f
index 971152e..9727007 100644
70114f
--- a/hw/display/ssd0323.c
70114f
+++ b/hw/display/ssd0323.c
70114f
@@ -312,18 +312,42 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
70114f
         return -EINVAL;
70114f
 
70114f
     s->cmd_len = qemu_get_be32(f);
70114f
+    if (s->cmd_len < 0 || s->cmd_len > ARRAY_SIZE(s->cmd_data)) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->cmd = qemu_get_be32(f);
70114f
     for (i = 0; i < 8; i++)
70114f
         s->cmd_data[i] = qemu_get_be32(f);
70114f
     s->row = qemu_get_be32(f);
70114f
+    if (s->row < 0 || s->row >= 80) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->row_start = qemu_get_be32(f);
70114f
+    if (s->row_start < 0 || s->row_start >= 80) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->row_end = qemu_get_be32(f);
70114f
+    if (s->row_end < 0 || s->row_end >= 80) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->col = qemu_get_be32(f);
70114f
+    if (s->col < 0 || s->col >= 64) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->col_start = qemu_get_be32(f);
70114f
+    if (s->col_start < 0 || s->col_start >= 64) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->col_end = qemu_get_be32(f);
70114f
+    if (s->col_end < 0 || s->col_end >= 64) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->redraw = qemu_get_be32(f);
70114f
     s->remap = qemu_get_be32(f);
70114f
     s->mode = qemu_get_be32(f);
70114f
+    if (s->mode != SSD0323_CMD && s->mode != SSD0323_DATA) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
70114f
 
70114f
     ss->cs = qemu_get_be32(f);