Commit 46d6ee12 authored by Etienne Carriere's avatar Etienne Carriere Committed by Greg Kroah-Hartman

tee: check shm references are consistent in offset/size

[ Upstream commit ab9d3db5 ]

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: default avatarAlexandre Jutras <alexandre.jutras@nxp.com>
Signed-off-by: default avatarEtienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: default avatarJens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d40e177f
...@@ -181,6 +181,17 @@ static int params_from_user(struct tee_context *ctx, struct tee_param *params, ...@@ -181,6 +181,17 @@ static int params_from_user(struct tee_context *ctx, struct tee_param *params,
if (IS_ERR(shm)) if (IS_ERR(shm))
return PTR_ERR(shm); return PTR_ERR(shm);
/*
* Ensure offset + size does not overflow offset
* and does not overflow the size of the referred
* shared memory object.
*/
if ((ip.a + ip.b) < ip.a ||
(ip.a + ip.b) > shm->size) {
tee_shm_put(shm);
return -EINVAL;
}
params[n].u.memref.shm_offs = ip.a; params[n].u.memref.shm_offs = ip.a;
params[n].u.memref.size = ip.b; params[n].u.memref.size = ip.b;
params[n].u.memref.shm = shm; params[n].u.memref.shm = shm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment