-
Notifications
You must be signed in to change notification settings - Fork 3k
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
No internal kv store for storing Root Of Trust key when using TDB_EXTERNAL_NO_RBP #11788
Comments
cc @ARMmbed/mbed-os-storage |
Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers. |
@Jaco-Liebenberg Thanks for your analysis, I can totally confirm it. The issue happens with I've created #13986 to fix this. Additionally, sometime after you created this issue, DeviceKey RoT needs to be manually generated in the main app now, so ARMmbed/mbed-os-example-kvstore#67 is also needed. @evedon Both PRs are ready for review, thanks. |
The analysis is correct but the proposed solution is a major breaking change. In the current implementation, SecureStore can be created on top of external Flash only and in that configuration less security features are provided. Only encryption is possible. Authentication, rollback protection and "write once" are only possible with TDBStore on top of internal flash. I think the solution is to use the @davidsaada could you advise please? |
@evedon This takes me long time back, so hopefully I'm not forgetting anything here. |
@evedon @davidsaada Thanks for the comments.
The PR doesn't alter the behaviour of anything. In the NO_RBP case, the internal TDB created purely for DeviceKey RoT, not for SecureStore itself. Just as before, rollback/replay protection remains disabled in SecureStore because of the flag: mbed-os/storage/kvstore/kv_config/source/kv_config.cpp Lines 946 to 948 in e77b1d8
So I think it's a non-breaking change?
Thanks for the explanation. Yea, from the |
Thanks for your reply @davidsaada |
An intended benefit of NO_RBP is it doesn't require an internal TDB. If the fix involves creating one anyway, NO_RBP would be kind of pointless? |
This is exactly why the design is flawed. It does not make sense to have a configuration which is specifically meant to work without internal TDB but creates one under the hood. |
Fixed in #14490 |
Description of defect
I might be missing something but this looks and smells like a bug to me.
No internal kvstore gets mapped in KVMap in which to store Root of Trust key when
storage.storage_type
gets set toTDB_EXTERNAL_NO_RBP
. I am well aware that because there is no Roll Back Protection an internal kvstore is not needed. But if we want to encrypt anything in the kvstore on the external TDB we need encryption keys. These encryption keys should be derived from the Root of Trust key which gets saved (and should be saved) in a kvstore in the internal memory of the processor. As such it is my understanding that an internal kvstore is still needed. Like I said I might be missing something but from examining SecureStore and DeviceKey, what I've said does seem to be the case.I came across this bug while playing around with the different storage configurations. I wanted to see the encryption of values stored in the kvstore in action and as such, I adapted the kv_store_global_api_example application as follows:
with the following mbed_app.json
I am aware that in this application I am creating a FlashAIPBlockDevice at the end of the internal flash memory of the processor and that I am then "tricking" the application into using that BlockDevice as if it is an external BlockDevice. That is by design. I am also aware that in doing so I might be causing the bug rather than it being an inherent bug of the overall system design, although from going through the code it is my understanding that this is not the case. I am also aware that should an internal kvstore be created in which the Root of Trust key be stored that that kvstore's memory would most probably coincide with the memory of my self-created FlashAIPBlockDevice.
Be all of that as it may, I still believe this example application is a good example to demonstrate the perceived bug I am reporting. Towards that goal please examine the call stack below:
Examining the call stack it can be seen that the kvstore_global_api has been used to set a value to the global kvstore, that the global kvstore referred it to the underlining SecureStore. That the SecureStore started the encryption process and requested a key derived from the Root Of Trust key. That the derived key generation process requested the Root of Trust, found there do not exist one yet, generated a new random key and started injecting this new Root of Trust. This was done calling
DeviceKey::write_key_to_kvstore
which in turn calledKVMap::get_internal_kv_instance
. The call stack is now at the point where it will return NULL forKVMap::get_internal_kv_instance
because an internal kvstore was never mapped.Like I said this might have happened because of my "trickery" above but examining
_storage_config_TDB_EXTERNAL_NO_RBP()
in conjunction with_storage_config_tdb_external_common()
it would seem that the bug would have happened even if a true external BlockDevice was used.Suggested solution
I do not at this point trust my understanding of the complete system design well enough to make anything more than a recommendation. That recommendation would be to always create a FlashAIPBlockDevice (even if it is just the last two sectors of the internal flash memory) and to always map that to the kvstore_config.internal_bd
Target(s) affected by this defect ?
This bug was discovered using a nucleo_f429zi but should affect all targets
Toolchain(s) (name and version) displaying this defect ?
This bug was discovered using gcc_arm version 8.2.1 but should affect all Toolchains
What version of Mbed-os are you using (tag or sha) ?
mbed-os-5.14.1, 679d248
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
mbed-cli version 1.10.1
How is this defect reproduced ?
This defect can be reproduced by running the application above or by setting
storage.storage_type
toTDB_EXTERNAL_NO_RBP
(providing you have some form of external storage to your disposal) in mbed_app.json and then using the Global Static API to set a value in the global kvstore.The text was updated successfully, but these errors were encountered: