<div dir="ltr"><div dir="ltr">Hi team,<div></div><div><a href="https://www.openssl.org/docs/man1.0.2/man3/CRYPTO_set_locking_callback.html">https://www.openssl.org/docs/man1.0.2/man3/CRYPTO_set_locking_callback.html</a> :  From this , learnt that for openssl multi-threaded applications to be run safely, the callback functions to be implemented.<br></div><div><br></div><div>

I am using this in a multi-threaded application and Above scenario was again recreated and in that case 2 threads were calling RSA_verify (same stack above). However, for SSL_do_handshake, SSL* objects are given separately and they are not shared between threads. So, we have not implemented callback functions.</div><div><br></div><div>Could you please clarify whether we need to implement locking callbacks for multi-threaded applications  even if the ssl objects we supply are provided separately for threads?</div><div><br></div><div>Many thanks.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 6, 2021 at 10:40 PM Gimhani Uthpala <<a href="mailto:gimhanieuthpala@gmail.com">gimhanieuthpala@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear team,<div>I'm running an application which uses openssl for secure communication between processes. I am getting seg-faults at openssl level. This only occurred very randomly and the following are stacks that seg faults  at openssl level in the given 2 cases. We are using openssl 1.0.2k. </div><div><br></div><div>Went through the security vulnerabilities list for this version but couldn't find a clue. Running valgrind too didn't give an exact clue related to the issue. Can you please guide me how can I find the exact root cause for the seg fault?  </div><div><br></div><div>I am calling SSL_do_handshake(ssl_ctx) from my code level and both the below seg faults are occuring from it's inside. </div><div></div><div><br></div><div>#0  0x00007fd64cdabdd3 in ASN1_item_verify () from /lib64/libcrypto.so.10<br>#1  0x00007fd64cdcac58 in internal_verify () from /lib64/libcrypto.so.10<br>#2  0x00007fd64cdccaef in X509_verify_cert () from /lib64/libcrypto.so.10<br>#3  0x00007fd64d111c68 in ssl_verify_cert_chain () from /lib64/libssl.so.10<br>#4  0x00007fd64d0e8cc6 in ssl3_get_client_certificate () from /lib64/libssl.so.10<br><b>#5  0x00007fd64d0ea3f8 in ssl3_accept () from /lib64/libssl.so.10</b><br></div><div><br></div><div><br></div><div> #0 0x00007ffb65529854 in RSA_verify () from /usr/lib64/libcrypto.so.10<br> #1 0x00007ffb6552f1fc in pkey_rsa_verify () from /usr/lib64/libcrypto.so.10<br> #2 0x00007ffb65561877 in EVP_DigestVerifyFinal () from /usr/lib64/libcrypto.so.10<br> #3 0x00007ffb6556af25 in ASN1_item_verify () from /usr/lib64/libcrypto.so.10<br> #4 0x00007ffb65589c58 in internal_verify () from /usr/lib64/libcrypto.so.10<br> #5 0x00007ffb6558baef in X509_verify_cert () from /usr/lib64/libcrypto.so.10<br> #6 0x00007ffb658d1417 in ssl_add_cert_chain () from /usr/lib64/libssl.so.10<br> #7 0x00007ffb658b6095 in ssl3_output_cert_chain () from /usr/lib64/libssl.so.10<br> #8 0x00007ffb658ae894 in ssl3_send_client_certificate () from /usr/lib64/libssl.so.10<br><b> #9 0x00007ffb658aeecf in ssl3_connect () from /usr/lib64/libssl.so.10<br> #10 0x00007ffb658b8e7e in ssl23_connect () from /usr/lib64/libssl.so.10</b><br></div><div><br></div><div>  I am setting context to use SSLv23_method() s. However, I can see ssl3_ methods being called. Is there any issue with that?  <br></div><div><br></div><div>Given below is SSL* object passed to SSL_do_handshake method.</div><div><br></div>(gdb) p *p_SSLCtx<br>$2 = {version = 771, type = 4096, method = 0x7ffb65af3320, rbio = 0x7ffb5819e140, wbio = 0x7ffb58193570, bbio = 0x7ffb58193570, rwstate = 1, in_handshake = 2, <b>handshake_func = 0x7ffb658aea30 <ssl3_connect></b>, server = 0, new_session = 0, quiet_shutdown = 0, shutdown = 0, state = 4467,<br>  rstate = 240, init_buf = 0x7ffb581934b0, init_msg = 0x7ffb581e10d4, init_num = 0, init_off = 0, <b>packet = 0x7ffb581e6633 "\026\003\003", packet_length = 0</b>, s2 = 0x0, s3 = 0x7ffb58195ee0, d1 = 0x0, read_ahead = 0, msg_callback = 0x0, msg_callback_arg = 0x0, hit = 0, param = 0x7ffb581933f0,<br>  cipher_list = 0x0, cipher_list_by_id = 0x0, mac_flags = 0, enc_read_ctx = 0x0, read_hash = 0x0, expand = 0x0, enc_write_ctx = 0x0, write_hash = 0x0, compress = 0x0, cert = 0x7ffb58195ba0, sid_ctx_length = 0, sid_ctx = '\000' <repeats 31 times>, session = 0x7ffb58198100,<br>  generate_session_id = 0x0,......<br><div> </div><div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div style="font-size:12.8px"><b>Gimhani Uthpala Kankanamge</b><br></div><div style="font-size:12.8px"><br></div></div><span></span></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div style="font-size:12.8px"><b>Gimhani Uthpala Kankanamge</b></div></div><span></span></div></div></div></div></div></div>