linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] [media] v4l2-common: fix overflow in v4l_bound_align_image()
@ 2014-09-10 16:51 Maciej Matraszek
  2014-09-10 17:10 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Matraszek @ 2014-09-10 16:51 UTC (permalink / raw)
  To: linux-media, linux-kernel, Mauro Carvalho Chehab, Hans Verkuil,
	Lars-Peter Clausen, Sylwester Nawrocki
  Cc: stable, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
	Sakari Ailus, Maciej Matraszek

Fix clamp_align() used in v4l_bound_align_image() to prevent overflow when
passed large value like UINT32_MAX. In the current implementation:
    clamp_align(UINT32_MAX, 8, 8192, 3)
returns 8, because in line:
    x = (x + (1 << (align - 1))) & mask;
x overflows to (-1 + 4) & 0x7 = 3, while expected value is 8192.

v4l_bound_align_image() is heavily used in VIDIOC_S_FMT
and VIDIOC_SUBDEV_S_FMT ioctls handlers, and documentation of the latter
explicitly states that:

"The modified format should be as close as possible to the original request."
  -- http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-subdev-g-fmt.html

Thus one would expect, that passing UINT32_MAX as format width and height
will result in setting maximum possible resolution for the device.
Particularly, when the driver doesn't support VIDIOC_ENUM_FRAMESIZES ioctl,
which is common in the codebase.

Fixes: b0d3159be9a3 ("V4L/DVB (11901): v4l2: Create helper function for bounding and aligning images")
Signed-off-by: Maciej Matraszek <m.matraszek@samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

---
v2: use clamp() instead of clamp_t(), as suggested by Sakari

 drivers/media/v4l2-core/v4l2-common.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index ccaa38f65cf1..2e9d81f4c1a5 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -435,16 +435,13 @@ static unsigned int clamp_align(unsigned int x, unsigned int min,
 	/* Bits that must be zero to be aligned */
 	unsigned int mask = ~((1 << align) - 1);
 
+	/* Clamp to aligned min and max */
+	x = clamp(x, (min + ~mask) & mask, max & mask);
+
 	/* Round to nearest aligned value */
 	if (align)
 		x = (x + (1 << (align - 1))) & mask;
 
-	/* Clamp to aligned value of min and max */
-	if (x < min)
-		x = (min + ~mask) & mask;
-	else if (x > max)
-		x = max & mask;
-
 	return x;
 }
 
-- 
1.9.1


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

* Re: [PATCH v2] [media] v4l2-common: fix overflow in v4l_bound_align_image()
  2014-09-10 16:51 [PATCH v2] [media] v4l2-common: fix overflow in v4l_bound_align_image() Maciej Matraszek
@ 2014-09-10 17:10 ` Greg KH
  2014-09-12 16:11   ` Maciej Matraszek
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2014-09-10 17:10 UTC (permalink / raw)
  To: Maciej Matraszek
  Cc: linux-media, linux-kernel, Mauro Carvalho Chehab, Hans Verkuil,
	Lars-Peter Clausen, Sylwester Nawrocki, stable,
	Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz, Sakari Ailus

On Wed, Sep 10, 2014 at 06:51:09PM +0200, Maciej Matraszek wrote:
> Fix clamp_align() used in v4l_bound_align_image() to prevent overflow when
> passed large value like UINT32_MAX. In the current implementation:
>     clamp_align(UINT32_MAX, 8, 8192, 3)
> returns 8, because in line:
>     x = (x + (1 << (align - 1))) & mask;
> x overflows to (-1 + 4) & 0x7 = 3, while expected value is 8192.
> 
> v4l_bound_align_image() is heavily used in VIDIOC_S_FMT
> and VIDIOC_SUBDEV_S_FMT ioctls handlers, and documentation of the latter
> explicitly states that:
> 
> "The modified format should be as close as possible to the original request."
>   -- http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-subdev-g-fmt.html
> 
> Thus one would expect, that passing UINT32_MAX as format width and height
> will result in setting maximum possible resolution for the device.
> Particularly, when the driver doesn't support VIDIOC_ENUM_FRAMESIZES ioctl,
> which is common in the codebase.
> 
> Fixes: b0d3159be9a3 ("V4L/DVB (11901): v4l2: Create helper function for bounding and aligning images")
> Signed-off-by: Maciej Matraszek <m.matraszek@samsung.com>
> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> ---

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>

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

* Re: [PATCH v2] [media] v4l2-common: fix overflow in v4l_bound_align_image()
  2014-09-10 17:10 ` Greg KH
@ 2014-09-12 16:11   ` Maciej Matraszek
  2014-09-12 16:29     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Matraszek @ 2014-09-12 16:11 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-media, linux-kernel, Mauro Carvalho Chehab, Hans Verkuil,
	Lars-Peter Clausen, Sylwester Nawrocki, stable,
	Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz, Sakari Ailus

On Wed, 2014-09-10 at 10:10 -0700, Greg KH wrote:
> > Fixes: b0d3159be9a3 ("V4L/DVB (11901): v4l2: Create helper function for bounding and aligning images")
> > Signed-off-by: Maciej Matraszek <m.matraszek@samsung.com>
> > Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > 
> > ---
> 
> <formletter>
> 
> This is not the correct way to submit patches for inclusion in the
> stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
> for how to do this properly.
> 
> </formletter>

Hi Greg,

I'm really sorry for this mistake.
Do I understand correctly that it is just a missing
'Cc: <stable@vger.kernel.org>' line?
Are there any other issues?

Thanks for your patience,
Maciej Matraszek



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

* Re: [PATCH v2] [media] v4l2-common: fix overflow in v4l_bound_align_image()
  2014-09-12 16:11   ` Maciej Matraszek
@ 2014-09-12 16:29     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2014-09-12 16:29 UTC (permalink / raw)
  To: Maciej Matraszek
  Cc: linux-media, linux-kernel, Mauro Carvalho Chehab, Hans Verkuil,
	Lars-Peter Clausen, Sylwester Nawrocki, stable,
	Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz, Sakari Ailus

On Fri, Sep 12, 2014 at 06:11:49PM +0200, Maciej Matraszek wrote:
> On Wed, 2014-09-10 at 10:10 -0700, Greg KH wrote:
> > > Fixes: b0d3159be9a3 ("V4L/DVB (11901): v4l2: Create helper function for bounding and aligning images")
> > > Signed-off-by: Maciej Matraszek <m.matraszek@samsung.com>
> > > Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > > 
> > > ---
> > 
> > <formletter>
> > 
> > This is not the correct way to submit patches for inclusion in the
> > stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
> > for how to do this properly.
> > 
> > </formletter>
> 
> Hi Greg,
> 
> I'm really sorry for this mistake.
> Do I understand correctly that it is just a missing
> 'Cc: <stable@vger.kernel.org>' line?

In the signed-off-by: area of the patch, yes, that is what is needed.

Otherwise, just randomly sending the email to that address means
nothing.

thanks,

greg k-h

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

end of thread, other threads:[~2014-09-12 16:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-10 16:51 [PATCH v2] [media] v4l2-common: fix overflow in v4l_bound_align_image() Maciej Matraszek
2014-09-10 17:10 ` Greg KH
2014-09-12 16:11   ` Maciej Matraszek
2014-09-12 16:29     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).