1 (edited by Zeddi 2013-10-11 00:34:50)

Topic: [SOLVED] fastmath memset for RSA-Key corrupts memory on eCos-Port WIP

Hi all,

I'm working on an eCos-port of the wolfSSL library (v 2.7.0) for embedded SSL. The target CPU we're using is a Freescale SPC5668.
So far a couple of the tests worked, but now I'm stuck in the "rsa_test" of the API tests.
I have USE_FAST_MATH defined, so memory allocations are used.

Inside this test, an RSA key is created:

RsaKey key;

Strangely, key points to an address in RAM instantly which has a couple of bytes 0ed (I assume unused), but after some dozen bytes, various variables used by eCos are stored (I especially found some bitmasks for strlen-function and a counter for malloc-function).

The system crashes when the function memset is called from within RsaPrivateKeyDecode -> GetInt -> mp_init with the following parameters:
s = 0x400033F4 (the target address of key)
c = 0
n = 552

This call overwrites 552 bytes of memory starting from address 0x400033F4. This results in various variables needed by eCos in being 0ed and thus corrupting the system context, causing a reboot of my hardware.

I'm not sure if this is a bug in wolfSSL or in eCos instead.
I am wondering though, why there is no previous malloc or similar for key to allocate free memory for the whole key.

Any help is greatly appreciated!
- Daniel

PS: The test worked when I had NOT defined USE_FAST_MATH. It crashed later, but this is another issue.

Share

Re: [SOLVED] fastmath memset for RSA-Key corrupts memory on eCos-Port WIP

Just as an update on this:
I also posted this issue onto the ecos-discuss mailing list now, including some further thoughts:
http://sourceware-org.1504.n7.nabble.co … 45720.html

Regards
- Daniel

Share

Re: [SOLVED] fastmath memset for RSA-Key corrupts memory on eCos-Port WIP

Another update with a solution (at least as a work-around):

Initially, I executed all the CyaSSL API and Hash tests inside my main thread and did not start an individual one for the tests.
This seemed to be the source of all the trouble.
I now moved all the CyaSSL-related stuff into an individual thread, created with a call to the cyg_thread_create()-function from eCos, and the tests are now working!

Share