@@ -180,20 +180,77 @@ void eq_iir_s32_default(struct processing_module *mod, struct input_stream_buffe
180180}
181181#endif /* CONFIG_FORMAT_S32LE */
182182
183+ static int eq_iir_blob_words_max (struct comp_dev * dev ,
184+ const struct sof_eq_iir_config * config ,
185+ uint32_t * coef_words_max )
186+ {
187+ size_t payload_bytes ;
188+
189+ /* Compute the size of the coefficient area in int32_t words from the
190+ * blob's self-declared size. The blob layout is:
191+ * sizeof(*config) header bytes
192+ * channels_in_config int32_t assign_response[]
193+ * coefficient data[]
194+ * channels_in_config is bounded above, so the multiply fits in size_t.
195+ */
196+ if (config -> size < sizeof (* config )) {
197+ comp_err (dev , "config size %u too small" , config -> size );
198+ return - EINVAL ;
199+ }
200+ payload_bytes = config -> size - sizeof (* config );
201+ if (payload_bytes % sizeof (int32_t ) ||
202+ payload_bytes < (size_t )config -> channels_in_config * sizeof (int32_t )) {
203+ comp_err (dev , "config size %u misaligned or too small" , config -> size );
204+ return - EINVAL ;
205+ }
206+ * coef_words_max = payload_bytes / sizeof (int32_t ) - config -> channels_in_config ;
207+ return 0 ;
208+ }
209+
210+ static int eq_iir_init_response (struct comp_dev * dev , int idx ,
211+ int32_t * coef_data , uint32_t coef_words_max ,
212+ uint32_t * j , struct sof_eq_iir_header * * eq_out )
213+ {
214+ struct sof_eq_iir_header * eq ;
215+ uint32_t header_end = * j + SOF_EQ_IIR_NHEADER ;
216+ uint32_t section_end ;
217+
218+ /* Header must fit before reading num_sections */
219+ if (header_end > coef_words_max ) {
220+ comp_err (dev , "response %d header out of bounds" , idx );
221+ return - EINVAL ;
222+ }
223+ eq = (struct sof_eq_iir_header * )& coef_data [* j ];
224+ /* Bound num_sections so the multiply cannot overflow and the section
225+ * data stays within the blob.
226+ */
227+ section_end = header_end + (uint32_t )SOF_EQ_IIR_NBIQUAD * eq -> num_sections ;
228+ if (eq -> num_sections > SOF_EQ_IIR_BIQUADS_MAX || section_end > coef_words_max ) {
229+ comp_err (dev , "response %d num_sections %u out of bounds" ,
230+ idx , eq -> num_sections );
231+ return - EINVAL ;
232+ }
233+ * eq_out = eq ;
234+ * j = section_end ;
235+ return 0 ;
236+ }
237+
183238static int eq_iir_init_coef (struct processing_module * mod , int nch )
184239{
185240 struct comp_data * cd = module_get_private_data (mod );
186241 struct sof_eq_iir_config * config = cd -> config ;
187242 struct iir_state_df1 * iir = cd -> iir ;
188243 struct sof_eq_iir_header * lookup [SOF_EQ_IIR_MAX_RESPONSES ];
189244 struct sof_eq_iir_header * eq ;
245+ uint32_t coef_words_max ;
190246 int32_t * assign_response ;
191247 int32_t * coef_data ;
192248 int size_sum = 0 ;
193249 int resp = 0 ;
194250 int i ;
195- int j ;
251+ uint32_t j ;
196252 int s ;
253+ int ret ;
197254
198255 comp_info (mod -> dev , "%u responses, %u channels, stream %d channels" ,
199256 config -> number_of_responses , config -> channels_in_config , nch );
@@ -210,17 +267,21 @@ static int eq_iir_init_coef(struct processing_module *mod, int nch)
210267 return - EINVAL ;
211268 }
212269
270+ ret = eq_iir_blob_words_max (mod -> dev , config , & coef_words_max );
271+ if (ret < 0 )
272+ return ret ;
273+
213274 /* Collect index of response start positions in all_coefficients[] */
214275 j = 0 ;
215276 assign_response = ASSUME_ALIGNED (& config -> data [0 ], 4 );
216- coef_data = ASSUME_ALIGNED (& config -> data [config -> channels_in_config ],
217- 4 );
277+ coef_data = ASSUME_ALIGNED (& config -> data [config -> channels_in_config ], 4 );
218278 for (i = 0 ; i < SOF_EQ_IIR_MAX_RESPONSES ; i ++ ) {
219279 if (i < config -> number_of_responses ) {
220- eq = (struct sof_eq_iir_header * )& coef_data [j ];
280+ ret = eq_iir_init_response (mod -> dev , i , coef_data ,
281+ coef_words_max , & j , & eq );
282+ if (ret < 0 )
283+ return ret ;
221284 lookup [i ] = eq ;
222- j += SOF_EQ_IIR_NHEADER
223- + SOF_EQ_IIR_NBIQUAD * eq -> num_sections ;
224285 } else {
225286 lookup [i ] = NULL ;
226287 }
@@ -315,6 +376,11 @@ int eq_iir_setup(struct processing_module *mod, int nch)
315376 struct comp_data * cd = module_get_private_data (mod );
316377 int delay_size ;
317378
379+ if (cd -> config -> size != cd -> config_size ) {
380+ comp_err (mod -> dev , "Incorrect configuration blob size" );
381+ return - EINVAL ;
382+ }
383+
318384 /* Free existing IIR channels data if it was allocated */
319385 eq_iir_free_delaylines (mod );
320386
0 commit comments