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

nrf9160 secure services causing a crash

I have been trying to use the secure services to read random from the CC310 and have been getting unpredictable crashes. I have been able to modify the secure_services sample code to create a crash, but it's the oddest thing. The combination of CONFIG_LOG=y and CONFIG_DK_LIBRARY=y along with a call to dk_buttons_init() is enough to cause the exception. No buttons need to be pressed and no log messages generated by me.

I'm using ncs 1.2.0 on a nRF9160 DK. Can anybody explain what's happening? Modified secure_services sample attached

Mike

secure_services.zip

Parents Reply Children
  • Hi again.

    There has been some further progress in finding the root cause, but it does not look like there is an easy fix, so it will probably take some time until it is properly fixed.

    Here is an explanation of what probably happens, given by one of our developers:

    "Short story: if a Zephyr thread context-switch occurs while doing a Secure call, the Zephyr kernel may crash.

    Elaboration:

    This might, actually, be happening in the scenario reported in this issue: I believe, so, because it seems the secure service takes some time to finish, so an NSPE Zephyr system time may fire, in the mean time, and lead to a thread re-schedule point.

     

    When in a regular function call, the Zephyr Cortex-M swap logic (running in PendSV IRQ, possibly tail-chained from a higher priority IRQ context) will simply stack the current execution context into the thread's stack, tweak PSP, and eventually return into the new thread's execution context, using that thread's stack(ed) information.

    When in a Secure function call, however, things are not as simple as the above scenario. The swap logic will still change the NSPE context, but it will return to the SPE to finish the secure service. When the secure service is complete, the TrustZone logic will attempt to branch to the NSPE (most likely using BXNS LR instruction), however, since the NSPE context has changed, the service call is not returning to the context it was called from.

     

    This bug, may be causing system crashes (possibly such as the one we are currently observing here), but is, also a direct Security violation, since secure service result is exposed to a NSPE context other than the caller."

    We are looking into what is the best way to ensure that a secure call always returns to the caller.

    Best regards,

    Didrik

  • I looked at the PR and it doesn't seem to be progressing at the moment. Is this still the intended way to resolve this? Actually my real question is when will a solution be available in a NCS SDK release?

  • miked531 said:
    I looked at the PR and it doesn't seem to be progressing at the moment.

     We are just coming out of the summer vacation period here in Norway, so the lack of progress might be due to low staffing during the vacation.

    As for when the solution will be available in an NCS release, I can not really give you an answer.

    Hopefully, it will be a part of the next release. Although it could also take longer, I will let you know if the developers have an estimate.

    Anyway, I have asked the developers for a status update.

Related