QSSLSocket Crash with call to supportsSsl()
-
Hi,
I am developing an app with tensorflow backend (libtensorflow + libtensorflow_framework). That library has libssl statically built into it for ease of downloading dataset over the internet.
When I develop the application, and try to utilize QsslSocket, the application segfaulted immediately; this is due to the fact that there are two versions of openssl loaded at runtime. I find this from the stack trace at the point of crash:
[New Thread 0x7fff51ffb700 (LWP 3497491)] OpenSSL 1.1.1d 10 Sep 2019 Thread 1 "upsNativeInterf" received signal SIGSEGV, Segmentation fault. 0x00007fffe74d10c3 in OPENSSL_strcasecmp () from /usr/local/lib/libtensorflow_framework.so.2 (gdb) bt #0 0x00007fffe74d10c3 in OPENSSL_strcasecmp () from /usr/local/lib/libtensorflow_framework.so.2 #1 0x00007fffe7484f98 in EVP_get_cipherbyname () from /usr/local/lib/libtensorflow_framework.so.2 #2 0x00007fffe04591e9 in ?? () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1 #3 0x00007fffe045c4a0 in ?? () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1 #4 0x00007fffe856a47f in __pthread_once_slow (once_control=0x7fffe04b8928, init_routine=0x7fffe045c2c0) at pthread_once.c:116 #5 0x00007fff2ff0caad in CRYPTO_THREAD_run_once () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 #6 0x00007fffe045c59b in OPENSSL_init_ssl () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1 #7 0x00007fffe8c21430 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Network.so.5 #8 0x00005555555657ee in MainWindow::MainWindow(QWidget*, QCommandLineParser*) () #9 0x0000555555561bde in main ()
As shown in the stacktrace, qt loaded libssl and then libtensorflow used it own version of libssl with the same symbol name, and that's where the crash happened.
I would like to know how would one deal with a situation like this, without having to modify libtensorflow and rebuild libtensorflow. My last resort is to create an https to http proxy so that qt wouldn't use qsslsocket at all. please help.
Reference: Proof that libtensorflow was statically linked with openssl.
objdump -x /usr/local/lib/libtensorflow.so | grep SSL 00000000008b80ea l F .text 000000000000001c _ZN4bssl6DeleteINS_11SSLKeyShareEEEvPT_.part.29 00000000008b8106 l F .text 000000000000009b _ZN4bsslL38SSL_SESSION_parse_bounded_octet_stringEP6cbs_stPhS2_hj 00000000008b81a1 l F .text 0000000000000059 _ZN4bsslL21SSL_SESSION_parse_u32EP6cbs_stPjjj 000000000b9eb060 l F .text 00000000000007c8 _ZN4bsslL25SSL_SESSION_to_bytes_fullEPK14ssl_session_stP6cbb_sti.part.16 00000000008b81fa l F .text 00000000000000e5 _ZN4bsslL31SSL_SESSION_parse_crypto_bufferEP6cbs_stPSt10unique_ptrI16crypto_buffer_stNS_8internal7DeleterIS3_EEEjP21crypto_buffer_pool_st 00000000008b82df l F .text 0000000000000058 _ZN4bsslL21SSL_SESSION_parse_u16EP6cbs_stPtjt.constprop.23 00000000008b8337 l F .text 00000000000000c2 _ZN4bsslL30SSL_SESSION_parse_octet_stringEP6cbs_stPNS_5ArrayIhEEj 000000000cd4e768 l O .rodata 000000000000000e _ZZ20SSL_SESSION_to_bytesE20kNotResumableSession 000000000ba0ad30 l F .text 00000000000007a6 _ZN4bsslL20do_read_server_helloEPNS_13SSL_HANDSHAKEE 00000000008b83f9 l F .text 000000000000001c _ZN4bssl6DeleteINS_11SSLKeyShareEEEvPT_.part.16 000000000ba576a0 l F .text 000000000000013e OPENSSL_built_in_curves_init 000000000e56b900 l O .bss 0000000000000004 OPENSSL_built_in_curves_once 000000000e56b920 l O .bss 00000000000000e0 OPENSSL_built_in_curves_storage 000000000b9d24f0 l F .text 00000000000000b9 SSL_ERROR_to_str
-
Update 12/10/2021 (today):
Found someone who has a similar problem. One work around is to recompile tensorflow without ssl... something that I do not want to do.
-
Update 12/10/2021 (today):
I just want to share this work-around to fix the issue w/o having to recompile libtensorflow. The temporary solution is to launch the qt application w/ a linker and tell it to preload libssl so that QT wouldn't lazy load the library when it is being accessed. With this fix, I am able to use SSL inside of QT and also tensorflow library (w/ its own version of ssl library).
command to run w/ libssl preloaded (in linux):
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 --preload /usr/lib/x86_64-linux-gnu/libssl.so ./upsNativeInterfence