openssl: Race condition on error strings cleanup?
This report is inspired by https://github.com/latchset/pkcs11-provider/issues/429#issuecomment-2276242417 and https://github.com/latchset/pkcs11-provider/issues/429#issuecomment-2276265853. This report is based on my understanding of the issue and may not be correct, we didn’t manage writing a simple reproducer here and now.
Looks like, when we have a default library context and a non-default one with loaded provider, the lock object is freed on freeing non-default context and attempt to lock it causes crash on exit.
Looks like it has nothing to do with OpenSSL atexit() handler as the crash is reproduced when we build OpenSSL with no-atexit.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 43 (34 by maintainers)
I guess the only fix here is to make openldap leak the SSL ctx and not try to free it in an atexit() handler
I have one more thing to add. For the reason that an application might want to call OPENSSL_cleanup() before it terminates to get a clean valgrind output, it is in general a bad idea to call OpenSSL from a library destructor. So actually it is partially a libldap fault, however the best way to resolve this is to simply not call OPENSSL_cleanup() at all. It is not really necessary.