Skip to content

Commit 116d1f8

Browse files
guilhermeivogregkh
authored andcommitted
iio: adc: xilinx-ams: fix out-of-bounds channel lookup in event handling
[ Upstream commit 947eb6f ] ams_event_to_channel() may return a pointer past the end of dev->channels when no matching scan_index is found. This can lead to invalid memory access in ams_handle_event(). Add a bounds check in ams_event_to_channel() and return NULL when no channel is found. Also guard the caller to safely handle this case. Fixes: d5c7062 ("iio: adc: Add Xilinx AMS driver") Signed-off-by: Guilherme Ivo Bozi <guilherme.bozi@usp.br> Reviewed-by: Salih Erim <salih.erim@amd.com> Tested-by: Salih Erim <salih.erim@amd.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9f92055 commit 116d1f8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/iio/adc/xilinx-ams.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ static const struct iio_chan_spec *ams_event_to_channel(struct iio_dev *dev,
861861
if (dev->channels[i].scan_index == scan_index)
862862
break;
863863

864+
if (i == dev->num_channels)
865+
return NULL;
866+
864867
return &dev->channels[i];
865868
}
866869

@@ -1002,6 +1005,8 @@ static void ams_handle_event(struct iio_dev *indio_dev, u32 event)
10021005
const struct iio_chan_spec *chan;
10031006

10041007
chan = ams_event_to_channel(indio_dev, event);
1008+
if (!chan)
1009+
return;
10051010

10061011
if (chan->type == IIO_TEMP) {
10071012
/*

0 commit comments

Comments
 (0)