coroutine: Fix use after free with qemu_coroutine_yield()

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>
(cherry picked from commit 80687b4dd6f43b3fef61fef8fbcb358457350562)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
1 file changed
tree: 43e8a7c009237539e82c2a0bb00234e0dc0cc4cf
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. default-configs/
  6. disas/
  7. docs/
  8. fpu/
  9. fsdev/
  10. gdb-xml/
  11. hw/
  12. include/
  13. libcacard/
  14. libdecnumber/
  15. linux-headers/
  16. linux-user/
  17. net/
  18. pc-bios/
  19. po/
  20. qapi/
  21. qga/
  22. qobject/
  23. qom/
  24. roms/
  25. scripts/
  26. slirp/
  27. stubs/
  28. sysconfigs/
  29. target-alpha/
  30. target-arm/
  31. target-cris/
  32. target-i386/
  33. target-lm32/
  34. target-m68k/
  35. target-microblaze/
  36. target-mips/
  37. target-moxie/
  38. target-openrisc/
  39. target-ppc/
  40. target-s390x/
  41. target-sh4/
  42. target-sparc/
  43. target-tricore/
  44. target-unicore32/
  45. target-xtensa/
  46. tcg/
  47. tests/
  48. trace/
  49. ui/
  50. util/
  51. .exrc
  52. .gitignore
  53. .gitmodules
  54. .mailmap
  55. .travis.yml
  56. accel.c
  57. aio-posix.c
  58. aio-win32.c
  59. arch_init.c
  60. async.c
  61. balloon.c
  62. block-migration.c
  63. block.c
  64. blockdev-nbd.c
  65. blockdev.c
  66. blockjob.c
  67. bootdevice.c
  68. bt-host.c
  69. bt-vhci.c
  70. Changelog
  71. CODING_STYLE
  72. configure
  73. COPYING
  74. COPYING.LIB
  75. coroutine-gthread.c
  76. coroutine-sigaltstack.c
  77. coroutine-ucontext.c
  78. coroutine-win32.c
  79. cpu-exec.c
  80. cpus.c
  81. cputlb.c
  82. device-hotplug.c
  83. device_tree.c
  84. disas.c
  85. dma-helpers.c
  86. dump.c
  87. exec.c
  88. gdbstub.c
  89. HACKING
  90. hmp-commands.hx
  91. hmp.c
  92. hmp.h
  93. iohandler.c
  94. ioport.c
  95. iothread.c
  96. kvm-all.c
  97. kvm-stub.c
  98. LICENSE
  99. main-loop.c
  100. MAINTAINERS
  101. Makefile
  102. Makefile.objs
  103. Makefile.target
  104. memory.c
  105. memory_mapping.c
  106. migration-exec.c
  107. migration-fd.c
  108. migration-rdma.c
  109. migration-tcp.c
  110. migration-unix.c
  111. migration.c
  112. module-common.c
  113. monitor.c
  114. nbd.c
  115. numa.c
  116. os-posix.c
  117. os-win32.c
  118. page_cache.c
  119. qapi-schema.json
  120. qdev-monitor.c
  121. qdict-test-data.txt
  122. qemu-bridge-helper.c
  123. qemu-char.c
  124. qemu-coroutine-io.c
  125. qemu-coroutine-lock.c
  126. qemu-coroutine-sleep.c
  127. qemu-coroutine.c
  128. qemu-doc.texi
  129. qemu-file-stdio.c
  130. qemu-file-unix.c
  131. qemu-file.c
  132. qemu-img-cmds.hx
  133. qemu-img.c
  134. qemu-img.texi
  135. qemu-io-cmds.c
  136. qemu-io.c
  137. qemu-log.c
  138. qemu-nbd.c
  139. qemu-nbd.texi
  140. qemu-options-wrapper.h
  141. qemu-options.h
  142. qemu-options.hx
  143. qemu-seccomp.c
  144. qemu-tech.texi
  145. qemu-timer.c
  146. qemu.nsi
  147. qemu.sasl
  148. qmp-commands.hx
  149. qmp.c
  150. qtest.c
  151. README
  152. rules.mak
  153. savevm.c
  154. softmmu_template.h
  155. spice-qemu-char.c
  156. tcg-runtime.c
  157. tci.c
  158. thread-pool.c
  159. thunk.c
  160. tpm.c
  161. trace-events
  162. translate-all.c
  163. translate-all.h
  164. user-exec.c
  165. VERSION
  166. version.rc
  167. vl.c
  168. vmstate.c
  169. xbzrle.c
  170. xen-common-stub.c
  171. xen-common.c
  172. xen-hvm-stub.c
  173. xen-hvm.c
  174. xen-mapcache.c