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

AddressSanitizer: stack-overflow from getAddress inside a fiber #4874

Open
zorael opened this issue Mar 11, 2025 · 4 comments
Open

AddressSanitizer: stack-overflow from getAddress inside a fiber #4874

zorael opened this issue Mar 11, 2025 · 4 comments
Labels
sanitizers ASan, libFuzzer, ...

Comments

@zorael
Copy link

zorael commented Mar 11, 2025

EndeavourOS/Arch x86_64, ldc 1.40.0 from repos and from the install.sh script.

If I compile my project with -fsanitize=address it crashes at runtime with a stack overflow.

Reduced;

import std;
import core.thread;

void main()
{
    void dg()
    {
        getAddress("irc.libera.chat");
    }

    auto fiber = new Fiber(&dg);
    fiber.call();
}
$ ldc -fsanitize=address -run test.d
AddressSanitizer:DEADLYSIGNAL
=================================================================
==38083==ERROR: AddressSanitizer: stack-overflow on address 0x7d4953bd3d48 (pc 0x7d4954248cd3 bp 0x7d4953bd4590 sp 0x7d4953bd3d50 T0)
#0 0x7d4954248cd3 in __libc_ns_samename /usr/src/debug/glibc/glibc/resolv/ns_samename.c:30:7
#1 0x7d495424bdc4 in __libc_res_nameinquery /usr/src/debug/glibc/glibc/resolv/res_nameinquery.c:111:14
#2 0x7d495424beef in __GI___libc_res_queriesmatch /usr/src/debug/glibc/glibc/resolv/res_queriesmatch.c:125:12
#3 0x7d495424e92b in send_dg /usr/src/debug/glibc/glibc/resolv/res_send.c:1223:7
#4 0x7d495424f433 in __res_context_send /usr/src/debug/glibc/glibc/resolv/res_send.c:373:8
#5 0x7d495424c163 in __res_context_query /usr/src/debug/glibc/glibc/resolv/res_query.c:218:10
#6 0x7d495424cf36 in __res_context_querydomain /usr/src/debug/glibc/glibc/resolv/res_query.c:629:9
#7 0x7d495424cf36 in __res_context_search /usr/src/debug/glibc/glibc/resolv/res_query.c:385:9
#8 0x7d4954244c90 in __GI__nss_dns_gethostbyname4_r /usr/src/debug/glibc/glibc/resolv/nss_dns/dns-host.c:418:11
#9 0x7d495425d711 in get_nss_addresses /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:652:17
#10 0x7d495425d711 in gaih_inet /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:1185:17
#11 0x7d495425d711 in getaddrinfo /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:2390:12
#12 0x5d3b0642d199 in getaddrinfo.part.0 asan_interceptors.cpp.o
#13 0x7d49545d4461 in _D3std6socket18getAddressInfoImplFMAxaMQePS4core3sys5posix5netdb8addrinfoZASQCwQCv11AddressInfo (/usr/lib/libphobos2-ldc-shared.so.110+0x1d4461) (BuildId: 99b0a4bdd1c37b27fb8336d379aedecc33d04375)
#14 0x7d49545d4b2d in _D3std6socket10getAddressFNfMAxaMQeZACQBkQBj7Address (/usr/lib/libphobos2-ldc-shared.so.110+0x1d4b2d) (BuildId: 99b0a4bdd1c37b27fb8336d379aedecc33d04375)
#15 0x5d3b063482eb in _D4test4mainFZ2dgMFNfZv (/tmp/test-6842be+0x82eb) (BuildId: 8e3e05de8c6c55b75b2cd6406dd293a490acba44)
#16 0x7d4954965642 in fiber_entryPoint (/usr/lib/libdruntime-ldc-shared.so.110+0xd7642) (BuildId: c4197bdbc13200c6ab1e7c45a0e639610fd85b3f)

