]> git.proxmox.com Git - mirror_qemu.git/commitdiff
migration/ram.c: Fix use-after-free in multifd_recv_unfill_packet()
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 9 Apr 2019 15:18:30 +0000 (16:18 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Tue, 9 Apr 2019 19:46:34 +0000 (20:46 +0100)
Coverity points out (CID 1400442) that in this code:

    if (packet->pages_alloc > p->pages->allocated) {
        multifd_pages_clear(p->pages);
        multifd_pages_init(packet->pages_alloc);
    }

we free p->pages in multifd_pages_clear() but continue to
use it in the following code. We also leak memory, because
multifd_pages_init() returns the pointer to a new MultiFDPages_t
struct but we are ignoring its return value.

Fix both of these bugs by adding the missing assignment of
the newly created struct to p->pages.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-id: 20190409151830.6024-1-peter.maydell@linaro.org
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
migration/ram.c

index f68beeeeffc213901c720735aa2116df410c021c..1ca9ba77b6a66d241431af6702a49c5b9845ed1b 100644 (file)
@@ -851,7 +851,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
      */
     if (packet->pages_alloc > p->pages->allocated) {
         multifd_pages_clear(p->pages);
-        multifd_pages_init(packet->pages_alloc);
+        p->pages = multifd_pages_init(packet->pages_alloc);
     }
 
     p->pages->used = be32_to_cpu(packet->pages_used);