Skip to content

Commit 39822cb

Browse files
authored
Merge pull request #1 from Patater/secure-caller-id
Secure the caller ID
2 parents 4eaaf7f + 219ff65 commit 39822cb

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

source/secure_number.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct box_context {
2323
uint32_t secret_number;
2424
int trusted_id;
2525
int previous_box_caller;
26+
int caller_id;
2627
};
2728

2829
static const UvisorBoxAclItem acl[] = {
@@ -42,19 +43,18 @@ UVISOR_BOX_CONFIG(box_number_store, acl, UVISOR_BOX_STACK_SIZE, box_context);
4243
UVISOR_BOX_RPC_GATEWAY_SYNC (box_number_store, secure_number_get_number, get_number, uint32_t, void);
4344
UVISOR_BOX_RPC_GATEWAY_ASYNC(box_number_store, secure_number_set_number, set_number, int, uint32_t);
4445

45-
static int caller_id;
46-
4746
static int get_caller_id()
4847
{
49-
if (caller_id != uvisor_ctx->previous_box_caller) {
48+
if (uvisor_ctx->caller_id != uvisor_ctx->previous_box_caller) {
5049

5150
led_blue = LED_ON;
5251
Thread::wait(100);
5352
led_blue = LED_OFF;
5453

55-
uvisor_ctx->previous_box_caller = caller_id;
54+
uvisor_ctx->previous_box_caller = uvisor_ctx->caller_id;
5655
}
57-
return caller_id;
56+
57+
return uvisor_ctx->caller_id;
5858
}
5959

6060
static uint32_t get_number(void)
@@ -70,6 +70,9 @@ static int set_number(uint32_t number)
7070
{
7171
const int id = get_caller_id();
7272

73+
/* Cache the name verification result. This allows future checks to replace
74+
* a relatively more expensive string compare with a cheaper integer
75+
* comparison. */
7376
if (uvisor_ctx->trusted_id == -1) {
7477
char name[UVISOR_MAX_BOX_NAMESPACE_LENGTH];
7578
memset(name, 0, sizeof(name));
@@ -112,7 +115,7 @@ static void number_store_main(const void *)
112115
int status;
113116

114117
/* NOTE: This serializes all access to the number store! */
115-
status = rpc_fncall_waitfor(my_fn_array, 2, &caller_id, UVISOR_WAIT_FOREVER);
118+
status = rpc_fncall_waitfor(my_fn_array, 2, &uvisor_ctx->caller_id, UVISOR_WAIT_FOREVER);
116119

117120
if (status) {
118121
printf("Failure is not an option.\r\n");

0 commit comments

Comments
 (0)