mirror of
https://github.com/qemu/qemu.git
synced 2025-10-30 10:30:10 +00:00
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: Ying Fang <fangying1@huawei.com>
Signed-off-by: Li Qiang <liq3ea@163.com>
Message-id: 20190831153922.121308-1-liq3ea@163.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
||
|---|---|---|
| .. | ||
| icons | ||
| keycodemapdb@6b3d716e2b | ||
| shader | ||
| cocoa.m | ||
| console-gl.c | ||
| console.c | ||
| curses_keys.h | ||
| curses.c | ||
| cursor_hidden.xpm | ||
| cursor_left_ptr.xpm | ||
| cursor.c | ||
| egl-context.c | ||
| egl-headless.c | ||
| egl-helpers.c | ||
| gtk-egl.c | ||
| gtk-gl-area.c | ||
| gtk.c | ||
| input-barrier.c | ||
| input-barrier.h | ||
| input-keymap.c | ||
| input-legacy.c | ||
| input-linux.c | ||
| input.c | ||
| kbd-state.c | ||
| keymaps.c | ||
| keymaps.h | ||
| Makefile.objs | ||
| qemu-pixman.c | ||
| qemu-x509.h | ||
| qemu.desktop | ||
| sdl2-2d.c | ||
| sdl2-gl.c | ||
| sdl2-input.c | ||
| sdl2.c | ||
| shader.c | ||
| spice-app.c | ||
| spice-core.c | ||
| spice-display.c | ||
| spice-input.c | ||
| trace-events | ||
| vgafont.h | ||
| vnc_keysym.h | ||
| vnc-auth-sasl.c | ||
| vnc-auth-sasl.h | ||
| vnc-auth-vencrypt.c | ||
| vnc-auth-vencrypt.h | ||
| vnc-enc-hextile-template.h | ||
| vnc-enc-hextile.c | ||
| vnc-enc-tight.c | ||
| vnc-enc-tight.h | ||
| vnc-enc-zlib.c | ||
| vnc-enc-zrle.c | ||
| vnc-enc-zrle.h | ||
| vnc-enc-zrle.inc.c | ||
| vnc-enc-zywrle-template.c | ||
| vnc-enc-zywrle.h | ||
| vnc-jobs.c | ||
| vnc-jobs.h | ||
| vnc-palette.c | ||
| vnc-palette.h | ||
| vnc-stubs.c | ||
| vnc-ws.c | ||
| vnc-ws.h | ||
| vnc.c | ||
| vnc.h | ||
| x_keymap.c | ||
| x_keymap.h | ||