Skip to content

Commit

Permalink
optee: Fix memory leak when failing to register shm pages
Browse files Browse the repository at this point in the history
commit ec185dd upstream.

Free the previously allocated pages when we encounter an error condition
while attempting to register the pages with the secure world.

Fixes: a249dd2 ("tee: optee: Fix dynamic shm pool allocations")
Fixes: 5a769f6 ("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>
  • Loading branch information
tyhicks authored and gregkh committed Aug 12, 2021
1 parent 55dac0d commit 255e179
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/tee/optee/shm_pool.c
Expand Up @@ -36,8 +36,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;
Expand All @@ -48,8 +50,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;
}

Expand Down

0 comments on commit 255e179

Please sign in to comment.