Skip to content

Commit 0fbc3cf

Browse files
Dan Carpentergregkh
authored andcommitted
iio: ssp_sensors: add more range checking in ssp_parse_dataframe()
commit 8167c9a upstream. The "idx" is validated at the start of the loop but it gets incremented during the iteration so it needs to be checked again. Fixes: 50dd64d ("iio: common: ssp_sensors: Add sensorhub driver") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/20210909091336.GA26312@kili Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent abe5b13 commit 0fbc3cf

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎drivers/iio/common/ssp_sensors/ssp_spi.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
273273
for (idx = 0; idx < len;) {
274274
switch (dataframe[idx++]) {
275275
case SSP_MSG2AP_INST_BYPASS_DATA:
276+
if (idx >= len)
277+
return -EPROTO;
276278
sd = dataframe[idx++];
277279
if (sd < 0 || sd >= SSP_SENSOR_MAX) {
278280
dev_err(SSP_DEV,
@@ -282,17 +284,22 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
282284

283285
if (indio_devs[sd]) {
284286
spd = iio_priv(indio_devs[sd]);
285-
if (spd->process_data)
287+
if (spd->process_data) {
288+
if (idx >= len)
289+
return -EPROTO;
286290
spd->process_data(indio_devs[sd],
287291
&dataframe[idx],
288292
data->timestamp);
293+
}
289294
} else {
290295
dev_err(SSP_DEV, "no client for frame\n");
291296
}
292297

293298
idx += ssp_offset_map[sd];
294299
break;
295300
case SSP_MSG2AP_INST_DEBUG_DATA:
301+
if (idx >= len)
302+
return -EPROTO;
296303
sd = ssp_print_mcu_debug(dataframe, &idx, len);
297304
if (sd) {
298305
dev_err(SSP_DEV,

0 commit comments

Comments
 (0)