[Git][ghc/ghc][master] rts: add missing ccs_mutex guard to internal_dlopen
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Tue Feb 27 21:59:10 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
61bc92cc by Cheng Shao at 2024-02-27T16:58:42-05:00
rts: add missing ccs_mutex guard to internal_dlopen
See added comment for details. Closes #24423.
- - - - -
3 changed files:
- rts/Linker.c
- rts/Profiling.c
- rts/Profiling.h
Changes:
=====================================
rts/Linker.c
=====================================
@@ -598,8 +598,27 @@ internal_dlopen(const char *dll_name)
// (see POSIX also)
ACQUIRE_LOCK(&dl_mutex);
+
+ // When dlopen() loads a profiled dynamic library, it calls the
+ // ctors which will call registerCcsList() to append the defined
+ // CostCentreStacks to CCS_LIST. This execution path starting from
+ // addDLL() was only protected by dl_mutex previously. However,
+ // another thread may be doing other things with the RTS linker
+ // that transitively calls refreshProfilingCCSs() which also
+ // accesses CCS_LIST, and those execution paths are protected by
+ // linker_mutex. So there's a risk of data race that may lead to
+ // segfaults (#24423), and we need to ensure the ctors are also
+ // protected by ccs_mutex.
+#if defined(PROFILING)
+ ACQUIRE_LOCK(&ccs_mutex);
+#endif
+
hdl = dlopen(dll_name, RTLD_LAZY|RTLD_LOCAL); /* see Note [RTLD_LOCAL] */
+#if defined(PROFILING)
+ RELEASE_LOCK(&ccs_mutex);
+#endif
+
errmsg = NULL;
if (hdl == NULL) {
/* dlopen failed; return a ptr to the error msg. */
=====================================
rts/Profiling.c
=====================================
@@ -59,7 +59,7 @@ CostCentre *CC_LIST = NULL;
static CostCentreStack *CCS_LIST = NULL;
#if defined(THREADED_RTS)
-static Mutex ccs_mutex;
+Mutex ccs_mutex;
#endif
/*
=====================================
rts/Profiling.h
=====================================
@@ -55,6 +55,10 @@ extern Arena *prof_arena;
void debugCCS( CostCentreStack *ccs );
#endif
+#if defined(THREADED_RTS)
+extern Mutex ccs_mutex;
+#endif
+
#endif
#include "EndPrivate.h"
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/61bc92cc0e992209c067c592f71750638aa73151
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/61bc92cc0e992209c067c592f71750638aa73151
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240227/816c546d/attachment-0001.html>
More information about the ghc-commits
mailing list