summaryrefslogtreecommitdiff
path: root/drivers/tee
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.microsoft.com>2021-06-15 01:33:10 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-08-12 14:22:13 +0300
commit1340dc3fb75ea69221f4f5dcb0cbace55ad0331c (patch)
tree7deb1202917823b9287467b2a9fe600864a26197 /drivers/tee
parent6b2ded93d35caa31e4349c3fee7d6b5f8b15e622 (diff)
downloadlinux-1340dc3fb75ea69221f4f5dcb0cbace55ad0331c.tar.xz
optee: Fix memory leak when failing to register shm pages
commit ec185dd3ab257dc2a60953fdf1b6622f524cc5b7 upstream. Free the previously allocated pages when we encounter an error condition while attempting to register the pages with the secure world. Fixes: a249dd200d03 ("tee: optee: Fix dynamic shm pool allocations") Fixes: 5a769f6ff439 ("optee: Fix multi page dynamic shm pool alloc") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tee')
-rw-r--r--drivers/tee/optee/shm_pool.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c
index d767eebf30bd..da06ce9b9313 100644
--- a/drivers/tee/optee/shm_pool.c
+++ b/drivers/tee/optee/shm_pool.c
@@ -32,8 +32,10 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
struct page **pages;
pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL);
- if (!pages)
- return -ENOMEM;
+ if (!pages) {
+ rc = -ENOMEM;
+ goto err;
+ }
for (i = 0; i < nr_pages; i++) {
pages[i] = page;
@@ -44,8 +46,14 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
rc = optee_shm_register(shm->ctx, shm, pages, nr_pages,
(unsigned long)shm->kaddr);
kfree(pages);
+ if (rc)
+ goto err;
}
+ return 0;
+
+err:
+ __free_pages(page, order);
return rc;
}