coroutine: Fix use after free with qemu_coroutine_yield()
authorKevin Wolf <kwolf@redhat.com>
Tue, 10 Feb 2015 10:17:53 +0000 (11:17 +0100)
committerKevin Wolf <kwolf@redhat.com>
Mon, 9 Mar 2015 10:11:59 +0000 (11:11 +0100)
Instead of using the same function for entering and exiting coroutines,
and hoping that it doesn't add any functionality that hurts with the
parameters used for exiting, we can just directly call into the real
task switch in qemu_coroutine_switch().

This fixes a use-after-free scenario where reentering a coroutine that
has yielded still accesses the old parent coroutine (which may have
meanwhile terminated) in the part of coroutine_swap() that follows
qemu_coroutine_switch().

Cc: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-coroutine.c

index 525247b0501dd2eff6a2185ac9fff08e57c2c216..5019b81dd547cc3413904f184afa8251a6a06b1c 100644 (file)
@@ -148,5 +148,5 @@ void coroutine_fn qemu_coroutine_yield(void)
     }
 
     self->caller = NULL;
-    coroutine_swap(self, to);
+    qemu_coroutine_switch(self, to, COROUTINE_YIELD);
 }