Skip to content

Commit f5d5641

Browse files
etienne-lmsjforissier
authored andcommitted
optee: check shm reference are consistent in offset/size
This change prevents userland from referencing TEE shared memory outside the area initially allocated by its owner. Prior this change an application could not reference or access memory it did not own but it could reference memory not explicitly allocated by owner but still allocated to the owner due to the memory allocation granule. Reported-by: Alexandre Jutras <[email protected]> Signed-off-by: Etienne Carriere <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
1 parent 94c2f2e commit f5d5641

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/tee/tee_core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ static int params_from_user(struct tee_context *ctx, struct tee_param *params,
284284
if (IS_ERR(shm))
285285
return PTR_ERR(shm);
286286

287+
/*
288+
* Ensure offset + size does not overflow offset
289+
* and does not overflow the size of the referred
290+
* shared memory object.
291+
*/
292+
if ((ip.a + ip.b) < ip.a ||
293+
(ip.a + ip.b) > shm->size) {
294+
tee_shm_put(shm);
295+
return -EINVAL;
296+
}
297+
287298
params[n].u.memref.shm_offs = ip.a;
288299
params[n].u.memref.size = ip.b;
289300
params[n].u.memref.shm = shm;

0 commit comments

Comments
 (0)