Skip to content

resolve: on_transaction_stream_error() may free multiple transactions - #30931

Merged
bluca merged 1 commit into
systemd:mainfrom
yuwata:resolve-transaction-stream-error
Jan 15, 2024
Merged

bluca merged 1 commit into
systemd:mainfrom
yuwata:resolve-transaction-stream-error

Conversation

@yuwata

@yuwata yuwata commented Jan 14, 2024 •

Copy link
Copy Markdown
Member

Fixes #30928.

@github-actions github-actions Bot added resolve please-review PR is ready for (re-)review by a maintainer labels Jan 14, 2024
@yuwata

yuwata commented Jan 14, 2024

Copy link
Copy Markdown
Member Author

cc @evverx

@evverx

evverx commented Jan 14, 2024

Copy link
Copy Markdown
Contributor

Fixes #30298

Looks like it should be #30928.

I'll try to run it once I'm not far from the containers where those things are run.

@evverx

evverx commented Jan 14, 2024

Copy link
Copy Markdown
Contributor

There is still a UAF with this patch applied as far as I can see:

=================================================================
==345469==ERROR: AddressSanitizer: heap-use-after-free on address 0x61200003a6c0 at pc 0x00000064d301 bp 0x7ffc255232c0 sp 0x7ffc255232b8
READ of size 8 at 0x61200003a6c0 thread T0
    #0 0x64d300 in on_transaction_stream_error /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:577:24
    #1 0x64c5d5 in on_stream_complete /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:670:25
    #2 0x5d274c in dns_stream_complete /home/vagrant/systemd/build/../src/resolve/resolved-dns-stream.c:84:17
    #3 0x5c972c in on_stream_io /home/vagrant/systemd/build/../src/resolve/resolved-dns-stream.c:310:32
    #4 0x7f9ec3e9658c in source_dispatch /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4187:21
    #5 0x7f9ec3e945b4 in sd_event_dispatch /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4808:21
    #6 0x7f9ec3e9a0ad in sd_event_run /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4869:21
    #7 0x7f9ec3e9b039 in sd_event_loop /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4891:21
    #8 0x75dc28 in run /home/vagrant/systemd/build/../src/resolve/resolved.c:92:13
    #9 0x75bc6d in main /home/vagrant/systemd/build/../src/resolve/resolved.c:99:1
    #10 0x7f9ec1e49b89 in __libc_start_call_main (/lib64/libc.so.6+0x27b89) (BuildId: f888be5f5e7d58e04cabb8c675c7ab94e77dd68c)
    #11 0x7f9ec1e49c4a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c4a) (BuildId: f888be5f5e7d58e04cabb8c675c7ab94e77dd68c)
    #12 0x427254 in _start (/home/vagrant/systemd/build/systemd-resolved+0x427254) (BuildId: 078b054ea81a78a117b442869cb124e2ba842cc2)
0x61200003a6c0 is located 0 bytes inside of 296-byte region [0x61200003a6c0,0x61200003a7e8)
freed by thread T0 here:
    #0 0x4c1bfa in free (/home/vagrant/systemd/build/systemd-resolved+0x4c1bfa) (BuildId: 078b054ea81a78a117b442869cb124e2ba842cc2)
    #1 0x609547 in dns_transaction_free /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:171:16
    #2 0x60cea3 in dns_transaction_gc /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:190:24
    #3 0x60c8ce in dns_transaction_flush_dnssec_transactions /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:48:17
    #4 0x6092bc in dns_transaction_free /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:164:9
    #5 0x60cea3 in dns_transaction_gc /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:190:24
    #6 0x614996 in dns_transaction_complete /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:460:9
    #7 0x6502cc in dns_transaction_dnssec_ready /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:960:9
    #8 0x62cda9 in dns_transaction_process_dnssec /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:970:13
    #9 0x61567f in dns_transaction_notify /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:2780:17
    #10 0x614661 in dns_transaction_complete /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:456:17
    #11 0x6320f1 in dns_transaction_prepare /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:1724:17
    #12 0x62dcde in dns_transaction_go /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:2117:13
    #13 0x6265cb in dns_transaction_retry /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:526:13
    #14 0x64d40f in on_transaction_stream_error /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:585:25
    #15 0x64c5d5 in on_stream_complete /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:670:25
    #16 0x5d274c in dns_stream_complete /home/vagrant/systemd/build/../src/resolve/resolved-dns-stream.c:84:17
    #17 0x5c972c in on_stream_io /home/vagrant/systemd/build/../src/resolve/resolved-dns-stream.c:310:32
    #18 0x7f9ec3e9658c in source_dispatch /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4187:21
    #19 0x7f9ec3e945b4 in sd_event_dispatch /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4808:21
    #20 0x7f9ec3e9a0ad in sd_event_run /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4869:21
    #21 0x7f9ec3e9b039 in sd_event_loop /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4891:21
    #22 0x75dc28 in run /home/vagrant/systemd/build/../src/resolve/resolved.c:92:13
    #23 0x75bc6d in main /home/vagrant/systemd/build/../src/resolve/resolved.c:99:1
    #24 0x7f9ec1e49b89 in __libc_start_call_main (/lib64/libc.so.6+0x27b89) (BuildId: f888be5f5e7d58e04cabb8c675c7ab94e77dd68c)
    #25 0x7f9ec1e49c4a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c4a) (BuildId: f888be5f5e7d58e04cabb8c675c7ab94e77dd68c)
    #26 0x427254 in _start (/home/vagrant/systemd/build/systemd-resolved+0x427254) (BuildId: 078b054ea81a78a117b442869cb124e2ba842cc2)
