stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <jmkrzyszt@gmail.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Janusz Krzysztofik <jmkrzyszt@gmail.com>
Subject: Re: [PATCH 03/14] media: ov6650: Fix unverified arguments used in .set_fmt()
Date: Wed, 08 May 2019 01:33:19 +0200	[thread overview]
Message-ID: <2020766.LXvJ9naVtX@z50> (raw)
In-Reply-To: <20190430135809.5mgf4govbqj3cxph@valkosipuli.retiisi.org.uk>

Hi Sakari,

Sorry for late answer, I've just found your message in Gmail spam folder.

On Tuesday, April 30, 2019 3:58:09 PM CEST Sakari Ailus wrote:
> Hi Janusz,
> 
> On Mon, Apr 08, 2019 at 11:42:31PM +0200, Janusz Krzysztofik wrote:
> > Commit 717fd5b4907ad ("[media] v4l2: replace try_mbus_fmt by set_fmt")
> > converted a former ov6650_try_fmt() video operation callback to an
> > ov6650_set_fmt() pad operation callback.  However, the function does not
> > verify correctness of user provided format->which flag and pad config
> > pointer arguments.  Fix it.
> > 
> > Fixes: 717fd5b4907ad ("[media] v4l2: replace try_mbus_fmt by set_fmt")
> > Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
> > Cc: stable@vger.kernel.org
> > ---
> >  drivers/media/i2c/ov6650.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> > 
> > diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
> > index 007f0ca24913..3062c9a6c57b 100644
> > --- a/drivers/media/i2c/ov6650.c
> > +++ b/drivers/media/i2c/ov6650.c
> > @@ -679,6 +679,17 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd,
> >  	if (format->pad)
> >  		return -EINVAL;
> >  
> > +	switch (format->which) {
> > +	case V4L2_SUBDEV_FORMAT_ACTIVE:
> > +		break;
> > +	case V4L2_SUBDEV_FORMAT_TRY:
> > +		if (cfg)
> > +			break;
> > +		/* fall through */
> > +	default:
> > +		return -EINVAL;
> > +	}
> 
> For this to return an error, there would need to be a problem on the
> caller's side. In other words, this isn't supposed to happen.

How about raising a bug if that happens nevertheless?

@@ -677,10 +677,20 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd,
 	struct ov6650 *priv = to_ov6650(client);
 
 	if (format->pad)
 		return -EINVAL;
 
+	switch (format->which) {
+	case V4L2_SUBDEV_FORMAT_TRY:
+		BUG_ON(!cfg);
+		/* fall through */
+	case V4L2_SUBDEV_FORMAT_ACTIVE:
+		break;
+	default:
+		BUG();
+	}
+
 	if (is_unscaled_ok(mf->width, mf->height, &priv->rect))
 		v4l_bound_align_image(&mf->width, 2, W_CIF, 1,
 				&mf->height, 2, H_CIF, 1, 0);
 
 	mf->field = V4L2_FIELD_NONE;


Thanks,
Janusz

> 
> Instead of adding such checks to all drivers, I think they instead should
> be added to the caller's side. The checks already exist for uAPI, but not
> for other drivers.
> 
> The same applies to patches until 7th (including).
> 
> > +
> >  	if (is_unscaled_ok(mf->width, mf->height, &priv->rect))
> >  		v4l_bound_align_image(&mf->width, 2, W_CIF, 1,
> >  				&mf->height, 2, H_CIF, 1, 0);
> 
> 





  reply	other threads:[~2019-05-07 23:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-08 21:42 [PATCH 00/14] media: ov6650: A collection of fixes Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 01/14] media: ov6650: Fix MODDULE_DESCRIPTION Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 02/14] media: ov6650: Fix control handler not freed on init error Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 03/14] media: ov6650: Fix unverified arguments used in .set_fmt() Janusz Krzysztofik
2019-04-30 13:58   ` Sakari Ailus
2019-05-07 23:33     ` Janusz Krzysztofik [this message]
2019-04-08 21:42 ` [PATCH 04/14] media: ov6650: Fix unverified arguments accepted by .get_fmt() Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 05/14] media: ov6650: Fix unverified arguments accepted by .enum_mbus_code() Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 06/14] media: ov6650: Fix unverified pad IDs accepted by .get/set_selectioon() Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 07/14] media: ov6650: Fix unverified pad IDs accepted by .g/s_frame_interval() Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 08/14] media: ov6650: Fix crop rectangle alignment not passed back Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 09/14] media: ov6650: Fix incorrect use of JPEG colorspace Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 10/14] media: ov6650: Fix some format attributes not under control Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 11/14] media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 12/14] media: ov6650: Fix default format not applied on device probe Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 13/14] media: ov6650: Fix stored frame format not in sync with hardware Janusz Krzysztofik
2019-04-08 21:42 ` [PATCH 14/14] media: ov6650: Fix stored crop rectangle " Janusz Krzysztofik

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=2020766.LXvJ9naVtX@z50 \
    --to=jmkrzyszt@gmail.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /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).