]> git.ipfire.org Git - thirdparty/krb5.git/commit
Block library unloading to avoid finalizer races 1368/head
authorGreg Hudson <ghudson@mit.edu>
Thu, 29 Aug 2024 19:25:54 +0000 (15:25 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 11 Sep 2024 20:18:39 +0000 (16:18 -0400)
commit1bfcf572241a4ec0e44e609e5c6b7c0b11b08eea
tree05b0fd8a6f7e81442d8323c26d24524f86c4e4ca
parentb9b654e5b469140d5603f27af5bf83ee9a826349
Block library unloading to avoid finalizer races

Library finalizers can run due to the library being unloaded or the
process exiting.  If the library is being unloaded, global memory
resources must be released to avoid memory leaks.  But if the process
is exiting, releasing memory resources can lead to race conditions if
another thread invokes functions from the library during or after
finalizer execution.  Most commonly this manifests as an assertion
error about trying to lock a destroyed mutex.

We can block unloading of our library on ELF platforms by passing "-z
nodelete" to the linker.  Add a shell variable "lib_unload_prevented"
to the shlib.conf outputs, set it on platforms where we can block
unloading, and suppress finalizers when it is set.

On Windows we can detect if the process is exiting by checking for a
non-null lpvReserved argument in DllMain().  Do not execute finalizers
when the process is executing.

ticket: 9139 (new)
src/aclocal.m4
src/config/shlib.conf
src/include/k5-platform.h
src/lib/win_glue.c