Skip to content

Basic handling of TAMPC#163

Draft
vlilleboe wants to merge 273 commits intonrfconnect:mainfrom
vlilleboe:tampc
Draft

Basic handling of TAMPC#163
vlilleboe wants to merge 273 commits intonrfconnect:mainfrom
vlilleboe:tampc

Conversation

@vlilleboe
Copy link
Copy Markdown
Contributor

No description provided.

theotherjimmy and others added 30 commits April 4, 2022 08:23
This reverts commit 5d32c3e.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
This reverts commit c813480.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
This reverts commit 756ee21.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
… interrupts"

This reverts commit 783e228.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
…ctivity"

This reverts commit 7106adb.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
…ructs"

This reverts commit ac6de68.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
…pheral"

This reverts commit b362d2d.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
…sabled"

This reverts commit 0febe1e.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
This reverts commit 54c0446.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
This reverts commit f87a0a9.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
This reverts commit a1ab8df.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
This reverts commit a81a322.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
Trusted Firmware-M v1.6.0
This file is modified from upstream to directly include the  version.
We have decided to do it manually so that it is easier to test a PR, as
we won't have to have a tag for that PR.
Further, this message might create a merge conflict which would inform future
version updaters to correct the version in this file.

Signed-off-by: Jimmy Brisson <theotherjimmy@gmail.com>
Add the non-secure API IOCTL functions for the nordic platform to the
set of source files exported in the install folder.
In the case where this is built by an external build system instead of
the platform_ns library then this source file needs to be included in
the non-secure application and its build system.

Change-Id: Icd0312bdc3e583f5eb32cde589e2bc3c9a67ffdc
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
…install

Add the non-secure API IOCTL functions for the Laird Connectivity
platform to the set of source files exported in the install folder.
In the case where this is built by an external build system instead of
the platform_ns library then this source file needs to be included in
the non-secure application and its build system.

Change-Id: I53dfdf48446270f2079d0f710125e9a68db577f7
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Make the last target_sources(tfm_ns...) conditional to NS=TRUE. The
current setup is causing bulid issues for musca_s1 since:

c51505f661 modules: tfm: Exclude non-secure TF-M application from build

Fails with:

CMake Error at platform/ext/target/arm/musca_s1/CMakeLists.txt:179:
  Cannot specify sources for target "tfm_ns" which is not built by this
  project.

NOTE: Temporary fix for zephyr fork of trusted-firmware-m, this commit
is not needed in upstream TF-M. This commit should be reverted in the
next upmerge.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add the psa_call_pack and psa_interface_svc to
the unprivilleged part of the image. When
isolation level >1 is used the PSA application
RoT partitions (such as PS) run in unprivilleged
mode and they need to be able to access these
functions when accessing any other RoT services
(such as ITS).

Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
Change-Id: Id82e8fadd1822930162b7bb8b1f434891c5f20d2
(cherry picked from commit 5fd79dc)
This forces DWARF version 4 output so that zephyr debugging and usage
still works with the pyelftools library which does not currently
support v5.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
…alls

Currently S calls are able to return PSA_ERROR_PROGRAMMER_ERROR for
malformed packet parameters, but NS calls will just stay in the error
handler causing a halt or reboot of device, i.e. this is a very easy
Denial-Of-Service attack.
Make sure that the SPM return the error code to NS in this case without
halting the whole device.

This patch will not be sent upstream since the library model is being
deprecated and fixes are no longer accepted.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I557ce35ccce0354421ccd9b2140684a1d833bf0e
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Use nrfx to define IRQ instead of nRF MDK IRQn definitions.
This makes the code more future proof for for future releases of the
hal_nordic repository.

Change-Id: Ib059a9266aca3098753e8d24335fc3d9edf56a36
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Fix interrupt support for serial box 0 on nrf5340 SoC.
Mispelled variable name caused compilation error.

Change-Id: Idaea5c7eb797c1b9338cfc49e997ac2b8af978c2
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
mbedTLS upstream code contains a warning about const
variable set but unused. Just ignore it to avoid Zephyr
tests to fail.

zephyr/modules/crypto/mbedtls/library/aes.c:307:23: warning:
'RT0' defined but not used [-Wunused-const-variable=]
      307 | static const uint32_t RT0[256] = { RT };
          |                       ^~~
