The "index" is a user provided value from 0-USHRT_MAX. If it's over
TEE_NUM_SESSIONS (31) then it results in an out of bounds read when we
call test_bit(index, sess->sess_mask).
Fixes: 757cc3e9ff1d ("tee: add AMD-TEE driver")
Signed-off-by: Dan Carpenter <dan.carpenter(a)oracle.com>
---
drivers/tee/amdtee/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/tee/amdtee/core.c b/drivers/tee/amdtee/core.c
index 6370bb55f512..dbc238c7c263 100644
--- a/drivers/tee/amdtee/core.c
+++ b/drivers/tee/amdtee/core.c
@@ -139,6 +139,9 @@ static struct amdtee_session *find_session(struct amdtee_context_data *ctxdata,
u32 index = get_session_index(session);
struct amdtee_session *sess;
+ if (index >= TEE_NUM_SESSIONS)
+ return NULL;
+
list_for_each_entry(sess, &ctxdata->sess_list, list_node)
if (ta_handle == sess->ta_handle &&
test_bit(index, sess->sess_mask))
--
2.11.0
Hello arm-soc maintainers,
Please pull these cleanup patches for shared memory in the TEE subsystem.
Thanks,
Jens
The following changes since commit 11a48a5a18c63fd7621bb050228cebf13566e4d8:
Linux 5.6-rc2 (2020-02-16 13:16:59 -0800)
are available in the Git repository at:
https://git.linaro.org/people/jens.wiklander/linux-tee.git tags/tee-cleanup-for-5.7
for you to fetch changes up to 758ecf13a41a9dc4f019c1381566132ef46c08ee:
tee: tee_shm_op_mmap(): use TEE_SHM_USER_MAPPED (2020-02-28 13:37:42 +0100)
----------------------------------------------------------------
Cleanup shared memory handing in TEE subsystem
The highlights are:
- Removing redundant or unused fields in struct tee_shm
- Only assign userspace shm IDs for shared memory objects originating from
user space
----------------------------------------------------------------
Jens Wiklander (5):
tee: remove linked list of struct tee_shm
tee: remove unused tee_shm_priv_alloc()
tee: don't assign shm id for private shms
tee: remove redundant teedev in struct tee_shm
tee: tee_shm_op_mmap(): use TEE_SHM_USER_MAPPED
drivers/tee/tee_core.c | 1 -
drivers/tee/tee_private.h | 3 +-
drivers/tee/tee_shm.c | 85 +++++++++++++----------------------------------
include/linux/tee_drv.h | 19 +----------
4 files changed, 27 insertions(+), 81 deletions(-)
Hi,
As SHM DMA memory is not unregistered by tee_shm_free() Linux tee driver
API in kexec path (Case A), we 're facing lot of issues including failures
in OP-TEE xtest. Can any one of you suggest the solution.
*Problem Description*
Case A
If tee_shm_free() is called in shutdown() of Linux tee_client_driver and
kexec kernel is booted, shutdown() & tee_shm_free() are invoked but
tee_shm_release() is not invoked on DMA SHM buffer.
Case B
If tee_shm_free() is called on SHM DMA buffer previously allocated from
rmmod path[module_exit()]
It unregisters the SHM memory and sends OPTEE_MSG_CMD_UNREGISTER_SHM to
optee_os through optee_shm_unregister().
*Call Sequence*
Case A: kexec path
*.shutdown()-->tee_shm_free()-->dma_buf_put()*
Case B: rmmod path
*.shutdown()-->tee_shm_free()-->tee_shm_release()-->optee_shm_unregister()
-->optee_do_call_with_arg() [cmd = OPTEE_MSG_CMD_UNREGISTER_SHM]*
*Repercussions of the issue: xtest failure due to out of memory*
If we register a big buffer of say 8MB in Linux tee client driver, if the
same memory is not unregistered, it can cause overhead of 2*1024*8 = 16KB
memory overhead for shm page book keeping data structures calloc'd in
optee_os. After kexec it causes 16 +16=32KB which significant memory on a
minimal heap of size, say 64KB. This causes failures with asymmetric crypto
operations of xtest due to out of memory error.
*Context*
In Linux kernel tee_client_driver probe() we 're calling tee_shm_alloc()
with flags=TEE_SHM_MAPPED | TEE_SHM_DMA_BUF
In remove() & shutdown() functions of the driver: we 're calling
tee_shm_free() on shm reference allocated in probe.
--
Thanks & Regards,
Rajesh
Hello arm-soc maintainers,
Please pull this AMDTEE driver fix for a memory leak in one of the error
paths of amdtee_open_session()
Thanks,
Jens
The following changes since commit 11a48a5a18c63fd7621bb050228cebf13566e4d8:
Linux 5.6-rc2 (2020-02-16 13:16:59 -0800)
are available in the Git repository at:
https://git.linaro.org/people/jens.wiklander/linux-tee.git tags/tee-amdtee-fix-for-5.6
for you to fetch changes up to b83685bceedbeed33a6adc2d0579a011708d2b18:
tee: amdtee: fix memory leak in amdtee_open_session() (2020-02-27 16:22:05 +0100)
----------------------------------------------------------------
Fix AMDTEE memory leak in amdtee_open_session()
----------------------------------------------------------------
Dan Carpenter (1):
tee: amdtee: fix memory leak in amdtee_open_session()
drivers/tee/amdtee/core.c | 48 +++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 24 deletions(-)
If CRYPTO_DEV_CCP_DD=m and AMDTEE=y, the following error is seen
while building call.c or core.c
drivers/tee/amdtee/call.o: In function `handle_unload_ta':
call.c:(.text+0x35f): undefined reference to `psp_tee_process_cmd'
drivers/tee/amdtee/core.o: In function `amdtee_driver_init':
core.c:(.init.text+0xf): undefined reference to `psp_check_tee_status
Fix the config dependency for AMDTEE here.
Reported-by: Hulk Robot <hulkci(a)huawei.com>
Fixes: 757cc3e9ff ("tee: add AMD-TEE driver")
Signed-off-by: Hongbo Yao <yaohongbo(a)huawei.com>
Reviewed-by: Rijo Thomas <Rijo-john.Thomas(a)amd.com>
---
drivers/tee/amdtee/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tee/amdtee/Kconfig b/drivers/tee/amdtee/Kconfig
index 4e32b6413b41..191f9715fa9a 100644
--- a/drivers/tee/amdtee/Kconfig
+++ b/drivers/tee/amdtee/Kconfig
@@ -3,6 +3,6 @@
config AMDTEE
tristate "AMD-TEE"
default m
- depends on CRYPTO_DEV_SP_PSP
+ depends on CRYPTO_DEV_SP_PSP && CRYPTO_DEV_CCP_DD
help
This implements AMD's Trusted Execution Environment (TEE) driver.
--
2.20.1