UAF in validator logging
I accidentally hit an UAF here by pressing Ctrl-C at the right time:
==116425==ERROR: AddressSanitizer: heap-use-after-free on address 0x621000a2a910 at pc 0x7f919d4af60f bp 0x7ffe4f120f80 sp 0x7ffe4f120f78
READ of size 4 at 0x621000a2a910 thread T0
#0 0x7f919d4af60e in dns_name_totext2 /home/ondrej/Projects/bind9/lib/dns/name.c:1133
#1 0x7f919d4af71f in dns_name_totext /home/ondrej/Projects/bind9/lib/dns/name.c:1108
#2 0x7f919d4bc78b in dns_name_format /home/ondrej/Projects/bind9/lib/dns/name.c:2070
#3 0x7f919d87345f in validator_logv /home/ondrej/Projects/bind9/lib/dns/validator.c:3181
#4 0x7f919d873c07 in validator_log /home/ondrej/Projects/bind9/lib/dns/validator.c:3203
#5 0x7f919d887ffc in dns_validator_destroy /home/ondrej/Projects/bind9/lib/dns/validator.c:3139
#6 0x7f919d7a5fe2 in validated /home/ondrej/Projects/bind9/lib/dns/resolver.c:5629
#7 0x7f919d887ddc in validator_done_cb /home/ondrej/Projects/bind9/lib/dns/validator.c:210
#8 0x7f919e86818a in isc__async_cb /home/ondrej/Projects/bind9/lib/isc/async.c:112
#9 0x7f919f2c609c (/lib/x86_64-linux-gnu/libuv.so.1+0xf09c) (BuildId: 7f7f8c148150666c7b116bf98bf6e27f96c697a9)
#10 0x7f919f2d9e3b (/lib/x86_64-linux-gnu/libuv.so.1+0x22e3b) (BuildId: 7f7f8c148150666c7b116bf98bf6e27f96c697a9)
#11 0x7f919f2c69e3 in uv_run (/lib/x86_64-linux-gnu/libuv.so.1+0xf9e3) (BuildId: 7f7f8c148150666c7b116bf98bf6e27f96c697a9)
#12 0x7f919e8ccfd9 in loop_thread /home/ondrej/Projects/bind9/lib/isc/loop.c:282
#13 0x7f919e91b361 in thread_body /home/ondrej/Projects/bind9/lib/isc/thread.c:88
#14 0x7f919e91b361 in isc_thread_main /home/ondrej/Projects/bind9/lib/isc/thread.c:119
#15 0x7f919e8d11f3 in isc_loopmgr_run /home/ondrej/Projects/bind9/lib/isc/loop.c:451
#16 0x557fd88f1431 in main /home/ondrej/Projects/bind9/bin/named/main.c:1535
#17 0x7f919b446189 (/lib/x86_64-linux-gnu/libc.so.6+0x27189) (BuildId: 0401bd8da6edab3e45399d62571357ab12545133)
#18 0x7f919b446244 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27244) (BuildId: 0401bd8da6edab3e45399d62571357ab12545133)
#19 0x557fd88f30a0 in _start (/home/ondrej/Projects/bind9/bin/named/.libs/named+0x1290a0) (BuildId: bec98a49caa4eb5d36abe6f420af83429908126a)
0x621000a2a910 is located 16 bytes inside of 4488-byte region [0x621000a2a900,0x621000a2ba88)
freed by thread T0 here:
#0 0x7f919ecd7298 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52
#1 0x7f919e8d9f3d in sdallocx /home/ondrej/Projects/bind9/lib/isc/jemalloc_shim.h:80
#2 0x7f919e8d9f3d in mem_put /home/ondrej/Projects/bind9/lib/isc/mem.c:328
#3 0x7f919e8d9f3d in isc__mem_putanddetach /home/ondrej/Projects/bind9/lib/isc/mem.c:561
#4 0x7f919d781c43 in fctx_destroy /home/ondrej/Projects/bind9/lib/dns/resolver.c:4326
#5 0x7f919d781c43 in fetchctx_unref /home/ondrej/Projects/bind9/lib/dns/resolver.c:6976
#6 0x7f919d783013 in fetchctx_detach /home/ondrej/Projects/bind9/lib/dns/resolver.c:6976
#7 0x7f919d7a5fa6 in validated /home/ondrej/Projects/bind9/lib/dns/resolver.c:5627
#8 0x7f919d887ddc in validator_done_cb /home/ondrej/Projects/bind9/lib/dns/validator.c:210
#9 0x7f919e86818a in isc__async_cb /home/ondrej/Projects/bind9/lib/isc/async.c:112
#10 0x7f919f2c609c (/lib/x86_64-linux-gnu/libuv.so.1+0xf09c) (BuildId: 7f7f8c148150666c7b116bf98bf6e27f96c697a9)
previously allocated by thread T0 here:
#0 0x7f919ecd85cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f919e8d9437 in mallocx /home/ondrej/Projects/bind9/lib/isc/jemalloc_shim.h:65
#2 0x7f919e8d9437 in mem_get /home/ondrej/Projects/bind9/lib/isc/mem.c:306
#3 0x7f919e8da85f in isc__mem_get /home/ondrej/Projects/bind9/lib/isc/mem.c:684
#4 0x7f919d7941fc in fctx_create /home/ondrej/Projects/bind9/lib/dns/resolver.c:4478
#5 0x7f919d7989a1 in get_attached_fctx /home/ondrej/Projects/bind9/lib/dns/resolver.c:10306
#6 0x7f919d7989a1 in dns_resolver_createfetch /home/ondrej/Projects/bind9/lib/dns/resolver.c:10411
#7 0x7f919c5e27c8 in ns_query_recurse /home/ondrej/Projects/bind9/lib/ns/query.c:6567
#8 0x7f919c61e81d in query_delegation_recurse /home/ondrej/Projects/bind9/lib/ns/query.c:8994
#9 0x7f919c61f4ac in query_delegation /home/ondrej/Projects/bind9/lib/ns/query.c:8940
#10 0x7f919c601c7f in query_gotanswer /home/ondrej/Projects/bind9/lib/ns/query.c:7721
#11 0x7f919c61132f in query_lookup /home/ondrej/Projects/bind9/lib/ns/query.c:6181
#12 0x7f919c635483 in query_coveringnsec /home/ondrej/Projects/bind9/lib/ns/query.c:10290
#13 0x7f919c601c9c in query_gotanswer /home/ondrej/Projects/bind9/lib/ns/query.c:7732
#14 0x7f919c61132f in query_lookup /home/ondrej/Projects/bind9/lib/ns/query.c:6181
#15 0x7f919c616857 in ns__query_start /home/ondrej/Projects/bind9/lib/ns/query.c:5822
#16 0x7f919c644708 in query_setup /home/ondrej/Projects/bind9/lib/ns/query.c:5534
#17 0x7f919c647bc8 in ns_query_start /home/ondrej/Projects/bind9/lib/ns/query.c:12148
#18 0x7f919c589607 in ns_client_request /home/ondrej/Projects/bind9/lib/ns/client.c:2225
#19 0x7f919e81a168 in isc___nm_readcb netmgr/netmgr.c:1785
#20 0x7f919e81a677 in isc__nm_readcb netmgr/netmgr.c:1800
#21 0x7f919e85e1fd in isc__nm_udp_read_cb netmgr/udp.c:586
#22 0x7f919f2d4fa4 (/lib/x86_64-linux-gnu/libuv.so.1+0x1dfa4) (BuildId: 7f7f8c148150666c7b116bf98bf6e27f96c697a9)
SUMMARY: AddressSanitizer: heap-use-after-free /home/ondrej/Projects/bind9/lib/dns/name.c:1133 in dns_name_totext2
Shadow bytes around the buggy address:
0x621000a2a680: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x621000a2a700: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x621000a2a780: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x621000a2a800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x621000a2a880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x621000a2a900: fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd
0x621000a2a980: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x621000a2aa00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x621000a2aa80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x621000a2ab00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x621000a2ab80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==116425==ABORTING
Aborted (core dumped)