zephyr/modules/crypto/mbedtls/library/aes.c:200:28: warning:
'RSb' defined but not used [-Wunused-const-variable=]
      200 | static const unsigned char RSb[256] =

Fixes #51025 (on Zephyr)

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
When using TF-M with upstream MbedTLS, the upstream project
generates a warning about const variables being set but not unused.

This warning causes CI to fail in some downstream consumers of TF-M
(Zephyr in this case). Add `-Wno-unused-const-variable` avoids this
warning.

Author: Flavio Ceolin <flavio.ceolin@intel.com>
Signed-off-by: Kevin Townsend <kevin.townsend@linaro.org>
Change-Id: I106d0d8598a6d075e3824202038fc37e0c5a9861
(cherry picked from commit 21266a0)
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This reverts commit 13abde2.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
…on nrf53"

This reverts commit cf34a76.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
…DK IRQn"

This reverts commit 36de288.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
SebastianBoe and others added 21 commits May 15, 2024 14:07
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Improve MPC configuration documentation.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I191ca14ba8a6880217cc740a77ea2806af1e0d61
Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no>

diff --git a/platform/ext/target/nordic_nrf/common/core/target_cfg.c b/platform/ext/target/nordic_nrf/common/core/target_cfg.c
index fa1a8ed..6692925 100644
--- a/platform/ext/target/nordic_nrf/common/core/target_cfg.c
+++ b/platform/ext/target/nordic_nrf/common/core/target_cfg.c
@@ -963,10 +963,30 @@ enum tfm_plat_err_t nrf_mpc_init_cfg(void)
 	/* On 54l the NRF_MPC00->REGION[]'s are fixed in HW and the
 	 * OVERRIDE indexes (that are useful to us) start at 0 and end
 	 * (inclusive) at 4.
+	 *
+	 * Note that the MPC regions configure all volatile and non-volatile memory as secure, so we only
+	 * need to explicitly OVERRIDE the non-secure addresses to permit non-secure access.
+	 *
+	 * Explicitly configuring memory as secure is not necessary.
+	 *
+	 * The last OVERRIDE in 54L is fixed in HW and exists to prevent
+	 * other bus masters than the KMU from accessing CRACEN protected RAM.
+	 *
+	 * Note that we must take care not to configure an OVERRIDE that
+	 * affects an active bus transaction.
+	 *
+	 * Note that we don't configure the NSC region to be NS because
+	 * from the MPC's perspective it is secure. NSC is only configurable from the SAU.
+	 *
+	 * Note that OVERRIDE[n].MASTERPORT has a reasonable reset value
+	 * so it is left unconfigured.
+	 *
+	 * Note that there are two owners in 54L. KMU with owner ID 1, and everything else with owner ID 0.
 	 */
-	uint32_t index = 0;

-	/* Configure the non-secure partition of the non-volatile
+	uint32_t index = 0;
+	/*
+	 * Configure the non-secure partition of the non-volatile
 	 * memory. This MPC region is intended to cover both the
 	 * non-secure partition in the NVM and also the FICR. The FICR
 	 * starts after the NVM and ends just before the UICR.
@@ -1001,13 +1021,8 @@ enum tfm_plat_err_t nrf_mpc_init_cfg(void)
 		tfm_core_panic();
 	}

-	/* TODO: NCSDK-25050: Review configuration. Any other addresses we need to override? */

-	/* Note that we don't configure the NSC region to be NS because it is secure */

-	/* Note that OVERRIDE[n].MASTERPORT has a reasonable reset value
-	 * so it is left unconfigured.
-	 */

 	return TFM_PLAT_ERR_SUCCESS;
 }
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Lock and disable any unused MPC overrides to prevent malicious
configuration.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I1956f113012d6b67100d814a52d7ce1490663953
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Adds handling of MPC and SPC errors.

Signed-off-by: Vidar Lillebø <vidar.lillebo@nordicsemi.no>
…e base addr

Refactor spu_peripheral_config to use base addresses instead of IDs as
future platforms will need the base address to identify which spu
instance to use.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: Ife60d1e76adffeb62f5ad32e0a85da8cfa467203
…resses

fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Refactor spu_peripheral_config to use base addresses instead of IDs as
future platforms will need the base address to identify which spu
instance to use.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: Ife60d1e76adffeb62f5ad32e0a85da8cfa467203
…tances

Add driver function.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: Ib1e442a54d599c4e42e74903d49920f24e9d8ec9
Port spu_peripheral_config to also support the new API.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I1763874ce74ad39cbf0ef256ef8edc669038d226
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Configure pins as secure on 54L.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: Id50ef81807c5109c01ed6405376f3cfa882c66e0
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Delete dead code in target_cfg.c.

It is redundant with the memset.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I96ffb4002d70a08c827d47fe87ae938b57731f0c
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Refactor UART security configuration to use
spu_peripheral_config_secure.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I00d21c4401fa7c67d51eaf14804c992262c73710
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Configure misc. peripherals as Secure.

See the code for which peripherals and why.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I3cf4f42d5d3bc0aa4dc266e0c1d8035ad69372a1
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Due to dependencies problems between the ITS and crypto partitions
refactoring the ITS encryption interface to use the HUK library and the
cracen driver directly.

Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no>
…ecure

Dont configure the volatile memory controller as a non-secure peripheral

(cherry picked from commit c670a6a)

Change-Id: I2489defaf6deb89beba7447ba079ea3e5afebca5
Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
Fix linking errors with psa_crypto_config observed in TFM test
applications.

To be reverted during the next TFM upmerge, as this isolated change is
already part of a larger commit upstream.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
!fixup [nrf noup] platform: nordic_nrf: Add support for 54l

Change the implementation for cracen ITS encryption to match
cryptocell.

Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no>

diff --git a/platform/ext/target/nordic_nrf/common/core/tfm_hal_its_encryption_cracen.c b/platform/ext/target/nordic_nrf/common/core/tfm_hal_its_encryption_cracen.c
index f759016..8871bc2 100644

Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no>
--- a/platform/ext/target/nordic_nrf/common/core/tfm_hal_its_encryption_cracen.c
+++ b/platform/ext/target/nordic_nrf/common/core/tfm_hal_its_encryption_cracen.c
@@ -110,10 +110,10 @@ static bool ctx_is_valid(struct tfm_hal_its_auth_crypt_ctx *ctx)
 }

 psa_status_t tfm_hal_its_get_aead(struct tfm_hal_its_auth_crypt_ctx *ctx,
-                                  const uint8_t *plaintext,
-                                  const size_t plaintext_size,
-                                  uint8_t *ciphertext,
-                                  const size_t ciphertext_size,
+                                  const uint8_t *input,
+                                  const size_t input_size,
+                                  uint8_t *output,
+                                  const size_t output_size,
                                   uint8_t *tag,
                                   const size_t tag_size,
                                   bool encrypt)
@@ -121,7 +121,8 @@ psa_status_t tfm_hal_its_get_aead(struct tfm_hal_its_auth_crypt_ctx *ctx,
     psa_status_t status;
     uint8_t key_out[CHACHA20_KEY_SIZE];
     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
-    size_t ciphertext_length;
+    cracen_aead_operation_t operation = {0};
+    size_t out_length;
     size_t tag_length = PSA_AEAD_TAG_LENGTH(PSA_KEY_TYPE_CHACHA20,
                                             PSA_BYTES_TO_BITS(CHACHA20_KEY_SIZE),
                                             TFM_ITS_AEAD_ALG);
@@ -134,13 +135,12 @@ psa_status_t tfm_hal_its_get_aead(struct tfm_hal_its_auth_crypt_ctx *ctx,
         return TFM_HAL_ERROR_INVALID_INPUT;
     }

-    if (encrypt && (ciphertext_size < PSA_AEAD_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_CHACHA20,
+    if (encrypt && (output_size < PSA_AEAD_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_CHACHA20,
                                                                    TFM_ITS_AEAD_ALG,
-                                                                   plaintext_size))){
+                                                                   input_size))){
         return TFM_HAL_ERROR_INVALID_INPUT;
     }

-
     status = hw_unique_key_derive_key(HUK_KEYSLOT_MKEK, NULL, 0, ctx->deriv_label, ctx->deriv_label_size, key_out, sizeof(key_out));
     if (status != HW_UNIQUE_KEY_SUCCESS) {
         return TFM_HAL_ERROR_GENERIC;
@@ -152,40 +152,35 @@ psa_status_t tfm_hal_its_get_aead(struct tfm_hal_its_auth_crypt_ctx *ctx,
     psa_set_key_bits(&attributes, PSA_BYTES_TO_BITS(CHACHA20_KEY_SIZE));

     if (encrypt) {
-        status = cracen_aead_encrypt(&attributes,
-                                  key_out,
-                                  sizeof(key_out),
-                                  TFM_ITS_AEAD_ALG,
-                                  ctx->nonce,
-                                  ctx->nonce_size,
-                                  ctx->aad,
-                                  ctx->add_size,
-                                  plaintext,
-                                  plaintext_size,
-                                  ciphertext,
-                                  ciphertext_size,
-                                  &ciphertext_length);
+        status = cracen_aead_encrypt_setup(&operation, &attributes, key_out, sizeof(key_out), TFM_ITS_AEAD_ALG);
     } else {
-        status = cracen_aead_decrypt(&attributes,
-                                  key_out,
-                                  sizeof(key_out),
-                                  TFM_ITS_AEAD_ALG,
-                                  ctx->nonce,
-                                  ctx->nonce_size,
-                                  ctx->aad,
-                                  ctx->add_size,
-                                  plaintext,
-                                  plaintext_size,
-                                  ciphertext,
-                                  ciphertext_size,
-                                  &ciphertext_length);
-    }
-    if(status != PSA_SUCCESS){
+        status = cracen_aead_decrypt_setup(&operation, &attributes, key_out, sizeof(key_out), TFM_ITS_AEAD_ALG);
+    }
+
+    if (status != PSA_SUCCESS) {
+        return status;
+    }
+
+    status = cracen_aead_set_nonce(&operation, ctx->nonce, ctx->nonce_size);
+    if (status != PSA_SUCCESS) {
         return status;
     }

-    /* copy tag from ciphertext buffer to tag buffer */
-    memcpy(tag, ciphertext + ciphertext_length - tag_length, tag_length);
+    status = cracen_aead_update_ad(&operation, ctx->aad, ctx->add_size);
+    if (status != PSA_SUCCESS) {
+        return status;
+    }
+
+    status = cracen_aead_update(&operation, input, input_size, output, output_size, &out_length);
+    if (status != PSA_SUCCESS) {
+        return status;
+    }
+
+    if (encrypt) {
+        status = cracen_aead_finish(&operation, output + out_length, output_size - out_length, &out_length, tag, tag_size, &tag_length);
+    } else {
+        status = cracen_aead_verify(&operation, output + out_length, output_size - out_length, &out_length , tag, tag_size);
+    }

     return status;
 }
Version check depends on upstream's tagging scheme which differs
from NCS's

Signed-off-by: Vidar Lillebø <vidar.lillebo@nordicsemi.no>
Configure NRF_REGULATORS and NRF_OSCILLATORS as secure for security
reasons.

Also, invoke nordicsemi_nrf54l_init from TF-M as the non-secure image
can no longer configure power or clocks.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I9bc7f2b158c0ad9da0c434954c9619da5b70d754
fixup! [nrf noup] platform: nordic_nrf: Add support for 54l

Remove TODO that has been addressed.

VPR is configured to be non-secure when NRF_SPU is memset to 0.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Change-Id: I8f1ee39a51f0d87855d2476b6337994cea5901f5
There are some hardware registers in Nordic platforms
which are mapped as secure only. In order to allow the
non-secure application to control these registers I added
here a secure service which allows 32-bit writes to secure
mapped memory. The writes are only allowed on  addresses and
masks defined in a header list. It is also possible to
provide an allowed_values list in order to further limit
the accepted values.

Renamed:  tfm_read_ranges.h -> tfm_platform_user_memory_ranges.h
since now it can be used for both reads and writes.

The list in the current platforms is empty and might be populated
later.

Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
Change-Id: Ifa31ba73ec07b216a7e987653255fcc6e9d3989c
(cherry picked from commit 57b3342)
Add a custom section in the linker script for the CRACEN KMU
driver use by nRF54L15. We need a buffer in a static memory
location which wil be used by the KMU to perform push
operations.

It's a noup since the KMU is not supported fully upstream
yet.

Ref: NCSDK-25121

Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
Signed-off-by: Vidar Lillebø <vidar.lillebo@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.