mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-26 18:43:33 -05:00
tee: amdtee: synchronize access to shm list
Synchronize access to shm or shared memory buffer list to prevent
race conditions due to concurrent updates to shared shm list by
multiple threads.
Fixes: 757cc3e9ff
("tee: add AMD-TEE driver")
Reviewed-by: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>
Signed-off-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
This commit is contained in:
parent
ff1f855804
commit
be353be278
2 changed files with 9 additions and 0 deletions
|
@ -70,6 +70,7 @@ struct amdtee_session {
|
||||||
struct amdtee_context_data {
|
struct amdtee_context_data {
|
||||||
struct list_head sess_list;
|
struct list_head sess_list;
|
||||||
struct list_head shm_list;
|
struct list_head shm_list;
|
||||||
|
struct mutex shm_mutex; /* synchronizes access to @shm_list */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct amdtee_driver_data {
|
struct amdtee_driver_data {
|
||||||
|
|
|
@ -42,6 +42,7 @@ static int amdtee_open(struct tee_context *ctx)
|
||||||
|
|
||||||
INIT_LIST_HEAD(&ctxdata->sess_list);
|
INIT_LIST_HEAD(&ctxdata->sess_list);
|
||||||
INIT_LIST_HEAD(&ctxdata->shm_list);
|
INIT_LIST_HEAD(&ctxdata->shm_list);
|
||||||
|
mutex_init(&ctxdata->shm_mutex);
|
||||||
|
|
||||||
ctx->data = ctxdata;
|
ctx->data = ctxdata;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -85,6 +86,7 @@ static void amdtee_release(struct tee_context *ctx)
|
||||||
list_del(&sess->list_node);
|
list_del(&sess->list_node);
|
||||||
release_session(sess);
|
release_session(sess);
|
||||||
}
|
}
|
||||||
|
mutex_destroy(&ctxdata->shm_mutex);
|
||||||
kfree(ctxdata);
|
kfree(ctxdata);
|
||||||
|
|
||||||
ctx->data = NULL;
|
ctx->data = NULL;
|
||||||
|
@ -155,11 +157,13 @@ u32 get_buffer_id(struct tee_shm *shm)
|
||||||
struct amdtee_shm_data *shmdata;
|
struct amdtee_shm_data *shmdata;
|
||||||
u32 buf_id = 0;
|
u32 buf_id = 0;
|
||||||
|
|
||||||
|
mutex_lock(&ctxdata->shm_mutex);
|
||||||
list_for_each_entry(shmdata, &ctxdata->shm_list, shm_node)
|
list_for_each_entry(shmdata, &ctxdata->shm_list, shm_node)
|
||||||
if (shmdata->kaddr == shm->kaddr) {
|
if (shmdata->kaddr == shm->kaddr) {
|
||||||
buf_id = shmdata->buf_id;
|
buf_id = shmdata->buf_id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&ctxdata->shm_mutex);
|
||||||
|
|
||||||
return buf_id;
|
return buf_id;
|
||||||
}
|
}
|
||||||
|
@ -364,7 +368,9 @@ int amdtee_map_shmem(struct tee_shm *shm)
|
||||||
shmnode->kaddr = shm->kaddr;
|
shmnode->kaddr = shm->kaddr;
|
||||||
shmnode->buf_id = buf_id;
|
shmnode->buf_id = buf_id;
|
||||||
ctxdata = shm->ctx->data;
|
ctxdata = shm->ctx->data;
|
||||||
|
mutex_lock(&ctxdata->shm_mutex);
|
||||||
list_add(&shmnode->shm_node, &ctxdata->shm_list);
|
list_add(&shmnode->shm_node, &ctxdata->shm_list);
|
||||||
|
mutex_unlock(&ctxdata->shm_mutex);
|
||||||
|
|
||||||
pr_debug("buf_id :[%x] kaddr[%p]\n", shmnode->buf_id, shmnode->kaddr);
|
pr_debug("buf_id :[%x] kaddr[%p]\n", shmnode->buf_id, shmnode->kaddr);
|
||||||
|
|
||||||
|
@ -385,12 +391,14 @@ void amdtee_unmap_shmem(struct tee_shm *shm)
|
||||||
handle_unmap_shmem(buf_id);
|
handle_unmap_shmem(buf_id);
|
||||||
|
|
||||||
ctxdata = shm->ctx->data;
|
ctxdata = shm->ctx->data;
|
||||||
|
mutex_lock(&ctxdata->shm_mutex);
|
||||||
list_for_each_entry(shmnode, &ctxdata->shm_list, shm_node)
|
list_for_each_entry(shmnode, &ctxdata->shm_list, shm_node)
|
||||||
if (buf_id == shmnode->buf_id) {
|
if (buf_id == shmnode->buf_id) {
|
||||||
list_del(&shmnode->shm_node);
|
list_del(&shmnode->shm_node);
|
||||||
kfree(shmnode);
|
kfree(shmnode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&ctxdata->shm_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int amdtee_invoke_func(struct tee_context *ctx,
|
int amdtee_invoke_func(struct tee_context *ctx,
|
||||||
|
|
Loading…
Add table
Reference in a new issue