public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][media-next] media: i2c: mt9v111: fix off-by-one array bounds check
@ 2018-07-31 13:33 Colin King
  2018-07-31 13:53 ` jacopo mondi
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King @ 2018-07-31 13:33 UTC (permalink / raw)
  To: Jacopo Mondi, Mauro Carvalho Chehab, linux-media
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The check of fse->index is off-by-one and should be using >= rather
than > to check the maximum allowed array index. Fix this.

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

Fixes: aab7ed1c3927 ("media: i2c: Add driver for Aptina MT9V111")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/media/i2c/mt9v111.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/mt9v111.c b/drivers/media/i2c/mt9v111.c
index da8f6ab91307..b1d13f1d695e 100644
--- a/drivers/media/i2c/mt9v111.c
+++ b/drivers/media/i2c/mt9v111.c
@@ -848,7 +848,7 @@ static int mt9v111_enum_frame_size(struct v4l2_subdev *subdev,
 				   struct v4l2_subdev_pad_config *cfg,
 				   struct v4l2_subdev_frame_size_enum *fse)
 {
-	if (fse->pad || fse->index > ARRAY_SIZE(mt9v111_frame_sizes))
+	if (fse->pad || fse->index >= ARRAY_SIZE(mt9v111_frame_sizes))
 		return -EINVAL;
 
 	fse->min_width = mt9v111_frame_sizes[fse->index].width;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][media-next] media: i2c: mt9v111: fix off-by-one array bounds check
  2018-07-31 13:33 [PATCH][media-next] media: i2c: mt9v111: fix off-by-one array bounds check Colin King
@ 2018-07-31 13:53 ` jacopo mondi
  2018-07-31 13:55   ` Colin Ian King
  0 siblings, 1 reply; 4+ messages in thread
From: jacopo mondi @ 2018-07-31 13:53 UTC (permalink / raw)
  To: Colin King
  Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1238 bytes --]

Hi Colin,
   thanks for the patch.

On Tue, Jul 31, 2018 at 02:33:43PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The check of fse->index is off-by-one and should be using >= rather
> than > to check the maximum allowed array index. Fix this.
>
> Detected by CoverityScan, CID#172122 ("Out-of-bounds read")
>
> Fixes: aab7ed1c3927 ("media: i2c: Add driver for Aptina MT9V111")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Acked-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
  j

> ---
>  drivers/media/i2c/mt9v111.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/i2c/mt9v111.c b/drivers/media/i2c/mt9v111.c
> index da8f6ab91307..b1d13f1d695e 100644
> --- a/drivers/media/i2c/mt9v111.c
> +++ b/drivers/media/i2c/mt9v111.c
> @@ -848,7 +848,7 @@ static int mt9v111_enum_frame_size(struct v4l2_subdev *subdev,
>  				   struct v4l2_subdev_pad_config *cfg,
>  				   struct v4l2_subdev_frame_size_enum *fse)
>  {
> -	if (fse->pad || fse->index > ARRAY_SIZE(mt9v111_frame_sizes))
> +	if (fse->pad || fse->index >= ARRAY_SIZE(mt9v111_frame_sizes))
>  		return -EINVAL;
>
>  	fse->min_width = mt9v111_frame_sizes[fse->index].width;
> --
> 2.17.1
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][media-next] media: i2c: mt9v111: fix off-by-one array bounds check
  2018-07-31 13:53 ` jacopo mondi
@ 2018-07-31 13:55   ` Colin Ian King
  2018-07-31 14:01     ` jacopo mondi
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2018-07-31 13:55 UTC (permalink / raw)
  To: jacopo mondi
  Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 882 bytes --]

On 31/07/18 14:53, jacopo mondi wrote:
> Hi Colin,
>    thanks for the patch.
> 
> On Tue, Jul 31, 2018 at 02:33:43PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The check of fse->index is off-by-one and should be using >= rather
>> than > to check the maximum allowed array index. Fix this.
>>
>> Detected by CoverityScan, CID#172122 ("Out-of-bounds read")
>>
>> Fixes: aab7ed1c3927 ("media: i2c: Add driver for Aptina MT9V111")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Acked-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> 
> Thanks
>   j
> 

Just to note, I also got a build warning on this driver, so that's
something that should be fixed up too.

drivers/media/i2c/mt9v111.c:887:15: warning: 'idx' may be used
uninitialized in this function [-Wmaybe-uninitialized]
  unsigned int idx;



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][media-next] media: i2c: mt9v111: fix off-by-one array bounds check
  2018-07-31 13:55   ` Colin Ian King
@ 2018-07-31 14:01     ` jacopo mondi
  0 siblings, 0 replies; 4+ messages in thread
From: jacopo mondi @ 2018-07-31 14:01 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1180 bytes --]

Hi Colin,

On Tue, Jul 31, 2018 at 02:55:25PM +0100, Colin Ian King wrote:
> On 31/07/18 14:53, jacopo mondi wrote:
> > Hi Colin,
> >    thanks for the patch.
> >
> > On Tue, Jul 31, 2018 at 02:33:43PM +0100, Colin King wrote:
> >> From: Colin Ian King <colin.king@canonical.com>
> >>
> >> The check of fse->index is off-by-one and should be using >= rather
> >> than > to check the maximum allowed array index. Fix this.
> >>
> >> Detected by CoverityScan, CID#172122 ("Out-of-bounds read")
> >>
> >> Fixes: aab7ed1c3927 ("media: i2c: Add driver for Aptina MT9V111")
> >> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >
> > Acked-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> >
> > Thanks
> >   j
> >
>
> Just to note, I also got a build warning on this driver, so that's
> something that should be fixed up too.
>
> drivers/media/i2c/mt9v111.c:887:15: warning: 'idx' may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>   unsigned int idx;

Yes, that's false positive but indeed gcc doesn't know about that.

A patch has already been sent and will hopefully be collected soon:
https://patchwork.linuxtv.org/patch/51259/

Thanks for noticing
   j

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-31 15:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-31 13:33 [PATCH][media-next] media: i2c: mt9v111: fix off-by-one array bounds check Colin King
2018-07-31 13:53 ` jacopo mondi
2018-07-31 13:55   ` Colin Ian King
2018-07-31 14:01     ` jacopo mondi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox