Skip to contentSkip to conversation

block/block-copy: fix use-after-free of task pointer

PATCH In review Vladimir Sementsov-Ogievskiy 3 participants 3 messages May 7, 2020 – May 8, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/block-copy: fix use-after-free of task pointer

Obviously, we should g_free the task after trace point and offset update.

Reported-by Coverity
Fixes 4ce5dd3e9b5ee0fac18625860eb3727399ee965e

---

Be free to add Coverity number to the commit message, I don't know it.

 block/block-copy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/block-copy.c +1 -1
index 03500680f7..4713c8f2a3 100644
@@ -591,13 +591,13 @@ static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s,
         }
         if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
             block_copy_task_end(task, 0);
-            g_free(task);
             progress_set_remaining(s->progress,
                                    bdrv_get_dirty_count(s->copy_bitmap) +
                                    s->in_flight_bytes);
             trace_block_copy_skip_range(s, task->offset, task->bytes);
             offset = task_end(task);
             bytes = end - offset;
+            g_free(task);
             continue;
         }
         task->zeroes = ret & BDRV_BLOCK_ZERO;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Vladimir Sementsov-Ogievskiy

Obviously, we should g_free the task after trace point and offset update.

Reported-by Coverity
Fixes 4ce5dd3e9b5ee0fac18625860eb3727399ee965e
Quoted 6 lines

---

Be free to add Coverity number to the commit message, I don't know it.

  block/block-copy.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 9 lines · Vladimir Sementsov-Ogievskiy

Obviously, we should g_free the task after trace point and offset update.

Reported-by Coverity
Fixes 4ce5dd3e9b5ee0fac18625860eb3727399ee965e

---

Be free to add Coverity number to the commit message, I don't know it.

Thanks, done, and applied to my block branch:

https://git.xanclic.moe/XanClic/qemu/commits/branch/block

Max