-
Notifications
You must be signed in to change notification settings - Fork 1.4k
CRACEN: Avoid possible race-condition on exit_ikg #25734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
CI InformationTo view the history of this post, click the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 1f2575547bffafffa293aa3affb7e40a29e1bce5 more detailssdk-nrf:
Github labels
List of changed files detected by CI (1)Outputs:ToolchainVersion: df3cc9d822 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
tomi-font
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this approach
|
|
||
| sx_pk_release_req(pkreq->req); | ||
| /* This locking may be recursive */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain a bit more why we're acquiring before releasing? (to make sure CRACEN stays enabled)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The race-condition seems to stem from ENABLE bit being set low too early. Having a (potentially) "double acquired" mutex ensures that we never reach the point where we set it low ahead-of-time. This means all processes can run to completion if they are ongoing.
The previous implementation acquired it immediately after releasing it. Potentially starting reset-related behavior a bit too early
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it, I meant to explain a bit more in the code as a comment so we're at least aware that it's important to keep the acquire before the release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comment
subsys/nrf_security/src/drivers/cracen/cracenpsa/src/ikg_signature.c
Outdated
Show resolved
Hide resolved
e82d31d to
61640de
Compare
tomi-font
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect (minus compliance error)
61640de to
4e216d6
Compare
-This commit changes the previous behavior of release/acquire for exit_ikg by relying on recursive locking, which avoid touching the CRACEN ENABLE registers for asymmetric operations. ref: NCSDK-36349 Signed-off-by: Frank Audun Kvamtrø <[email protected]>
4e216d6 to
1f25755
Compare
| int status; | ||
| struct sx_pk_acq_req oldreq = *pkreq; | ||
|
|
||
| sx_pk_release_req(pkreq->req); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this as a quick patch, but it is quite ugly. Would it not be better here to create a "sx_pk_change_req_cmd" function and then just reuse the same req with the new command instead of acquiring two of them? That would also be more generic so we can use that as a pattern in the other functions that have multiple command changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can update the previous PR (this) with your idea so we have a comparison
|
Hi, I have attempted to re-run my test with this change, and unfortunately it does not work. In I think So then in the next call ( |
|
Ah, you're right, |
Thanks for testing this out! We'll go with an alternate solution |

-This commit changes the previous behavior of release/acquire for
exit_ikg by relying on recursive locking, which avoid touching the
CRACEN ENABLE registers for asymmetric operations.
ref: NCSDK-36349