cadence_uart: bounds check write offset

cadence_uart_init() initializes an I/O memory region of size 0x1000
bytes.  However in uart_write(), the 'offset' parameter (offset within
region) is divided by 4 and then used to index the array 'r' of size
CADENCE_UART_R_MAX which is much smaller: (0x48/4).  If 'offset>>=2'
exceeds CADENCE_UART_R_MAX, this will cause an out-of-bounds memory
write where the offset and the value are controlled by guest.

This will corrupt QEMU memory, in most situations this causes the vm to
crash.

Fix by checking the offset against the array size.

Cc: qemu-stable@nongnu.org
Reported-by: 李强 <liqiang6-s@360.cn>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Message-id: 20160418100735.GA517@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit 5eb0b194e9b01ba0f3613e6ddc2cb9f63ce96ae5)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
1 file changed
tree: 8658d0e4046c0a47ec84b903feccdeffd0edd807
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. contrib/
  6. crypto/
  7. default-configs/
  8. disas/
  9. docs/
  10. fpu/
  11. fsdev/
  12. gdb-xml/
  13. hw/
  14. include/
  15. libdecnumber/
  16. linux-headers/
  17. linux-user/
  18. migration/
  19. net/
  20. pc-bios/
  21. po/
  22. qapi/
  23. qga/
  24. qobject/
  25. qom/
  26. replay/
  27. roms/
  28. scripts/
  29. slirp/
  30. stubs/
  31. target-alpha/
  32. target-arm/
  33. target-cris/
  34. target-i386/
  35. target-lm32/
  36. target-m68k/
  37. target-microblaze/
  38. target-mips/
  39. target-moxie/
  40. target-openrisc/
  41. target-ppc/
  42. target-s390x/
  43. target-sh4/
  44. target-sparc/
  45. target-tilegx/
  46. target-tricore/
  47. target-unicore32/
  48. target-xtensa/
  49. tcg/
  50. tests/
  51. trace/
  52. ui/
  53. util/
  54. .dir-locals.el
  55. .exrc
  56. .gitignore
  57. .gitmodules
  58. .mailmap
  59. .travis.yml
  60. accel.c
  61. aio-posix.c
  62. aio-win32.c
  63. arch_init.c
  64. async.c
  65. balloon.c
  66. block.c
  67. blockdev-nbd.c
  68. blockdev.c
  69. blockjob.c
  70. bootdevice.c
  71. bt-host.c
  72. bt-vhci.c
  73. Changelog
  74. CODING_STYLE
  75. configure
  76. COPYING
  77. COPYING.LIB
  78. cpu-exec-common.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-info.hx
  91. hmp-commands.hx
  92. hmp.c
  93. hmp.h
  94. iohandler.c
  95. ioport.c
  96. iothread.c
  97. kvm-all.c
  98. kvm-stub.c
  99. LICENSE
  100. main-loop.c
  101. MAINTAINERS
  102. Makefile
  103. Makefile.objs
  104. Makefile.target
  105. memory.c
  106. memory_mapping.c
  107. module-common.c
  108. monitor.c
  109. nbd.c
  110. numa.c
  111. os-posix.c
  112. os-win32.c
  113. page_cache.c
  114. qapi-schema.json
  115. qdev-monitor.c
  116. qdict-test-data.txt
  117. qemu-bridge-helper.c
  118. qemu-char.c
  119. qemu-doc.texi
  120. qemu-ga.texi
  121. qemu-img-cmds.hx
  122. qemu-img.c
  123. qemu-img.texi
  124. qemu-io-cmds.c
  125. qemu-io.c
  126. qemu-log.c
  127. qemu-nbd.c
  128. qemu-nbd.texi
  129. qemu-options-wrapper.h
  130. qemu-options.h
  131. qemu-options.hx
  132. qemu-seccomp.c
  133. qemu-tech.texi
  134. qemu-timer.c
  135. qemu.nsi
  136. qemu.sasl
  137. qjson.c
  138. qmp-commands.hx
  139. qmp.c
  140. qtest.c
  141. README
  142. rules.mak
  143. softmmu_template.h
  144. spice-qemu-char.c
  145. tcg-runtime.c
  146. tci.c
  147. thread-pool.c
  148. thunk.c
  149. tpm.c
  150. trace-events
  151. translate-all.c
  152. translate-all.h
  153. translate-common.c
  154. user-exec.c
  155. VERSION
  156. version.rc
  157. vl.c
  158. xen-common-stub.c
  159. xen-common.c
  160. xen-hvm-stub.c
  161. xen-hvm.c
  162. xen-mapcache.c