qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0.14] savevm: fix corruption in vmstate_subsection_load().
@ 2011-02-03  4:34 Yoshiaki Tamura
  2011-02-03 12:59 ` [Qemu-devel] " Juan Quintela
  2011-02-04 12:50 ` [Qemu-devel] " Anthony Liguori
  0 siblings, 2 replies; 3+ messages in thread
From: Yoshiaki Tamura @ 2011-02-03  4:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, Yoshiaki Tamura, quintela

Although it's rare to happen in live migration, when the head of a
byte stream contains 0x05 which is the marker of subsection, the
loader gets corrupted because vmstate_subsection_load() continues even
the device doesn't require it.  This patch adds a checker whether
subsection is needed, and skips following routines if not needed.

Signed-off-by: Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
---
 savevm.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/savevm.c b/savevm.c
index 4453217..6d83b0f 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1638,6 +1638,12 @@ static const VMStateDescription *vmstate_get_subsection(const VMStateSubsection
 static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
                                    void *opaque)
 {
+    const VMStateSubsection *sub = vmsd->subsections;
+
+    if (!sub || !sub->needed) {
+        return 0;
+    }
+
     while (qemu_peek_byte(f) == QEMU_VM_SUBSECTION) {
         char idstr[256];
         int ret;
@@ -1650,10 +1656,11 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
         idstr[len] = 0;
         version_id = qemu_get_be32(f);
 
-        sub_vmsd = vmstate_get_subsection(vmsd->subsections, idstr);
+        sub_vmsd = vmstate_get_subsection(sub, idstr);
         if (sub_vmsd == NULL) {
             return -ENOENT;
         }
+        assert(!sub_vmsd->subsections);
         ret = vmstate_load_state(f, sub_vmsd, opaque, version_id);
         if (ret) {
             return ret;
@@ -1677,6 +1684,7 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
             qemu_put_byte(f, len);
             qemu_put_buffer(f, (uint8_t *)vmsd->name, len);
             qemu_put_be32(f, vmsd->version_id);
+            assert(!vmsd->subsections);
             vmstate_save_state(f, vmsd, opaque);
         }
         sub++;
-- 
1.7.1.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: [PATCH 0.14] savevm: fix corruption in vmstate_subsection_load().
  2011-02-03  4:34 [Qemu-devel] [PATCH 0.14] savevm: fix corruption in vmstate_subsection_load() Yoshiaki Tamura
@ 2011-02-03 12:59 ` Juan Quintela
  2011-02-04 12:50 ` [Qemu-devel] " Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Juan Quintela @ 2011-02-03 12:59 UTC (permalink / raw)
  To: Yoshiaki Tamura; +Cc: pbonzini, aliguori, qemu-devel

Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp> wrote:
> Although it's rare to happen in live migration, when the head of a
> byte stream contains 0x05 which is the marker of subsection, the
> loader gets corrupted because vmstate_subsection_load() continues even
> the device doesn't require it.  This patch adds a checker whether
> subsection is needed, and skips following routines if not needed.

This only fixes "partially" the problem :(

I agree with bonzini that it is better than what we had until we get the
time to try a better aproach.  I was thinking about only allowing
subsections at the top level, but that still don't improve things, would
have to think more about the problem.

Reviewed-by: Juan Quintela <quintela@redhat.com>

> Signed-off-by: Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  savevm.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/savevm.c b/savevm.c
> index 4453217..6d83b0f 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -1638,6 +1638,12 @@ static const VMStateDescription *vmstate_get_subsection(const VMStateSubsection
>  static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
>                                     void *opaque)
>  {
> +    const VMStateSubsection *sub = vmsd->subsections;
> +
> +    if (!sub || !sub->needed) {
> +        return 0;
> +    }
> +
>      while (qemu_peek_byte(f) == QEMU_VM_SUBSECTION) {
>          char idstr[256];
>          int ret;
> @@ -1650,10 +1656,11 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
>          idstr[len] = 0;
>          version_id = qemu_get_be32(f);
>  
> -        sub_vmsd = vmstate_get_subsection(vmsd->subsections, idstr);
> +        sub_vmsd = vmstate_get_subsection(sub, idstr);
>          if (sub_vmsd == NULL) {
>              return -ENOENT;
>          }
> +        assert(!sub_vmsd->subsections);
>          ret = vmstate_load_state(f, sub_vmsd, opaque, version_id);
>          if (ret) {
>              return ret;
> @@ -1677,6 +1684,7 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
>              qemu_put_byte(f, len);
>              qemu_put_buffer(f, (uint8_t *)vmsd->name, len);
>              qemu_put_be32(f, vmsd->version_id);
> +            assert(!vmsd->subsections);
>              vmstate_save_state(f, vmsd, opaque);
>          }
>          sub++;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH 0.14] savevm: fix corruption in vmstate_subsection_load().
  2011-02-03  4:34 [Qemu-devel] [PATCH 0.14] savevm: fix corruption in vmstate_subsection_load() Yoshiaki Tamura
  2011-02-03 12:59 ` [Qemu-devel] " Juan Quintela
@ 2011-02-04 12:50 ` Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2011-02-04 12:50 UTC (permalink / raw)
  To: Yoshiaki Tamura; +Cc: pbonzini, aliguori, qemu-devel, quintela

On 02/02/2011 10:34 PM, Yoshiaki Tamura wrote:
> Although it's rare to happen in live migration, when the head of a
> byte stream contains 0x05 which is the marker of subsection, the
> loader gets corrupted because vmstate_subsection_load() continues even
> the device doesn't require it.  This patch adds a checker whether
> subsection is needed, and skips following routines if not needed.
>
> Signed-off-by: Yoshiaki Tamura<tamura.yoshiaki@lab.ntt.co.jp>
> Acked-by: Paolo Bonzini<pbonzini@redhat.com>
>    

Applied to master, Thanks.

Regards,

Anthony Liguori

> ---
>   savevm.c |   10 +++++++++-
>   1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/savevm.c b/savevm.c
> index 4453217..6d83b0f 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -1638,6 +1638,12 @@ static const VMStateDescription *vmstate_get_subsection(const VMStateSubsection
>   static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
>                                      void *opaque)
>   {
> +    const VMStateSubsection *sub = vmsd->subsections;
> +
> +    if (!sub || !sub->needed) {
> +        return 0;
> +    }
> +
>       while (qemu_peek_byte(f) == QEMU_VM_SUBSECTION) {
>           char idstr[256];
>           int ret;
> @@ -1650,10 +1656,11 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
>           idstr[len] = 0;
>           version_id = qemu_get_be32(f);
>
> -        sub_vmsd = vmstate_get_subsection(vmsd->subsections, idstr);
> +        sub_vmsd = vmstate_get_subsection(sub, idstr);
>           if (sub_vmsd == NULL) {
>               return -ENOENT;
>           }
> +        assert(!sub_vmsd->subsections);
>           ret = vmstate_load_state(f, sub_vmsd, opaque, version_id);
>           if (ret) {
>               return ret;
> @@ -1677,6 +1684,7 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
>               qemu_put_byte(f, len);
>               qemu_put_buffer(f, (uint8_t *)vmsd->name, len);
>               qemu_put_be32(f, vmsd->version_id);
> +            assert(!vmsd->subsections);
>               vmstate_save_state(f, vmsd, opaque);
>           }
>           sub++;
>    

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-04 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-03  4:34 [Qemu-devel] [PATCH 0.14] savevm: fix corruption in vmstate_subsection_load() Yoshiaki Tamura
2011-02-03 12:59 ` [Qemu-devel] " Juan Quintela
2011-02-04 12:50 ` [Qemu-devel] " Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).