public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Maximilian Luz <luzmaximilian@gmail.com>
To: sakari.ailus@linux.intel.com
Cc: bingbu.cao@intel.com, linux-media@vger.kernel.org,
	tian.shu.qiu@intel.com, tomi.valkeinen@ideasonboard.com,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: Re: [PATCH 1/1] ipu3-imgu: Fix NULL pointer dereference in active selection access
Date: Wed, 7 Sep 2022 15:44:44 +0200	[thread overview]
Message-ID: <db44a24b-2a9a-6682-4825-eedc4ecb1340@gmail.com> (raw)
In-Reply-To: <20220825190351.3241444-1-sakari.ailus@linux.intel.com>

Hi,

On Thu, 25 Aug 2022 22:03:51 +0300, 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.

Thank you for this fix, this however only addresses
imgu_subdev_get_selection(), but the issue is also present in
imgu_subdev_set_selection(). I assume that a similar fix is needed for that.
I've added a diff for that below. Feel free to squash that into your patch or
let me know if I should submit this separately.

Regards,
Max

---
  drivers/staging/media/ipu3/ipu3-v4l2.c | 25 ++++++++++++-------------
  1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c
index 2234bb8d48b3..079f2635c70d 100644
--- a/drivers/staging/media/ipu3/ipu3-v4l2.c
+++ b/drivers/staging/media/ipu3/ipu3-v4l2.c
@@ -223,10 +223,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd,
                                      struct v4l2_subdev_selection *sel)
  {
         struct imgu_device *imgu = v4l2_get_subdevdata(sd);
-       struct imgu_v4l2_subdev *imgu_sd = container_of(sd,
-                                                       struct imgu_v4l2_subdev,
-                                                       subdev);
-       struct v4l2_rect *rect, *try_sel;
+       struct imgu_v4l2_subdev *imgu_sd =
+               container_of(sd, struct imgu_v4l2_subdev, subdev);
+       struct v4l2_rect *rect;

         dev_dbg(&imgu->pci_dev->dev,
                  "set subdev %u sel which %u target 0x%4x rect [%ux%u]",
@@ -238,22 +237,22 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd,

         switch (sel->target) {
         case V4L2_SEL_TGT_CROP:
-               try_sel = v4l2_subdev_get_try_crop(sd, sd_state, sel->pad);
-               rect = &imgu_sd->rect.eff;
+               if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
+                       rect = v4l2_subdev_get_try_crop(sd, sd_state, sel->pad);
+               else
+                       rect = &imgu_sd->rect.eff;
                 break;
         case V4L2_SEL_TGT_COMPOSE:
-               try_sel = v4l2_subdev_get_try_compose(sd, sd_state, sel->pad);
-               rect = &imgu_sd->rect.bds;
+               if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
+                       rect = v4l2_subdev_get_try_compose(sd, sd_state, sel->pad);
+               else
+                       rect = &imgu_sd->rect.bds;
                 break;
         default:
                 return -EINVAL;
         }

-       if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
-               *try_sel = sel->r;
-       else
-               *rect = sel->r;
-
+       *rect = sel->r;
         return 0;
  }

--
2.37.3


  parent reply	other threads:[~2022-09-07 13:45 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
2022-09-07 13:44 ` Maximilian Luz [this message]
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=db44a24b-2a9a-6682-4825-eedc4ecb1340@gmail.com \
    --to=luzmaximilian@gmail.com \
    --cc=bingbu.cao@intel.com \
    --cc=laurent.pinchart@ideasonboard.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