block/block-copy: fix use-after-free of task pointer
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Thu, 7 May 2020 18:38:00 +0000 (21:38 +0300)
committerMax Reitz <mreitz@redhat.com>
Wed, 13 May 2020 12:20:31 +0000 (14:20 +0200)
Obviously, we should g_free the task after trace point and offset
update.

Reported-by: Coverity (CID 1428756)
Fixes: 4ce5dd3e9b5ee0fac18625860eb3727399ee965e
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200507183800.22626-1-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
block/block-copy.c

index 03500680f726e52bace761e1378166b020e0e392..4713c8f2a3d27f9767a3ca7c2f139f8a7fa8aff7 100644 (file)
@@ -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;