Skip to content

Commit 262234d

Browse files
authored
Merge pull request #3817 from AlessandroA/update_uvisor
Update uVisor to v0.27.0
2 parents 9844a39 + ad436c4 commit 262234d

File tree

25 files changed

+346
-218
lines changed

25 files changed

+346
-218
lines changed

cmsis/core_cmSecureAccess.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
* @param value[in] Value to write at the address location.
5454
*/
5555
#define SECURE_WRITE(address, value) \
56-
uvisor_write(main, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
56+
uvisor_write(public_box, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
5757

5858
/** Get the value at the target address.
5959
*
6060
* @param address[in] Target address
6161
* @returns The value `*address`.
6262
*/
6363
#define SECURE_READ(address) \
64-
uvisor_read(main, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
64+
uvisor_read(public_box, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
6565

6666
/** Get the selected bits at the target address.
6767
*
@@ -70,7 +70,7 @@
7070
* @returns The value `*address & mask`.
7171
*/
7272
#define SECURE_BITS_GET(address, mask) \
73-
UVISOR_BITS_GET(main, UVISOR_RGW_SHARED, address, mask)
73+
UVISOR_BITS_GET(public_box, UVISOR_RGW_SHARED, address, mask)
7474

7575
/** Check the selected bits at the target address.
7676
*
@@ -79,7 +79,7 @@
7979
* @returns The value `((*address & mask) == mask)`.
8080
*/
8181
#define SECURE_BITS_CHECK(address, mask) \
82-
UVISOR_BITS_CHECK(main, UVISOR_RGW_SHARED, address, mask)
82+
UVISOR_BITS_CHECK(public_box, UVISOR_RGW_SHARED, address, mask)
8383

8484
/** Set the selected bits to 1 at the target address.
8585
*
@@ -88,7 +88,7 @@
8888
* @param mask[in] Bits to select out of the target address
8989
*/
9090
#define SECURE_BITS_SET(address, mask) \
91-
UVISOR_BITS_SET(main, UVISOR_RGW_SHARED, address, mask)
91+
UVISOR_BITS_SET(public_box, UVISOR_RGW_SHARED, address, mask)
9292

9393
/** Clear the selected bits at the target address.
9494
*
@@ -97,7 +97,7 @@
9797
* @param mask[in] Bits to select out of the target address
9898
*/
9999
#define SECURE_BITS_CLEAR(address, mask) \
100-
UVISOR_BITS_CLEAR(main, UVISOR_RGW_SHARED, address, mask)
100+
UVISOR_BITS_CLEAR(public_box, UVISOR_RGW_SHARED, address, mask)
101101

102102
/** Set the selected bits at the target address to the given value.
103103
*
@@ -108,7 +108,7 @@
108108
* must be already shifted to the correct bit position
109109
*/
110110
#define SECURE_BITS_SET_VALUE(address, mask, value) \
111-
UVISOR_BITS_SET_VALUE(main, UVISOR_RGW_SHARED, address, mask, value)
111+
UVISOR_BITS_SET_VALUE(public_box, UVISOR_RGW_SHARED, address, mask, value)
112112

113113
/** Toggle the selected bits at the target address.
114114
*
@@ -117,7 +117,7 @@
117117
* @param mask[in] Bits to select out of the target address
118118
*/
119119
#define SECURE_BITS_TOGGLE(address, mask) \
120-
UVISOR_BITS_TOGGLE(main, UVISOR_RGW_SHARED, address, mask)
120+
UVISOR_BITS_TOGGLE(public_box, UVISOR_RGW_SHARED, address, mask)
121121

122122
#else
123123

features/FEATURE_UVISOR/AUTHORS.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
588 Milosch Meriac
2-
506 Alessandro Angelino
3-
95 Jaeden Amero
4-
61 Niklas Hauser
1+
592 Milosch Meriac
2+
544 Alessandro Angelino
3+
98 Jaeden Amero
4+
64 Niklas Hauser
55
4 Irit Arkin
66
3 Hugo Vincent
77
3 JaredCJR
88
3 Jim Huang
9+
2 Jan Jongboom
10+
2 Nathan Chong
911
2 Vincenzo Frascino
1012
2 tonyyanxuan
1113
1 Aksel Skauge Mellbye
12-
1 Nathan Chong
14+
1 Amanda Butler
1315
1 ccli8

features/FEATURE_UVISOR/README.md

Lines changed: 226 additions & 117 deletions
Large diffs are not rendered by default.

features/FEATURE_UVISOR/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.26.2
1+
v0.27.0

features/FEATURE_UVISOR/importer/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ TARGET_LIST_DIR_DST:=$(addprefix $(TARGET_SUPPORTED)/,$(TARGET_LIST))
4545
TARGET_LIST_RELEASE:=$(addsuffix /release,$(TARGET_LIST_DIR_DST))
4646
TARGET_LIST_DEBUG:=$(addsuffix /debug,$(TARGET_LIST_DIR_DST))
4747

48+
# mbed OS paths
49+
MBED_OS_ROOT:=../../..
50+
MBED_OS_CMSIS:=$(MBED_OS_ROOT)/cmsis
51+
4852
.PHONY: all deploy rsync publish uvisor uvisor-compile clean cache update
4953

5054
all: uvisor
@@ -75,6 +79,10 @@ rsync:
7579
cp $(UVISOR_DIR)/core/system/inc/page_allocator_config.h $(TARGET_LIB_SRC)/page_allocator_config.h
7680
rsync -a --delete $(UVISOR_API)/rtx/src/ $(TARGET_LIB_SRC)/rtx
7781
#
82+
# Copying the secure API header file...
83+
# Note: This will not be needed when we upstream the file to CMSIS.
84+
cp $(UVISOR_DIR)/core/cmsis/inc/core_cmSecureAccess.h $(MBED_OS_CMSIS)/
85+
#
7886
# Copying the documentation...
7987
cp $(UVISOR_DIR)/docs/api/QUICKSTART.md $(TARGET_PREFIX)/README.md
8088
#

features/FEATURE_UVISOR/includes/uvisor-lib/rtx/rtx_box_index.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define __RTX_BOX_INDEX_H__
1919

2020
#include "cmsis_os.h"
21-
#include "api/inc/vmpu_exports.h"
2221

2322
#ifdef __cplusplus
2423
extern "C" {

features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <stdint.h>
2525

2626
UVISOR_EXTERN const uint32_t __uvisor_mode;
27-
UVISOR_EXTERN void const * const main_cfg_ptr;
27+
UVISOR_EXTERN void const * const public_box_cfg_ptr;
2828

2929
#define UVISOR_DISABLED 0
3030
#define UVISOR_PERMISSIVE 1
@@ -41,32 +41,30 @@ UVISOR_EXTERN void const * const main_cfg_ptr;
4141
\
4242
UVISOR_EXTERN const uint32_t __uvisor_mode = (mode); \
4343
\
44-
static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig main_cfg = { \
44+
static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig public_box_cfg = { \
4545
UVISOR_BOX_MAGIC, \
4646
UVISOR_BOX_VERSION, \
47-
0, \
48-
0, \
49-
sizeof(RtxBoxIndex), \
5047
{ \
48+
sizeof(RtxBoxIndex), \
49+
0, \
50+
sizeof(uvisor_rpc_t), \
5151
0, \
52-
sizeof(uvisor_rpc_outgoing_message_queue_t), \
53-
sizeof(uvisor_rpc_incoming_message_queue_t), \
54-
sizeof(uvisor_rpc_fn_group_queue_t), \
5552
}, \
53+
0, \
5654
NULL, \
5755
NULL, \
5856
acl_list, \
5957
acl_list_count \
6058
}; \
6159
\
62-
UVISOR_EXTERN const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const main_cfg_ptr = &main_cfg;
60+
UVISOR_EXTERN const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const public_box_cfg_ptr = &public_box_cfg;
6361

6462
/* Creates a global page heap with at least `minimum_number_of_pages` each of size `page_size` in bytes.
6563
* The total page heap size is at least `minimum_number_of_pages * page_size`. */
6664
#define UVISOR_SET_PAGE_HEAP(page_size, minimum_number_of_pages) \
6765
const uint32_t __uvisor_page_size = (page_size); \
6866
uint8_t __attribute__((section(".keep.uvisor.page_heap"))) \
69-
main_page_heap_reserved[ (page_size) * (minimum_number_of_pages) ]
67+
public_page_heap_reserved[ (page_size) * (minimum_number_of_pages) ]
7068

7169

7270
/* this macro selects an overloaded macro (variable number of arguments) */
@@ -92,15 +90,13 @@ UVISOR_EXTERN void const * const main_cfg_ptr;
9290
static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig box_name ## _cfg = { \
9391
UVISOR_BOX_MAGIC, \
9492
UVISOR_BOX_VERSION, \
95-
UVISOR_MIN_STACK(stack_size), \
96-
__uvisor_box_heapsize, \
97-
sizeof(RtxBoxIndex), \
9893
{ \
94+
sizeof(RtxBoxIndex), \
9995
context_size, \
100-
sizeof(uvisor_rpc_outgoing_message_queue_t), \
101-
sizeof(uvisor_rpc_incoming_message_queue_t), \
102-
sizeof(uvisor_rpc_fn_group_queue_t), \
96+
sizeof(uvisor_rpc_t), \
97+
__uvisor_box_heapsize, \
10398
}, \
99+
UVISOR_MIN_STACK(stack_size), \
104100
__uvisor_box_lib_config, \
105101
__uvisor_box_namespace, \
106102
acl_list, \
@@ -155,6 +151,6 @@ UVISOR_EXTERN void const * const main_cfg_ptr;
155151
#define UVISOR_BOX_HEAPSIZE(heap_size) \
156152
static const uint32_t __uvisor_box_heapsize = heap_size;
157153

158-
#define uvisor_ctx (*__uvisor_ps)
154+
#define __uvisor_ctx (((UvisorBoxIndex *) __uvisor_ps)->bss.address_of.context)
159155

160156
#endif /* __UVISOR_API_BOX_CONFIG_H__ */

features/FEATURE_UVISOR/includes/uvisor/api/inc/rpc_exports.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "api/inc/pool_queue_exports.h"
2121
#include "api/inc/uvisor_semaphore_exports.h"
2222
#include "api/inc/rpc_gateway_exports.h"
23+
#include "api/inc/vmpu_exports.h"
2324

2425
typedef uint32_t (*TFN_Ptr)(uint32_t, uint32_t, uint32_t, uint32_t);
2526

@@ -137,4 +138,23 @@ typedef UVISOR_RPC_OUTGOING_MESSAGE_TYPE(UVISOR_RPC_OUTGOING_MESSAGE_SLOTS) uvis
137138
typedef UVISOR_RPC_INCOMING_MESSAGE_TYPE(UVISOR_RPC_INCOMING_MESSAGE_SLOTS) uvisor_rpc_incoming_message_queue_t;
138139
typedef UVISOR_RPC_FN_GROUP_TYPE(UVISOR_RPC_FN_GROUP_SLOTS) uvisor_rpc_fn_group_queue_t;
139140

141+
typedef struct uvisor_rpc_t {
142+
/* Outgoing message queue */
143+
uvisor_rpc_outgoing_message_queue_t outgoing_message_queue;
144+
145+
/* Incoming message queue */
146+
uvisor_rpc_incoming_message_queue_t incoming_message_queue;
147+
148+
/* Function group queue */
149+
uvisor_rpc_fn_group_queue_t fn_group_queue;
150+
151+
/* Counter to avoid waiting on the same RPC result twice by accident. */
152+
uint32_t result_counter;
153+
} uvisor_rpc_t;
154+
155+
static inline uvisor_rpc_t * uvisor_rpc(UvisorBoxIndex * const index)
156+
{
157+
return (uvisor_rpc_t *) index->bss.address_of.rpc;
158+
}
159+
140160
#endif

features/FEATURE_UVISOR/includes/uvisor/api/inc/unsupported.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ UVISOR_EXTERN const uint32_t __uvisor_mode;
4242

4343
#define UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, acl_list_count) \
4444
UVISOR_EXTERN const uint32_t __uvisor_mode = UVISOR_DISABLED; \
45-
static const void *main_acl = acl_list; \
46-
extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const main_cfg_ptr = &main_acl;
45+
static const void *public_box_acl = acl_list; \
46+
extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const public_box_cfg_ptr = &public_box_acl;
4747

4848
#define __UVISOR_BOX_CONFIG_NOCONTEXT(box_name, acl_list, stack_size) \
4949
static const void *box_acl_ ## box_name = acl_list; \

features/FEATURE_UVISOR/includes/uvisor/api/inc/vmpu_exports.h

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
#include "api/inc/uvisor_exports.h"
2121
#include "api/inc/pool_queue_exports.h"
22-
#include "api/inc/rpc_exports.h"
2322
#include <stdint.h>
2423

2524
/* The maximum box namespace length is 37 so that it is exactly big enough for
2625
* a human-readable hex string GUID (as formatted by RFC 4122) followed by a
2726
* terminating NULL. */
2827
#define UVISOR_MAX_BOX_NAMESPACE_LENGTH 37
2928

29+
/** Invalid box id for use in marking objects with invalid ownership. */
30+
#define UVISOR_BOX_ID_INVALID ((uint8_t) -1)
31+
3032
/* supervisor user access modes */
3133
#define UVISOR_TACL_UEXECUTE 0x0001UL
3234
#define UVISOR_TACL_UWRITE 0x0002UL
@@ -150,72 +152,70 @@ typedef struct {
150152
UvisorBoxAcl acl;
151153
} UVISOR_PACKED UvisorBoxAclItem;
152154

155+
/* This struct contains all the BSS sections that uVisor allocates for a secure
156+
* box. It can be used to keep the sizes of the sections or their pointers. */
157+
typedef struct uvisor_bss_sections_t {
158+
uint32_t index;
159+
uint32_t context;
160+
uint32_t rpc;
161+
uint32_t heap;
162+
} UVISOR_PACKED UvisorBssSections;
163+
164+
/* The number of per-box BSS sections. */
165+
#define UVISOR_BSS_SECTIONS_COUNT (sizeof(UvisorBssSections) / sizeof(uint32_t))
166+
167+
/* Compile-time per-box configuration table
168+
* Each box has one of this table in flash. Every other data structure that this
169+
* table might point to must be in flash as well. The uVisor core must check the
170+
* sanity of the table before trusting its fields. */
153171
typedef struct {
154-
/* Contains user provided size of box context without guards of buffers. */
155-
uint32_t context_size;
156-
/* Contains total memory used by the RPC queues (incl. management and pool). */
157-
uint32_t rpc_outgoing_message_size;
158-
uint32_t rpc_incoming_message_size;
159-
uint32_t rpc_fn_group_size;
160-
} UVISOR_PACKED uvisor_sizes_t;
161-
162-
/* The number of additional bss sections per box bss.
163-
* The size of each section is stored in the box config, and uVisor core will
164-
* iterate over the box bss, split it into sections as defined by the size table
165-
* and assign a pointer to beginning of that section into the box index pointer table.
166-
*/
167-
#define UVISOR_BOX_INDEX_SIZE_COUNT (sizeof(uvisor_sizes_t) / sizeof(uint32_t))
168-
169-
typedef struct {
170-
uint32_t magic;
171-
uint32_t version;
172-
173-
/* Box stack size includes stack guards and rounding buffer. */
174-
uint32_t stack_size;
175-
/* Contains user provided size of box heap without guards of buffers. */
176-
uint32_t heap_size;
177-
/* Contains the size of the index (must be at least sizeof(UvisorBoxIndex)). */
178-
uint32_t index_size;
172+
const uint32_t magic;
173+
const uint32_t version;
179174

175+
/* The UvisorBssSections struct is union-ed with a size_t array to allow for
176+
* loops to scan the sizes of all the BSS sections and allocate the
177+
* necessary space for each of them. */
180178
union {
181-
uint32_t bss_size[UVISOR_BOX_INDEX_SIZE_COUNT];
182-
uvisor_sizes_t sizes;
183-
};
179+
size_t sizes[UVISOR_BSS_SECTIONS_COUNT];
180+
UvisorBssSections size_of;
181+
} const bss;
182+
183+
/* Contains the size of the secure box static stack. */
184+
/* Note: This does not include guards. */
185+
/* Note: It is kept separately from the BSS sections as it's implementation
186+
* specific where the stack sits with respect to the BSS. */
187+
const uint32_t stack_size;
184188

185189
/* Opaque-to-uVisor data that potentially contains uvisor-lib-specific or
186190
* OS-specific per-box configuration */
187191
const void * const lib_config;
188192

189-
const char * box_namespace;
193+
const char * const box_namespace;
190194
const UvisorBoxAclItem * const acl_list;
191-
uint32_t acl_count;
195+
const uint32_t acl_count;
192196
} UVISOR_PACKED UvisorBoxConfig;
193197

198+
/* Enumeration-time per-box index table
199+
* Each box has one of this table in SRAM. The index tables are initialized at
200+
* box enumeration time and are then managed by the secure boxes themselves. */
201+
/* Note: Each box is able to read and write its own version of this table. Do
202+
* not trust these pointers in the uVisor core. */
194203
typedef struct {
204+
/* The UvisorSramPointers struct is union-ed with a void * array to allow
205+
* for loops to scan the pointers to all the SRAM sections and access them
206+
* individually. */
195207
union {
196-
void * bss_ptr[UVISOR_BOX_INDEX_SIZE_COUNT];
197-
struct {
198-
/* Pointer to the user context */
199-
void * ctx;
200-
/* Pointer to the RPC queues */
201-
uvisor_rpc_outgoing_message_queue_t * rpc_outgoing_message_queue;
202-
uvisor_rpc_incoming_message_queue_t * rpc_incoming_message_queue;
203-
uvisor_rpc_fn_group_queue_t * rpc_fn_group_queue;
204-
};
205-
};
206-
/* Pointer to the box heap */
207-
void * box_heap;
208+
void * pointers[UVISOR_BSS_SECTIONS_COUNT];
209+
UvisorBssSections address_of;
210+
} bss;
211+
208212
/* Size of the box heap */
209213
uint32_t box_heap_size;
210214
/* Pointer to the currently active heap.
211215
* This is set to `NULL` by uVisor, signalling to the user lib that the
212216
* box heap needs to be initialized before use! */
213217
void * active_heap;
214218

215-
/* Counter that helps to avoid waiting on the same RPC message result twice
216-
* by accident. */
217-
uint32_t rpc_result_counter;
218-
219219
/* Box ID */
220220
int box_id_self;
221221

0 commit comments

Comments
 (0)