linux-stable/drivers/tee
Rijo Thomas 1c95574350 tee: amdtee: fix use-after-free vulnerability in amdtee_close_session
commit f4384b3e54 upstream.

There is a potential race condition in amdtee_close_session that may
cause use-after-free in amdtee_open_session. For instance, if a session
has refcount == 1, and one thread tries to free this session via:

    kref_put(&sess->refcount, destroy_session);

the reference count will get decremented, and the next step would be to
call destroy_session(). However, if in another thread,
amdtee_open_session() is called before destroy_session() has completed
execution, alloc_session() may return 'sess' that will be freed up
later in destroy_session() leading to use-after-free in
amdtee_open_session.

To fix this issue, treat decrement of sess->refcount and removal of
'sess' from session list in destroy_session() as a critical section, so
that it is executed atomically.

Fixes: 757cc3e9ff ("tee: add AMD-TEE driver")
Cc: stable@vger.kernel.org
Signed-off-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-19 23:11:06 +02:00
..
amdtee tee: amdtee: fix use-after-free vulnerability in amdtee_close_session 2023-10-19 23:11:06 +02:00
optee ARM: SoC drivers for 6.5 2023-06-29 15:22:19 -07:00
Kconfig tee: combine "config" and "menu" for TEE's menuconfig 2022-04-05 07:32:23 +02:00
Makefile tee: add AMD-TEE driver 2020-01-04 13:49:51 +08:00
tee_core.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
tee_private.h tee: add tee_shm_register_{user,kernel}_buf() 2022-02-16 07:49:41 +01:00
tee_shm.c tee: Pass a pointer to virt_to_page() 2023-03-30 08:34:52 +02:00
tee_shm_pool.c tee: refactor TEE_SHM_* flags 2022-02-16 07:49:41 +01:00