On Wed, Dec 23, 2020 at 11:58:30PM -0700, Theo de Raadt wrote:
> Brad Smith <[email protected]> wrote:
> 
> > On 12/23/2020 10:35 PM, Alexey Sokolov wrote:
> > >> Synopsis:        getaddrinfo() is not thread-safe in 6.8
> > >> Category:        system
> > >> Environment:
> > >   System      : OpenBSD 6.8
> > >   Details     : OpenBSD 6.8 (GENERIC.MP) #1: Tue Nov  3 09:06:04 MST 2020
> > >                   
> > > [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> > >
> > >   Architecture: OpenBSD.amd64
> > >   Machine     : amd64
> > >> Description:
> > > Hi, getaddrinfo() crashes when multiple threads run getaddrinfo()
> > > concurrently. This didn't happen in 6.7.
> > > It looks like asr_ctx which is supposed to be thread-local according to
> > > _asr_use_resolver(), is actually static / shared between threads.
> > >> How-To-Repeat:
> > > Compile this code (gcc a.c -pthread), and run. It will segfault in
> > > several seconds. Happens with both gcc (4.2.1) and egcc (8.4.0).
> > 
> > Before going any further. Use the system compiler. That is Clang (cc).
> 
> I disagree.   As the test appears fairly idiomatic threading code, I
> find it unlikely a compiler change should matter.

FWIW I compiled psychon's code with clang (cc) with cc -g -o threadtest \
        threadtest.c -lpthread

and got this:

pjp@arda$ ./threadtest                                                          
Segmentation fault (core dumped)                                                
pjp@arda$ gdb ./threadtest threadtest.core         
...
#0  0x00000f22d59c228c in getaddrinfo_async_run (as=0xf229d095000, ar=Variable "
ar" is not available)                                                           
                    
    at /usr/src/lib/libc/asr/getaddrinfo_async.c:513                            
513             return AS_FAMILY(as);                                           
(gdb) print *as     
...
is->as_family_idx     
$2 = 34                                 
(gdb) where   
#0  0x00000f22d59c228c in getaddrinfo_async_run (as=0xf229d095000, ar=Variable "
ar" is not available.                                                           
)
    at /usr/src/lib/libc/asr/getaddrinfo_async.c:513
#1  0x00000f22d59ba4d7 in _libc_asr_run_sync (as=0xf229d095000, 
    ar=0x7f7ffffe8448) at /usr/src/lib/libc/asr/asr.c:178
#2  0x00000f22d599e008 in _libc_getaddrinfo (
    hostname=0xf201c7ce6b8 "ipv4.google.com", servname=0x0, 
...
(gdb) info threads
* 1 process 608275  0x00000f22d59c228c in getaddrinfo_async_run (
    as=0xf229d095000, ar=Variable "ar" is not available.
) at /usr/src/lib/libc/asr/getaddrinfo_async.c:513
...

This means that the other 4 threads exited by now, here is my system's
kern.version:


kern.version=OpenBSD 6.8 (GENERIC.MP) #2: Sat Dec  5 07:17:48 MST 2020
    
[email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP

latest smtpd patch not on it (yet)...

Best Regards,
-peter

Reply via email to