This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

cc310 platform mutex init error

Hi,

On zephyr, I am using the cryptocell as my backend to do the following operation:

mbedtls_entropy_context entropy;
mbedtls_entropy_init( &entropy );

My memory is getting corrupted in the init function. Specifically when the mutex for the context is initialized. 

What happens is the portion of the stack that this variable "entropy" gets assigned, has some old values in it.

When the mutex gets initialized, the location mutex->mutex has an old value in it. The initialization function does not set this value to zero, and instead initializes a kernel mutex there.

If you look at the following line you will see that if mutex->mutex is not null, then mutex->mutex does not get memset to 0. It seems to me that mutex->mutex should get memset to 0 no matter what.

https://github.com/NordicPlayground/nrfxlib/blob/master/crypto/nrf_cc310_platform/src/nrf_cc310_platform_mutex_zephyr.c#L108-L109

Why would the flag have a useful value that is being checked also. We are trying to init. Anything at these memory locations should be assumed to be garbage.

Am I missing something? Originally I thought I was maybe just over running out of stack, but I double my stack size and still had this issue at he same place.

My current fix it to memset the structure myself like this:

mbedtls_entropy_context entropy;
memset(&entropy, 0,sizeof(entropy));
mbedtls_entropy_init( &entropy );

But I guess I have to do this for every mbedtls structure that has a mutex. Which is annoying to keep rack of.

Related