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
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
13 To fix validate after load.
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.
21 For completeness, validate mode as well.
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)
28 hw/display/ssd0323.c | 24 ++++++++++++++++++++++++
29 1 file changed, 24 insertions(+)
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)
38 s->cmd_len = qemu_get_be32(f);
39 + if (s->cmd_len < 0 || s->cmd_len > ARRAY_SIZE(s->cmd_data)) {
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) {
49 s->row_start = qemu_get_be32(f);
50 + if (s->row_start < 0 || s->row_start >= 80) {
53 s->row_end = qemu_get_be32(f);
54 + if (s->row_end < 0 || s->row_end >= 80) {
57 s->col = qemu_get_be32(f);
58 + if (s->col < 0 || s->col >= 64) {
61 s->col_start = qemu_get_be32(f);
62 + if (s->col_start < 0 || s->col_start >= 64) {
65 s->col_end = qemu_get_be32(f);
66 + if (s->col_end < 0 || s->col_end >= 64) {
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) {
75 qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
77 ss->cs = qemu_get_be32(f);