From: Weili Qian qianweili@huawei.com
Currently, the async_get_queue_task() only checks whether op in task is NULL. However, instructions executed by the CPU core are out of order. Therefore, it cannot be ensured that type and ctx are assigned values when op is assigned values in async_add_poll_task(). If the value of ctx in the task is NULL or the value of type is invalid, the CPU core will access an abnormal address, resulting in segment error. Therefore, before using ctx or type, check whether the value is valid.
Signed-off-by: Weili Qian qianweili@huawei.com --- src/uadk_async.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/uadk_async.c b/src/uadk_async.c index 4f2ec6a..7536bd5 100644 --- a/src/uadk_async.c +++ b/src/uadk_async.c @@ -147,7 +147,8 @@ err: if (pthread_mutex_unlock(&poll_queue.async_task_mutex)) return NULL;
- if (cur_task && !cur_task->op) + if (!cur_task || !cur_task->op || + !cur_task->ctx || cur_task->type == ASYNC_TASK_MAX) return NULL;
return cur_task; @@ -197,6 +198,8 @@ int async_get_free_task(int *id) task_queue = poll_queue.head; task = &task_queue[idx]; task->op = NULL; + task->ctx = NULL; + task->type = ASYNC_TASK_MAX; ret = UADK_E_SUCCESS;
out: