]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
stdlib: resolve a double lock init issue after fork [BZ #32994]
authorDavide Cavalca <davide@cavalca.name>
Thu, 31 Jul 2025 15:32:58 +0000 (17:32 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 1 Aug 2025 11:30:28 +0000 (13:30 +0200)
The __abort_fork_reset_child (introduced in
d40ac01cbbc66e6d9dbd8e3485605c63b2178251) call resets the lock after the
fork. This causes a DRD regression in valgrind
(https://bugs.kde.org/show_bug.cgi?id=503668), as it's effectively a
double initialization, despite it being actually ok in this case. As
suggested in https://sourceware.org/bugzilla/show_bug.cgi?id=32994#c2
we replace it here with a memcpy of another initialized lock instead,
which makes valgrind happy.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit d9a348d0927c7a1aec5caf3df3fcd36956b3eb23)

NEWS
stdlib/abort.c

diff --git a/NEWS b/NEWS
index 9cb8de11f91ba590597a9f1e517655c59d30d58a..4610b8bbc66b10fa2d603391b720f939721d56bd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,7 @@ Version 2.42.1
 
 The following bugs were resolved with this release:
 
-  [insert bugs here]
+  [32994] stdlib: resolve a double lock init issue after fork
 \f
 Version 2.42
 
index caa9e6dc0494e7a7b15c637246762a54ee273f4a..904244a2fb5b985ebbcf7ebad1ee56c1b12fc1f2 100644 (file)
@@ -19,6 +19,7 @@
 #include <internal-signals.h>
 #include <libc-lock.h>
 #include <pthreadP.h>
+#include <string.h>
 #include <unistd.h>
 
 /* Try to get a machine dependent instruction which will make the
@@ -42,7 +43,10 @@ __libc_rwlock_define_initialized (static, lock);
 void
 __abort_fork_reset_child (void)
 {
-  __libc_rwlock_init (lock);
+  /* Reinitialize lock without calling pthread_rwlock_init, to
+     avoid a valgrind DRD false positive.  */
+  __libc_rwlock_define_initialized (, reset_lock);
+  memcpy (&lock, &reset_lock, sizeof (lock));
 }
 
 void