previously allocated by thread T0 here:
    #0 0x4c1ea2 in malloc (/home/vagrant/systemd/build/systemd-resolved+0x4c1ea2) (BuildId: 078b054ea81a78a117b442869cb124e2ba842cc2)
    #1 0x611131 in malloc_multiply /home/vagrant/systemd/build/../src/basic/alloc-util.h:119:16
    #2 0x60e2aa in dns_transaction_new /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:281:13
    #3 0x659ee7 in dns_transaction_add_dnssec_transaction /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:2276:21
    #4 0x63a669 in dns_transaction_request_dnssec_rr /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:2339:13
    #5 0x629fd6 in dns_transaction_request_dnssec_keys /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:2616:29
    #6 0x61e912 in dns_transaction_process_reply /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:1437:13
    #7 0x64ce0a in dns_transaction_on_stream_packet /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:613:9
    #8 0x64b792 in on_stream_packet /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:686:24
    #9 0x5cf751 in on_stream_io /home/vagrant/systemd/build/../src/resolve/resolved-dns-stream.c:430:37
    #10 0x7f9ec3e9658c in source_dispatch /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4187:21
    #11 0x7f9ec3e945b4 in sd_event_dispatch /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4808:21
    #12 0x7f9ec3e9a0ad in sd_event_run /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4869:21
    #13 0x7f9ec3e9b039 in sd_event_loop /home/vagrant/systemd/build/../src/libsystemd/sd-event/sd-event.c:4891:21
    #14 0x75dc28 in run /home/vagrant/systemd/build/../src/resolve/resolved.c:92:13
    #15 0x75bc6d in main /home/vagrant/systemd/build/../src/resolve/resolved.c:99:1
    #16 0x7f9ec1e49b89 in __libc_start_call_main (/lib64/libc.so.6+0x27b89) (BuildId: f888be5f5e7d58e04cabb8c675c7ab94e77dd68c)
    #17 0x7f9ec1e49c4a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c4a) (BuildId: f888be5f5e7d58e04cabb8c675c7ab94e77dd68c)
    #18 0x427254 in _start (/home/vagrant/systemd/build/systemd-resolved+0x427254) (BuildId: 078b054ea81a78a117b442869cb124e2ba842cc2)
SUMMARY: AddressSanitizer: heap-use-after-free /home/vagrant/systemd/build/../src/resolve/resolved-dns-transaction.c:577:24 in on_transaction_stream_error
Shadow bytes around the buggy address:
  0x61200003a400: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x61200003a480: fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa
  0x61200003a500: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x61200003a580: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x61200003a600: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
=>0x61200003a680: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd
  0x61200003a700: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x61200003a780: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
  0x61200003a800: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x61200003a880: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x61200003a900: fd fd fd fd fd fd fd fd fd fd fd fd fd 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
==345469==ABORTING

@yuwata
yuwata force-pushed the resolve-transaction-stream-error branch from 91f7d3f to 1572c28 Compare January 14, 2024 04:18
@yuwata

yuwata commented Jan 14, 2024

Copy link
Copy Markdown
Member Author

@evverx Thank you for testing this so quickly. Updated. Could you test again? Or, please let me know how to reproduce the issue.

@evverx

evverx commented Jan 15, 2024 •

Copy link
Copy Markdown
Contributor

@yuwata I can no longer reproduce the UAF.

I think it would be nice to add a test case but unfortunately I'm not sure how to integrate it into the testsuite. Unlike, say, the crashes caused by EDEs triggered by single packets here it's necessary to get resolved to switch to tcp, send a few packets and then stop responding and all that should be combined with DNSSEC. I've been trying to figure out how that sort of tests can be added to the CI but it hasn't worked out yet :-)

@bluca
bluca merged commit 3db1e6a into systemd:main Jan 15, 2024
@github-actions github-actions Bot removed the please-review PR is ready for (re-)review by a maintainer label Jan 15, 2024
@yuwata
yuwata deleted the resolve-transaction-stream-error branch January 15, 2024 10:40
@yuwata

yuwata commented Jan 15, 2024

Copy link
Copy Markdown
Member Author

@mrc0mmand Do you have any idea about adding a testcase about the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

resolved: Invalid read of size 8 in on_stream_complete

3 participants