Skip to content
Snippets Groups Projects
  1. Sep 17, 2019
    • Li Qiang's avatar
      vnc: fix memory leak when vnc disconnect · 6bf21f3d
      Li Qiang authored
      
      Currently when qemu receives a vnc connect, it creates a 'VncState' to
      represent this connection. In 'vnc_worker_thread_loop' it creates a
      local 'VncState'. The connection 'VcnState' and local 'VncState' exchange
      data in 'vnc_async_encoding_start' and 'vnc_async_encoding_end'.
      In 'zrle_compress_data' it calls 'deflateInit2' to allocate the libz library
      opaque data. The 'VncState' used in 'zrle_compress_data' is the local
      'VncState'. In 'vnc_zrle_clear' it calls 'deflateEnd' to free the libz
      library opaque data. The 'VncState' used in 'vnc_zrle_clear' is the connection
      'VncState'. In currently implementation there will be a memory leak when the
      vnc disconnect. Following is the asan output backtrack:
      
      Direct leak of 29760 byte(s) in 5 object(s) allocated from:
          0 0xffffa67ef3c3 in __interceptor_calloc (/lib64/libasan.so.4+0xd33c3)
          1 0xffffa65071cb in g_malloc0 (/lib64/libglib-2.0.so.0+0x571cb)
          2 0xffffa5e968f7 in deflateInit2_ (/lib64/libz.so.1+0x78f7)
          3 0xaaaacec58613 in zrle_compress_data ui/vnc-enc-zrle.c:87
          4 0xaaaacec58613 in zrle_send_framebuffer_update ui/vnc-enc-zrle.c:344
          5 0xaaaacec34e77 in vnc_send_framebuffer_update ui/vnc.c:919
          6 0xaaaacec5e023 in vnc_worker_thread_loop ui/vnc-jobs.c:271
          7 0xaaaacec5e5e7 in vnc_worker_thread ui/vnc-jobs.c:340
          8 0xaaaacee4d3c3 in qemu_thread_start util/qemu-thread-posix.c:502
          9 0xffffa544e8bb in start_thread (/lib64/libpthread.so.0+0x78bb)
          10 0xffffa53965cb in thread_start (/lib64/libc.so.6+0xd55cb)
      
      This is because the opaque allocated in 'deflateInit2' is not freed in
      'deflateEnd'. The reason is that the 'deflateEnd' calls 'deflateStateCheck'
      and in the latter will check whether 's->strm != strm'(libz's data structure).
      This check will be true so in 'deflateEnd' it just return 'Z_STREAM_ERROR' and
      not free the data allocated in 'deflateInit2'.
      
      The reason this happens is that the 'VncState' contains the whole 'VncZrle',
      so when calling 'deflateInit2', the 's->strm' will be the local address.
      So 's->strm != strm' will be true.
      
      To fix this issue, we need to make 'zrle' of 'VncState' to be a pointer.
      Then the connection 'VncState' and local 'VncState' exchange mechanism will
      work as expection. The 'tight' of 'VncState' has the same issue, let's also turn
      it to a pointer.
      
      Reported-by: default avatarYing Fang <fangying1@huawei.com>
      Signed-off-by: default avatarLi Qiang <liq3ea@163.com>
      Message-id: 20190831153922.121308-1-liq3ea@163.com
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      6bf21f3d
  2. Feb 04, 2016
    • Peter Maydell's avatar
      ui: Clean up includes · e16f4c87
      Peter Maydell authored
      
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-2-git-send-email-peter.maydell@linaro.org
      e16f4c87
  3. Aug 21, 2011
  4. Apr 09, 2011
    • Michael Tokarev's avatar
      vnc: tight: Fix crash after 2GB of output · 2caa9e9d
      Michael Tokarev authored
      
      fix 2Gb integer overflow in in VNC tight and zlib encodings
      
      As found by Roland Dreier <roland@purestorage.com> (excellent
      catch!), when amount of VNC compressed data produced by zlib
      and sent to client exceeds 2Gb, integer overflow occurs because
      currently, we calculate amount of data produced at each step by
      comparing saved total_out with new total_out, and total_out is
      something which grows without bounds.  Compare it with previous
      avail_out instead of total_out, and leave total_out alone.
      
      The same code is used in vnc-enc-tight.c and vnc-enc-zlib.c,
      so fix both cases.
      
      There, there's no actual need to save previous_out value, since
      capacity-offset (which is how that value is calculated) stays
      the same so it can be recalculated again after call to deflate(),
      but whole thing becomes less readable this way.
      
      Reported-by: default avatarRoland Dreier <roland@purestorage.com>
      Signed-off-by: default avatarMichael Tokarev <mjt@tls.msk.ru>
      Signed-off-by: default avatarCorentin Chary <corentin.chary@gmail.com>
      Signed-off-by: default avatarAurelien Jarno <aurelien@aurel32.net>
      2caa9e9d
  5. Jul 26, 2010
  6. Jun 01, 2010
  7. May 03, 2010
Loading