Re: [PATCH] [media] atmel-isc: fix off-by-one comparison and out of bounds read issue

From: Wu, Songjun
Date: Mon Mar 13 2017 - 01:56:30 EST




On 3/9/2017 18:57, Hans Verkuil wrote:
Hi Songjun,

On 08/03/17 03:25, Wu, Songjun wrote:
Hi Colin,

Thank you for your comment.
It is a bug, will be fixed in the next patch.

Do you mean that you will provide a new patch for this? Is there anything
wrong with this patch? It seems reasonable to me.

Hi Hans,

I see this patch is merged in git://linuxtv.org/media_tree.git.
So I do not need submit isc-pipeline-v3 patch, just submit the patches, based on the current master branch?

Regards,

Hans


On 3/7/2017 22:30, Colin King wrote:
From: Colin Ian King <colin.king@xxxxxxxxxxxxx>

The are only HIST_ENTRIES worth of entries in hist_entry however the
for-loop is iterating one too many times leasing to a read access off
the end off the array ctrls->hist_entry. Fix this by iterating by
the correct number of times.

Detected by CoverityScan, CID#1415279 ("Out-of-bounds read")

Signed-off-by: Colin Ian King <colin.king@xxxxxxxxxxxxx>
---
drivers/media/platform/atmel/atmel-isc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c
index b380a7d..7dacf8c 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -1298,7 +1298,7 @@ static void isc_hist_count(struct isc_device *isc)
regmap_bulk_read(regmap, ISC_HIS_ENTRY, hist_entry, HIST_ENTRIES);

*hist_count = 0;
- for (i = 0; i <= HIST_ENTRIES; i++)
+ for (i = 0; i < HIST_ENTRIES; i++)
*hist_count += i * (*hist_entry++);
}