qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Lieven <pl@kamp.de>
Subject: [Qemu-devel] [PATCH 6/6] migration: catch unknown flags in ram_load
Date: Mon, 16 Jun 2014 05:15:39 +0200	[thread overview]
Message-ID: <1402888539-14961-7-git-send-email-quintela@redhat.com> (raw)
In-Reply-To: <1402888539-14961-1-git-send-email-quintela@redhat.com>

From: Peter Lieven <pl@kamp.de>

if a saved vm has unknown flags in the memory data qemu
currently simply ignores this flag and continues which
yields in an unpredictable result.

This patch catches all unknown flags and aborts the
loading of the vm. Additionally error reports are thrown
if the migration aborts abnormally.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c | 42 +++++++++++++++++++++++-------------------
 migration.c |  2 +-
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 23044c1..8ddaf35 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1040,17 +1040,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
     int flags, ret = 0;
-    int error;
     static uint64_t seq_iter;

     seq_iter++;

     if (version_id != 4) {
         ret = -EINVAL;
-        goto done;
     }

-    do {
+    while (!ret) {
         addr = qemu_get_be64(f);

         flags = addr & ~TARGET_PAGE_MASK;
@@ -1078,7 +1076,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                                          " in != " RAM_ADDR_FMT, id, length,
                                          block->length);
                             ret =  -EINVAL;
-                            goto done;
                         }
                         break;
                     }
@@ -1088,21 +1085,22 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                     error_report("Unknown ramblock \"%s\", cannot "
                                  "accept migration", id);
                     ret = -EINVAL;
-                    goto done;
+                }
+                if (ret) {
+                    break;
                 }

                 total_ram_bytes -= length;
             }
-        }
-
-        if (flags & RAM_SAVE_FLAG_COMPRESS) {
+        } else if (flags & RAM_SAVE_FLAG_COMPRESS) {
             void *host;
             uint8_t ch;

             host = host_from_stream_offset(f, addr, flags);
             if (!host) {
+                error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
                 ret = -EINVAL;
-                goto done;
+                break;
             }

             ch = qemu_get_byte(f);
@@ -1112,33 +1110,39 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)

             host = host_from_stream_offset(f, addr, flags);
             if (!host) {
+                error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
                 ret = -EINVAL;
-                goto done;
+                break;
             }

             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
         } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
             void *host = host_from_stream_offset(f, addr, flags);
             if (!host) {
+                error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
                 ret = -EINVAL;
-                goto done;
+                break;
             }

             if (load_xbzrle(f, addr, host) < 0) {
+                error_report("Failed to decompress XBZRLE page at "
+                             RAM_ADDR_FMT, addr);
                 ret = -EINVAL;
-                goto done;
+                break;
             }
         } else if (flags & RAM_SAVE_FLAG_HOOK) {
             ram_control_load_hook(f, flags);
+        } else if (flags & RAM_SAVE_FLAG_EOS) {
+            /* normal exit */
+            break;
+        } else {
+            error_report("Unknown migration flags: %#x", flags);
+            ret = -EINVAL;
+            break;
         }
-        error = qemu_file_get_error(f);
-        if (error) {
-            ret = error;
-            goto done;
-        }
-    } while (!(flags & RAM_SAVE_FLAG_EOS));
+        ret = qemu_file_get_error(f);
+    }

-done:
     DPRINTF("Completed load of VM with exit code %d seq iteration "
             "%" PRIu64 "\n", ret, seq_iter);
     return ret;
diff --git a/migration.c b/migration.c
index 873fa96..8d675b3 100644
--- a/migration.c
+++ b/migration.c
@@ -98,7 +98,7 @@ static void process_incoming_migration_co(void *opaque)
     qemu_fclose(f);
     free_xbzrle_decoded_buf();
     if (ret < 0) {
-        fprintf(stderr, "load of migration failed\n");
+        error_report("load of migration failed: %s", strerror(-ret));
         exit(EXIT_FAILURE);
     }
     qemu_announce_self();
-- 
1.9.3

  parent reply	other threads:[~2014-06-16  3:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-16  3:15 [Qemu-devel] [PULL 0/6] migration queue Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 1/6] savevm: Remove all the unneeded version_minimum_id_old (ppc) Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 2/6] savevm: Remove all the unneeded version_minimum_id_old (x86) Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 3/6] vmstate: Refactor opening of files Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 4/6] migration: Increase default max_downtime from 30ms to 300ms Juan Quintela
2014-06-16  3:15 ` [Qemu-devel] [PATCH 5/6] rdma: Fix block during rdma migration Juan Quintela
2014-06-16  3:15 ` Juan Quintela [this message]
2014-06-16 17:31   ` [Qemu-devel] [PATCH 6/6] migration: catch unknown flags in ram_load Eric Blake
2014-06-17  9:31     ` Peter Lieven
2014-06-17 20:32       ` Eric Blake
2014-06-16 10:39 ` [Qemu-devel] [PULL 0/6] migration queue Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1402888539-14961-7-git-send-email-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).