1 From 984fcc9ad2abc4429422c045d68e17f1eb1fa4b2 Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Thu, 3 Apr 2014 19:52:09 +0300
4 Subject: [PATCH] tsc210x: fix buffer overrun on invalid state load
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 s->precision, nextprecision, function and nextfunction
12 come from wire and are used
13 as idx into resolution[] in TSC_CUT_RESOLUTION.
15 Validate after load to avoid buffer overrun.
17 Cc: Andreas Färber <afaerber@suse.de>
18 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
19 Signed-off-by: Juan Quintela <quintela@redhat.com>
20 (cherry picked from commit 5193be3be35f29a35bc465036cd64ad60d43385f)
22 hw/input/tsc210x.c | 12 ++++++++++++
23 1 file changed, 12 insertions(+)
25 diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c
26 index 485c9e5..aa5b688 100644
27 --- a/hw/input/tsc210x.c
28 +++ b/hw/input/tsc210x.c
29 @@ -1070,9 +1070,21 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int version_id)
30 s->enabled = qemu_get_byte(f);
31 s->host_mode = qemu_get_byte(f);
32 s->function = qemu_get_byte(f);
33 + if (s->function < 0 || s->function >= ARRAY_SIZE(mode_regs)) {
36 s->nextfunction = qemu_get_byte(f);
37 + if (s->nextfunction < 0 || s->nextfunction >= ARRAY_SIZE(mode_regs)) {
40 s->precision = qemu_get_byte(f);
41 + if (s->precision < 0 || s->precision >= ARRAY_SIZE(resolution)) {
44 s->nextprecision = qemu_get_byte(f);
45 + if (s->nextprecision < 0 || s->nextprecision >= ARRAY_SIZE(resolution)) {
48 s->filter = qemu_get_byte(f);
49 s->pin_func = qemu_get_byte(f);
50 s->ref = qemu_get_byte(f);