module_adapter: dp: Improve module adapter creation function#10565
module_adapter: dp: Improve module adapter creation function#10565softwarecki wants to merge 5 commits intothesofproject:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves error handling and initialization order in the module adapter creation flow for data processing tasks. The changes ensure that task creation failures are properly detected and handled, prevent potential use-after-free issues, and guarantee that module fields are initialized before the DP thread can access them.
Changes:
- Add error checking for DP task initialization to catch creation failures
- Fix task pointer assignment to only occur on successful initialization
- Reorder module field initialization to happen before DP thread creation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/schedule/zephyr_dp_schedule_thread.c | Modified scheduler_dp_task_init() to defer task pointer assignment until after successful thread creation |
| src/audio/module_adapter/module_adapter.c | Added error handling for DP task creation and moved module field initialization before thread creation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b7ea2ac to
db5625c
Compare
| list_init(&mod->raw_data_buffers_list); | ||
| #if CONFIG_USERSPACE | ||
| mod->user_ctx = user_ctx; | ||
| #endif /* CONFIG_USERSPACE */ |
There was a problem hiding this comment.
I suppose this isn't breaking anything and in fact does seem logical, but for the understanding: is this use of uninitialised data really happening? This is called in IPC context. The DP thread suspends immediately when started - I suppose in the "thread" variant too? The thread shouldn't be woken up before this IPC processing completes?
There was a problem hiding this comment.
Yes, the dp thread creation function uses user_ctx. If we don't assign this value first, a kernel dp thread will be created instead of a userspace thread.
Move mod field initialization in module_adapter_new_ext() before creating the dp thread. Moving the initialization earlier prevents the dp thread from use uninitialized data. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Check the value returned by the pipeline_comp_dp_task_init() call in module_adapter_new_ext(). Update scheduler_dp_task_init() to assign the output task structure pointer only on success. The function allocates task structure and free it on failure. Returning a non-null task on error could lead to a double free in the module adapter or use after free. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Fix use after free in module_adapter_new_ext() by removing the dst access after freeing mod. The dst points to a field inside the previously allocated mod structure. The structure is freed on error so its fields do not need to be cleared beforehand. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
db5625c to
6de726a
Compare
Remove the no longer needed user_memory_init_shared(). Add the dp thread to the memory domain directly in the dp scheduler. The function originally added the common partition to the memory domain and added thread to that domain. The userspace proxy now adds the common partition to memory domain, so the function cannot perform this step. Grant access to thread only when userspace is used. Kernel threads have access to all the memory, no need to additionally grant access to them. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Total of 153 commits. Changes include: d885cfebaa3 soc: intel_adsp/ace: Fix MMU mapping for shared heap bb8d441d201 tests: llext: add harvard to scope, build for nsim/nsim_em ebf1f9d019b tests: llext: fixes for arcmwdt, gcc Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
6de726a to
f2a7c05
Compare
pipeline_comp_dp_task_init()to ensure the dp thread is created successfully. This prevents execution from continuing with an invalid task.scheduler_dp_task_init()to assign the output task pointer only on success. The function frees the allocated task structure on failure, so returning a non-null task could lead to a double free or use after free.module_adapter_new_ext()to occur before creating the dp thread. This prevents the thread from use uninitialized fields.