<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">Hello OpenSSL.</span><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">I know that thread safety in OpenSSL is a much discussed topic. I have read several GitHub issues[1], Stack Overflow threads[2], and I have read the blog paper[3] too.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">However, I am still facing issues when I use `SSL_CTX` and `SSL` objects.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">I use `SSL_CTX` and `SSL` inside a threaded application. Threads are managed using pthread primitives.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Basically, I create a `SSL_CTX`, and I fill it depending on the TLS method.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">At this point, the `SSL_CTX` is final. I never change it again.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Then, I create n `SSL`s from the `SSL_CTX`, and I spawn n pthreads. Each pthread takes the ownership of a single `SSL`. Finally, each</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">pthread is going to use its `SSL` object for establishing some TLS connections.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">`SSL` objects never get destroyed, instead I use `SSL_clear` for kind of recycling them.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">My question is: Is my app thread safe ? I wonder, because I am facing random null deref.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">If I create a `SSL_CTX` for each thread, everything is fine.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Best regards,</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Thomas B.</div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">[1] <a href="https://github.com/openssl/openssl/issues/2165" class="">https://github.com/openssl/openssl/issues/2165</a></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">[2] <a href="https://stackoverflow.com/questions/40583314/ssl-new-thread-safe-or-not" class="">https://stackoverflow.com/questions/40583314/ssl-new-thread-safe-or-not</a> </div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">[3] <a href="https://www.openssl.org/blog/blog/2017/02/21/threads/" class="">https://www.openssl.org/blog/blog/2017/02/21/threads/</a> </div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">NB: I'am using OpenSSL 1.1.1, from git.</div></body></html>