Skip to content

Commit b9a4027

Browse files
tomchydegjorva
authored andcommitted
suit: Add API to verify write access to variables
Add API that checks if manifest with given component ID is entitled to change the value of manifest variable. Ref: NCSDK-30807 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 643ce24 commit b9a4027

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

subsys/suit/platform/include/suit_platform_internal.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ int suit_plat_component_id_get(suit_component_t handle, struct zcbor_string **co
6969
/** Return component type based on component handle */
7070
int suit_plat_component_type_get(suit_component_t handle, suit_component_type_t *component_type);
7171

72+
/**
73+
* @brief Verify if a manifest with given component ID is entitled to modify the manifest variable.
74+
*
75+
* @param[in] manifest_component_id Component ID of a manifest that is requesting write access.
76+
* @param[in] id Manifest variable ID.
77+
*
78+
* @retval SUIT_PLAT_SUCCESS if modifications are allowed.
79+
* @retval SUIT_ERR_DECODING if decoding manifest component ID failed.
80+
* @retval SUIT_ERR_UNAUTHORIZED_COMPONENT if manifest is not allowed to modify the variable.
81+
*/
82+
int suit_plat_authorize_var_rw_access(struct zcbor_string *manifest_component_id, uint32_t id);
83+
7284
#ifdef __cplusplus
7385
}
7486
#endif

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <suit_plat_decode_util.h>
1111
#include <suit_plat_component_compatibility.h>
1212
#include <zephyr/logging/log.h>
13+
#ifdef CONFIG_SUIT_MANIFEST_VARIABLES
14+
#include <suit_manifest_variables.h>
15+
#include <suit_storage_mpi.h>
16+
#endif /* CONFIG_SUIT_MANIFEST_VARIABLES */
1317

1418
LOG_MODULE_REGISTER(suit_plat_authenticate, CONFIG_SUIT_LOG_LEVEL);
1519

@@ -190,3 +194,66 @@ int suit_plat_authorize_process_dependency(struct zcbor_string *parent_component
190194

191195
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
192196
}
197+
198+
int suit_plat_authorize_var_rw_access(struct zcbor_string *manifest_component_id, uint32_t id)
199+
{
200+
#ifdef CONFIG_SUIT_MANIFEST_VARIABLES
201+
suit_manifest_role_t role = SUIT_MANIFEST_UNKNOWN;
202+
uint32_t required_access_bits = 0xFF;
203+
suit_manifest_class_id_t *class_id = NULL;
204+
suit_plat_err_t plat_ret;
205+
uint32_t access_mask;
206+
207+
if ((manifest_component_id == NULL) || (manifest_component_id->value == NULL) ||
208+
(manifest_component_id->len == 0)) {
209+
return SUIT_ERR_DECODING;
210+
}
211+
212+
/* Check if component ID is a manifest class */
213+
if (suit_plat_decode_manifest_class_id(manifest_component_id, &class_id) !=
214+
SUIT_PLAT_SUCCESS) {
215+
LOG_ERR("Component ID is not a manifest class");
216+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
217+
}
218+
219+
if (suit_storage_mpi_role_get(class_id, &role) != SUIT_PLAT_SUCCESS) {
220+
LOG_ERR("Failed to identify manifest role");
221+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
222+
}
223+
224+
plat_ret = suit_mfst_var_get_access_mask(id, &access_mask);
225+
if (plat_ret != SUIT_PLAT_SUCCESS) {
226+
LOG_ERR("Unsupported manifest variable %d: %d", id, plat_ret);
227+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
228+
}
229+
230+
switch (role) {
231+
case SUIT_MANIFEST_APP_ROOT:
232+
case SUIT_MANIFEST_APP_RECOVERY:
233+
case SUIT_MANIFEST_APP_LOCAL_1:
234+
case SUIT_MANIFEST_APP_LOCAL_2:
235+
case SUIT_MANIFEST_APP_LOCAL_3:
236+
required_access_bits = MFST_VAR_ACCESS_APP;
237+
break;
238+
case SUIT_MANIFEST_RAD_RECOVERY:
239+
case SUIT_MANIFEST_RAD_LOCAL_1:
240+
case SUIT_MANIFEST_RAD_LOCAL_2:
241+
required_access_bits = MFST_VAR_ACCESS_RAD;
242+
break;
243+
case SUIT_MANIFEST_SEC_TOP:
244+
case SUIT_MANIFEST_SEC_SDFW:
245+
case SUIT_MANIFEST_SEC_SYSCTRL:
246+
required_access_bits = MFST_VAR_ACCESS_SEC;
247+
break;
248+
default:
249+
LOG_ERR("Unsupported manifest role: %d", role);
250+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
251+
}
252+
253+
if ((access_mask & required_access_bits) == required_access_bits) {
254+
return SUIT_SUCCESS;
255+
}
256+
257+
#endif /* CONFIG_SUIT_MANIFEST_VARIABLES */
258+
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
259+
}

0 commit comments

Comments
 (0)