linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, Thierry Reding <treding@nvidia.com>,
	Ezequiel Garcia <ezequiel@collabora.com>
Subject: Re: [PATCH 1/1] v4l: ioctl: Validate num_planes before using it
Date: Thu, 10 Jan 2019 16:18:35 +0200	[thread overview]
Message-ID: <20190110141835.e33xv2stayiz2ijc@paasikivi.fi.intel.com> (raw)
In-Reply-To: <da827442-80cb-2a18-fcb4-0b4c88f8a0cb@xs4all.nl>

On Thu, Jan 10, 2019 at 03:11:35PM +0100, Hans Verkuil wrote:
> On 01/10/19 14:41, Sakari Ailus wrote:
> > On Thu, Jan 10, 2019 at 02:02:14PM +0100, Hans Verkuil wrote:
> >> On 01/10/19 13:43, Sakari Ailus wrote:
> >>> 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;
> >>
> >> I would check this not here but in check_fmt: all *_FMT ioctls call that function
> >> first, so it makes sense to do the check there.
> > 
> > Even G_FMT? I'm not saying no though. There's just a slight chance of
> > breaking something as it hasn't been a problem to call G_FMT with incorrect
> > number of planes in the mplane format; the number would be overwritten
> > anyway.
> 
> Not G_FMT since everything after the type field is zeroed.
> 
> > Apart from that, this leaves just the four locations --- putting this to a
> > separate function will reduce the calls to that function to just two.
> 
> I was a bit too quick with my comment about check_fmt. Your original patch
> is fine.
> 
> I'll Ack your patch.

Thanks. Could you pick this to your tree as you did Thierry's patch?

I'll submit the other patch in a moment.

> 
> Regards,
> 
> 	Hans
> 
> > 
> >>
> >> v4l_print_format should also be adjusted (take the minimum of num_planes and
> >> VIDEO_MAX_PLANES), since it can still be called even if check_fmt returns an
> >> error if num_planes is too large.
> >>
> >> In fact, the change to v4l_print_format should be a separate patch since that
> >> should be backported. It can leak memory in the kernel log if num_planes is
> >> too large.
> >>
> >> Regards,
> >>
> >> 	Hans
> >>
> >>>  		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);
> >>>
> >>
> > 
> 

-- 
Sakari Ailus
sakari.ailus@linux.intel.com

  reply	other threads:[~2019-01-10 14:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190110141835.e33xv2stayiz2ijc@paasikivi.fi.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=ezequiel@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).