Skip to content

AddressSanitizer reports heap-use-after-free in systemd-resolved when DNSOverTLS=opportunistic #9511

Closed

Description

@evverx

I found the following backtrace in the journal of a container where DNSOverTLS was set to opportunistic. I'll try to get more details shortly, but I'll leave it here in case anyone could figure it out by just looking at the backtrace:

Started Network Name Resolution.
=================================================================
==44==ERROR: AddressSanitizer: heap-use-after-free on address 0x61600000cea0 at pc 0x55d98ae22856 bp 0x7ffe2e8b2170 sp 0x7ffe2e8b2160
READ of size 8 at 0x61600000cea0 thread T0
    #0 0x55d98ae22855 in on_stream_complete ../src/resolve/resolved-dns-transaction.c:540
    #1 0x55d98ae75f23 in dns_stream_complete ../src/resolve/resolved-dns-stream.c:62
    #2 0x55d98ae79264 in on_stream_timeout ../src/resolve/resolved-dns-stream.c:314
    #3 0x7f9d412d2d7a in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3109
    #4 0x7f9d412d7746 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:3514
    #5 0x7f9d412d83ad in sd_event_run ../src/libsystemd/sd-event/sd-event.c:3571
    #6 0x7f9d412d86aa in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:3593
    #7 0x55d98adaaf43 in main ../src/resolve/resolved.c:96
    #8 0x7f9d3eb40f29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
    #9 0x55d98ada9719 in _start (/usr/lib/systemd/systemd-resolved+0x161719)
0x61600000cea0 is located 544 bytes inside of 592-byte region [0x61600000cc80,0x61600000ced0)
freed by thread T0 here:
    #0 0x7f9d41e1b4b8 in __interceptor_free (/usr/lib64/libasan.so.4+0xde4b8)
    #1 0x55d98ae74cc1 in mfree ../src/basic/alloc-util.h:34
    #2 0x55d98ae7d485 in dns_stream_unref ../src/resolve/resolved-dns-stream.c:522
    #3 0x55d98ae2233d in on_stream_complete ../src/resolve/resolved-dns-transaction.c:526
    #4 0x55d98ae75f23 in dns_stream_complete ../src/resolve/resolved-dns-stream.c:62
    #5 0x55d98ae79264 in on_stream_timeout ../src/resolve/resolved-dns-stream.c:314
    #6 0x7f9d412d2d7a in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3109
    #7 0x7f9d412d7746 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:3514
    #8 0x7f9d412d83ad in sd_event_run ../src/libsystemd/sd-event/sd-event.c:3571
    #9 0x7f9d412d86aa in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:3593
    #10 0x55d98adaaf43 in main ../src/resolve/resolved.c:96
    #11 0x7f9d3eb40f29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
previously allocated by thread T0 here:
    #0 0x7f9d41e1ba38 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdea38)
    #1 0x55d98ae7d835 in dns_stream_new ../src/resolve/resolved-dns-stream.c:545
    #2 0x55d98ae24226 in dns_transaction_emit_tcp ../src/resolve/resolved-dns-transaction.c:642
    #3 0x55d98ae2ff25 in dns_transaction_go ../src/resolve/resolved-dns-transaction.c:1761
    #4 0x55d98ae0b334 in dns_query_candidate_go ../src/resolve/resolved-dns-query.c:156
    #5 0x55d98ae11bb5 in dns_query_go ../src/resolve/resolved-dns-query.c:757
    #6 0x55d98adcefe3 in bus_method_resolve_hostname ../src/resolve/resolved-bus.c:353
    #7 0x7f9d411de9a0 in method_callbacks_run ../src/libsystemd/sd-bus/bus-objects.c:402
    #8 0x7f9d411e603f in object_find_and_run ../src/libsystemd/sd-bus/bus-objects.c:1260
    #9 0x7f9d411e72a0 in bus_process_object ../src/libsystemd/sd-bus/bus-objects.c:1376
    #10 0x7f9d4122afd6 in process_message ../src/libsystemd/sd-bus/sd-bus.c:2661
    #11 0x7f9d4122b448 in process_running ../src/libsystemd/sd-bus/sd-bus.c:2703
    #12 0x7f9d4122d5f7 in bus_process_internal ../src/libsystemd/sd-bus/sd-bus.c:2922
    #13 0x7f9d4122d7bf in sd_bus_process ../src/libsystemd/sd-bus/sd-bus.c:2949
    #14 0x7f9d41230405 in io_callback ../src/libsystemd/sd-bus/sd-bus.c:3302
    #15 0x7f9d412d2c43 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3101
    #16 0x7f9d412d7746 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:3514
    #17 0x7f9d412d83ad in sd_event_run ../src/libsystemd/sd-event/sd-event.c:3571
    #18 0x7f9d412d86aa in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:3593
    #19 0x55d98adaaf43 in main ../src/resolve/resolved.c:96
    #20 0x7f9d3eb40f29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
SUMMARY: AddressSanitizer: heap-use-after-free ../src/resolve/resolved-dns-transaction.c:540 in on_stream_complete
Shadow bytes around the buggy address:
  0x0c2c7fff9980: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff9990: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff99a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff99b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff99c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c2c7fff99d0: fd fd fd fd[fd]fd fd fd fd fd fa fa fa fa fa fa
  0x0c2c7fff99e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff99f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9a00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9a10: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9a20: 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
==44==ABORTING

There seems to be another one:

=================================================================
==182==ERROR: AddressSanitizer: heap-use-after-free on address 0x61600000c38c at pc 0x5633f4a51437 bp 0x7ffdf35d2a70 sp 0x7ffdf35d2a60
READ of size 4 at 0x61600000c38c thread T0
    #0 0x5633f4a51436 in on_stream_complete ../src/resolve/resolved-dns-transaction.c:528
    #1 0x5633f4aa4f23 in dns_stream_complete ../src/resolve/resolved-dns-stream.c:62
    #2 0x5633f4aa94ca in on_stream_io ../src/resolve/resolved-dns-stream.c:405
    #3 0x7f468830bc43 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3101
    #4 0x7f4688310746 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:3514
    #5 0x7f46883113ad in sd_event_run ../src/libsystemd/sd-event/sd-event.c:3571
    #6 0x7f46883116aa in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:3593
    #7 0x5633f49d9f43 in main ../src/resolve/resolved.c:96
    #8 0x7f4685b79f29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
    #9 0x5633f49d8719 in _start (/usr/lib/systemd/systemd-resolved+0x161719)
0x61600000c38c is located 12 bytes inside of 592-byte region [0x61600000c380,0x61600000c5d0)
freed by thread T0 here:
    #0 0x7f4688e544b8 in __interceptor_free (/usr/lib64/libasan.so.4+0xde4b8)
    #1 0x5633f4aa3cc1 in mfree ../src/basic/alloc-util.h:34
    #2 0x5633f4aac485 in dns_stream_unref ../src/resolve/resolved-dns-stream.c:522
    #3 0x5633f4a5133d in on_stream_complete ../src/resolve/resolved-dns-transaction.c:526
    #4 0x5633f4aa4f23 in dns_stream_complete ../src/resolve/resolved-dns-stream.c:62
    #5 0x5633f4aa94ca in on_stream_io ../src/resolve/resolved-dns-stream.c:405
    #6 0x7f468830bc43 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3101
    #7 0x7f4688310746 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:3514
    #8 0x7f46883113ad in sd_event_run ../src/libsystemd/sd-event/sd-event.c:3571
    #9 0x7f46883116aa in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:3593
    #10 0x5633f49d9f43 in main ../src/resolve/resolved.c:96
    #11 0x7f4685b79f29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
previously allocated by thread T0 here:
    #0 0x7f4688e54a38 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdea38)
    #1 0x5633f4aac835 in dns_stream_new ../src/resolve/resolved-dns-stream.c:545
    #2 0x5633f4a53226 in dns_transaction_emit_tcp ../src/resolve/resolved-dns-transaction.c:642
    #3 0x5633f4a5ef25 in dns_transaction_go ../src/resolve/resolved-dns-transaction.c:1761
    #4 0x5633f4a3a334 in dns_query_candidate_go ../src/resolve/resolved-dns-query.c:156
    #5 0x5633f4a40bb5 in dns_query_go ../src/resolve/resolved-dns-query.c:757
    #6 0x5633f49fdfe3 in bus_method_resolve_hostname ../src/resolve/resolved-bus.c:353
    #7 0x7f46882179a0 in method_callbacks_run ../src/libsystemd/sd-bus/bus-objects.c:402
    #8 0x7f468821f03f in object_find_and_run ../src/libsystemd/sd-bus/bus-objects.c:1260
    #9 0x7f46882202a0 in bus_process_object ../src/libsystemd/sd-bus/bus-objects.c:1376
    #10 0x7f4688263fd6 in process_message ../src/libsystemd/sd-bus/sd-bus.c:2661
    #11 0x7f4688264448 in process_running ../src/libsystemd/sd-bus/sd-bus.c:2703
    #12 0x7f46882665f7 in bus_process_internal ../src/libsystemd/sd-bus/sd-bus.c:2922
    #13 0x7f46882667bf in sd_bus_process ../src/libsystemd/sd-bus/sd-bus.c:2949
    #14 0x7f4688269405 in io_callback ../src/libsystemd/sd-bus/sd-bus.c:3302
    #15 0x7f468830bc43 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3101
    #16 0x7f4688310746 in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:3514
    #17 0x7f46883113ad in sd_event_run ../src/libsystemd/sd-event/sd-event.c:3571
    #18 0x7f46883116aa in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:3593
    #19 0x5633f49d9f43 in main ../src/resolve/resolved.c:96
    #20 0x7f4685b79f29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
SUMMARY: AddressSanitizer: heap-use-after-free ../src/resolve/resolved-dns-transaction.c:528 in on_stream_complete
Shadow bytes around the buggy address:
  0x0c2c7fff9820: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9830: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9840: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9850: fd fd fd fd fd fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff9860: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c2c7fff9870: fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9880: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff9890: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff98a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c2c7fff98b0: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
  0x0c2c7fff98c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
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
==182==ABORTING

Activity

  1. added
    bug 🐛
    on Jul 5, 2018
  2. added a commit that references this issue on Jul 12, 2018
    18df5fb
  3. added a commit that references this issue on Oct 31, 2018
    ffd851d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛resolve

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions