]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
aio-epoll: Fix use-after-free of node
authorFam Zheng <famz@redhat.com>
Mon, 16 Nov 2015 06:32:14 +0000 (14:32 +0800)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 17 Nov 2015 10:35:57 +0000 (18:35 +0800)
aio_epoll_update needs the fields in node, so delay the free.

Reported-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-id: 1447655534-13974-1-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
aio-posix.c

index 06148a9ba3673f6ec20a08285615e61b7248b171..482b31650203b3ab3e25cc2d652b64274030012c 100644 (file)
@@ -210,6 +210,7 @@ void aio_set_fd_handler(AioContext *ctx,
 {
     AioHandler *node;
     bool is_new = false;
+    bool deleted = false;
 
     node = find_aio_handler(ctx, fd);
 
@@ -228,7 +229,7 @@ void aio_set_fd_handler(AioContext *ctx,
                  * releasing the walking_handlers lock.
                  */
                 QLIST_REMOVE(node, node);
-                g_free(node);
+                deleted = true;
             }
         }
     } else {
@@ -253,6 +254,9 @@ void aio_set_fd_handler(AioContext *ctx,
 
     aio_epoll_update(ctx, node, is_new);
     aio_notify(ctx);
+    if (deleted) {
+        g_free(node);
+    }
 }
 
 void aio_set_event_notifier(AioContext *ctx,