SUMMARY: AddressSanitizer: stack-overflow /usr/src/debug/glibc/glibc/resolv/ns_samename.c:30:7 in __libc_ns_samename
==38083==ABORTING
Error: /tmp/test-6842be failed with status: 1
@JohanEngelen
Copy link
Member

Can you try running with ASAN_OPTIONS=detect_stack_use_after_return=0? (compile to binary and then run the binary with that environment variable set)
https://forum.dlang.org/post/kfynyurrefxcbohedhtb@forum.dlang.org

@JohanEngelen JohanEngelen added the sanitizers ASan, libFuzzer, ... label Mar 11, 2025
@zorael
Copy link
Author

zorael commented Mar 11, 2025

It seems to give the same error.

$ ASAN_OPTIONS=detect_stack_use_after_return=0 ldc -fsanitize=address -run test.d
AddressSanitizer:DEADLYSIGNAL
=================================================================
==370888==ERROR: AddressSanitizer: stack-overflow on address 0x7e80f2996d48 (pc 0x7e80f3048cd3 bp 0x7e80f2997590 sp 0x7e80f2996d50 T0)
#0 0x7e80f3048cd3 in __libc_ns_samename /usr/src/debug/glibc/glibc/resolv/ns_samename.c:30:7
#1 0x7e80f304bdc4 in __libc_res_nameinquery /usr/src/debug/glibc/glibc/resolv/res_nameinquery.c:111:14
#2 0x7e80f304beef in __GI___libc_res_queriesmatch /usr/src/debug/glibc/glibc/resolv/res_queriesmatch.c:125:12
#3 0x7e80f304e92b in send_dg /usr/src/debug/glibc/glibc/resolv/res_send.c:1223:7
#4 0x7e80f304f433 in __res_context_send /usr/src/debug/glibc/glibc/resolv/res_send.c:373:8
#5 0x7e80f304c163 in __res_context_query /usr/src/debug/glibc/glibc/resolv/res_query.c:218:10
#6 0x7e80f304cf36 in __res_context_querydomain /usr/src/debug/glibc/glibc/resolv/res_query.c:629:9
#7 0x7e80f304cf36 in __res_context_search /usr/src/debug/glibc/glibc/resolv/res_query.c:385:9
#8 0x7e80f3044c90 in __GI__nss_dns_gethostbyname4_r /usr/src/debug/glibc/glibc/resolv/nss_dns/dns-host.c:418:11
#9 0x7e80f305d711 in get_nss_addresses /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:652:17
#10 0x7e80f305d711 in gaih_inet /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:1185:17
#11 0x7e80f305d711 in getaddrinfo /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:2390:12
#12 0x569090cdb199 in getaddrinfo.part.0 asan_interceptors.cpp.o
#13 0x7e80f33d4461 in _D3std6socket18getAddressInfoImplFMAxaMQePS4core3sys5posix5netdb8addrinfoZASQCwQCv11AddressInfo (/usr/lib/libphobos2-ldc-shared.so.110+0x1d4461) (BuildId: 99b0a4bdd1c37b27fb8336d379aedecc33d04375)
#14 0x7e80f33d4b2d in _D3std6socket10getAddressFNfMAxaMQeZACQBkQBj7Address (/usr/lib/libphobos2-ldc-shared.so.110+0x1d4b2d) (BuildId: 99b0a4bdd1c37b27fb8336d379aedecc33d04375)
#15 0x569090bf62eb in _D4test4mainFZ2dgMFNfZv (/tmp/test-009e06+0x82eb) (BuildId: 8e3e05de8c6c55b75b2cd6406dd293a490acba44)
#16 0x7e80f3726642 in fiber_entryPoint (/usr/lib/libdruntime-ldc-shared.so.110+0xd7642) (BuildId: c4197bdbc13200c6ab1e7c45a0e639610fd85b3f)

SUMMARY: AddressSanitizer: stack-overflow /usr/src/debug/glibc/glibc/resolv/ns_samename.c:30:7 in __libc_ns_samename
==370888==ABORTING
Error: /tmp/test-009e06 failed with status: 1

