Skip to content
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

DeviceKey: [Security Fix] Generated ROT-key is still used when TRNG fails #9278

Merged
merged 1 commit into from
Jan 9, 2019
Merged

Conversation

boomer41
Copy link
Contributor

@boomer41 boomer41 commented Jan 7, 2019

Description

Fix security bug in DeviceKey's implementation.
With the current implementation, a possible failure of the TRNG cannot be noticed, as the return value in line 269 is immediately overriden in line 274.
When the TRNG somehow fails (e. g. not (yet) ready), the key may stay zeroed out. This is falsely reported back to the generation logic as a success, thus making the RootOfTrust possibly predictable.

This fix ensures that a failed TRNG is properly propagated back to the caller, and that the output is not used as ROT.

@Securityteam (if any): I'd suggest a small security notice to the users that the DeviceKey may be insecure, as the TRNG may have unknowingly failed.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

@boomer41 boomer41 changed the title Fix security bug in DeviceKey's ROT generation DeviceKey: Generated ROT-key is still used when TRNG fails Jan 7, 2019
@boomer41 boomer41 changed the title DeviceKey: Generated ROT-key is still used when TRNG fails DeviceKey: [Security Fix] Generated ROT-key is still used when TRNG fails Jan 7, 2019
@ciarmcom ciarmcom requested review from a team January 7, 2019 18:00
@ciarmcom
Copy link
Member

ciarmcom commented Jan 7, 2019

@boomer41, thank you for your changes.
@ARMmbed/mbed-os-storage @ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@yossi2le yossi2le left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for that catch.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 8, 2019

@Securityteam (if any): I'd suggest a small security notice to the users that the DeviceKey may be insecure, as the TRNG may have unknowingly failed.

@yossi2le can you review this one as well?

@yossi2le
Copy link
Contributor

yossi2le commented Jan 8, 2019

@Securityteam (if any): I'd suggest a small security notice to the users that the DeviceKey may be insecure, as the TRNG may have unknowingly failed.

@boomer41 can you please explain why we need the security notice after this fix will be merged? Do you think there is a real reason to suspect that TRNG may fail and mbedtls_entropy_func will return a success status?

@boomer41
Copy link
Contributor Author

boomer41 commented Jan 8, 2019

@yossi2le I don't know the characteristics of every HAL implementation of the TRNG for every supported CPU. I don't know how the entropy function actually works internally either.

I also can't imagine that the TRNG actually has failed in a single case. But some users may have strict security policies that enforces key rotation when where is only a slight possibility for insecure keys.

This is only suggestion, as I don't know ARM's or mbed's security policy. This is up to you to decide.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 8, 2019

CI started

@boomer41
Copy link
Contributor Author

boomer41 commented Jan 8, 2019

@yossi2le I just found this:


When mbedtls polls for entropy, it initializes a trng_t structure via trng_init every time, uses it, and then destroys it.

As an example, on the STM-family of CPUs, only one trng_t structure can be created.

error("Only 1 RNG instance supported\r\n");

When the ROT is generated in a separate task, whilst another TRNG operation in another Task is also running, the TRNG could actually fail.

Or did I miss something?

@yossi2le
Copy link
Contributor

yossi2le commented Jan 8, 2019

@boomer41
Thanks for the info. I don't think adding the security message is the correct way to go. Actually, we can add one more check for the generate_key_by_random to see that the buffer is indeed changed after the call to mbedtls_entropy_func but it's not a bulletproof either.
In my opinion, after fixing this bug the security issue should be resolved.

In regards to the STM example you provided, the system will halt if this situation will arise. the
error("Only 1 RNG instance supported\r\n")
is actually causing a runtime error and the operation is stopped.

@boomer41
Copy link
Contributor Author

boomer41 commented Jan 8, 2019

@yossi2le
Thank you for that information regarding error().

But I do think we don't understand each other. With "security message" i do mean some kind of email broadcasted to the users, informing them that already generated DeviceKeys may/could be insecure.

If you do already mean this, I apologize.
Thanks.

@yossi2le
Copy link
Contributor

yossi2le commented Jan 8, 2019

@boomer41 Thanks for the clarification. I apologize but I indeed misunderstood your request. I will pass your remark forward and I agree we should distribute this message out.
Thanks for everything.

@mbed-ci
Copy link

mbed-ci commented Jan 8, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@cmonr
Copy link
Contributor

cmonr commented Jan 8, 2019

jenkins-ci/greentea-test failure unrelated to PR.

Restarted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants