Skip to content

There is a heap-use-after-free in resolved in on_mdns_packet #23873

Closed

Description

@evverx

systemd version the issue has been seen with

f63d1b0

Steps to reproduce the problem

I'm not sure how to reproduce it reliably yet

Additional program output to the terminal or log subsystem illustrating the issue

Received mdns UDP packet of size 179, ifindex=15, ttl=255, fragsize=0, sender=192.168.89.22, destination=224.0.0.251
Got mDNS reply packet
Checking for conflicts...
Processing incoming packet of size 179 on transaction 36300 (rcode=SUCCESS).
Regular transaction 36300 for <C._qotd._tcp.local IN TXT> on scope mdns on ve-root/INET now complete with <success> from network (unsigned; non-confidential).
Freeing transaction 63428.
Freeing transaction 40232.
Freeing transaction 15344.
Looking up RR for C.local IN A.
Looking up RR for C.local IN AAAA.
Cache miss for C.local IN AAAA
Firing regular transaction 48789 for <C.local IN AAAA> scope mdns on ve-root/INET6 (validate=yes).
Delaying mdns transaction 48789 for 110065us.
Cache miss for C.local IN A
Firing regular transaction 58320 for <C.local IN A> scope mdns on ve-root/INET (validate=yes).
Delaying mdns transaction 58320 for 74143us.
Freeing transaction 36300.
=================================================================
==983858==ERROR: AddressSanitizer: heap-use-after-free on address 0x612000690ea8 at pc 0x000000539601 bp 0x7ffda15d9f50 sp 0x7ffda15d9f48
READ of size 8 at 0x612000690ea8 thread T0
    #0 0x539600 in on_mdns_packet ../src/resolve/resolved-mdns.c:413
    #1 0x7f156cbb40a7  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11b40a7)
    #2 0x7f156cbbc95c  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11bc95c)
    #3 0x7f156cbbdac0  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11bdac0)
    #4 0x7f156cbbde41  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11bde41)
    #5 0x553402 in run ../src/resolve/resolved.c:92
    #6 0x55369c in main ../src/resolve/resolved.c:99
    #7 0x7f156a64043f in __libc_start_call_main (/lib64/libc.so.6+0x4043f)
    #8 0x7f156a6404ef in __libc_start_main@@GLIBC_2.34 (/lib64/libc.so.6+0x404ef)
    #9 0x40c0a4 in _start (/home/vagrant/systemd/build/systemd-resolved+0x40c0a4)

0x612000690ea8 is located 232 bytes inside of 280-byte region [0x612000690dc0,0x612000690ed8)
freed by thread T0 here:
    #0 0x7f156daae627 in free (/lib64/libasan.so.6+0xae627)
    #1 0x4a40ca in dns_transaction_free ../src/resolve/resolved-dns-transaction.c:161
    #2 0x4a4628 in dns_transaction_gc ../src/resolve/resolved-dns-transaction.c:180
    #3 0x43a930 in dns_query_candidate_stop ../src/resolve/resolved-dns-query.c:56
    #4 0x43eaec in dns_query_stop ../src/resolve/resolved-dns-query.c:354
    #5 0x44389a in dns_query_complete ../src/resolve/resolved-dns-query.c:588
    #6 0x448bcc in dns_query_accept ../src/resolve/resolved-dns-query.c:925
    #7 0x448f6b in dns_query_ready ../src/resolve/resolved-dns-query.c:957
    #8 0x43e7db in dns_query_candidate_notify ../src/resolve/resolved-dns-query.c:340
    #9 0x4a9b08 in dns_transaction_complete ../src/resolve/resolved-dns-transaction.c:436
    #10 0x4b1a94 in dns_transaction_process_dnssec ../src/resolve/resolved-dns-transaction.c:975
    #11 0x4b600f in dns_transaction_process_reply ../src/resolve/resolved-dns-transaction.c:1398
    #12 0x539567 in on_mdns_packet ../src/resolve/resolved-mdns.c:418
    #11 0x7f156c9f54c0  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0xff54c0)
    #12 0x7f156c9f59d7  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0xff59d7)
    #13 0x7f156c9f8838  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0xff8838)
    #14 0x7f156c9f89d2  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0xff89d2)
    #15 0x7f156c9fc0d3  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0xffc0d3)
    #16 0x7f156cbb40a7  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11b40a7)
    #17 0x7f156cbbc95c  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11bc95c)
    #18 0x7f156cbbdac0  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11bdac0)
    #19 0x7f156cbbde41  (/home/vagrant/systemd/build/src/shared/libsystemd-shared-251.so+0x11bde41)
    #20 0x553402 in run ../src/resolve/resolved.c:92
    #21 0x55369c in main ../src/resolve/resolved.c:99
    #22 0x7f156a64043f in __libc_start_call_main (/lib64/libc.so.6+0x4043f)

SUMMARY: AddressSanitizer: heap-use-after-free ../src/resolve/resolved-mdns.c:413 in on_mdns_packet
Shadow bytes around the buggy address:
  0x0c24800ca180: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c24800ca190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c24800ca1a0: 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa
  0x0c24800ca1b0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c24800ca1c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c24800ca1d0: fd fd fd fd fd[fd]fd fd fd fd fd fa fa fa fa fa
  0x0c24800ca1e0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c24800ca1f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c24800ca200: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
  0x0c24800ca210: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c24800ca220: 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
  Shadow gap:              cc
==983858==ABORTING

Activity

  1. added
    bug 🐛
    on Jun 30, 2022
  2. evverx commented on Jul 1, 2022

    @evverx
    ContributorAuthor

    Here's a better backtrace:

    Jul 01 02:17:43 C systemd-resolved[58]: Received mdns UDP packet of size 176, ifindex=2, ttl=255, fragsize=0, sender=192.168.74.65, destination=224.0.0.251
    Jul 01 02:17:43 C systemd-resolved[58]: Got mDNS reply packet
    Jul 01 02:17:43 C systemd-resolved[58]: Checking for conflicts...
    Jul 01 02:17:43 C systemd-resolved[58]: Processing incoming packet of size 176 on transaction 5760 (rcode=SUCCESS).
    Jul 01 02:17:43 C systemd-resolved[58]: Regular transaction 5760 for <H._qotd._tcp.local IN TXT> on scope mdns on host0/INET now complete with <success> from network (unsigned; non-confidential).
    Jul 01 02:17:43 C systemd-resolved[58]: Freeing transaction 7262.
    Jul 01 02:17:43 C systemd-resolved[58]: Freeing transaction 18451.
    Jul 01 02:17:43 C systemd-resolved[58]: Freeing transaction 24385.
    Jul 01 02:17:43 C systemd-resolved[58]: Looking up RR for H.local IN A.
    Jul 01 02:17:43 C systemd-resolved[58]: Looking up RR for H.local IN AAAA.
    Jul 01 02:17:43 C systemd-resolved[58]: Positive cache hit for H.local IN A
    Jul 01 02:17:43 C systemd-resolved[58]: Regular transaction 47315 for <H.local IN A> on scope mdns on host0/INET now complete with <success> from cache (unsigned; non-confidential).
    Jul 01 02:17:43 C systemd-resolved[58]: Positive cache hit for H.local IN AAAA
    Jul 01 02:17:43 C systemd-resolved[58]: Regular transaction 12909 for <H.local IN AAAA> on scope mdns on host0/INET6 now complete with <success> from cache (unsigned; non-confidential).
    Jul 01 02:17:43 C systemd-resolved[58]: Freeing transaction 47315.
    Jul 01 02:17:43 C systemd-resolved[58]: Freeing transaction 12909.
    Jul 01 02:17:43 C systemd-resolved[58]: Sent message type=method_return sender=n/a destination=:1.4741 path=n/a interface=n/a member=n/a cookie=23657 reply_cookie=2 signature=a(qqqsa(iiay)s)aayssst error-name=n/a error-message=n/a
    Jul 01 02:17:43 C systemd-resolved[58]: Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RemoveMatch cookie=23658 reply_cookie=0 signature=s error-name=n/a error-message=n/a
    Jul 01 02:17:43 C systemd-resolved[58]: Freeing transaction 5760.
    Jul 01 02:17:43 C systemd-resolved[58]: READ of size 8 at 0x61200156a928 thread T0
    Jul 01 02:17:43 C systemd-resolved[58]: ==58==ERROR: AddressSanitizer: heap-use-after-free on address 0x61200156a928 at pc 0x000000539601 bp 0x7ffeb2ec9fd0 sp 0x7ffeb2ec9fc8
    Jul 01 02:17:44 C systemd-resolved[58]:     #0 0x539600 in on_mdns_packet ../src/resolve/resolved-mdns.c:413
    Jul 01 02:17:44 C systemd-resolved[58]:     #1 0x7f33227b40a7 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3593
    Jul 01 02:17:44 C systemd-resolved[58]:     #2 0x7f33227bc95c in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:4177
    Jul 01 02:17:44 C systemd-resolved[58]:     #3 0x7f33227bdac0 in sd_event_run ../src/libsystemd/sd-event/sd-event.c:4238
    Jul 01 02:17:44 C systemd-resolved[58]:     #4 0x7f33227bde41 in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:4259
    Jul 01 02:17:44 C systemd-resolved[58]:     #5 0x553402 in run ../src/resolve/resolved.c:92
    Jul 01 02:17:44 C systemd-resolved[58]:     #6 0x55369c in main ../src/resolve/resolved.c:99
    Jul 01 02:17:44 C systemd-resolved[58]:     #7 0x7f332024043f in __libc_start_call_main (/lib64/libc.so.6+0x4043f)
    Jul 01 02:17:44 C systemd-resolved[58]:     #8 0x7f33202404ef in __libc_start_main@@GLIBC_2.34 (/lib64/libc.so.6+0x404ef)
    Jul 01 02:17:44 C systemd-resolved[58]:     #9 0x40c0a4 in _start (/usr/lib/systemd/systemd-resolved+0x40c0a4)
    Jul 01 02:17:44 C systemd-resolved[58]: 0x61200156a928 is located 232 bytes inside of 280-byte region [0x61200156a840,0x61200156a958)
    Jul 01 02:17:44 C systemd-resolved[58]: freed by thread T0 here:
    Jul 01 02:17:44 C systemd-resolved[58]:     #0 0x7f33236ae627 in free (/lib64/libasan.so.6+0xae627)
    Jul 01 02:17:44 C systemd-resolved[58]:     #1 0x4a40ca in dns_transaction_free ../src/resolve/resolved-dns-transaction.c:161
    Jul 01 02:17:44 C systemd-resolved[58]:     #2 0x4a4628 in dns_transaction_gc ../src/resolve/resolved-dns-transaction.c:180
    Jul 01 02:17:44 C systemd-resolved[58]:     #3 0x43a930 in dns_query_candidate_stop ../src/resolve/resolved-dns-query.c:56
    Jul 01 02:17:44 C systemd-resolved[58]:     #4 0x43eaec in dns_query_stop ../src/resolve/resolved-dns-query.c:354
    Jul 01 02:17:44 C systemd-resolved[58]:     #5 0x44389a in dns_query_complete ../src/resolve/resolved-dns-query.c:588
    Jul 01 02:17:44 C systemd-resolved[58]:     #6 0x448bcc in dns_query_accept ../src/resolve/resolved-dns-query.c:925
    Jul 01 02:17:44 C systemd-resolved[58]:     #7 0x448f6b in dns_query_ready ../src/resolve/resolved-dns-query.c:957
    Jul 01 02:17:44 C systemd-resolved[58]:     #8 0x43e7db in dns_query_candidate_notify ../src/resolve/resolved-dns-query.c:340
    Jul 01 02:17:44 C systemd-resolved[58]:     #9 0x4a9b08 in dns_transaction_complete ../src/resolve/resolved-dns-transaction.c:436
    Jul 01 02:17:44 C systemd-resolved[58]:     #10 0x4b1a94 in dns_transaction_process_dnssec ../src/resolve/resolved-dns-transaction.c:975
    Jul 01 02:17:44 C systemd-resolved[58]:     #11 0x4b600f in dns_transaction_process_reply ../src/resolve/resolved-dns-transaction.c:1398
    Jul 01 02:17:44 C systemd-resolved[58]:     #12 0x539567 in on_mdns_packet ../src/resolve/resolved-mdns.c:418
    Jul 01 02:17:44 C systemd-resolved[58]:     #13 0x7f33227b40a7 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3593
    Jul 01 02:17:44 C systemd-resolved[58]:     #14 0x7f33227bc95c in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:4177
    Jul 01 02:17:44 C systemd-resolved[58]:     #15 0x7f33227bdac0 in sd_event_run ../src/libsystemd/sd-event/sd-event.c:4238
    Jul 01 02:17:44 C systemd-resolved[58]:     #16 0x7f33227bde41 in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:4259
    Jul 01 02:17:44 C systemd-resolved[58]:     #17 0x553402 in run ../src/resolve/resolved.c:92
    Jul 01 02:17:44 C systemd-resolved[58]:     #18 0x55369c in main ../src/resolve/resolved.c:99
    Jul 01 02:17:44 C systemd-resolved[58]:     #19 0x7f332024043f in __libc_start_call_main (/lib64/libc.so.6+0x4043f)
    Jul 01 02:17:44 C systemd-resolved[58]: previously allocated by thread T0 here:
    Jul 01 02:17:44 C systemd-resolved[58]:     #0 0x7f33236ae91f in __interceptor_malloc (/lib64/libasan.so.6+0xae91f)
    Jul 01 02:17:44 C systemd-resolved[58]:     #1 0x49ebc6 in malloc_multiply ../src/basic/alloc-util.h:104
    Jul 01 02:17:44 C systemd-resolved[58]:     #2 0x4a555e in dns_transaction_new ../src/resolve/resolved-dns-transaction.c:271
    Jul 01 02:17:44 C systemd-resolved[58]:     #3 0x43c6db in dns_query_candidate_add_transaction ../src/resolve/resolved-dns-query.c:137
    Jul 01 02:17:44 C systemd-resolved[58]:     #4 0x43e28d in dns_query_candidate_setup_transactions ../src/resolve/resolved-dns-query.c:286
    Jul 01 02:17:44 C systemd-resolved[58]:     #5 0x443d0a in dns_query_add_candidate ../src/resolve/resolved-dns-query.c:624
    Jul 01 02:17:44 C systemd-resolved[58]:     #6 0x445b2d in dns_query_go ../src/resolve/resolved-dns-query.c:771
    Jul 01 02:17:44 C systemd-resolved[58]:     #7 0x41c7cf in bus_method_resolve_service ../src/resolve/resolved-bus.c:1377
    Jul 01 02:17:44 C systemd-resolved[58]:     #8 0x7f332258b373 in method_callbacks_run ../src/libsystemd/sd-bus/bus-objects.c:406
    Jul 01 02:17:44 C systemd-resolved[58]:     #9 0x7f3322594b73 in object_find_and_run ../src/libsystemd/sd-bus/bus-objects.c:1310
    Jul 01 02:17:44 C systemd-resolved[58]:     #10 0x7f3322596235 in bus_process_object ../src/libsystemd/sd-bus/bus-objects.c:1430
    Jul 01 02:17:44 C systemd-resolved[58]:     #11 0x7f33225f54c0 in process_message ../src/libsystemd/sd-bus/sd-bus.c:2962
    Jul 01 02:17:44 C systemd-resolved[58]:     #12 0x7f33225f59d7 in process_running ../src/libsystemd/sd-bus/sd-bus.c:3004
    Jul 01 02:17:44 C systemd-resolved[58]:     #13 0x7f33225f8838 in bus_process_internal ../src/libsystemd/sd-bus/sd-bus.c:3224
    Jul 01 02:17:44 C systemd-resolved[58]:     #14 0x7f33225f89d2 in sd_bus_process ../src/libsystemd/sd-bus/sd-bus.c:3251
    Jul 01 02:17:44 C systemd-resolved[58]:     #15 0x7f33225fc0d3 in io_callback ../src/libsystemd/sd-bus/sd-bus.c:3602
    Jul 01 02:17:44 C systemd-resolved[58]:     #16 0x7f33227b40a7 in source_dispatch ../src/libsystemd/sd-event/sd-event.c:3593
    Jul 01 02:17:44 C systemd-resolved[58]:     #17 0x7f33227bc95c in sd_event_dispatch ../src/libsystemd/sd-event/sd-event.c:4177
    Jul 01 02:17:44 C systemd-resolved[58]:     #18 0x7f33227bdac0 in sd_event_run ../src/libsystemd/sd-event/sd-event.c:4238
    Jul 01 02:17:44 C systemd-resolved[58]:     #19 0x7f33227bde41 in sd_event_loop ../src/libsystemd/sd-event/sd-event.c:4259
    Jul 01 02:17:44 C systemd-resolved[58]:     #20 0x553402 in run ../src/resolve/resolved.c:92
    Jul 01 02:17:44 C systemd-resolved[58]:     #21 0x55369c in main ../src/resolve/resolved.c:99
    Jul 01 02:17:44 C systemd-resolved[58]:     #22 0x7f332024043f in __libc_start_call_main (/lib64/libc.so.6+0x4043f)
    Jul 01 02:17:44 C systemd-resolved[58]: SUMMARY: AddressSanitizer: heap-use-after-free ../src/resolve/resolved-mdns.c:413 in on_mdns_packet
    Jul 01 02:17:44 C systemd-resolved[58]: Shadow bytes around the buggy address:
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a54d0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a54e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a54f0: fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5500: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5510: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]: =>0x0c24802a5520: fd fd fd fd fd[fd]fd fd fd fd fd fa fa fa fa fa
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5530: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5540: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5550: fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5560: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]:   0x0c24802a5570: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Jul 01 02:17:44 C systemd-resolved[58]: Shadow byte legend (one shadow byte represents 8 application bytes):
    Jul 01 02:17:44 C systemd-resolved[58]:   Addressable:           00
    Jul 01 02:17:44 C systemd-resolved[58]:   Partially addressable: 01 02 03 04 05 06 07
    Jul 01 02:17:44 C systemd-resolved[58]:   Heap left redzone:       fa
    Jul 01 02:17:44 C systemd-resolved[58]:   Freed heap region:       fd
    Jul 01 02:17:44 C systemd-resolved[58]:   Stack left redzone:      f1
    Jul 01 02:17:44 C systemd-resolved[58]:   Stack mid redzone:       f2
    Jul 01 02:17:44 C systemd-resolved[58]:   Stack right redzone:     f3
    Jul 01 02:17:44 C systemd-resolved[58]:   Stack after return:      f5
    Jul 01 02:17:44 C systemd-resolved[58]:   Stack use after scope:   f8
    Jul 01 02:17:44 C systemd-resolved[58]:   Global redzone:          f9
    Jul 01 02:17:44 C systemd-resolved[58]:   Global init order:       f6
    Jul 01 02:17:44 C systemd-resolved[58]:   Poisoned by user:        f7
    Jul 01 02:17:44 C systemd-resolved[58]:   Container overflow:      fc
    Jul 01 02:17:44 C systemd-resolved[58]:   Array cookie:            ac
    Jul 01 02:17:44 C systemd-resolved[58]:   Intra object redzone:    bb
    Jul 01 02:17:44 C systemd-resolved[58]:   ASan internal:           fe
    Jul 01 02:17:44 C systemd-resolved[58]:   Left alloca redzone:     ca
    Jul 01 02:17:44 C systemd-resolved[58]:   Right alloca redzone:    cb
    Jul 01 02:17:44 C systemd-resolved[58]:   Shadow gap:              cc
    Jul 01 02:17:44 C systemd-resolved[58]: ==58==ABORTING
  3. changed the title [-]There is a heap-use-after-free in resolved[/-] [+]There is a heap-use-after-free in resolved in on_mdns_packet[/+] on Jul 4, 2022
  4. added this to the v252 milestone on Jul 4, 2022
  5. added a commit that references this issue on Aug 23, 2022
  6. added a commit that references this issue on Jan 27, 2023
  7. added a commit that references this issue on Nov 1, 2023
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions