Update qemu package to mitigate CVE-2015-3456
[packages/centos6/qemu.git] / 0002-vmstate-add-VMS_MUST_EXIST.patch
1 From 105071cc70a454680e6bf11e2d9d7b73c7ce7491 Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Thu, 3 Apr 2014 19:50:31 +0300
4 Subject: [PATCH] vmstate: add VMS_MUST_EXIST
5
6 Can be used to verify a required field exists or validate
7 state in some other way.
8
9 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
10 Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
11 Signed-off-by: Juan Quintela <quintela@redhat.com>
12 (cherry picked from commit 5bf81c8d63db0216a4d29dc87f9ce530bb791dd1)
13 ---
14  include/migration/vmstate.h |  1 +
15  vmstate.c                   | 10 ++++++++++
16  2 files changed, 11 insertions(+)
17
18 diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
19 index e7e1705..de970ab 100644
20 --- a/include/migration/vmstate.h
21 +++ b/include/migration/vmstate.h
22 @@ -100,6 +100,7 @@ enum VMStateFlags {
23      VMS_MULTIPLY         = 0x200,  /* multiply "size" field by field_size */
24      VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
25      VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
26 +    VMS_MUST_EXIST       = 0x1000, /* Field must exist in input */
27  };
28  
29  typedef struct {
30 diff --git a/vmstate.c b/vmstate.c
31 index b689f2f..d856319 100644
32 --- a/vmstate.c
33 +++ b/vmstate.c
34 @@ -78,6 +78,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
35                      return ret;
36                  }
37              }
38 +        } else if (field->flags & VMS_MUST_EXIST) {
39 +            fprintf(stderr, "Input validation failed: %s/%s\n",
40 +                    vmsd->name, field->name);
41 +            return -1;
42          }
43          field++;
44      }
45 @@ -138,6 +142,12 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
46                      field->info->put(f, addr, size);
47                  }
48              }
49 +        } else {
50 +            if (field->flags & VMS_MUST_EXIST) {
51 +                fprintf(stderr, "Output state validation failed: %s/%s\n",
52 +                        vmsd->name, field->name);
53 +                assert(!(field->flags & VMS_MUST_EXIST));
54 +            }
55          }
56          field++;
57      }