Skip to content

Commit 0f631da

Browse files
etienne-lmsGseoC
authored andcommitted
core: verify number of TEE parameters used for standard invocation
Adds missing tests on the number of TEE parameters used to invoke OP-TEE using standard message entry. The max supported value is given by GPD TEE specification as TEE_NUM_PARAMS. Change-Id: Ibd1b72b6685b3c6c00b19963f1cf64c4f3638498 Signed-off-by: Etienne Carriere <[email protected]> Reviewed-on: https://gerrit.st.com/c/mpu/oe/optee/optee_os/+/271365 Reviewed-by: CITOOLS <[email protected]> Reviewed-by: CIBUILD <[email protected]> Reviewed-by: Etienne CARRIERE <[email protected]> Reviewed-by: Gatien CHEVALLIER <[email protected]> Tested-by: Etienne CARRIERE <[email protected]> Domain-Review: Lionel DEBIEVE <[email protected]>
1 parent 76c62d9 commit 0f631da

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

core/tee/entry_std.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,21 @@ static void entry_open_session(struct optee_msg_arg *arg, uint32_t num_params)
358358
TEE_UUID uuid;
359359
struct tee_ta_param param;
360360
size_t num_meta;
361+
size_t num_sess_params = 0;
361362
uint64_t saved_attr[TEE_NUM_PARAMS] = { 0 };
362363

363364
res = get_open_session_meta(num_params, arg->params, &num_meta, &uuid,
364365
&clnt_id);
365366
if (res != TEE_SUCCESS)
366367
goto out;
367368

368-
res = copy_in_params(arg->params + num_meta, num_params - num_meta,
369+
if (SUB_OVERFLOW(num_params, num_meta, &num_sess_params) ||
370+
num_sess_params > TEE_NUM_PARAMS) {
371+
res = TEE_ERROR_BAD_PARAMETERS;
372+
goto out;
373+
}
374+
375+
res = copy_in_params(arg->params + num_meta, num_sess_params,
369376
&param, saved_attr);
370377
if (res != TEE_SUCCESS)
371378
goto cleanup_shm_refs;
@@ -374,7 +381,7 @@ static void entry_open_session(struct optee_msg_arg *arg, uint32_t num_params)
374381
&clnt_id, TEE_TIMEOUT_INFINITE, &param);
375382
if (res != TEE_SUCCESS)
376383
s = NULL;
377-
copy_out_param(&param, num_params - num_meta, arg->params + num_meta,
384+
copy_out_param(&param, num_sess_params, arg->params + num_meta,
378385
saved_attr);
379386

380387
/*
@@ -386,7 +393,7 @@ static void entry_open_session(struct optee_msg_arg *arg, uint32_t num_params)
386393
&session_pnum);
387394

388395
cleanup_shm_refs:
389-
cleanup_shm_refs(saved_attr, &param, num_params - num_meta);
396+
cleanup_shm_refs(saved_attr, &param, num_sess_params);
390397

391398
out:
392399
if (s)
@@ -427,14 +434,19 @@ static void entry_invoke_command(struct optee_msg_arg *arg, uint32_t num_params)
427434

428435
bm_timestamp();
429436

437+
if (num_params > TEE_NUM_PARAMS) {
438+
res = TEE_ERROR_BAD_PARAMETERS;
439+
goto out;
440+
}
441+
430442
res = copy_in_params(arg->params, num_params, &param, saved_attr);
431443
if (res != TEE_SUCCESS)
432-
goto out;
444+
goto cleanup_shm_refs;
433445

434446
s = tee_ta_get_session(arg->session, true, &tee_open_sessions);
435447
if (!s) {
436448
res = TEE_ERROR_BAD_PARAMETERS;
437-
goto out;
449+
goto cleanup_shm_refs;
438450
}
439451

440452
res = tee_ta_invoke_command(&err_orig, s, NSAPP_IDENTITY,
@@ -446,9 +458,10 @@ static void entry_invoke_command(struct optee_msg_arg *arg, uint32_t num_params)
446458

447459
copy_out_param(&param, num_params, arg->params, saved_attr);
448460

449-
out:
461+
cleanup_shm_refs:
450462
cleanup_shm_refs(saved_attr, &param, num_params);
451463

464+
out:
452465
arg->ret = res;
453466
arg->ret_origin = err_orig;
454467
}

0 commit comments

Comments
 (0)