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