Skip to contentSkip to conversation

snapshot: Reset err to NULL to avoid double free

PATCH Applied Chris Spiegel 3 participants 3 messages Oct 6, 2014 – Oct 28, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 snapshot: Reset err to NULL to avoid double free

If an error occurs in bdrv_snapshot_delete_by_id_or_name(), "err" is freed. If "err" is not set to NULL before calling bdrv_snapshot_delete_by_id_or_name() again, it will not be updated on error, and will be freed again.

This can be triggered by starting a VM with at least two drives and then attempting to delete a non-existent snapshot.

---
 savevm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
savevm.c +2 -1
index 2d8eb96..08ec678 100644
@@ -1246,7 +1246,7 @@ int load_vmstate(const char *name)
 void do_delvm(Monitor *mon, const QDict *qdict)
 {
     BlockDriverState *bs;
-    Error *err = NULL;
+    Error *err;
     const char *name = qdict_get_str(qdict, "name");
 
     if (!find_vmstate_bs()) {
@@ -1257,6 +1257,7 @@ void do_delvm(Monitor *mon, const QDict *qdict)
     bs = NULL;
     while ((bs = bdrv_next(bs))) {
         if (bdrv_can_snapshot(bs)) {
+            err = NULL;
             bdrv_snapshot_delete_by_id_or_name(bs, name, &err);
             if (err) {
                 monitor_printf(mon,
Signature · 1 line
2.1.2
Reviewed-by on v1 1/1
#1 lore raw

Copying stable and maintainers.

Quoted 9 lines · Chris Spiegel

If an error occurs in bdrv_snapshot_delete_by_id_or_name(), "err" is freed. If "err" is not set to NULL before calling bdrv_snapshot_delete_by_id_or_name() again, it will not be updated on error, and will be freed again.

This can be triggered by starting a VM with at least two drives and then attempting to delete a non-existent snapshot.

Broken in commit a89d89d.

With the above sentence added to the commit message:

I checked the commit and the file for similar bugs, didn't find any.

#2 lore raw
In reply to Chris Spiegel
Quoted 5 lines · Chris Spiegel

If an error occurs in bdrv_snapshot_delete_by_id_or_name(), "err" is freed. If "err" is not set to NULL before calling bdrv_snapshot_delete_by_id_or_name() again, it will not be updated on error, and will be freed again.

Quoted 7 lines

This can be triggered by starting a VM with at least two drives and then attempting to delete a non-existent snapshot.

---
 savevm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan