38 lines
1.4 KiB
Diff
38 lines
1.4 KiB
Diff
|
commit b07505993dd8b2f367cf3b630f6da186e4e8550d
|
||
|
Author: Ingo Franzki <ifranzki@linux.ibm.com>
|
||
|
Date: Wed Feb 10 15:12:25 2021 +0100
|
||
|
|
||
|
Avoid deadlock in dlclose() after a fork
|
||
|
|
||
|
Calling dlclose() in a atfork handler may cause a deadlock.
|
||
|
dlclose() may itself modify the atfork handler table to remove
|
||
|
any fork handlers that the to be unloaded library has registered.
|
||
|
Since the atfork handler table is currently locked when we are in
|
||
|
an atfork handler, this would produce a deadlock.
|
||
|
|
||
|
Skip the dlclose() if we are in an atfork handler to avoid the deadlock.
|
||
|
|
||
|
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
|
||
|
|
||
|
diff --git a/usr/lib/api/api_interface.c b/usr/lib/api/api_interface.c
|
||
|
index 3ccb6d41..f1ee9132 100644
|
||
|
--- a/usr/lib/api/api_interface.c
|
||
|
+++ b/usr/lib/api/api_interface.c
|
||
|
@@ -1516,7 +1516,15 @@ CK_RV C_Finalize(CK_VOID_PTR pReserved)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- DL_UnLoad(sltp, slotID);
|
||
|
+ /*
|
||
|
+ * Calling dlclose() in a atfork handler may cause a deadlock.
|
||
|
+ * dlclose() may itself modify the atfork handler table to remove
|
||
|
+ * any fork handlers that the to be unloaded library has registered.
|
||
|
+ * Since the atfork handler table is currently locked when we are in
|
||
|
+ * an atfork handler, this would produce a deadlock.
|
||
|
+ */
|
||
|
+ if (!in_child_fork_initializer)
|
||
|
+ DL_UnLoad(sltp, slotID);
|
||
|
}
|
||
|
|
||
|
// Un register from Slot D
|