@JohanEngelen
Copy link
Member

It seems to give the same error.

$ ASAN_OPTIONS=detect_stack_use_after_return=0 ldc -fsanitize=address -run test.d

Just to be sure, can you compile to a binary, and then run the binary?

$ ldc -fsanitize=address test.d -o test
$ ASAN_OPTIONS=detect_stack_use_after_return=0 test

@zorael
Copy link
Author

zorael commented Mar 11, 2025

Sure:

$ ldc -fsanitize=address test.d
$ ASAN_OPTIONS=detect_stack_use_after_return=0 ./test
AddressSanitizer:DEADLYSIGNAL
=================================================================
==395979==ERROR: AddressSanitizer: stack-overflow on address 0x77a708855d48 (pc 0x77a70810bcd3 bp 0x77a708856590 sp 0x77a708855d50 T0)
#0 0x77a70810bcd3 in __libc_ns_samename /usr/src/debug/glibc/glibc/resolv/ns_samename.c:30:7
#1 0x77a70810edc4 in __libc_res_nameinquery /usr/src/debug/glibc/glibc/resolv/res_nameinquery.c:111:14
#2 0x77a70810eeef in __GI___libc_res_queriesmatch /usr/src/debug/glibc/glibc/resolv/res_queriesmatch.c:125:12
#3 0x77a70811192b in send_dg /usr/src/debug/glibc/glibc/resolv/res_send.c:1223:7
#4 0x77a708112433 in __res_context_send /usr/src/debug/glibc/glibc/resolv/res_send.c:373:8
#5 0x77a70810f163 in __res_context_query /usr/src/debug/glibc/glibc/resolv/res_query.c:218:10
#6 0x77a70810ff36 in __res_context_querydomain /usr/src/debug/glibc/glibc/resolv/res_query.c:629:9
#7 0x77a70810ff36 in __res_context_search /usr/src/debug/glibc/glibc/resolv/res_query.c:385:9
#8 0x77a708107c90 in __GI__nss_dns_gethostbyname4_r /usr/src/debug/glibc/glibc/resolv/nss_dns/dns-host.c:418:11
#9 0x77a708120711 in get_nss_addresses /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:652:17
#10 0x77a708120711 in gaih_inet /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:1185:17
#11 0x77a708120711 in getaddrinfo /usr/src/debug/glibc/glibc/nss/getaddrinfo.c:2390:12
#12 0x570073ee6199 in getaddrinfo.part.0 asan_interceptors.cpp.o
#13 0x77a7085d4461 in _D3std6socket18getAddressInfoImplFMAxaMQePS4core3sys5posix5netdb8addrinfoZASQCwQCv11AddressInfo (/usr/lib/libphobos2-ldc-shared.so.110+0x1d4461) (BuildId: 99b0a4bdd1c37b27fb8336d379aedecc33d04375)
#14 0x77a7085d4b2d in _D3std6socket10getAddressFNfMAxaMQeZACQBkQBj7Address (/usr/lib/libphobos2-ldc-shared.so.110+0x1d4b2d) (BuildId: 99b0a4bdd1c37b27fb8336d379aedecc33d04375)
#15 0x570073e012eb in _D4test4mainFZ2dgMFNfZv (/tmp/test+0x82eb) (BuildId: 8e3e05de8c6c55b75b2cd6406dd293a490acba44)
#16 0x77a70839a642 in fiber_entryPoint (/usr/lib/libdruntime-ldc-shared.so.110+0xd7642) (BuildId: c4197bdbc13200c6ab1e7c45a0e639610fd85b3f)

SUMMARY: AddressSanitizer: stack-overflow /usr/src/debug/glibc/glibc/resolv/ns_samename.c:30:7 in __libc_ns_samename
==395979==ABORTING

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

No branches or pull requests

2 participants