Skip to content

drc: validate host config blob sizes (dcblock, drc, multiband_drc)#10930

Merged
kv2019i merged 3 commits into
thesofproject:mainfrom
lgirdwood:fix-drc
Jun 18, 2026
Merged

drc: validate host config blob sizes (dcblock, drc, multiband_drc)#10930
kv2019i merged 3 commits into
thesofproject:mainfrom
lgirdwood:fix-drc

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Hardening of the DRC-family components against host config blobs that are
smaller than the structures read out of them (out-of-bounds reads of
adjacent heap otherwise):

  • dcblock: require the blob to cover the coefficient array before copying it
  • drc: require the blob to be at least sizeof(struct sof_drc_config)
  • multiband_drc: require the blob to cover the base config and all
    num_bands per-band coefficient entries

No functional change for valid configurations.

lrgirdwo added 3 commits June 11, 2026 14:40
The coefficient copy always read a fixed number of bytes from the config
blob regardless of its actual size, over-reading adjacent heap for a
short blob. Fall back to passthrough unless the blob holds the whole
coefficient array.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
DRC setup dereferenced the config blob as a fixed struct without
verifying the blob was at least that large, over-reading adjacent heap
for a short blob. Require the blob to cover the config struct.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Setup read a base config struct and per-band coefficients from the blob
without a size check, over-reading for a short blob. Require the blob to
cover the base struct and num_bands band entries.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Copilot AI review requested due to automatic review settings June 16, 2026 14:20
@lgirdwood lgirdwood requested a review from a team as a code owner June 16, 2026 14:20

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.

Hardens DRC-family modules against undersized host config blobs to prevent out-of-bounds reads during setup/config parsing.

Changes:

  • Add minimum-size validation for drc config blobs (must cover struct sof_drc_config).
  • Add minimum-size validation for dcblock coefficient blobs (must cover the coefficient array before copying).
  • Add base+per-band payload validation for multiband_drc blobs, including a num_bands upper bound.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/audio/multiband_drc/multiband_drc.c Validates blob size for base config + num_bands coefficient payload before setup.
src/audio/drc/drc.c Ensures blob is at least sizeof(struct sof_drc_config) before dereferencing/configuring.
src/audio/dcblock/dcblock.c Ensures blob is large enough for coefficient copy; otherwise switches to passthrough.

Comment on lines +372 to +379
/* the blob holds a base struct followed by num_bands variable-length
* band coefficients; require the base struct first, then the full
* per-band payload, so setup cannot read past the blob
*/
if (cd->config && data_size >= sizeof(struct sof_multiband_drc_config) &&
cd->config->num_bands <= SOF_MULTIBAND_DRC_MAX_BANDS &&
data_size >= sizeof(struct sof_multiband_drc_config) +
(size_t)cd->config->num_bands * sizeof(struct sof_drc_params)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

num_bands is bounded to SOF_MULTIBAND_DRC_MAX_BANDS before the multiplication (the && short-circuits left-to-right), so num_bands * sizeof(band) is at most MAX_BANDS * a small struct — it can't overflow size_t. The first term also requires data_size >= sizeof(base) before num_bands is even read.

Comment on lines +376 to 380
if (cd->config && data_size >= sizeof(struct sof_multiband_drc_config) &&
cd->config->num_bands <= SOF_MULTIBAND_DRC_MAX_BANDS &&
data_size >= sizeof(struct sof_multiband_drc_config) +
(size_t)cd->config->num_bands * sizeof(struct sof_drc_params)) {
ret = multiband_drc_setup(mod, channels, rate);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This matches the component's existing behaviour: an absent/!enabled config leaves it in passthrough rather than failing prepare(), so a too-small blob is treated the same way (skip setup, run passthrough). I kept that to avoid changing the failure semantics, but I'm happy to add a comp_warn() so a malformed blob is visible in the logs if you'd prefer.

Comment thread src/audio/drc/drc.c
Comment on lines +356 to 360
/* the blob is dereferenced as a struct sof_drc_config below and in
* drc_setup(), so require it to be at least that large
*/
if (cd->config && data_size >= sizeof(struct sof_drc_config)) {
ret = drc_setup(mod, channels, rate);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as multiband_drc: the existing code already falls back to pass-through (drc_default_pass) when there's no usable config, so an undersized blob takes that same safe path rather than failing prepare(). Can add a comp_warn() for diagnosability if you'd like.

Comment on lines +212 to 215
if (cd->config && data_size >= sizeof(cd->R_coeffs))
dcblock_copy_coefficients(mod);
else
dcblock_set_passthrough(mod);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed it's safe but silent — I left it matching the existing passthrough fallback, but a comp_warn() when the blob is non-NULL yet too small is a reasonable addition. Happy to add it if you want it in this PR.

@kv2019i kv2019i merged commit e5b585c into thesofproject:main Jun 18, 2026
45 of 46 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.

6 participants