Skip to content

audio: copier: fix channel and memcpy validation#10897

Merged
kv2019i merged 2 commits into
thesofproject:mainfrom
abonislawski:fix/copier_set_gain_channels
Jun 17, 2026
Merged

audio: copier: fix channel and memcpy validation#10897
kv2019i merged 2 commits into
thesofproject:mainfrom
abonislawski:fix/copier_set_gain_channels

Conversation

@abonislawski

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 12, 2026 11:42
@abonislawski abonislawski requested a review from pblaszko as a code owner June 12, 2026 11:42
channels is host-controlled (8-bit, 0-255).
Without validation it drives the memcpy length (channels * sizeof(uint16_t))
against a MAX_GAIN_COEFFS_CNT-sized stack buffer and, for channels == 0,
causes divide-by-zero in the coefficient replication loop.
Reject values outside [1, MAX_GAIN_COEFFS_CNT].

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates copier gain DMA control to use an unsigned channel count, adds explicit channel-count validation, and fixes memcpy_s destination size validation to prevent incorrect bounds checking.

Changes:

  • Switch channels parameter/type from int to uint32_t for copier gain configuration.
  • Add runtime validation for channels (non-zero and within MAX_GAIN_COEFFS_CNT).
  • Correct memcpy_s usage by passing the full destination buffer size.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/audio/copier/copier_gain.h Updates copier_set_gain() API to take uint32_t channels.
src/audio/copier/copier_gain.c Uses uint32_t channels, validates range, and fixes memcpy_s destination size argument.

Comment thread src/audio/copier/copier_gain.h

struct ipc4_copier_module_cfg *copier_cfg = cd->dd[0]->dai_spec_config;
const int channels = copier_cfg->base.audio_fmt.channels_count;
const uint32_t channels = copier_cfg->base.audio_fmt.channels_count;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned int would do too. In the function prototype too of course.

The first memcpy_s call passed gain_coef_size
(= channels * sizeof(uint16_t), host-controlled) as
the dest_size argument, defeating the bounds check.
Pass sizeof(static_gain) — the true buffer capacity
so memcpy_s can enforce the limit.

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
@abonislawski abonislawski force-pushed the fix/copier_set_gain_channels branch from 466596f to a0e659f Compare June 17, 2026 07:26
@abonislawski

Copy link
Copy Markdown
Member Author

Just rerun, no changes

@kv2019i kv2019i merged commit 79662c5 into thesofproject:main Jun 17, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants