Skip to contentSkip to conversation

migration: catch unknown flags in ram_load

PATCH Superseded Peter Lieven 3 participants 5 messages May 10, 2014 – May 12, 2014

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 arch_init.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch_init.c +4 -3
index 995f56d..582b716 100644
@@ -1084,9 +1084,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 
                 total_ram_bytes -= length;
             }
-        }
-
-        if (flags & RAM_SAVE_FLAG_COMPRESS) {
+        } else if (flags & RAM_SAVE_FLAG_COMPRESS) {
             void *host;
             uint8_t ch;
 
@@ -1121,6 +1119,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
         } else if (flags & RAM_SAVE_FLAG_HOOK) {
             ram_control_load_hook(f, flags);
+        } else if (!(flags & RAM_SAVE_FLAG_EOS)) {
+            ret = -EINVAL;
+            goto done;
         }
         error = qemu_file_get_error(f);
         if (error) {
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines

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 9 lines

this patch catches all unknown flags and
aborts the loading of the vm.

---
arch_init.c | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
#2 lore raw
In reply to Peter Lieven
Quoted 9 lines · Peter Lieven

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.

.....

Once here, shouldn't be better to do this as:

change do {} while () for while (true) {}

arch_init.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1127

Quoted 11 lines
arch_init.c +3 -0
@@ -1121,6 +1119,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
         } else if (flags & RAM_SAVE_FLAG_HOOK) {
             ram_control_load_hook(f, flags);
+        } else if (!(flags & RAM_SAVE_FLAG_EOS)) {
+            ret = -EINVAL;
+            goto done;
         }
         error = qemu_file_get_error(f);
         if (error) {
        } else if (flags & RAM_SAVE_FLAG_HOOK) {
            ram_control_load_hook(f, flags);

+ } else if (flags & RAM_SAVE_FLAG_EOS) {
+ break;
+ } else {
+ ret = -EINVAL;

+           goto done;
        }
          error = qemu_file_get_error(f);
          if (error) {
        }

This way, we are checking RAM_SAVE_FLAG_EOS the same way than any other flag? And we don't have to duplicate the FLAG_NAME?

Unrelated to this patch, all the flags are a bitmap, but really, the ones that can be together are RAM_SAVE_FLAG_CONTINUE and the rest, all the others need to be alone. I am telling this because we have used already 8 flags, and we are using the low bits of offset to save the flags, we have 10 flags? Perhaps changing the last flag to mean that the low bits pass to be a counter?

PD. No, I haven't investigated right now how RAM_SAVE_FLAG_HOOK works with all of this.

Later, Juan.

#3 lore raw

Am 12.05.2014 12:19, schrieb Juan Quintela:

Quoted 41 lines
Quoted 9 lines · Peter Lieven

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.

.....

Once here, shouldn't be better to do this as:

change do {} while () for while (true) {}

arch_init.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1127

Quoted 11 lines
arch_init.c +3 -0
@@ -1121,6 +1119,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
         } else if (flags & RAM_SAVE_FLAG_HOOK) {
             ram_control_load_hook(f, flags);
+        } else if (!(flags & RAM_SAVE_FLAG_EOS)) {
+            ret = -EINVAL;
+            goto done;
         }
         error = qemu_file_get_error(f);
         if (error) {
        } else if (flags & RAM_SAVE_FLAG_HOOK) {
            ram_control_load_hook(f, flags);
arch_init.c +5 -0
+       } else if (flags & RAM_SAVE_FLAG_EOS) {
+           break;
+       } else {
+           ret = -EINVAL;
+           goto done;
        }
          error = qemu_file_get_error(f);
          if (error) {
        }
Quoted 2 lines

This way, we are checking RAM_SAVE_FLAG_EOS the same way than any other flag? And we don't have to duplicate the FLAG_NAME?

Ok, I will send a v2.

Quoted 7 lines

Unrelated to this patch, all the flags are a bitmap, but really, the ones that can be together are RAM_SAVE_FLAG_CONTINUE and the rest, all the others need to be alone. I am telling this because we have used already 8 flags, and we are using the low bits of offset to save the flags, we have 10 flags? Perhaps changing the last flag to mean that the low bits pass to be a counter?

Some better encoding would indeed be useful. I already thought that we might run out of flags soon. We have 11 flags I think, but there is not much space left. Reserving the last flag to indicate that the lower 10 bits a are counter might be a good option.

Peter

Quoted 6 lines

PD. No, I haven't investigated right now how RAM_SAVE_FLAG_HOOK works with all of this.

Later, Juan.

#4 lore raw

Am 12.05.2014 12:25, schrieb Peter Lieven:

Quoted 38 lines

Am 12.05.2014 12:19, schrieb Juan Quintela:

Quoted 37 lines
Quoted 9 lines · Peter Lieven

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.

.....

Once here, shouldn't be better to do this as:

change do {} while () for while (true) {}

arch_init.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1127

Quoted 11 lines
arch_init.c +3 -0
@@ -1121,6 +1119,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
         } else if (flags & RAM_SAVE_FLAG_HOOK) {
             ram_control_load_hook(f, flags);
+        } else if (!(flags & RAM_SAVE_FLAG_EOS)) {
+            ret = -EINVAL;
+            goto done;
         }
         error = qemu_file_get_error(f);
         if (error) {
        } else if (flags & RAM_SAVE_FLAG_HOOK) {
            ram_control_load_hook(f, flags);
arch_init.c +5 -0
+       } else if (flags & RAM_SAVE_FLAG_EOS) {
+           break;
+       } else {
+           ret = -EINVAL;
+           goto done;
        }
          error = qemu_file_get_error(f);
          if (error) {

we can also drop the error variable I think and change the loop to

while (!ret) {}

Quoted 25 lines
Quoted 5 lines
        }

This way, we are checking RAM_SAVE_FLAG_EOS the same way than any other flag? And we don't have to duplicate the FLAG_NAME?

Ok, I will send a v2.

Quoted 6 lines

Unrelated to this patch, all the flags are a bitmap, but really, the ones that can be together are RAM_SAVE_FLAG_CONTINUE and the rest, all the others need to be alone. I am telling this because we have used already 8 flags, and we are using the low bits of offset to save the flags, we have 10 flags? Perhaps changing the last flag to mean that the low bits pass to be a counter?

Some better encoding would indeed be useful. I already thought that we might run out of flags soon. We have 11 flags I think, but there is not much space left. Reserving the last flag to indicate that the lower 10 bits a are counter might be a good option.

Peter

Quoted 5 lines

PD. No, I haven't investigated right now how RAM_SAVE_FLAG_HOOK works with all of this.

Later, Juan.