mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Biren Pandya <birenpandya@gmail.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] media: i2c: ov7740: Fix use-after-destroy in remove()
Date: Wed, 8 Jul 2026 11:59:17 +0300	[thread overview]
Message-ID: <ak4RZfYX3EPkGQHk@kekkonen.localdomain> (raw)
In-Reply-To: <20260615210412.34567-2-birenpandya@gmail.com>

Hi Biren,

On Tue, Jun 16, 2026 at 02:34:11AM +0530, Biren Pandya wrote:
> The ov7740_remove() function had a severe teardown order bug where it
> destroyed the driver's mutex before freeing the V4L2 control handler
> which relies on that mutex, leading to a use-after-destroy kernel panic.
> Furthermore, the driver explicitly called v4l2_ctrl_handler_free() and
> mutex_destroy() sequentially, but then called ov7740_free_controls()
> which invokes both of them a second time, resulting in a double-free.
> 
> This patch fixes the issue by unregistering the subdevice first, and
> relying exclusively on ov7740_free_controls() to safely tear down the
> mutex and control handler in the correct order.
> 
> Fixes: 39c5c4471b8d ("media: i2c: Add the ov7740 image sensor driver")
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>

Can you add Cc: stable... for v2, please?

> ---
>  drivers/media/i2c/ov7740.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
> index 632fb80469be..62c124a1353a 100644
> --- a/drivers/media/i2c/ov7740.c
> +++ b/drivers/media/i2c/ov7740.c
> @@ -1116,10 +1116,8 @@ static void ov7740_remove(struct i2c_client *client)
>  	struct v4l2_subdev *sd = i2c_get_clientdata(client);
>  	struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
>  
> -	mutex_destroy(&ov7740->mutex);
> -	v4l2_ctrl_handler_free(ov7740->subdev.ctrl_handler);
> -	media_entity_cleanup(&ov7740->subdev.entity);
>  	v4l2_async_unregister_subdev(sd);
> +	media_entity_cleanup(&ov7740->subdev.entity);
>  	ov7740_free_controls(ov7740);
>  
>  	pm_runtime_get_sync(&client->dev);

-- 
Kind regards,

Sakari Ailus

  reply	other threads:[~2026-07-08  8:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15 21:04 [PATCH 0/2] media: i2c: ov7740: Fix remove() teardown and PM runtime Biren Pandya
2026-06-15 21:04 ` [PATCH 1/2] media: i2c: ov7740: Fix use-after-destroy in remove() Biren Pandya
2026-07-08  8:59   ` Sakari Ailus [this message]
2026-06-15 21:04 ` [PATCH 2/2] media: i2c: ov7740: Fix unchecked pm_runtime_get_sync() " Biren Pandya
2026-07-08  8:46   ` Sakari Ailus
     [not found] ` <20260708125720.27156-4-birenpandya@gmail.com>
2026-07-08 12:57   ` [PATCH v2 1/2] media: i2c: ov7740: fix unbalanced pm_runtime_get_sync in remove Biren Pandya
2026-07-08 12:57   ` [PATCH v2 2/2] media: i2c: ov7740: fix use-after-destroy " Biren Pandya

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=ak4RZfYX3EPkGQHk@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=birenpandya@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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

all inboxes | Powered by JetHome®