peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0021-ssi-sd-fix-buffer-overrun-on-invalid-state-load.patch

70114f
From d2c50b94a808f06d778746aec63ce2cb4eb1222f Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Mon, 28 Apr 2014 16:08:14 +0300
70114f
Subject: [PATCH] ssi-sd: fix buffer overrun on invalid state load
70114f
70114f
CVE-2013-4537
70114f
70114f
s->arglen is taken from wire and used as idx
70114f
in ssi_sd_transfer().
70114f
70114f
Validate it before access.
70114f
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit a9c380db3b8c6af19546a68145c8d1438a09c92b)
70114f
---
70114f
 hw/sd/ssi-sd.c | 9 +++++++++
70114f
 1 file changed, 9 insertions(+)
70114f
70114f
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
70114f
index 3273c8a..b012e57 100644
70114f
--- a/hw/sd/ssi-sd.c
70114f
+++ b/hw/sd/ssi-sd.c
70114f
@@ -230,8 +230,17 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
70114f
     for (i = 0; i < 5; i++)
70114f
         s->response[i] = qemu_get_be32(f);
70114f
     s->arglen = qemu_get_be32(f);
70114f
+    if (s->mode == SSI_SD_CMDARG &&
70114f
+        (s->arglen < 0 || s->arglen >= ARRAY_SIZE(s->cmdarg))) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
     s->response_pos = qemu_get_be32(f);
70114f
     s->stopping = qemu_get_be32(f);
70114f
+    if (s->mode == SSI_SD_RESPONSE &&
70114f
+        (s->response_pos < 0 || s->response_pos >= ARRAY_SIZE(s->response) ||
70114f
+        (!s->stopping && s->arglen > ARRAY_SIZE(s->response)))) {
70114f
+        return -EINVAL;
70114f
+    }
70114f
 
70114f
     ss->cs = qemu_get_be32(f);
70114f