Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report:SmartDNS crashes due to misaligned memory access in fast_ping.c. #1779

Open
dqp10515 opened this issue Jul 17, 2024 · 3 comments

Comments

@dqp10515
Copy link

Issue Description

SmartDNS crashes due to misaligned memory access in fast_ping.c.

System Information

  • SmartDNS Version: clone and built on 20240717 with master branch

Steps to Reproduce

  1. Compile SmartDNS with ASan:
    CC=clang CFLAGS="-g -fsanitize=address,undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address,undefined" make clean
    CC=clang CFLAGS="-g -fsanitize=address,undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address,undefined" make all -j
    cd smartdns/src
    CC=clang CFLAGS="-g -fsanitize=address,undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address,undefined" make clean
    CC=clang CFLAGS="-g -fsanitize=address,undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address,undefined" make all -j
    cd smartdns/test
    CC=clang CFLAGS="-g -fsanitize=address,undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address,undefined" make clean
    CC=clang CFLAGS="-g -fsanitize=address,undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address,undefined" make all V=1 -j
  2. Start SmartDNS using the following command:
smartdns/src/smartdns -c smartdns/etc/smartdns/smartdns.conf -f -x
  1. Observe the crash after some DNS requests are processed.

Logs

server side:

[2024-07-17 13:24:51,990][NOTICE][       smartdns.c:558 ] smartdns starting...(Copyright (C) Nick Peng <pymumu@gmail.com>, build: 1.20240714-2229 (Release46-5-g550d455-dirty))
[2024-07-17 13:24:51,993][ INFO][     dns_server.c:9013] bind ip :5555, type 0
[2024-07-17 13:24:51,993][ INFO][     dns_server.c:9332] IPV6 is not ready or speed check is disabled, disable IPV6 features
[2024-07-17 13:24:51,994][ INFO][     dns_server.c:9219] auto enable cache persist.
[2024-07-17 13:24:51,994][ INFO][      dns_cache.c:758 ] load cache file /var/cache/smartdns/smartdns.cache, total 7 records
[2024-07-17 13:24:51,994][ INFO][     dns_client.c:1273] add server 8.8.8.8:53, type: udp
[2024-07-17 13:24:52,017][ INFO][     dns_client.c:1273] add server 1.1.1.1:853, type: tls
[2024-07-17 13:24:52,021][ INFO][     dns_server.c:4503] result: www.baidu.com, client: 127.0.0.1, qtype: 1, id: 57399, group: default, time: 0ms
[2024-07-17 13:24:52,021][ INFO][     dns_client.c:4253] request: www.baidu.com, qtype: 1, id: 50380, group: default
[2024-07-17 13:24:52,029][FATAL][       smartdns.c:679 ] process exit with signal 6, code = -6, errno = 0, pid = 1116534, self = 1116534, pc = 0x2, addr = 0x110976, build(Jul 14 2024 22:29:30 x86_64)
[2024-07-17 13:24:52,029][FATAL][           util.c:1857] Stack:
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #01: 0x67215c print_stack() from smartdns/src/smartdns+0x27215c
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #02: 0x76c8fb () from smartdns/src/smartdns+0x36c8fb
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #03: 0x7fea052f83c0 () from /lib/x86_64-linux-gnu/libpthread.so.0+0x153c0
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #04: 0x7fea04fba18b gsignal() from /lib/x86_64-linux-gnu/libc.so.6+0x4618b
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #05: 0x7fea04f99859 abort() from /lib/x86_64-linux-gnu/libc.so.6+0x25859
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #06: 0x52058f () from smartdns/src/smartdns+0x12058f
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #07: 0x51d9fc () from smartdns/src/smartdns+0x11d9fc
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #08: 0x529d91 () from smartdns/src/smartdns+0x129d91
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #09: 0x52d16a () from smartdns/src/smartdns+0x12d16a
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #10: 0x52d525 __ubsan_handle_type_mismatch_v1() from smartdns/src/smartdns+0x12d525
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #11: 0x606864 () from smartdns/src/smartdns+0x206864
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #12: 0x604e00 () from smartdns/src/smartdns+0x204e00
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #13: 0x60067d () from smartdns/src/smartdns+0x20067d
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #14: 0x5fe6ab () from smartdns/src/smartdns+0x1fe6ab
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #15: 0x5ec319 () from smartdns/src/smartdns+0x1ec319
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #16: 0x7fea052ec609 () from /lib/x86_64-linux-gnu/libpthread.so.0+0x9609
[2024-07-17 13:24:52,029][FATAL][           util.c:1869] #17: 0x7fea05096293 clone() from /lib/x86_64-linux-gnu/libc.so.6+0x122293
[2024-07-17 13:24:52,030][ INFO][     dns_server.c:4503] result: baidu.com, client: 127.0.0.1, qtype: 28, id: 54161, group: default, time: 1ms
[2024-07-17 13:24:52,030][ INFO][     dns_client.c:4253] request: baidu.com, qtype: 28, id: 39730, group: default
[2024-07-17 13:24:52,038][ INFO][     dns_client.c:4253] request: www.baidu.com, qtype: 5, id: 11505, group: default
[2024-07-17 13:24:52,039][ INFO][     dns_server.c:4503] result: www.baidu.com, client: 127.0.0.1, qtype: 5, id: 29224, group: default, time: 1ms
[2024-07-17 13:24:52,047][ INFO][     dns_client.c:4253] request: www.baidu.com, qtype: 14, id: 55488, group: default
[2024-07-17 13:24:52,048][ INFO][     dns_server.c:4503] result: www.baidu.com, client: 127.0.0.1, qtype: 14, id: 6726, group: default, time: 1ms
[2024-07-17 13:24:52,056][ INFO][     dns_client.c:4253] request: www.baidu.com, qtype: 9, id: 36080, group: default
[2024-07-17 13:24:52,056][ INFO][     dns_server.c:4503] result: www.baidu.com, client: 127.0.0.1, qtype: 9, id: 2259, group: default, time: 1ms
[2024-07-17 13:24:52,065][ INFO][     dns_server.c:4503] result: ad.test.com, client: 127.0.0.1, qtype: 1, id: 24687, group: default, time: 0ms
[2024-07-17 13:24:52,065][ INFO][     dns_client.c:4253] request: ad.test.com, qtype: 1, id: 63765, group: default
[2024-07-17 13:24:52,073][ INFO][     dns_client.c:4253] request: test.com, qtype: 2, id: 16444, group: default
[2024-07-17 13:24:52,074][ INFO][     dns_server.c:4503] result: test.com, client: 127.0.0.1, qtype: 2, id: 55919, group: default, time: 1ms
[2024-07-17 13:24:52,082][ INFO][     dns_server.c:4503] result: ad.test.org, client: 127.0.0.1, qtype: 1, id: 59105, group: default, time: 0ms
[2024-07-17 13:24:52,082][ INFO][     dns_client.c:4253] request: ad.test.org, qtype: 1, id: 32156, group: default
[2024-07-17 13:24:52,097][ INFO][     dns_server.c:4503] result: thekelleys.org.uk, client: 127.0.0.1, qtype: 1, id: 11398, group: default, time: 0ms
[2024-07-17 13:24:52,097][ INFO][     dns_client.c:4253] request: thekelleys.org.uk, qtype: 1, id: 5414, group: default
[2024-07-17 13:24:52,105][ INFO][     dns_client.c:4253] request: thekelleys.org.uk, qtype: 13, id: 25378, group: default
[2024-07-17 13:24:52,106][ INFO][     dns_server.c:4503] result: thekelleys.org.uk, client: 127.0.0.1, qtype: 13, id: 33162, group: default, time: 1ms
[2024-07-17 13:24:52,113][ INFO][     dns_client.c:4253] request: thekelleys.org.uk, qtype: 7, id: 34166, group: default
[2024-07-17 13:24:52,594][ INFO][     dns_server.c:1235] result: ad.test.org, qtype: 1, rtcode: 3, id: 0
[2024-07-17 13:24:52,714][ INFO][     dns_server.c:4503] result: thekelleys.org.uk, client: 127.0.0.1, qtype: 7, id: 65432, group: default, time: 600ms

