Skip to contentSkip to conversation

migration: catch unknown flag combinations in ram_load

PATCH In review Peter Lieven 6 participants 19 messages Jun 24, 2014 – Sep 30, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: catch unknown flag combinations in ram_load

this patch extends commit db80fac by not only checking for unknown flags, but also filtering out unknown flag combinations.

---
 arch_init.c |   62 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 30 deletions(-)
arch_init.c +32 -30
index 8ddaf35..fb06d07 100644
@@ -1038,8 +1038,7 @@ void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    ram_addr_t addr;
-    int flags, ret = 0;
+    int flags = 0, ret = 0;
     static uint64_t seq_iter;
 
     seq_iter++;
@@ -1048,21 +1047,24 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
-    while (!ret) {
-        addr = qemu_get_be64(f);
+    while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
+        ram_addr_t addr, total_ram_bytes;
+        void *host;
+        uint8_t ch;
 
+        addr = qemu_get_be64(f);
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
-        if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
+        switch (flags & ~RAM_SAVE_FLAG_CONTINUE) {
+        case RAM_SAVE_FLAG_MEM_SIZE:
             /* Synchronize RAM block list */
-            char id[256];
-            ram_addr_t length;
-            ram_addr_t total_ram_bytes = addr;
-
-            while (total_ram_bytes) {
+            total_ram_bytes = addr;
+            while (!ret && total_ram_bytes) {
                 RAMBlock *block;
                 uint8_t len;
+                char id[256];
+                ram_addr_t length;
 
                 len = qemu_get_byte(f);
                 qemu_get_buffer(f, (uint8_t *)id, len);
@@ -1086,16 +1088,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                                  "accept migration", id);
                     ret = -EINVAL;
                 }
-                if (ret) {
-                    break;
-                }
 
                 total_ram_bytes -= length;
             }
-        } else if (flags & RAM_SAVE_FLAG_COMPRESS) {
-            void *host;
-            uint8_t ch;
-
+            break;
+        case RAM_SAVE_FLAG_COMPRESS:
             host = host_from_stream_offset(f, addr, flags);
             if (!host) {
                 error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
@@ -1105,9 +1102,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 
             ch = qemu_get_byte(f);
             ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
-        } else if (flags & RAM_SAVE_FLAG_PAGE) {
-            void *host;
-
+            break;
+        case RAM_SAVE_FLAG_PAGE:
             host = host_from_stream_offset(f, addr, flags);
             if (!host) {
                 error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
@@ -1116,8 +1112,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
 
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
-        } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
-            void *host = host_from_stream_offset(f, addr, flags);
+            break;
+        case RAM_SAVE_FLAG_XBZRLE:
+            host = host_from_stream_offset(f, addr, flags);
             if (!host) {
                 error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
                 ret = -EINVAL;
@@ -1130,17 +1127,22 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                 ret = -EINVAL;
                 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;
+        case RAM_SAVE_FLAG_EOS:
+            /* normal exit */
             break;
+        default:
+            if (flags & RAM_SAVE_FLAG_HOOK) {
+                ram_control_load_hook(f, flags);
+            } else {
+                error_report("Unknown combination of migration flags: %#x",
+                             flags);
+                ret = -EINVAL;
+            }
+        }
+        if (!ret) {
+            ret = qemu_file_get_error(f);
         }
-        ret = qemu_file_get_error(f);
     }
 
     DPRINTF("Completed load of VM with exit code %d seq iteration "
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Peter Lieven

this patch extends commit db80fac by not only checking for unknown flags, but also filtering out unknown flag combinations.

---
 arch_init.c |   62 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 30 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

Hi Juan,

Am 25.06.2014 um 13:55 schrieb Juan Quintela <[email protected]>:

Quoted 5 lines
Quoted 4 lines · Peter Lieven

this patch extends commit db80fac by not only checking for unknown flags, but also filtering out unknown flag combinations.

Quoted 7 lines
Quoted 2 lines

Will be on next pull request, thanks.

Have you forgotten to pull this one? It might be too late for 2.1 though.

Peter

#4 lore raw

(CC'ing Peter Maydell for his thoughts)

Quoted 12 lines · Peter Lieven

Hi Juan,

Am 25.06.2014 um 13:55 schrieb Juan Quintela <[email protected]>:

Quoted 8 lines
Quoted 6 lines · Peter Lieven

this patch extends commit db80fac by not only checking for unknown flags, but also filtering out unknown flag combinations.

Quoted 6 lines
Quoted 4 lines

Will be on next pull request, thanks.

Have you forgotten to pull this one? It might be too late for 2.1 though.

Juan is away for a couple of weeks. This looks like a good fix to pull in for 2.1, though. Peter, do you agree? Can you pick this up if so?

Thanks,

Amit

#5 lore raw
Quoted 17 lines · Amit Shah

(CC'ing Peter Maydell for his thoughts)

Quoted 14 lines · Peter Lieven

Hi Juan,

Am 25.06.2014 um 13:55 schrieb Juan Quintela <[email protected]>:

Quoted 10 lines
Quoted 6 lines · Peter Lieven

this patch extends commit db80fac by not only checking for unknown flags, but also filtering out unknown flag combinations.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Will be on next pull request, thanks.

Have you forgotten to pull this one? It might be too late for 2.1 though.

Juan is away for a couple of weeks. This looks like a good fix to pull in for 2.1, though. Peter, do you agree? Can you pick this up if so?

What's the bug it's fixing? I had a look at the commit message, but that suggests it's just tightening up sanity checking, not fixing an actual issue... Maybe you can clarify.

thanks
-- PMM

#6 lore raw
Quoted 23 lines · Peter Maydell
Quoted 22 lines · Amit Shah

(CC'ing Peter Maydell for his thoughts)

Quoted 18 lines · Peter Lieven

Hi Juan,

Am 25.06.2014 um 13:55 schrieb Juan Quintela <[email protected]>:

Quoted 5 lines
Quoted 4 lines · Peter Lieven

this patch extends commit db80fac by not only checking for unknown flags, but also filtering out unknown flag combinations.

Quoted 7 lines
Quoted 2 lines

Will be on next pull request, thanks.

Have you forgotten to pull this one? It might be too late for 2.1 though.

Quoted 7 lines
Quoted 3 lines

Juan is away for a couple of weeks. This looks like a good fix to pull in for 2.1, though. Peter, do you agree? Can you pick this up if so?

What's the bug it's fixing? I had a look at the commit message, but that suggests it's just tightening up sanity checking, not fixing an actual issue... Maybe you can clarify.

Right, it improves correctness: after this patch, we ensure a rogue or corrupt migration stream cannot cause problems on the dest.

Amit

#7 lore raw
Quoted 6 lines · Amit Shah
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Amit Shah

Juan is away for a couple of weeks. This looks like a good fix to pull in for 2.1, though. Peter, do you agree? Can you pick this up if so?

Quoted 6 lines
Quoted 3 lines

What's the bug it's fixing? I had a look at the commit message, but that suggests it's just tightening up sanity checking, not fixing an actual issue... Maybe you can clarify.

Right, it improves correctness: after this patch, we ensure a rogue or corrupt migration stream cannot cause problems on the dest.

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

thanks
-- PMM

#8 lore raw
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Amit Shah
Quoted 8 lines · Peter Maydell
Quoted 3 lines · Amit Shah

Juan is away for a couple of weeks. This looks like a good fix to pull in for 2.1, though. Peter, do you agree? Can you pick this up if so?

What's the bug it's fixing? I had a look at the commit message, but that suggests it's just tightening up sanity checking, not fixing an actual issue... Maybe you can clarify.

Quoted 8 lines
Quoted 2 lines

Right, it improves correctness: after this patch, we ensure a rogue or corrupt migration stream cannot cause problems on the dest.

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Amit

#9 lore raw
Quoted 10 lines · Amit Shah
Quoted 5 lines · Peter Maydell

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Thanks; it seems better to double-check given where we are in the release cycle.

-- PMM

author Reviewed-by Eric Blake
#10 lore raw

Am 09.07.2014 13:00, schrieb Peter Maydell:

Quoted 7 lines · Amit Shah
Quoted 6 lines · Peter Maydell
Quoted 5 lines

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Quoted 5 lines
Quoted 3 lines

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Thanks; it seems better to double-check given where we are in the release cycle.

We have also an:

Maybe he tested as well.

If there are any doubts we should postpone this for 2.2. The preceding patch is in 2.1 and should catch already a lot of cases.

Peter

#11 lore raw
Quoted 11 lines · Peter Lieven

Am 09.07.2014 13:00, schrieb Peter Maydell:

Quoted 10 lines · Amit Shah
Quoted 9 lines · Peter Maydell
Quoted 5 lines

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Quoted 8 lines
Quoted 2 lines

Thanks; it seems better to double-check given where we are in the release cycle.

We have also an:

Maybe he tested as well.

No, while I did a review, and can even do a compile test, I have not done a migration test, so I'm not comfortable with a Tested-by yet. Is it something you need me to try today?

Quoted 3 lines

If there are any doubts we should postpone this for 2.2. The preceding patch is in 2.1 and should catch already a lot of cases.

I'm 50-50 on whether this is 2.1 material - it is a bug fix for hardening against malicious incoming migration streams, but without testing that it doesn't break normal migration, it is rather late in the game.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#12 lore raw
In reply to Peter Maydell
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Amit Shah
Quoted 5 lines · Peter Maydell

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Quoted 6 lines
Quoted 3 lines

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Thanks; it seems better to double-check given where we are in the release cycle.

I tested using the autotest migration tests, which start a guest, migrate it, and then login to the guest to see if everything's fine.

I used qemu-2.0 and qemu.git against qemu.git+patch and both tests passed fine.

But since Peter and Eric have reservations, let's just postpone this till 2.2. That saves me from further tests as well!

Amit

#13 lore raw

Am 11.07.2014 um 14:52 schrieb Amit Shah <[email protected]>:

Quoted 16 lines · Peter Maydell
Quoted 8 lines · Amit Shah
Quoted 7 lines · Peter Maydell
Quoted 5 lines

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Quoted 6 lines
Quoted 3 lines

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Thanks; it seems better to double-check given where we are in the release cycle.

Quoted 8 lines

I tested using the autotest migration tests, which start a guest, migrate it, and then login to the guest to see if everything's fine.

I used qemu-2.0 and qemu.git against qemu.git+patch and both tests passed fine.

But since Peter and Eric have reservations, let's just postpone this till 2.2. That saves me from further tests as well!

Since 2.1 is out meanwhile can you please send a pull request for this patch now?

Thanks,
Peter

#14 lore raw
Quoted 22 lines · Peter Lieven

Am 11.07.2014 um 14:52 schrieb Amit Shah <[email protected]>:

Quoted 19 lines · Peter Maydell
Quoted 8 lines · Amit Shah
Quoted 7 lines · Peter Maydell
Quoted 5 lines

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Quoted 6 lines
Quoted 3 lines

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Thanks; it seems better to double-check given where we are in the release cycle.

I tested using the autotest migration tests, which start a guest, migrate it, and then login to the guest to see if everything's fine.

Quoted 8 lines
Quoted 5 lines

I used qemu-2.0 and qemu.git against qemu.git+patch and both tests passed fine.

But since Peter and Eric have reservations, let's just postpone this till 2.2. That saves me from further tests as well!

Since 2.1 is out meanwhile can you please send a pull request for this patch now?

Juan is back, I'll let him pick it through his tree.

Thanks,

Amit

#15 lore raw
Quoted 19 lines · Amit Shah
Quoted 18 lines · Peter Lieven

Am 11.07.2014 um 14:52 schrieb Amit Shah <[email protected]>:

Quoted 16 lines · Peter Maydell
Quoted 7 lines · Amit Shah
Quoted 6 lines · Peter Maydell
Quoted 5 lines

OK; we're treating those as bugs so yes, I think this is 2.1 material. Has somebody other than the original author tested it? (That's a step that would usually be done by Juan as the maintainer.) If somebody can provide a Tested-by: I'm happy to apply it to master.

Quoted 5 lines
Quoted 3 lines

Not really sure if Juan did that as part of his 'thanks, applied' workflow, but I'll run this through the autotest migration tests and report back.

Thanks; it seems better to double-check given where we are in the release cycle.

I tested using the autotest migration tests, which start a guest, migrate it, and then login to the guest to see if everything's fine.

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

I used qemu-2.0 and qemu.git against qemu.git+patch and both tests passed fine.

But since Peter and Eric have reservations, let's just postpone this till 2.2. That saves me from further tests as well!

Since 2.1 is out meanwhile can you please send a pull request for this patch now?

Juan is back, I'll let him pick it through his tree.

Juan, have you picked this up?

Thanks,
Peter

#16 lore raw

Il 02/09/2014 11:17, Peter Lieven ha scritto:

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Juan is back, I'll let him pick it through his tree.

Juan, have you picked this up?

commit db80facefa62dff42bb50c73b0f03eda5f732b49

Author: Peter Lieven <[email protected]>
Date:   Tue Jun 10 11:29:16 2014 +0200

migration: catch unknown flags in ram_load

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.

Paolo

#17 lore raw

Il 23/09/2014 11:46, Paolo Bonzini ha scritto:

Quoted 16 lines

Il 02/09/2014 11:17, Peter Lieven ha scritto:

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Juan is back, I'll let him pick it through his tree.

Juan, have you picked this up?

commit db80facefa62dff42bb50c73b0f03eda5f732b49

Author: Peter Lieven <[email protected]>
Date:   Tue Jun 10 11:29:16 2014 +0200

migration: catch unknown flags in ram_load

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.

Quoted 6 lines

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

Never mind, this is a different patch.

Paolo

#18 lore raw
Quoted 14 lines · Paolo Bonzini

Il 23/09/2014 11:46, Paolo Bonzini ha scritto:

Quoted 13 lines

Il 02/09/2014 11:17, Peter Lieven ha scritto:

Quoted 2 lines
Quoted 1 line

Juan is back, I'll let him pick it through his tree.

Juan, have you picked this up?

commit db80facefa62dff42bb50c73b0f03eda5f732b49

Author: Peter Lieven <[email protected]>
Date:   Tue Jun 10 11:29:16 2014 +0200

migration: catch unknown flags in ram_load

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.

Quoted 7 lines
Quoted 6 lines

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

Never mind, this is a different patch.

However, the diferent patch is still missing. Juan, can you pick up

[PATCH] migration: catch unknown flag combinations in ram_load

please.

Thank you,
Peter