From: Bingbu Cao <bingbu.cao@linux.intel.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>, linux-media@vger.kernel.org
Cc: Bingbu Cao <bingbu.cao@intel.com>,
Tianshu Qiu <tian.shu.qiu@intel.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Subject: Re: [PATCH 1/1] ipu3-imgu: Fix NULL pointer dereference in active selection access
Date: Fri, 26 Aug 2022 18:40:24 +0800 [thread overview]
Message-ID: <0f351df8-3f2c-74fc-3f9e-089761d53c63@linux.intel.com> (raw)
In-Reply-To: <20220825190351.3241444-1-sakari.ailus@linux.intel.com>
Sakari,
Thanks for your patch, does it make sense that prevent the
NULL deference and throw warning in v4l2-subdev API? Though it
is the responsibility of driver to keep it safe.
Reviewed-by: Bingbu Cao <bingbu.cao@intel.com>
On 8/26/22 3:03 AM, Sakari Ailus wrote:
> What the IMGU driver did was that it first acquired the pointers to active
> and try V4L2 subdev state, and only then figured out which one to use.
>
> The problem with that approach and a later patch (see Fixes: tag) is that
> as sd_state argument to v4l2_subdev_get_try_crop() et al is NULL, there is
> now an attempt to dereference that.
>
> Fix this.
>
> Also rewrap lines a little.
>
> Fixes: 0d346d2a6f54 ("media: v4l2-subdev: add subdev-wide state struct")
> Cc: stable@vger.kernel.org # for v5.14 and later
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> drivers/staging/media/ipu3/ipu3-v4l2.c | 31 ++++++++++++--------------
> 1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c
> index d1c539cefba87..2234bb8d48b34 100644
> --- a/drivers/staging/media/ipu3/ipu3-v4l2.c
> +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c
> @@ -192,33 +192,30 @@ static int imgu_subdev_get_selection(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *sd_state,
> struct v4l2_subdev_selection *sel)
> {
> - struct v4l2_rect *try_sel, *r;
> - struct imgu_v4l2_subdev *imgu_sd = container_of(sd,
> - struct imgu_v4l2_subdev,
> - subdev);
> + struct imgu_v4l2_subdev *imgu_sd =
> + container_of(sd, struct imgu_v4l2_subdev, subdev);
>
> if (sel->pad != IMGU_NODE_IN)
> return -EINVAL;
>
> switch (sel->target) {
> case V4L2_SEL_TGT_CROP:
> - try_sel = v4l2_subdev_get_try_crop(sd, sd_state, sel->pad);
> - r = &imgu_sd->rect.eff;
> - break;
> + if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
> + sel->r = *v4l2_subdev_get_try_crop(sd, sd_state,
> + sel->pad);
> + else
> + sel->r = imgu_sd->rect.eff;
> + return 0;
> case V4L2_SEL_TGT_COMPOSE:
> - try_sel = v4l2_subdev_get_try_compose(sd, sd_state, sel->pad);
> - r = &imgu_sd->rect.bds;
> - break;
> + if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
> + sel->r = *v4l2_subdev_get_try_compose(sd, sd_state,
> + sel->pad);
> + else
> + sel->r = imgu_sd->rect.bds;
> + return 0;
> default:
> return -EINVAL;
> }
> -
> - if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
> - sel->r = *try_sel;
> - else
> - sel->r = *r;
> -
> - return 0;
> }
>
> static int imgu_subdev_set_selection(struct v4l2_subdev *sd,
>
--
Best regards,
Bingbu Cao
next prev parent reply other threads:[~2022-08-26 10:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-25 19:03 [PATCH 1/1] ipu3-imgu: Fix NULL pointer dereference in active selection access Sakari Ailus
2022-08-26 10:40 ` Bingbu Cao [this message]
2022-09-07 13:44 ` Maximilian Luz
2022-09-07 19:09 ` Laurent Pinchart
2022-09-07 21:29 ` Maximilian Luz
2022-09-07 20:01 ` Sakari Ailus
2022-09-07 21:26 ` Maximilian Luz
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=0f351df8-3f2c-74fc-3f9e-089761d53c63@linux.intel.com \
--to=bingbu.cao@linux.intel.com \
--cc=bingbu.cao@intel.com \
--cc=linux-media@vger.kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tian.shu.qiu@intel.com \
--cc=tomi.valkeinen@ideasonboard.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