Skip to contentSkip to conversation

FAILED: patch "[PATCH] tee: optee: Fix incorrect page free bug" failed to apply to 5.4-stable tree

PATCH [email protected] 1 participant 1 message Dec 27, 2021

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 18549bf4b21c739a9def39f27dcac53e27286ab5 Mon Sep 17 00:00:00 2001
From: Sumit Garg <[email protected]>
Date: Thu, 16 Dec 2021 11:17:25 +0530
Subject: [PATCH] tee: optee: Fix incorrect page free bug

Pointer to the allocated pages (struct page *page) has already progressed towards the end of allocation. It is incorrect to perform __free_pages(page, order) using this pointer as we would free any arbitrary pages. Fix this by stop modifying the page pointer.

Fixes ec185dd3ab25 ("optee: Fix memory leak when failing to register shm pages")
drivers/tee/optee/core.c +2 -4
index ab2edfcc6c70..2a66a5203d2f 100644
@@ -48,10 +48,8 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool_mgr *poolm,
 			goto err;
 		}
 
-		for (i = 0; i < nr_pages; i++) {
-			pages[i] = page;
-			page++;
-		}
+		for (i = 0; i < nr_pages; i++)
+			pages[i] = page + i;
 
 		shm->flags |= TEE_SHM_REGISTER;
 		rc = shm_register(shm->ctx, shm, pages, nr_pages,