mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tee: fix illegal pointer dereference in tee_shm_put()
@ 2025-11-06 10:20 yangzhao
  2025-11-06 11:31 ` Jens Wiklander
  0 siblings, 1 reply; 4+ messages in thread
From: yangzhao @ 2025-11-06 10:20 UTC (permalink / raw)
  To: op-tee, linux-kernel; +Cc: Jens Wiklander, Sumit Garg, yangzhao

In tee_shm_put(), there is not only the NULL pointer dereference,
but also the illegal pointer dereference.

shutdown() --->
    __optee_disable_shm_cache -->
        shm = reg_pair_to_ptr(...);
        tee_shm_free(shm); -->
            tee_shm_put(shm); //crash: shm->ctx maybe NULL pointer or illegal pointer

Check whether the pointer is NULL and whether the pointer address is valid.

This issue occurs when rich world uses the 6.x version of the kernel and
optee secure world uses a lower version (such as version 3.2), and it is
highly likely to trigger a kernel panic when conducting hibernate tests.

Fixes: e4a718a3a47e ("tee: fix NULL pointer dereference in tee_shm_put")
Signed-off-by: yangzhao <yangzhao@kylinos.cn>
---
 drivers/tee/tee_shm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 4a47de4bb2e5..de01d16409c1 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -722,7 +722,14 @@ void tee_shm_put(struct tee_shm *shm)
 	struct tee_device *teedev;
 	bool do_release = false;
 
-	if (!shm || !shm->ctx || !shm->ctx->teedev)
+	/* checking pointer */
+	if (IS_ERR_OR_NULL(shm) || !virt_addr_valid(shm))
+		return;
+
+	if (IS_ERR_OR_NULL(shm->ctx) || !virt_addr_valid(shm->ctx))
+		return;
+
+	if (IS_ERR_OR_NULL(shm->ctx->teedev) || !virt_addr_valid(shm->ctx->teedev))
 		return;
 
 	teedev = shm->ctx->teedev;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-10  7:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-06 10:20 [PATCH] tee: fix illegal pointer dereference in tee_shm_put() yangzhao
2025-11-06 11:31 ` Jens Wiklander
2025-11-07  6:14   ` yangzhao
2025-11-10  7:03     ` Jens Wiklander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®