Blame SOURCES/opencryptoki-3.16.0-b07505993dd8b2f367cf3b630f6da186e4e8550d.patch

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