]> sourceware.org Git - newlib-cygwin.git/commit
Cygwin: fork: fix a potential hang in fork
authorCorinna Vinschen <corinna@vinschen.de>
Mon, 29 Aug 2022 10:25:24 +0000 (12:25 +0200)
committerCorinna Vinschen <corinna@vinschen.de>
Mon, 29 Aug 2022 10:25:24 +0000 (12:25 +0200)
commit717c36c0a4e387a73146c1181b7b89f091176e85
tree9356ba66ced8412129d42bcc94c6046b2fdf05ca
parentf59ff93046341e688bc36ea81bddd60eea405e21
Cygwin: fork: fix a potential hang in fork

while debugging a problem introduced in commit
63b503916d42 ("Cygwin: tls_pathbuf: Use Windows heap")
a hang in fork was encountered using the original implementation
of tls_pathbuf:

Using tmp_pathbuf inside the code block guarded by __malloc_trylock
may call malloc from tmp_pathbuf::w_get and thus trying to lock an
exclusive SRW lock recursively, which results in a deadlock.

Allocate a small SECURITY_ATTRIBUTES block on the stack rather than
allocating a 64K tmp_pathbuf.  This avoids the potential malloc call.

Drop the __malloc_trylock call entirely.  There must not be a malloc
call inside the frok::parent block guarded by __malloc_lock, and
just trying to lock is too dangerous inside fork while other threads
might actually chage the content of the heap.  Additionally, add a
comment frowning on malloc usage inside tis code block.

Fixes: 44a79a6eca3d ("Cygwin: convert malloc lock to SRWLOCK")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/fork.cc
winsup/cygwin/local_includes/cygmalloc.h
This page took 0.029818 seconds and 5 git commands to generate.