ASan report:

fast_ping.c:1598:18: runtime error: member access within misaligned address 0x7fe9fe58a034 for type 'struct fast_ping_packet', which requires 8 byte alignment
0x7fe9fe58a034: note: pointer points here
  ac 11 00 05 00 00 0f 20  76 09 00 01 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
    #0 0x606863  (smartdns/src/smartdns+0x606863)
    #1 0x604dff  (smartdns/src/smartdns+0x604dff)
    #2 0x60067c  (smartdns/src/smartdns+0x60067c)
    #3 0x5fe6aa  (smartdns/src/smartdns+0x5fe6aa)
    #4 0x5ec318  (smartdns/src/smartdns+0x5ec318)
    #5 0x7fea052ec608  (/lib/x86_64-linux-gnu/libpthread.so.0+0x9608)
    #6 0x7fea05096292  (/lib/x86_64-linux-gnu/libc.so.6+0x122292)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior fast_ping.c:1598:18 in 
@pymumu
Copy link
Owner

pymumu commented Jul 18, 2024

The smartdns code currently does not strictly adhere to byte alignment, which may lead to degraded performance or exceptions on certain architectures during runtime.

In what situations is byte alignment required?

@pymumu
Copy link
Owner

pymumu commented Jul 20, 2024

Please check the latest code.

@dqp10515
Copy link
Author

Thank you for updating the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants