Skip to content

Commit cc6bc5f

Browse files
committed
core: verify size of allocated shared memory
Makes sure that normal world cannot change the size of allocated shared memory, resulting in a smaller buffer being allocated. Suggested-by: Bastien Simondi <bsimondi@netflix.com> [1.1] Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
1 parent 9348854 commit cc6bc5f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

core/arch/arm/kernel/thread.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -1625,25 +1625,30 @@ static void thread_rpc_free(unsigned int bt, uint64_t cookie, struct mobj *mobj)
16251625
}
16261626

16271627
static struct mobj *get_rpc_alloc_res(struct optee_msg_arg *arg,
1628-
unsigned int bt)
1628+
unsigned int bt, size_t size)
16291629
{
16301630
struct mobj *mobj = NULL;
16311631
uint64_t cookie = 0;
1632+
size_t psize = 0;
16321633

16331634
if (arg->ret || arg->num_params != 1)
16341635
return NULL;
16351636

1637+
psize = arg->params[0].u.tmem.size;
1638+
if (psize < size)
1639+
return NULL;
1640+
16361641
if (arg->params[0].attr == OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT) {
16371642
cookie = arg->params[0].u.tmem.shm_ref;
16381643
mobj = mobj_shm_alloc(arg->params[0].u.tmem.buf_ptr,
1639-
arg->params[0].u.tmem.size,
1644+
psize,
16401645
cookie);
16411646
} else if (arg->params[0].attr == (OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
16421647
OPTEE_MSG_ATTR_NONCONTIG)) {
16431648
cookie = arg->params[0].u.tmem.shm_ref;
16441649
mobj = msg_param_mobj_from_noncontig(
16451650
arg->params[0].u.tmem.buf_ptr,
1646-
arg->params[0].u.tmem.size,
1651+
psize,
16471652
cookie,
16481653
true);
16491654
} else {
@@ -1684,7 +1689,7 @@ static struct mobj *thread_rpc_alloc(size_t size, size_t align, unsigned int bt)
16841689
reg_pair_from_64(carg, rpc_args + 1, rpc_args + 2);
16851690
thread_rpc(rpc_args);
16861691

1687-
return get_rpc_alloc_res(arg, bt);
1692+
return get_rpc_alloc_res(arg, bt, size);
16881693
}
16891694

16901695
struct mobj *thread_rpc_alloc_payload(size_t size)

0 commit comments

Comments
 (0)