簡體   English   中英

由於RDRAND,OpenSSL在Valgrind下生成核心轉儲

[英]OpenSSL produces core dump under Valgrind due to RDRAND

這是我的代碼:

#include <openssl/rsa.h>

int main(){
    BIGNUM *bne = NULL; 
    unsigned long e = RSA_F4;
    RSA *r = NULL;

    bne = BN_new();
    BN_set_word(bne,e);
    r = RSA_new();
    int ret = RSA_generate_key_ex(r, 1024, bne, NULL);

    const BIGNUM *n = NULL;
    const BIGNUM *d = NULL;
    RSA_get0_key(r, &n, NULL, &d);

    BN_print_fp(stdout, n);
    RSA_free(r);
    BN_free(bne);

    return  0;
}

這是我編譯它的方式:

gcc -Wall -Wextra -Wl,-rpath,/home/roman/Dropbox/uni/RSA/my_work/library/lib -g sharedLibraryTest.c -o sharedLibraryTest -I/home/roman/Dropbox/uni/RSA/my_work/library/include - L/home/roman/Dropbox/uni/RSA/my_work/library/lib -lcrypto -ldl 

當我用./sharedLibraryTest正常運行時,一切都很好。 但是,當我在Valgrind中運行它時,它說Illegal instruction (core dumped)並且有一些我不理解的內存泄漏(我看不到任何內容)。

你知道是什么原因造成的嗎? 我正在運行OpenSSL 1_1_0e。


這是Valgrind輸出。

$ valgrind ./sharedLibraryTest 
==4500== Memcheck, a memory error detector
==4500== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4500== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==4500== Command: ./sharedLibraryTest
==4500== 
vex amd64->IR: unhandled instruction bytes: 0x48 0xF 0xC7 0xF0 0x72 0x2 0xE2 0xF8
vex amd64->IR:   REX=1 REX.W=1 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=0F
vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
==4500== valgrind: Unrecognised instruction at address 0x5026fa5.
==4500==    at 0x5026FA5: OPENSSL_ia32_rdrand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4FC2B12: rand_bytes (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4EF698E: BN_rand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4EF5430: BN_generate_prime_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4FCA616: RSA_generate_key_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x400963: main (sharedLibraryTest.c:12)
==4500== Your program just tried to execute an instruction that Valgrind
==4500== did not recognise.  There are two possible reasons for this.
==4500== 1. Your program has a bug and erroneously jumped to a non-code
==4500==    location.  If you are running Memcheck and you just saw a
==4500==    warning about a bad jump, it's probably your program's fault.
==4500== 2. The instruction is legitimate but Valgrind doesn't handle it,
==4500==    i.e. it's Valgrind's fault.  If you think this is the case or
==4500==    you are not sure, please let us know and we'll try to fix it.
==4500== Either way, Valgrind will now raise a SIGILL signal which will
==4500== probably kill your program.
==4500== 
==4500== Process terminating with default action of signal 4 (SIGILL)
==4500==  Illegal opcode at address 0x5026FA5
==4500==    at 0x5026FA5: OPENSSL_ia32_rdrand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4FC2B12: rand_bytes (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4EF698E: BN_rand (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4EF5430: BN_generate_prime_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x4FCA616: RSA_generate_key_ex (in /home/roman/Dropbox/uni/RSA/my_work/library/lib/libcrypto.so.1.1)
==4500==    by 0x400963: main (sharedLibraryTest.c:12)
==4500== 
==4500== HEAP SUMMARY:
==4500==     in use at exit: 6,216 bytes in 32 blocks
==4500==   total heap usage: 146 allocs, 114 frees, 14,880 bytes allocated
==4500== 
==4500== LEAK SUMMARY:
==4500==    definitely lost: 0 bytes in 0 blocks
==4500==    indirectly lost: 0 bytes in 0 blocks
==4500==      possibly lost: 0 bytes in 0 blocks
==4500==    still reachable: 6,216 bytes in 32 blocks
==4500==         suppressed: 0 bytes in 0 blocks
==4500== Rerun with --leak-check=full to see details of leaked memory
==4500== 
==4500== For counts of detected and suppressed errors, rerun with: -v
==4500== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction (core dumped)

這看起來像valgrind中的一個已知錯誤,已經有一個補丁

問題是valgrind不支持libcrypto正在使用的CPU指令。 解決方案是不告訴libcrypto該指令可用。

內存泄漏很可能是異常終止的結果。 也就是說,不調用不同對象的析構函數。

解決方案

  1. 獲取最新的穩定版本

  2. 應用補丁

  3. 從在線倉庫獲取SVN版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM