Skip to content

Commit 0d62ceb

Browse files
tomchyrlubos
authored andcommitted
suit: Apply limitations to CAND_* components
Apply the following policies: - CAND_MFST may be defined only in Nordic top, Application root and recovery manifests. - CAND_IMG cannot be defined by Nordic top and Application root manifests. Ref: NCSDK-29237 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent c99f283 commit 0d62ceb

File tree

12 files changed

+416
-3
lines changed

12 files changed

+416
-3
lines changed

subsys/suit/mci/src/suit_mci_nrf54h20.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,10 @@ mci_err_t suit_mci_memory_access_rights_validate(const suit_manifest_class_id_t
423423
return MCI_ERR_NOACCESS;
424424

425425
case SUIT_MANIFEST_SEC_SDFW:
426-
/* Sec manifest - TODO - implement checks based on UICR/SICR
426+
/* SDFW & SDFW Recovery manifest - ability to operate on memory ranges intentionally
427+
* blocked.
427428
*/
428-
return SUIT_PLAT_SUCCESS;
429+
return MCI_ERR_NOACCESS;
429430

430431
case SUIT_MANIFEST_SEC_SYSCTRL:
431432
/* Sysctrl manifest - TODO - implement checks based on UICR/SICR

subsys/suit/platform/sdfw/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ zephyr_library_link_libraries_ifdef(CONFIG_SUIT_STREAM suit_stream_sources_inter
3838
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_SINK_SELECTOR suit_sink_selector_interface)
3939
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_DEVCONFIG suit_storage_interface)
4040
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_STORAGE suit_storage_interface)
41+
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_PLAT_CHECK_COMPONENT_COMPATIBILITY suit_storage_interface)
4142
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_STREAM_SOURCE_MEMPTR suit_stream_sources_interface)
4243
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_DEVCONFIG suit_mci)
4344
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_AUTHENTICATE suit_mci)

subsys/suit/platform/sdfw/src/suit_plat_component_compatibility.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
#include <suit_mci.h>
88
#include <suit_plat_decode_util.h>
99
#include <suit_platform_internal.h>
10+
#include <suit_storage_mpi.h>
1011

1112
/* -1 indicates no boot capability for given cpu id */
1213
#define NO_BOOT_CAPABILITY_CPU_ID 255
1314

1415
int suit_plat_component_compatibility_check(const suit_manifest_class_id_t *class_id,
1516
struct zcbor_string *component_id)
1617
{
18+
suit_manifest_role_t role = SUIT_MANIFEST_UNKNOWN;
1719
suit_manifest_class_id_t *decoded_class_id;
1820
suit_component_type_t type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
1921
intptr_t address;
@@ -37,6 +39,10 @@ int suit_plat_component_compatibility_check(const suit_manifest_class_id_t *clas
3739
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
3840
}
3941

42+
if (suit_storage_mpi_role_get(class_id, &role) != SUIT_PLAT_SUCCESS) {
43+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
44+
}
45+
4046
switch (type) {
4147
case SUIT_COMPONENT_TYPE_MEM:
4248
/* Decode component_id */
@@ -57,6 +63,7 @@ int suit_plat_component_compatibility_check(const suit_manifest_class_id_t *clas
5763
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
5864
}
5965
break;
66+
6067
case SUIT_COMPONENT_TYPE_SOC_SPEC:
6168
if (suit_plat_decode_component_number(component_id, &number) != SUIT_PLAT_SUCCESS) {
6269
return SUIT_ERR_DECODING;
@@ -67,12 +74,37 @@ int suit_plat_component_compatibility_check(const suit_manifest_class_id_t *clas
6774
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
6875
}
6976
break;
77+
7078
case SUIT_COMPONENT_TYPE_CAND_MFST:
79+
if (suit_plat_decode_component_number(component_id, &number) != SUIT_PLAT_SUCCESS) {
80+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
81+
}
82+
83+
if ((role != SUIT_MANIFEST_SEC_TOP) && (role != SUIT_MANIFEST_APP_ROOT) &&
84+
(role != SUIT_MANIFEST_APP_RECOVERY)) {
85+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
86+
}
87+
break;
88+
7189
case SUIT_COMPONENT_TYPE_CAND_IMG:
90+
if (suit_plat_decode_component_number(component_id, &number) != SUIT_PLAT_SUCCESS) {
91+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
92+
}
93+
94+
if ((role == SUIT_MANIFEST_SEC_TOP) || (role == SUIT_MANIFEST_APP_ROOT)) {
95+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
96+
}
97+
break;
98+
7299
case SUIT_COMPONENT_TYPE_CACHE_POOL:
73100
if (suit_plat_decode_component_number(component_id, &number) != SUIT_PLAT_SUCCESS) {
74101
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
75102
}
103+
104+
if ((role == SUIT_MANIFEST_SEC_TOP) || (role == SUIT_MANIFEST_SEC_SDFW) ||
105+
(role == SUIT_MANIFEST_SEC_SYSCTRL) || (role == SUIT_MANIFEST_APP_ROOT)) {
106+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
107+
}
76108
break;
77109

78110
case SUIT_COMPONENT_TYPE_INSTLD_MFST:
@@ -90,6 +122,7 @@ int suit_plat_component_compatibility_check(const suit_manifest_class_id_t *clas
90122
}
91123

92124
break;
125+
93126
default:
94127
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
95128
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_FLASH_SIMULATOR=y
8+
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&flash0 {
8+
partitions {
9+
compatible = "fixed-partitions";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
13+
/* Use the last 40KB of NVM as suit storage. */
14+
suit_storage: partition@f6000 {
15+
reg = <0xf6000 DT_SIZE_K(40)>;
16+
};
17+
};
18+
};
19+
20+
/ {
21+
sram0: memory@20000000 {
22+
compatible = "mmio-sram";
23+
reg = <0x20000000 DT_SIZE_K(256)>;
24+
};
25+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_FLASH_SIMULATOR=y
8+
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&flash0 {
8+
partitions {
9+
compatible = "fixed-partitions";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
13+
/* Use the last 40KB of NVM as suit storage. */
14+
suit_storage: partition@f6000 {
15+
reg = <0xf6000 DT_SIZE_K(40)>;
16+
};
17+
};
18+
};
19+
20+
/ {
21+
sram0: memory@20000000 {
22+
compatible = "mmio-sram";
23+
reg = <0x20000000 DT_SIZE_K(256)>;
24+
};
25+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&flash0 {
8+
partitions {
9+
compatible = "fixed-partitions";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
13+
/* Use the last 40KB of NVM as suit storage. */
14+
suit_storage: partition@f6000 {
15+
reg = <0xf6000 DT_SIZE_K(40)>;
16+
};
17+
};
18+
};

tests/subsys/suit/check_image_match/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66

77
CONFIG_ZTEST=y
8+
CONFIG_FLASH=y
89

910
CONFIG_SUIT=y
1011
CONFIG_SUIT_PROCESSOR=y
@@ -32,6 +33,7 @@ CONFIG_SUIT_LOG_LEVEL_DBG=y
3233

3334
CONFIG_SUIT_PLAT_CHECK_COMPONENT_COMPATIBILITY=y
3435
CONFIG_SUIT_AUTHENTICATE=y
36+
CONFIG_SUIT_STORAGE=y
3537
CONFIG_SUIT_MCI=y
3638
CONFIG_SUIT_METADATA=y
3739
CONFIG_SUIT_EXECUTION_MODE=y

tests/subsys/suit/unit/mocks/include/mock_suit_storage.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ FAKE_VALUE_FUNC(int, suit_storage_install_envelope, const suit_manifest_class_id
2323
FAKE_VALUE_FUNC(int, suit_storage_update_cand_get, const suit_plat_mreg_t **, size_t *);
2424
FAKE_VALUE_FUNC(int, suit_storage_update_cand_set, suit_plat_mreg_t *, size_t);
2525

26+
/* suit_storage_mpi.c */
27+
FAKE_VALUE_FUNC(int, suit_storage_mpi_role_get, const suit_manifest_class_id_t *,
28+
suit_manifest_role_t *);
29+
2630
static inline void mock_suit_storage_reset(void)
2731
{
2832
RESET_FAKE(suit_storage_init);
2933
RESET_FAKE(suit_storage_installed_envelope_get);
3034
RESET_FAKE(suit_storage_install_envelope);
3135
RESET_FAKE(suit_storage_update_cand_get);
3236
RESET_FAKE(suit_storage_update_cand_set);
37+
RESET_FAKE(suit_storage_mpi_role_get);
3338
}
3439

3540
#endif /* MOCK_SUIT_STORAGE_H__ */

0 commit comments

Comments
 (0)