]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tee: optee: prevent use-after-free when the client exits before the supplicant
authorAmirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>
Mon, 16 Feb 2026 22:24:06 +0000 (14:24 -0800)
committerJens Wiklander <jens.wiklander@linaro.org>
Mon, 2 Mar 2026 13:36:50 +0000 (14:36 +0100)
commit387a926ee166814611acecb960207fe2f3c4fd3e
treedd06e244ffe37215a7775890c24e057d0ad390f8
parent6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
tee: optee: prevent use-after-free when the client exits before the supplicant

Commit 70b0d6b0a199 ("tee: optee: Fix supplicant wait loop") made the
client wait as killable so it can be interrupted during shutdown or
after a supplicant crash. This changes the original lifetime expectations:
the client task can now terminate while the supplicant is still processing
its request.

If the client exits first it removes the request from its queue and
kfree()s it, while the request ID remains in supp->idr. A subsequent
lookup on the supplicant path then dereferences freed memory, leading to
a use-after-free.

Serialise access to the request with supp->mutex:

  * Hold supp->mutex in optee_supp_recv() and optee_supp_send() while
    looking up and touching the request.
  * Let optee_supp_thrd_req() notice that the client has terminated and
    signal optee_supp_send() accordingly.

With these changes the request cannot be freed while the supplicant still
has a reference, eliminating the race.

Fixes: 70b0d6b0a199 ("tee: optee: Fix supplicant wait loop")
Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>
Tested-by: Ox Yeh <ox.yeh@mediatek.com>
Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
drivers/tee/optee/supp.c