This is a note to let you know that I've just added the patch titled optee: Fix memory leak when failing to register shm pages to the 5.13-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: optee-fix-memory-leak-when-failing-to-register-shm-pages.patch and it can be found in the queue-5.13 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From ec185dd3ab257dc2a60953fdf1b6622f524cc5b7 Mon Sep 17 00:00:00 2001 From: Tyler Hicks <tyhicks@xxxxxxxxxxxxxxxxxxx> Date: Mon, 14 Jun 2021 17:33:10 -0500 Subject: optee: Fix memory leak when failing to register shm pages From: Tyler Hicks <tyhicks@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxx Signed-off-by: Tyler Hicks <tyhicks@xxxxxxxxxxxxxxxxxxx> Reviewed-by: Jens Wiklander <jens.wiklander@xxxxxxxxxx> Reviewed-by: Sumit Garg <sumit.garg@xxxxxxxxxx> Signed-off-by: Jens Wiklander <jens.wiklander@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/tee/optee/shm_pool.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/tee/optee/shm_pool.c +++ b/drivers/tee/optee/shm_pool.c @@ -36,8 +36,10 @@ static int pool_op_alloc(struct tee_shm_ 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; @@ -48,8 +50,14 @@ static int pool_op_alloc(struct tee_shm_ 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; } Patches currently in stable-queue which might be from tyhicks@xxxxxxxxxxxxxxxxxxx are queue-5.13/optee-clear-stale-cache-entries-during-initialization.patch queue-5.13/tee-correct-inappropriate-usage-of-tee_shm_dma_buf-flag.patch queue-5.13/optee-fix-memory-leak-when-failing-to-register-shm-pages.patch queue-5.13/optee-fix-tee-out-of-memory-failure-seen-during-kexec-reboot.patch queue-5.13/tpm_ftpm_tee-free-and-unregister-tee-shared-memory-during-kexec.patch queue-5.13/tee-add-tee_shm_alloc_kernel_buf.patch queue-5.13/optee-refuse-to-load-the-driver-under-the-kdump-kernel.patch