aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Drake <cygwin@jdrake.com>2025-09-19 13:36:30 -0700
committerJeremy Drake <cygwin@jdrake.com>2025-09-20 11:35:32 -0700
commit8a5d39527f9a56d1a623e86d30af6b590fd1472d (patch)
tree7d5c42fc319a553f65c19f00a8091b63f3221332
parent3a03874f73db015d93c3b54c6bad32a2852c591e (diff)
downloadnewlib-8a5d39527f9a56d1a623e86d30af6b590fd1472d.zip
newlib-8a5d39527f9a56d1a623e86d30af6b590fd1472d.tar.gz
newlib-8a5d39527f9a56d1a623e86d30af6b590fd1472d.tar.bz2
Cygwin: lock cygheap during fork
another thread may simultaneously be doing a cmalloc/cfree while the cygheap is being copied to the child. Addresses: https://cygwin.com/pipermail/cygwin/2025-September/258801.html Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
-rw-r--r--winsup/cygwin/fork.cc7
-rw-r--r--winsup/cygwin/release/3.6.54
2 files changed, 10 insertions, 1 deletions
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 4abc525..7156fc3 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -329,6 +329,7 @@ frok::parent (volatile char * volatile stack_here)
/* NEVER, EVER, call a function which in turn calls malloc&friends while this
malloc lock is active! */
__malloc_lock ();
+ cygheap->lock ();
bool locked = true;
/* Remove impersonation */
@@ -483,6 +484,7 @@ frok::parent (volatile char * volatile stack_here)
impure, impure_beg, impure_end,
NULL);
+ cygheap->unlock ();
__malloc_unlock ();
locked = false;
if (!rc)
@@ -568,7 +570,10 @@ cleanup:
if (fix_impersonation)
cygheap->user.reimpersonate ();
if (locked)
- __malloc_unlock ();
+ {
+ cygheap->unlock ();
+ __malloc_unlock ();
+ }
/* Remember to de-allocate the fd table. */
if (hchild)
diff --git a/winsup/cygwin/release/3.6.5 b/winsup/cygwin/release/3.6.5
index 6a37b6a..d7cf838 100644
--- a/winsup/cygwin/release/3.6.5
+++ b/winsup/cygwin/release/3.6.5
@@ -25,3 +25,7 @@ Fixes:
- Fix Ctrl-O (FLUSHO) handling.
Addresses: https://cygwin.com/pipermail/cygwin/2025-August/258717.html
+
+- Fix multi-thread safety of fork()/exec() by adding the same locking as was
+ done for spawn.
+ Addresses: https://cygwin.com/pipermail/cygwin/2025-September/258801.html