Topic: [SOLVED] meet 'Segmentation fault' when using wc_ecc_make_key_ex()

Hi,
    When I call wc_make_key_ex() function, I always met 'Segmentation fault' issue.
    The crash point is : at the end of this function, when call mp_clear(&a);  process crashed.
    Currently, I have no idea for this, could you please help me to resolve this issue? (wolfSSL version : 3.9.10)

     

wc_ecc_del_point_h(base, key->heap);
#ifndef USE_FAST_MATH
    mp_clear(&a);   /* This function cause crash*/
    mp_clear(&prime);
    mp_clear(&order);

Share

Re: [SOLVED] meet 'Segmentation fault' when using wc_ecc_make_key_ex()

Hi cxdinter,

Thank you so much for the report.

It looks like that scenario could happen if your call to wc_RNG_GenerateBlock did not return 0 (in wc_ecc_make_key_ex at line 2507). In that case variable "a" would be un-initialized from the stack and the call to "mp_clear" could cause a seg fault due to invalid pointer.

Will you confirm your wc_RNG_GenerateBlock return code? It should be zero indicating success.

I've pushed a fix for that here:
https://github.com/wolfSSL/wolfssl/pull/626

Let me know if that helps.

Thanks,
David Garske, wolfSSL

Share

Re: [SOLVED] meet 'Segmentation fault' when using wc_ecc_make_key_ex()

dgarske wrote:

Hi cxdinter,

Thank you so much for the report.

It looks like that scenario could happen if your call to wc_RNG_GenerateBlock did not return 0 (in wc_ecc_make_key_ex at line 2507). In that case variable "a" would be un-initialized from the stack and the call to "mp_clear" could cause a seg fault due to invalid pointer.

Will you confirm your wc_RNG_GenerateBlock return code? It should be zero indicating success.

I've pushed a fix for that here:
https://github.com/wolfSSL/wolfssl/pull/626

Let me know if that helps.

Thanks,
David Garske, wolfSSL

Hi,
    Your analysis is correct. The return value of wc_RNG_GenerateBlock () is -199, not 0. So it caused crash.
    After added your patch, crash issue is fixed.
    But, I can't generate ECC key, because function returned when wc_RNG_GenerateBlock () return not 0.

    Finally, I find the root cause is : before use wc_RNG_GenerateBlock (), I haven't called wc_InitRng().
     
    Thanks a lot!

Share