When running layer_reolad.vtc with ASAN CFLAGS, ASAN finds a heap-use-after-free in dom_destroy(). This is found using latest Varnish Cache and latest libvmod dynamic. The issue could be hidden by allocating the fallback director after the dynamic director, this results in the director/domain being freed in the "right" order.
Steps to reproduce:
Configure varnish with --enable-asan and then before make set enviorment vairables ASAN_OPTIONS=abort_on_error=1,detect_odr_violation=1,detect_leaks=1,detect_stack_use_after_return=1,detect_invalid_pointer_pairs=1,handle_segv=0,handle_sigbus=0,use_sigaltstack=0,disable_coredump=0 and LSAN_OPTIONS=abort_on_error=1,use_sigaltstack=0,suppressions=${path_to}/varnish-cache/tools/lsan.suppr
configure libvmod-dynamic with CFLAGS='-fsanitize=address' ./configure and export the same SAN options as Varnish
When running
layer_reolad.vtc
with ASAN CFLAGS, ASAN finds aheap-use-after-free
indom_destroy()
. This is found using latest Varnish Cache and latest libvmod dynamic. The issue could be hidden by allocating the fallback director after the dynamic director, this results in the director/domain being freed in the "right" order.Steps to reproduce:
--enable-asan
and then before make set enviorment vairablesASAN_OPTIONS=abort_on_error=1,detect_odr_violation=1,detect_leaks=1,detect_stack_use_after_return=1,detect_invalid_pointer_pairs=1,handle_segv=0,handle_sigbus=0,use_sigaltstack=0,disable_coredump=0
andLSAN_OPTIONS=abort_on_error=1,use_sigaltstack=0,suppressions=${path_to}/varnish-cache/tools/lsan.suppr
CFLAGS='-fsanitize=address' ./configure
and export the same SAN options as VarnishCollapsible VTC Log:
toggle view log
``` **** dT 0.000 * top TEST ./tests/layer_reload.vtc starting **** top extmacro def pkg_version=trunk **** top extmacro def pkg_branch=trunk **** top extmacro def pwd=/home/swojcik/code/libvmod-dynamic/src **** top extmacro def date(...) **** top extmacro def string(...) **** top extmacro def vmod_dynamic=dynamic from "/home/swojcik/code/libvmod-dynamic/src/.libs/libvmod_dynamic.so" **** top extmacro def localhost=127.0.0.1 **** top extmacro def bad_backend=127.0.0.1:41381 **** top extmacro def listen_addr=127.0.0.1:0 **** top extmacro def bad_ip=192.0.2.255 **** top macro def testdir=/home/swojcik/code/libvmod-dynamic/src/./tests **** top macro def tmpdir=/tmp/vtc.2872792.2223da65 **** top macro def vtcid=vtc.2872792.2223da65 ** top === varnishtest "Reloading after creating backend in init" * top VTEST Reloading after creating backend in init ** top === feature cmd "getent hosts example.com" **** dT 0.024 ** top === shell { **** top shell_cmd|exec 2>&1 ; **** top shell_cmd|\tcat >/tmp/vtc.2872792.2223da65/f1 <<-EOF **** top shell_cmd|\tvcl 4.1; **** top shell_cmd|\timport dynamic from "/home/swojcik/code/libvmod-dynamic/src/.libs/libvmod_dynamic.so"; **** top shell_cmd|\timport directors; **** top shell_cmd| **** top shell_cmd|\tbackend none none; **** top shell_cmd| **** top shell_cmd|\tsub vcl_init { **** top shell_cmd|\t\tnew dir = directors.fallback(); **** top shell_cmd|\t\tnew res = dynamic.resolver(); **** top shell_cmd|\t\tnew dyn = dynamic.director(domain_usage_timeout = 0.1s, resolver = res.use()); **** top shell_cmd|\t\tdir.add_backend(dyn.backend(host={"example.com"}, port={"80"}) ); **** top shell_cmd|\t} **** top shell_cmd|\tEOF **** dT 0.028 **** top shell_status = 0x0000 ** top === varnish v1 -cliok "vcl.load vcl1 ${tmpdir}/f1" **** dT 0.033 ** v1 Launch *** v1 CMD: cd ${pwd} && exec varnishd -d -n /tmp/vtc.2872792.2223da65/v1 -i v1 -p debug=+vcl_keep -p debug=+vmod_so_keep -p debug=+vsm_keep -l 2m -p auto_restart=off -p syslog_cli_traffic=off -p thread_pool_min=10 -p debug=+vtc_mode -p vsl_mask=+Debug,+H2RxHdr,+H2RxBody -p h2_initial_window_size=1m -p h2_rx_window_low_water=64k -a '127.0.0.1:0' -M '127.0.0.1 38685' -P /tmp/vtc.2872792.2223da65/v1/varnishd.pid *** v1 CMD: cd /home/swojcik/code/libvmod-dynamic/src && exec varnishd -d -n /tmp/vtc.2872792.2223da65/v1 -i v1 -p debug=+vcl_keep -p debug=+vmod_so_keep -p debug=+vsm_keep -l 2m -p auto_restart=off -p syslog_cli_traffic=off -p thread_pool_min=10 -p debug=+vtc_mode -p vsl_mask=+Debug,+H2RxHdr,+H2RxBody -p h2_initial_window_size=1m -p h2_rx_window_low_water=64k -a '127.0.0.1:0' -M '127.0.0.1 38685' -P /tmp/vtc.2872792.2223da65/v1/varnishd.pid **** dT 0.034 *** v1 PID: 2872812 **** v1 macro def v1_pid=2872812 **** v1 macro def v1_name=/tmp/vtc.2872792.2223da65/v1 **** dT 0.054 *** v1 debug|Debug: Version: varnish-trunk revision d77da13b9baf268196075bda0808d0d2e8721470 *** v1 debug|Debug: Platform: Linux,6.5.0-17-generic,x86_64,-jnone,-sdefault,-sdefault,-hcritbit *** v1 debug|200 317 *** v1 debug|----------------------------- *** v1 debug|Varnish Cache CLI 1.0 *** v1 debug|----------------------------- *** v1 debug|Linux,6.5.0-17-generic,x86_64,-jnone,-sdefault,-sdefault,-hcritbit *** v1 debug|varnish-trunk revision d77da13b9baf268196075bda0808d0d2e8721470 *** v1 debug| *** v1 debug|Type 'help' for command list. *** v1 debug|Type 'quit' to close CLI session. *** v1 debug|Type 'start' to launch worker process. *** v1 debug| **** dT 0.153 **** v1 CLIPOLL 1 0x1 0x0 0x0 *** v1 CLI connection fd = 4 **** dT 0.154 *** v1 CLI RX 107 **** v1 CLI RX|ygvcsiionoelhdqmokrfteicbjzhrzuc **** v1 CLI RX| **** v1 CLI RX|Authentication required. **** v1 CLI TX|auth 90608ea81d2bbbfa7774fd79c416390009fbabba31979c1a26762f0a0fe266fd **** dT 0.155 *** v1 CLI RX 200 **** v1 CLI RX|----------------------------- **** v1 CLI RX|Varnish Cache CLI 1.0 **** v1 CLI RX|----------------------------- **** v1 CLI RX|Linux,6.5.0-17-generic,x86_64,-jnone,-sdefault,-sdefault,-hcritbit **** v1 CLI RX|varnish-trunk revision d77da13b9baf268196075bda0808d0d2e8721470 **** v1 CLI RX| **** v1 CLI RX|Type 'help' for command list. **** v1 CLI RX|Type 'quit' to close CLI session. **** v1 CLI RX|Type 'start' to launch worker process. **** dT 0.156 **** v1 CLI TX|vcl.load vcl1 /tmp/vtc.2872792.2223da65/f1 **** dT 0.256 *** v1 vsl|No VSL chunk found (child not started ?) **** dT 0.356 *** v1 vsl|No VSL chunk found (child not started ?) **** dT 0.456 *** v1 vsl|No VSL chunk found (child not started ?) **** dT 0.556 *** v1 vsl|No VSL chunk found (child not started ?) **** dT 0.657 *** v1 vsl|No VSL chunk found (child not started ?) **** dT 0.757 *** v1 vsl|No VSL chunk found (child not started ?) **** dT 0.832 *** v1 CLI RX 200 **** v1 CLI RX|Message from VCC-compiler: **** v1 CLI RX|----------------------------------------------------- **** v1 CLI RX|Suppressions used: **** v1 CLI RX| count bytes template **** v1 CLI RX| 2 136 HSH_config **** v1 CLI RX| 9 360 vcc_ **** v1 CLI RX|----------------------------------------------------- **** v1 CLI RX| **** v1 CLI RX|Message from dlopen: **** v1 CLI RX|----------------------------------------------------- **** v1 CLI RX|Suppressions used: **** v1 CLI RX| count bytes template **** v1 CLI RX| 2 136 HSH_config **** v1 CLI RX|----------------------------------------------------- **** v1 CLI RX| **** v1 CLI RX|VCL compiled. ** v1 CLI 200