Skip to contentSkip to conversation

Issue with optee fixing supplicant wait loop

DISCUSSION Amirreza Zarrabi via OP-TEE 2 participants 3 messages May 28, 2025 – Jun 6, 2025

lore
Share & tools
lore
#0 lore raw

Hi Jens, Sumit,

The following change has recently been merged: tee: optee: Fix supplicant wait loop
(https://github.com/torvalds/linux/commit/70b0d6b0a199c5a3ee6c72f5e61681ed6f759612).

This fix addresses the issue where the supplicant may terminate before the client due to the shutdown sequence or a crash. However, it introduces a potential new issue - now that the client is killable, what happens if it terminates before the supplicant?

During cleanup, the client would remove/free the request, while the request would still be available in the request idr for the supplicant. Although I have not been able to reproduce it, this could theoretically result in a kernel page fault.

To address this, there are a few options:
(1) Use rcu and access request under a read lock in optee_supp_recv and optee_supp_send.
(2) Reuse supp->mutex, ensuring that most of these functions run within the lock, even though it may not always be necessary.

Could you confirm whether this behavior was intentional? If not, I am happy to prepare a patch. Additionally, please let me know whether you prefer solution
(1) or (2), or if you have any other suggestions.

Thank you for your time.

Regards,
Amir

#1 lore raw

Hi Amir,

Quoted 6 lines · Amirreza Zarrabi

Hi Jens, Sumit,

The following change has recently been merged: tee: optee: Fix supplicant wait loop
(https://github.com/torvalds/linux/commit/70b0d6b0a199c5a3ee6c72f5e61681ed6f759612).

Quoted 7 lines

This fix addresses the issue where the supplicant may terminate before the client due to the shutdown sequence or a crash. However, it introduces a potential new issue - now that the client is killable, what happens if it terminates before the supplicant?

During cleanup, the client would remove/free the request, while the request would still be available in the request idr for the supplicant. Although I have not been able to reproduce it, this could theoretically result in a kernel page fault.

You're right, a use-after-free is possible.

Quoted 9 lines

To address this, there are a few options:
(1) Use rcu and access request under a read lock in optee_supp_recv and optee_supp_send.
(2) Reuse supp->mutex, ensuring that most of these functions run within the lock, even though it may not always be necessary.

Could you confirm whether this behavior was intentional? If not, I am happy to prepare a patch. Additionally, please let me know whether you prefer solution
(1) or (2), or if you have any other suggestions.

A patch to fix this is welcome. I generally prefer a less complicated alternative, so if possible, please avoid RCU.

Cheers,
Jens

Quoted 7 lines

Thank you for your time.

Regards,
Amir

#2 lore raw

Hi Jens,

Thanks. Sent a patch.
Not tested, just wanted to confirm you are ok with it :).

Regards,
Amir

Quoted 43 lines · Jens Wiklander

Hi Amir,

Quoted 6 lines · Amirreza Zarrabi

Hi Jens, Sumit,

The following change has recently been merged: tee: optee: Fix supplicant wait loop
(https://github.com/torvalds/linux/commit/70b0d6b0a199c5a3ee6c72f5e61681ed6f759612).

Quoted 7 lines

This fix addresses the issue where the supplicant may terminate before the client due to the shutdown sequence or a crash. However, it introduces a potential new issue - now that the client is killable, what happens if it terminates before the supplicant?

During cleanup, the client would remove/free the request, while the request would still be available in the request idr for the supplicant. Although I have not been able to reproduce it, this could theoretically result in a kernel page fault.

You're right, a use-after-free is possible.

Quoted 9 lines

To address this, there are a few options:
(1) Use rcu and access request under a read lock in optee_supp_recv and optee_supp_send.
(2) Reuse supp->mutex, ensuring that most of these functions run within the lock, even though it may not always be necessary.

Could you confirm whether this behavior was intentional? If not, I am happy to prepare a patch. Additionally, please let me know whether you prefer solution
(1) or (2), or if you have any other suggestions.

A patch to fix this is welcome. I generally prefer a less complicated alternative, so if possible, please avoid RCU.

Cheers,
Jens

Quoted 7 lines

Thank you for your time.

Regards,
Amir