Fam Zheng 271c0f68b4 aio: Fix use-after-free in cancellation path
The current flow of canceling a thread from THREAD_ACTIVE state is:

  1) Caller wants to cancel a request, so it calls thread_pool_cancel.

  2) thread_pool_cancel waits on the conditional variable
     elem->check_cancel.

  3) The worker thread changes state to THREAD_DONE once the task is
     done, and notifies elem->check_cancel to allow thread_pool_cancel
     to continue execution, and signals the notifier (pool->notifier) to
     allow callback function to be called later. But because of the
     global mutex, the notifier won't get processed until step 4) and 5)
     are done.

  4) thread_pool_cancel continues, leaving the notifier signaled, it
     just returns to caller.

  5) Caller thinks the request is already canceled successfully, so it
     releases any related data, such as freeing elem->common.opaque.

  6) In the next main loop iteration, the notifier handler,
     event_notifier_ready, is called. It finds the canceled thread in
     THREAD_DONE state, so calls elem->common.cb, with an (likely)
     dangling opaque pointer. This is a use-after-free.

Fix it by calling event_notifier_ready before leaving
thread_pool_cancel.

Test case update: This change will let cancel complete earlier than
test-thread-pool.c expects, so update the code to check this case: if
it's already done, done_cb sets .aiocb to NULL, skip calling
bdrv_aio_cancel on them.

Reported-by: Ulrich Obergfell <uobergfe@redhat.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-05-28 14:28:46 +02:00
2014-05-26 08:42:43 +02:00
2014-05-20 13:05:58 +02:00
2014-05-15 14:24:05 +02:00
2014-05-09 09:11:31 -04:00
2014-05-19 11:36:48 +02:00
2014-05-15 14:24:05 +02:00
2014-05-24 19:43:52 +02:00
2014-05-22 18:14:01 +01:00
2014-05-27 22:45:03 +01:00
2014-05-20 11:57:52 +01:00
2014-05-24 00:07:29 +04:00
2014-05-24 00:07:29 +04:00
2014-05-24 00:07:29 +04:00
2014-05-09 22:59:40 +02:00
2014-05-07 16:16:43 +00:00

Read the documentation in qemu-doc.html or on http://wiki.qemu-project.org

- QEMU team
Description
Original Xbox Emulator for Windows, macOS, and Linux (Active Development)
Readme 532 MiB
Languages
C 82.5%
C++ 7%
Python 3.3%
Dylan 2.8%
Shell 1.5%
Other 2.6%