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: linux-media@vger.kernel.org, mchehab@kernel.org,
	dongchun.zhu@mediatek.com, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak
Date: Wed, 8 Jul 2026 11:16:23 +0300	[thread overview]
Message-ID: <ak4HV9dN5GadUeLj@kekkonen.localdomain> (raw)
In-Reply-To: <20260613083235.57363-1-birenpandya@gmail.com>

Hi Biren,

Thanks for the patch.

On Sat, Jun 13, 2026 at 02:02:35PM +0530, Biren Pandya wrote:
> The ov02a10_check_hwcfg() function calls fwnode_handle_put(ep)
> immediately after allocating and parsing the endpoint. However, it
> subsequently calls fwnode_property_read_u32() using the same 'ep'
> handle, leading to a potential use-after-free.
> 
> Additionally, reading the optional 'ovti,mipi-clock-voltage' property
> used to overwrite the 'ret' variable. If the property was missing,
> 'ret' would become negative, and this failure code would be incorrectly
> returned at the end of the function, causing probe to fail entirely.
> 
> Fix the use-after-free by moving fwnode_handle_put(ep) to the end of
> the endpoint property reading block, and adding it to the error path of
> v4l2_fwnode_endpoint_alloc_parse().
> 
> Fix the error leak by avoiding assigning the result of
> fwnode_property_read_u32() to 'ret'.
> 
> Fixes: cf10e09b9a4b ("media: i2c: Add OV02A10 image sensor driver")
> Cc: stable@vger.kernel.org
> 
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> ---
>  drivers/media/i2c/ov02a10.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov02a10.c b/drivers/media/i2c/ov02a10.c
> index 143dcfe..53ff86b 100644
> --- a/drivers/media/i2c/ov02a10.c
> +++ b/drivers/media/i2c/ov02a10.c
> @@ -821,9 +821,10 @@ static int ov02a10_check_hwcfg(struct device *dev, struct ov02a10 *ov02a10)
>  		return -ENXIO;
>  
>  	ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
> -	fwnode_handle_put(ep);
> -	if (ret)
> +	if (ret) {
> +		fwnode_handle_put(ep);
>  		return ret;
> +	}
>  
>  	/* Optional indication of MIPI clock voltage unit */
>  	ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage",
> @@ -832,6 +833,8 @@ static int ov02a10_check_hwcfg(struct device *dev, struct ov02a10 *ov02a10)
>  	if (!ret)
>  		ov02a10->mipi_clock_voltage = clk_volt;
>  
> +	fwnode_handle_put(ep);
> +
>  	for (i = 0; i < ARRAY_SIZE(link_freq_menu_items); i++) {
>  		for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
>  			if (link_freq_menu_items[i] ==

I'd fix this by moving the fwnode_property_read_u32() before finding the
endpoint. That doesn't involve complicating the error handling.

-- 
Regards.

Sakari Ailus

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-13  8:32 Biren Pandya
2026-07-08  8:16 ` Sakari Ailus [this message]
2026-07-08 15:38 ` [PATCH v4] media: i2c: ov02a10: fix endpoint parsing use-after-free Biren Pandya
2026-07-08 18:12 ` Biren Pandya
2026-07-08 19:40   ` Andy Shevchenko

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

all inboxes | Powered by JetHome®