hw-1

openssl crash sha1_block_data_order

openssl crash sha1_block_data_order

openssl crash

1
2
3
4
Program terminated with signal 11, Segmentation fault.
#0 0xf7779875c in sha1_block_data_order () from /opt/xxx/xxx/libxxx.so
#1 0xf7797926 in SHA1_Update () from /opt/xxx/xxx/libxxx.so
#2 0x00000000 in ?? ()

1,因为多线程调用,openssl在多线程调用时为了保证线程安全,需要在每个调用线程里明确设置两个callback函数

Is OpenSSL thread-safe?
Yes (with limitations: an SSL connection may not concurrently be used by multiple threads). On Windows and many Unix systems, OpenSSL automatically uses the multi-threaded versions of the standard libraries. If your platform is not one of these, consult the INSTALL file.

Multi-threaded applications must provide two callback functions to OpenSSL by calling CRYPTO_set_locking_callback() and CRYPTO_set_id_callback(), for all versions of OpenSSL up to and including 0.9.8[abc…]. As of version 1.0.0, CRYPTO_set_id_callback() and associated APIs are deprecated by CRYPTO_THREADID_set_callback() and friends. This is described in the threads(3) manpage.

2,编译openssl的时候我们加上了-fPIC选项,fPIC作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),则产生的代码中,没有绝对地址,全部使用相对地址,故而代码可以被加载器加载到内存的任意位置,都可以正确的执行。

gcc在生成位置无关代码的时候,内部使用了ebx作为基址寄存器。如果不使用内嵌汇编,那么gcc自然会帮助你维持ebx的值始终有效。但是如果使用了内嵌汇编,gcc常常就有点力不从心了,所以这时候,一定要自己留意保存好ebx的值。