Update qemu package to mitigate CVE-2015-3456
[packages/centos6/qemu.git] / 0015-ssd0323-fix-buffer-overun-on-invalid-state-load.patch
1 From 0cbd8c5754d6f56b53717e92353772777a799b87 Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Thu, 3 Apr 2014 19:52:05 +0300
4 Subject: [PATCH] ssd0323: fix buffer overun on invalid state load
5
6 CVE-2013-4538
7
8 s->cmd_len used as index in ssd0323_transfer() to store 32-bit field.
9 Possible this field might then be supplied by guest to overwrite a
10 return addr somewhere. Same for row/col fields, which are indicies into
11 framebuffer array.
12
13 To fix validate after load.
14
15 Additionally, validate that the row/col_start/end are within bounds;
16 otherwise the guest can provoke an overrun by either setting the _end
17 field so large that the row++ increments just walk off the end of the
18 array, or by setting the _start value to something bogus and then
19 letting the "we hit end of row" logic reset row to row_start.
20
21 For completeness, validate mode as well.
22
23 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
24 Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
25 Signed-off-by: Juan Quintela <quintela@redhat.com>
26 (cherry picked from commit ead7a57df37d2187813a121308213f41591bd811)
27 ---
28  hw/display/ssd0323.c | 24 ++++++++++++++++++++++++
29  1 file changed, 24 insertions(+)
30
31 diff --git a/hw/display/ssd0323.c b/hw/display/ssd0323.c
32 index 971152e..9727007 100644
33 --- a/hw/display/ssd0323.c
34 +++ b/hw/display/ssd0323.c
35 @@ -312,18 +312,42 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
36          return -EINVAL;
37  
38      s->cmd_len = qemu_get_be32(f);
39 +    if (s->cmd_len < 0 || s->cmd_len > ARRAY_SIZE(s->cmd_data)) {
40 +        return -EINVAL;
41 +    }
42      s->cmd = qemu_get_be32(f);
43      for (i = 0; i < 8; i++)
44          s->cmd_data[i] = qemu_get_be32(f);
45      s->row = qemu_get_be32(f);
46 +    if (s->row < 0 || s->row >= 80) {
47 +        return -EINVAL;
48 +    }
49      s->row_start = qemu_get_be32(f);
50 +    if (s->row_start < 0 || s->row_start >= 80) {
51 +        return -EINVAL;
52 +    }
53      s->row_end = qemu_get_be32(f);
54 +    if (s->row_end < 0 || s->row_end >= 80) {
55 +        return -EINVAL;
56 +    }
57      s->col = qemu_get_be32(f);
58 +    if (s->col < 0 || s->col >= 64) {
59 +        return -EINVAL;
60 +    }
61      s->col_start = qemu_get_be32(f);
62 +    if (s->col_start < 0 || s->col_start >= 64) {
63 +        return -EINVAL;
64 +    }
65      s->col_end = qemu_get_be32(f);
66 +    if (s->col_end < 0 || s->col_end >= 64) {
67 +        return -EINVAL;
68 +    }
69      s->redraw = qemu_get_be32(f);
70      s->remap = qemu_get_be32(f);
71      s->mode = qemu_get_be32(f);
72 +    if (s->mode != SSD0323_CMD && s->mode != SSD0323_DATA) {
73 +        return -EINVAL;
74 +    }
75      qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
76  
77      ss->cs = qemu_get_be32(f);