-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
tfm: Move TF-M attestation data to provisioned OTP region #17522
base: main
Are you sure you want to change the base?
tfm: Move TF-M attestation data to provisioned OTP region #17522
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 80f74a9c9e7e93affb1c977345cd857bcfa92fa1 more detailssdk-nrf:
Github labels
List of changed files detected by CI (16)
Outputs:ToolchainVersion: b77d8c1312 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds. Note: This comment is automatically posted by the Documentation Publishing GitHub Action. |
5f309ff
to
956c258
Compare
include/bl_storage.h
Outdated
#if CONFIG_BUILD_WITH_TFM | ||
|
||
static uint32_t get_monotonic_counter_collection_size(const struct counter_collection *collection) | ||
{ | ||
/* Add only the constant part of the counter_collection. */ |
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.
Why are these functions introduced inside header file? These are not marked as inline. Also, as these are static, it means that multiple implementations might end up in the flash. One for each .c file that uses these.
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 functions are inside header file as they are used both in MCUboot and in application (TF-M). This is how it was previously achieved and I did not change this (yet). Having the functions inside bl_storage.c would mean that the bl_storage.c would be split with functions / headers that are available in MCUboot and functions / headers that are available in TF-M.
I guess we are already kind of doing the same in header file, so if you think that moving this split to bl_storage.c would be an improvement, I can give it a go.
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.
Functions moved to bl_storage.c.
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.
Otherwise looks OK, but I don't understand why the implementation is inside header file and not in bl_storage.c
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.
Overall this looks good!
Some comments but I don't see anything seriously wrong with this.
Next time if you can please split such a change to more commits so that it is a bit more easy to follow.
I will give a second look to this before I approve.
@@ -0,0 +1,38 @@ | |||
# Copyright (c) 2024 Nordic Semiconductor |
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.
Doesn't that seem a bit out of place here?
I think that placing this in the same file with the rest of the TFM configurations makes it more logical to me:
sdk-nrf/modules/trusted-firmware-m/Kconfig
Line 473 in 9190d3a
I am not an expert on sysbuild but is the the only way to have this information to be visible by all the images in the build?
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 provisioning is done for the MCUboot, so it does not see the Kconfigs of the application. It might be possible to change this to include Kconfigs of the application, but whether this makes sense would need input from @nordicjm.
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.
sysbuild files go in sysbuild, this is the correct folder
@@ -336,6 +458,124 @@ NRFX_STATIC_INLINE int update_life_cycle_state(enum lcs next_lcs) | |||
return -EINVALIDLCS; | |||
} | |||
|
|||
#if CONFIG_BUILD_WITH_TFM |
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.
This should is be defined in the TFM build I think.
12eebf3
to
db6ad7e
Compare
Memory footprint analysis revealed the following potential issuessample.matter.template.release[nrf7002dk/nrf5340/cpuapp]: High ROM usage: 820682[B] - link (cc: @kkasperczyk-no @ArekBalysNordic @markaj-nordic) Note: This message is automatically posted and updated by the CI (latest/sdk-nrf/PR-17522/17) |
Tried running: With my commit and without my commits. There was no difference, except saving 14 bytes with b0n, so I think that the space warning is due to other commits on main branch. I did have to disable the following: |
db6ad7e
to
9e47ba2
Compare
Yeah, unfortunately it's a little bit useless warning, because we never know which commit it applies to... |
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.
Looks OK in general.
I left few remarks.
enum tfm_plat_err_t tfm_attest_hal_get_verification_service(uint32_t *size, uint8_t *buf) | ||
{ | ||
const char *url = CONFIG_TFM_ATTEST_VERIFICATION_SERVICE_URL; | ||
uint32_t url_len = strlen(url); |
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.
Is it intentional here that url_len does not contain NUL byte?
uint32_t url_len = strlen(url); | |
uint32_t url_len = sizeof(CONFIG_TFM_ATTEST_VERIFICATION_SERVICE_URL); |
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.
Yes. This is intentional. The data is fed to be CBOR encoded, which includes the length of the data. The null byte is not needed.
memcpy(buf, url, url_len); | ||
*size = url_len; |
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.
If you used strlen( )
in the beginning, then memcpy()
would only copy the string without the terminating NUL character.
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.
This is intentional.
/* Ensure word alignment, since the data is stored in memory region | ||
* with word sized read limitation. Perform both build time and run | ||
* time asserts to catch the issue as soon as possible. | ||
*/ | ||
BUILD_ASSERT(offsetof(struct bl_storage_data, key_data) % 4 == 0); | ||
__ASSERT(((uint32_t)p_key % 4 == 0), "Key address is not word aligned"); | ||
|
||
otp_copy32(p_buf, (volatile uint32_t *restrict)p_key, SB_PUBLIC_KEY_HASH_LEN); | ||
otp_copy(p_buf, p_key, SB_PUBLIC_KEY_HASH_LEN); |
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.
Is it really that we cannot guarantee the word alignment anymore?
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 restored the check. I thought the check was originally added as the otp_copy32 required the alignment, but now I am unsure about this.
9e47ba2
to
6b5e913
Compare
You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds. Note: This comment is automatically posted by the Documentation Publish GitHub Action. |
Add bl_storage.c to TF-M to reduce complexity on bl_storage.h. Signed-off-by: Markus Lassila <[email protected]>
ad7a4f0
to
c15aa85
Compare
Ping: @Vge0rge, @nrfconnect/ncs-pluto |
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
c15aa85
to
4b311e5
Compare
4b311e5
to
2cf35a2
Compare
@@ -69,7 +135,11 @@ static bool key_is_valid(uint32_t key_idx) | |||
} | |||
|
|||
/* Invalid value. */ | |||
#if defined(CONFIG_BUILD_WITH_TFM) | |||
abort(); |
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 curious, why abort instead of tfm_core_panic here?
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.
Oversight. This can be tfm_core_panic, but it will need to be forward declared.
@@ -39,7 +48,7 @@ def add_hw_counters(provision_data, num_counter_slots_version, mcuboot_counters_ | |||
assert num_counter_slots_version % 2 == 0, "--num-counters-slots-version must be an even number" | |||
assert mcuboot_counters_slots % 2 == 0, "--mcuboot-counters-slots must be an even number" | |||
|
|||
provision_data += struct.pack('H', 1) # Type "counter collection" | |||
provision_data += struct.pack('H', BL_COLLECTION_TYPE_MONOTONIC_COUNTERS) |
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.
This line is fine but I think that this function will not work for nRF54L15. The counters for this have 32 bit length but here in python when we add the counters in line 57 we do:
provision_data += bytes(2 * num_counter_slots_version * [0xFF])
Which should be wrong I think, we need to update the function.
Optional fields to TF-M attestation were previously stored in tfm_otp_nv_counters region, which we were not able to provision. This moves the psa_certification_reference to the provisioned OTP-region and adds support for accessing the variable data in bl_storage.h. Verification service URL and profile may change with device upgrades, for this reason they are added as Kconfigs. Note that we still need to keep the tfm_otp_nv_counters region when TFM_PARTITION_PROTECTED_STORAGE and TFM_PS_ROLLBACK_PROTECTION are enabled. TF-M will increase monotonic counters every time new data is written and given the limited size of our OTP-region it would not support many updates. NCSDK-17932 Signed-off-by: Markus Lassila <[email protected]>
2cf35a2
to
80f74a9
Compare
Optional fields to TF-M attestation were previously stored in tfm_otp_nv_counters region, which we were not able to provision. This moves the psa_certification_reference to the provisioned OTP-region and adds support for accessing the variable data in
bl_storage.h.
Verification service URL and profile may change with device upgrades, for this reason they are added as Kconfigs.
Note that we still need to keep the tfm_otp_nv_counters region when TFM_PARTITION_PROTECTED_STORAGE and TFM_PS_ROLLBACK_PROTECTION are enabled. TF-M will increase monotonic counters every time new data is written and given the limited size of our OTP-region it would not support many updates.
NCSDK-17932