qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: quintela@redhat.com, Peter Lieven <pl@kamp.de>,
	qemu-stable@nongnu.org, dgilbert@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCHv2] migration: catch unknown flags in ram_load
Date: Tue, 13 May 2014 14:20:41 +0200	[thread overview]
Message-ID: <1399983641-32470-1-git-send-email-pl@kamp.de> (raw)

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.

CC: qemu-stable@nongnu.org
Signed-off-by: Peter Lieven <pl@kamp.de>
---
v1->v2: rework loop from do ... while to while [Juan]

 arch_init.c |   35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 995f56d..322d129 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1030,17 +1030,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;
@@ -1069,7 +1067,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                                     " in != " RAM_ADDR_FMT "\n", id, length,
                                     block->length);
                             ret =  -EINVAL;
-                            goto done;
                         }
                         break;
                     }
@@ -1079,21 +1076,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                     fprintf(stderr, "Unknown ramblock \"%s\", cannot "
                             "accept migration\n", 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) {
                 ret = -EINVAL;
-                goto done;
+                break;
             }
 
             ch = qemu_get_byte(f);
@@ -1104,7 +1101,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             host = host_from_stream_offset(f, addr, flags);
             if (!host) {
                 ret = -EINVAL;
-                goto done;
+                break;
             }
 
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
@@ -1112,24 +1109,24 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             void *host = host_from_stream_offset(f, addr, flags);
             if (!host) {
                 ret = -EINVAL;
-                goto done;
+                break;
             }
 
             if (load_xbzrle(f, addr, host) < 0) {
                 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) {
+            break;
+        } else {
+            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;
-- 
1.7.9.5

             reply	other threads:[~2014-05-13 12:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-13 12:20 Peter Lieven [this message]
2014-05-13 12:47 ` [Qemu-devel] [PATCHv2] migration: catch unknown flags in ram_load Eric Blake

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=1399983641-32470-1-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=dgilbert@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=quintela@redhat.com \
    /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).