Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 367
dai-zephyr: fix use-after-free in dai copy#7660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1461,6 +1461,37 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev, | ||
| return 0; | ||
| } | ||
| static void set_new_local_buffer(struct dai_data *dd, struct comp_dev *dev) | ||
| { | ||
| struct comp_buffer __sparse_cache *dma_buf = buffer_acquire(dd->dma_buffer); | ||
| struct comp_buffer __sparse_cache *local_buf; | ||
| uint32_t dma_fmt = audio_stream_get_frm_fmt(&dma_buf->stream); | ||
| uint32_t local_fmt; | ||
| buffer_release(dma_buf); | ||
| if (dev->direction == SOF_IPC_STREAM_PLAYBACK) | ||
| dd->local_buffer = list_first_item(&dev->bsource_list, | ||
| struct comp_buffer, | ||
| sink_list); | ||
| else | ||
| dd->local_buffer = list_first_item(&dev->bsink_list, | ||
| struct comp_buffer, | ||
| source_list); | ||
| local_buf = buffer_acquire(dd->local_buffer); | ||
| local_fmt = audio_stream_get_frm_fmt(&local_buf->stream); | ||
| buffer_release(local_buf); | ||
| dd->process = pcm_get_conversion_function(local_fmt, dma_fmt); | ||
| if (!dd->process) { | ||
| comp_err(dev, "converter function NULL: local fmt %d dma fmt %d\n", | ||
| local_fmt, dma_fmt); | ||
| dd->local_buffer = NULL; | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use a temporary variable in lines 1473-1480 above and only assign
| ||
| } | ||
| } | ||
| /* copy and process stream data from source to sink buffers */ | ||
| int dai_zephyr_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_func *converter) | ||
| { | ||
| @@ -1504,6 +1535,15 @@ int dai_zephyr_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun | ||
| buffer_release(buf_c); | ||
| /* handle module runtime unbind */ | ||
| if (!dd->local_buffer) { | ||
| set_new_local_buffer(dd, dev); | ||
| if (!dd->local_buffer) { | ||
| comp_warn(dev, "dai_zephyr_copy(): local buffer unbound, cannot copy"); | ||
btian1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return 0; | ||
| } | ||
| } | ||
| /* calculate minimum size to copy */ | ||
| if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { | ||
| @@ -1743,6 +1783,29 @@ static uint64_t dai_get_processed_data(struct comp_dev *dev, uint32_t stream_no, | ||
| return ret; | ||
| } | ||
| #ifdef CONFIG_IPC_MAJOR_4 | ||
| int dai_zephyr_unbind(struct dai_data *dd, struct comp_dev *dev, void *data) | ||
| { | ||
| struct comp_buffer __sparse_cache *local_buf_c; | ||
| struct ipc4_module_bind_unbind *bu; | ||
| int buf_id; | ||
| bu = (struct ipc4_module_bind_unbind *)data; | ||
| buf_id = IPC4_COMP_ID(bu->extension.r.src_queue, bu->extension.r.dst_queue); | ||
| if (dd && dd->local_buffer) { | ||
| local_buf_c = buffer_acquire(dd->local_buffer); | ||
| if (local_buf_c->id == buf_id) { | ||
| comp_dbg(dev, "dai_zephyr_unbind: local_buffer %x unbound", buf_id); | ||
| dd->local_buffer = NULL; | ||
| } | ||
| buffer_release(local_buf_c); | ||
| } | ||
| return 0; | ||
| } | ||
| #endif /* CONFIG_IPC_MAJOR_4 */ | ||
| static const struct comp_driver comp_dai = { | ||
| .type = SOF_COMP_DAI, | ||
| .uid = SOF_RT_UUID(dai_comp_uuid), | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -52,4 +52,7 @@ int dai_zephyr_get_hw_params(struct dai_data *dd, struct comp_dev *dev, | ||
| int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev, | ||
| struct comp_buffer *multi_endpoint_buffer, | ||
| int num_endpoints); | ||
| int dai_zephyr_unbind(struct dai_data *dd, struct comp_dev *dev, void *data); | ||
btian1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| #endif /* __SOF_LIB_DAI_COPIER_H__ */ | ||
Uh oh!
There was an error while loading. Please reload this page.