Bug 23530 - getaddrinfo returns EAI_SYSTEM with errno = 0
Summary: getaddrinfo returns EAI_SYSTEM with errno = 0
Status: UNCONFIRMED
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-15 15:54 UTC by Arseniy Simonov
Modified: 2018-08-16 13:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arseniy Simonov 2018-08-15 15:54:50 UTC
getaddrinfo manpage for EAI_SYSTEM return code says: "Other system error, check errno for details.".
However, there is a case when errno is not set.

The case is hard to reproduce. It occurres when process reaches its limit for open file descriptors and many threads call getaddrinfo concurrently.

Expected result:
getaddrinfo returnes -11 (EAI_SYSTEM), errno is set to 24 (EMFILE)

Actual result:
getaddrinfo returnes -11 (EAI_SYSTEM), errno is set to 0

The exact place where errno is lost:

__res_context_search returnes <0, errno 24
_nss_dns_gethostbyname4_r returnes NETDB_INTERNAL, errno 0 (rewritten)
gaih_inet maps NETDB_INTERNAL to EAI_SYSTEM

Old value = 24
New value = 0
0x00007ffff5a68d75 in _nss_dns_gethostbyname4_r (name=name@entry=0x555555556b2e "google.com", pat=pat@entry=0x7ffff6e7f698, buffer=0x7ffff6e7f920 "\377\002", buflen=1024, errnop=errnop@entry=0x7ffff6e80660, herr
nop=herrnop@entry=0x7ffff6e806c4, ttlp=0x0) at nss_dns/dns-host.c:386
#0  0x00007ffff5a68d75 in _nss_dns_gethostbyname4_r (name=name@entry=0x555555556b2e "google.com", pat=pat@entry=0x7ffff6e7f698, buffer=0x7ffff6e7f920 "\377\002", buflen=1024, errnop=errnop@entry=0x7ffff6e80660, 
herrnop=herrnop@entry=0x7ffff6e806c4, ttlp=0x0) at nss_dns/dns-host.c:386
#1  0x00007ffff7324d55 in gaih_inet (name=name@entry=0x555555556b2e "google.com", service=<optimized out>, req=req@entry=0x7ffff6e7fda0, pai=pai@entry=0x7ffff6e7f8a8, naddrs=naddrs@entry=0x7ffff6e7f8a4, tmpbuf=t
mpbuf@entry=0x7ffff6e7f910) at ../sysdeps/posix/getaddrinfo.c:786
#2  0x00007ffff7326ce4 in __GI_getaddrinfo (name=<optimized out>, service=<optimized out>, hints=0x7ffff6e7fda0, pai=0x7ffff6e7fd90) at ../sysdeps/posix/getaddrinfo.c:2300
#3  0x0000555555555281 in <lambda()>::operator()(void) const (__closure=0x55555576be78) at proof.c:34
#4  0x00005555555556ad in std::__invoke_impl<void, main(int, char**)::<lambda()> >(std::__invoke_other, <lambda()> &&) (__f=...) at /usr/include/c++/7/bits/invoke.h:60
#5  0x00005555555554c8 in std::__invoke<main(int, char**)::<lambda()> >(<lambda()> &&) (__fn=...) at /usr/include/c++/7/bits/invoke.h:95
#6  0x00005555555558d4 in std::thread::_Invoker<std::tuple<main(int, char**)::<lambda()> > >::_M_invoke<0>(std::_Index_tuple<0>) (this=0x55555576be78) at /usr/include/c++/7/thread:234
#7  0x0000555555555890 in std::thread::_Invoker<std::tuple<main(int, char**)::<lambda()> > >::operator()(void) (this=0x55555576be78) at /usr/include/c++/7/thread:243
#8  0x0000555555555860 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<main(int, char**)::<lambda()> > > >::_M_run(void) (this=0x55555576be70) at /usr/include/c++/7/thread:186
#9  0x00007ffff78e6733 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007ffff7bbd6db in start_thread (arg=0x7ffff6e80700) at pthread_create.c:463
#11 0x00007ffff734088f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95