I am working with version 3.0.3 of the plug & trust middle-ware.
I have extended the OpenSSL engine to support ciphers (AES-256-CBC). Now the engine hangs in a deadlock on a mutex when being deinitialised - even when using elliptic curves and not ciphers.
What happens is that OpenSSL's global_engine_lock, which is of type pthread_rwlock_t has already been locked once in engine_table_cleanup() (OpenSSL crypto/engine/eng_table.c) when EmbSe_Finish() is called. When sss_session_close() is called inside EmbSe_Finish(), this involves encryption again. And since the engine now support ciphers, OpenSSL locks the global_engine_lock again. I can see that pthread_rwlock_wrlock() returns EDEADLK at this point, indicating that the mutex cannot be locked again. But OpenSSL doesn't check this error code. So it ends up calling pthread_rwlock_unlock() twice which - according to the documentation - leads to undefined behavior.
I can't tell exactly where the second locking happens, but I saw that CMAX_Init() was active at this point.
Are you aware of this problem? Do you have any proposal on how to solve it? Would you say it is a bug in OpenSSL to lock the mutex twice or are we not allowed to use OpenSSL's encryption from EmbSe_Finish()?
Best regards