linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] v4l: ioctl: Validate num_planes before using it
@ 2019-01-10 12:43 Sakari Ailus
  2019-01-10 12:51 ` Thierry Reding
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Sakari Ailus @ 2019-01-10 12:43 UTC (permalink / raw)
  To: linux-media; +Cc: hverkuil, Thierry Reding, Ezequiel Garcia

The for loop to reset the memory of the plane reserved fields runs over
num_planes provided by the user without validating it. Ensure num_planes
is no more than VIDEO_MAX_PLANES before the loop.

Fixes: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero v4l2_plane_pix_format reserved fields")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
Hi folks,

This patch goes on top of Thierry's patch "media: v4l2-ioctl: Clear only
per-plane reserved fields".

 drivers/media/v4l2-core/v4l2-ioctl.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 392f1228af7b5..9e68a608ac6d3 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1551,6 +1551,8 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
 		if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane))
 			break;
 		CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
+		if (p->fmt.pix_mp.num_planes > VIDEO_MAX_PLANES)
+			break;
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], bytesperline);
 		return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
@@ -1581,6 +1583,8 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
 		if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane))
 			break;
 		CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
+		if (p->fmt.pix_mp.num_planes > VIDEO_MAX_PLANES)
+			break;
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], bytesperline);
 		return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
@@ -1648,6 +1652,8 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
 		if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane))
 			break;
 		CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
+		if (p->fmt.pix_mp.num_planes > VIDEO_MAX_PLANES)
+			break;
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], bytesperline);
 		return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg);
@@ -1678,6 +1684,8 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
 		if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane))
 			break;
 		CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
+		if (p->fmt.pix_mp.num_planes > VIDEO_MAX_PLANES)
+			break;
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], bytesperline);
 		return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg);
-- 
2.11.0


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

end of thread, other threads:[~2019-02-15 16:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 12:43 [PATCH 1/1] v4l: ioctl: Validate num_planes before using it Sakari Ailus
2019-01-10 12:51 ` Thierry Reding
2019-01-10 13:02 ` Hans Verkuil
2019-01-10 13:30   ` Sakari Ailus
2019-01-10 13:41   ` Sakari Ailus
2019-01-10 14:11     ` Hans Verkuil
2019-01-10 14:18       ` Sakari Ailus
2019-01-10 14:12 ` Hans Verkuil
2019-02-15 15:52 ` Ezequiel Garcia
2019-02-15 16:05   ` Hans Verkuil
2019-02-15 16:14     ` Ezequiel Garcia

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).