Blame SOURCES/opencryptoki-3.16.0-b07505993dd8b2f367cf3b630f6da186e4e8550d.patch

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