1 From b6f53085cc618bc7e58be702afacad1b5dcae5ba Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Thu, 3 Apr 2014 19:51:31 +0300
4 Subject: [PATCH] hw/pci/pcie_aer.c: fix buffer overruns on invalid state load
7 hw/pci/pcie_aer.c pcie aer log can overrun the buffer if log_num is
10 There are two issues in this file:
11 1. log_max from remote can be larger than on local
12 then buffer will overrun with data coming from state file.
13 2. log_num can be larger then we get data corruption
14 again with an overflow but not adversary controlled.
18 Reported-by: Anthony Liguori <anthony@codemonkey.ws>
19 Reported-by: Michael S. Tsirkin <mst@redhat.com>
20 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
21 Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22 Signed-off-by: Juan Quintela <quintela@redhat.com>
23 (cherry picked from commit 5f691ff91d323b6f97c6600405a7f9dc115a0ad1)
25 hw/pci/pcie_aer.c | 10 +++++++++-
26 1 file changed, 9 insertions(+), 1 deletion(-)
28 diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
29 index 991502e..535be2c 100644
30 --- a/hw/pci/pcie_aer.c
31 +++ b/hw/pci/pcie_aer.c
32 @@ -795,6 +795,13 @@ static const VMStateDescription vmstate_pcie_aer_err = {
36 +static bool pcie_aer_state_log_num_valid(void *opaque, int version_id)
38 + PCIEAERLog *s = opaque;
40 + return s->log_num <= s->log_max;
43 const VMStateDescription vmstate_pcie_aer_log = {
44 .name = "PCIE_AER_ERROR_LOG",
46 @@ -802,7 +809,8 @@ const VMStateDescription vmstate_pcie_aer_log = {
47 .minimum_version_id_old = 1,
48 .fields = (VMStateField[]) {
49 VMSTATE_UINT16(log_num, PCIEAERLog),
50 - VMSTATE_UINT16(log_max, PCIEAERLog),
51 + VMSTATE_UINT16_EQUAL(log_max, PCIEAERLog),
52 + VMSTATE_VALIDATE("log_num <= log_max", pcie_aer_state_log_num_valid),
53 VMSTATE_STRUCT_VARRAY_POINTER_UINT16(log, PCIEAERLog, log_num,
54 vmstate_pcie_aer_err, PCIEAERErr),