Skip to content

Commit 3c51666

Browse files
committed
audio: copier: validate channels_count in copier_set_gain
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>
1 parent 3f7738d commit 3c51666

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/audio/copier/copier_gain.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int copier_gain_dma_control(union ipc4_connector_node_id node, const char *confi
150150
}
151151

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

155155
ret = copier_set_gain(dev, cd->dd[0]->gain_data, gain_data, channels);
156156
if (ret)
@@ -162,7 +162,7 @@ int copier_gain_dma_control(union ipc4_connector_node_id node, const char *confi
162162
}
163163

164164
int copier_set_gain(struct comp_dev *dev, struct copier_gain_params *gain_params,
165-
struct gain_dma_control_data *gain_data, int channels)
165+
struct gain_dma_control_data *gain_data, uint32_t channels)
166166
{
167167
uint16_t static_gain[MAX_GAIN_COEFFS_CNT];
168168
int ret;
@@ -172,6 +172,11 @@ int copier_set_gain(struct comp_dev *dev, struct copier_gain_params *gain_params
172172
return -EINVAL;
173173
}
174174

175+
if (channels == 0 || channels > MAX_GAIN_COEFFS_CNT) {
176+
comp_err(dev, "invalid channels count %u", channels);
177+
return -EINVAL;
178+
}
179+
175180
/* Set gain coefficients */
176181
comp_info(dev, "Update gain coefficients from DMA_CONTROL ipc");
177182

src/audio/copier/copier_gain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef __SOF_COPIER_GAIN_H__
99
#define __SOF_COPIER_GAIN_H__
1010

11+
#include <stdint.h>
1112
#include <sof/audio/buffer.h>
1213
#include <ipc4/base_fw.h>
1314
#include <ipc4/gateway.h>
@@ -219,7 +220,7 @@ enum copier_gain_state copier_gain_eval_state(struct copier_gain_params *gain_pa
219220
* @return 0 on success, otherwise a negative error code.
220221
*/
221222
int copier_set_gain(struct comp_dev *dev, struct copier_gain_params *gain_params,
222-
struct gain_dma_control_data *gain_data, int channels);
223+
struct gain_dma_control_data *gain_data, uint32_t channels);
223224

224225
/**
225226
* Checks for unity gain mode.

0 commit comments

Comments
 (0)