-
Notifications
You must be signed in to change notification settings - Fork 349
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
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
Collaborator
Author
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. @lyakh Took a look at this, but actually I'd prefer not to. We know at this point already that the old value of "dd->local_buffer" is invalid and will be soon freed from the heap, so we want to erase in any case. I.e. even if no converter is found, we want to reset dd->local_buffer.
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. sorry, maybe I didn't explain well. This function is only called
Collaborator
Author
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. Right, now I get your point @lyakh . Let me do a small fixup to this in separate PR given I got a green run on the CI and ok from reviewers and we can't of really need to have this fix asap in the tree.
Collaborator
Author
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. -> #7690 |
||
| } | ||
| } | ||
|
|
||
| /* 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.
Show resolved
Hide resolved
|
||
| 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), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.