mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak
@ 2026-06-13  8:32 Biren Pandya
  2026-07-08  8:16 ` Sakari Ailus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Biren Pandya @ 2026-06-13  8:32 UTC (permalink / raw)
  To: linux-media
  Cc: sakari.ailus, mchehab, dongchun.zhu, linux-kernel, Biren Pandya, stable

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] ==
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak
  2026-06-13  8:32 [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak Biren Pandya
@ 2026-07-08  8:16 ` Sakari Ailus
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2026-07-08  8:16 UTC (permalink / raw)
  To: Biren Pandya; +Cc: linux-media, mchehab, dongchun.zhu, linux-kernel, stable

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4] media: i2c: ov02a10: fix endpoint parsing use-after-free
  2026-06-13  8:32 [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak Biren Pandya
  2026-07-08  8:16 ` Sakari Ailus
@ 2026-07-08 15:38 ` Biren Pandya
  2026-07-08 18:12 ` Biren Pandya
  2 siblings, 0 replies; 5+ messages in thread
From: Biren Pandya @ 2026-07-08 15:38 UTC (permalink / raw)
  To: sakari.ailus, mchehab, dongchun.zhu, andriy.shevchenko,
	linux-media, linux-kernel
  Cc: Biren Pandya, stable, Vladimir Zapolskiy

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_property_read_u32() before
the endpoint is parsed and freed. Avoid the error leak by not
assigning the result of fwnode_property_read_u32() to 'ret'.

Fixes: 91807efbe8ec ("media: i2c: add OV02A10 image sensor driver")
Cc: stable@vger.kernel.org
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
---
Changes in v4:
- Collapsed fwnode_property_read_u32() into a single line per Vladimir's review.

Changes in v3:
- Moved property reads before parse to avoid UAF.
- Fixed error leak by dropping assignment to ret.
- Added Fixes/Cc stable.
- Picked up Reviewed-by.
---
 drivers/media/i2c/ov02a10.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/ov02a10.c b/drivers/media/i2c/ov02a10.c
index 143dcfe104456..98f8fc5b6a5ae 100644
--- a/drivers/media/i2c/ov02a10.c
+++ b/drivers/media/i2c/ov02a10.c
@@ -820,18 +820,15 @@ static int ov02a10_check_hwcfg(struct device *dev, struct ov02a10 *ov02a10)
 	if (!ep)
 		return -ENXIO;
 
+	/* Optional indication of MIPI clock voltage unit */
+	if (!fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage", &clk_volt))
+		ov02a10->mipi_clock_voltage = clk_volt;
+
 	ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
 	fwnode_handle_put(ep);
 	if (ret)
 		return ret;
 
-	/* Optional indication of MIPI clock voltage unit */
-	ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage",
-				       &clk_volt);
-
-	if (!ret)
-		ov02a10->mipi_clock_voltage = clk_volt;
-
 	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] ==
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4] media: i2c: ov02a10: fix endpoint parsing use-after-free
  2026-06-13  8:32 [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak Biren Pandya
  2026-07-08  8:16 ` Sakari Ailus
  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
  2 siblings, 1 reply; 5+ messages in thread
From: Biren Pandya @ 2026-07-08 18:12 UTC (permalink / raw)
  To: sakari.ailus, mchehab, andriy.shevchenko, dongchun.zhu,
	linux-media, linux-kernel
  Cc: Biren Pandya, stable, Vladimir Zapolskiy

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_property_read_u32() before
the endpoint is parsed and freed. Avoid the error leak by not
assigning the result of fwnode_property_read_u32() to 'ret'.

Fixes: 91807efbe8ec ("media: i2c: add OV02A10 image sensor driver")
Cc: stable@vger.kernel.org
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
---
Changes in v4:
- Collapsed fwnode_property_read_u32() into a single line per Vladimir's review.

Changes in v3:
- Moved property reads before parse to avoid UAF.
- Fixed error leak by dropping assignment to ret.
- Added Fixes/Cc stable.
- Picked up Reviewed-by.
---
 drivers/media/i2c/ov02a10.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/ov02a10.c b/drivers/media/i2c/ov02a10.c
index 143dcfe104456..98f8fc5b6a5ae 100644
--- a/drivers/media/i2c/ov02a10.c
+++ b/drivers/media/i2c/ov02a10.c
@@ -820,18 +820,15 @@ static int ov02a10_check_hwcfg(struct device *dev, struct ov02a10 *ov02a10)
 	if (!ep)
 		return -ENXIO;
 
+	/* Optional indication of MIPI clock voltage unit */
+	if (!fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage", &clk_volt))
+		ov02a10->mipi_clock_voltage = clk_volt;
+
 	ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
 	fwnode_handle_put(ep);
 	if (ret)
 		return ret;
 
-	/* Optional indication of MIPI clock voltage unit */
-	ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage",
-				       &clk_volt);
-
-	if (!ret)
-		ov02a10->mipi_clock_voltage = clk_volt;
-
 	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] ==
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] media: i2c: ov02a10: fix endpoint parsing use-after-free
  2026-07-08 18:12 ` Biren Pandya
@ 2026-07-08 19:40   ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-07-08 19:40 UTC (permalink / raw)
  To: Biren Pandya
  Cc: sakari.ailus, mchehab, dongchun.zhu, linux-media, linux-kernel,
	stable, Vladimir Zapolskiy

On Wed, Jul 08, 2026 at 11:42:48PM +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_property_read_u32() before
> the endpoint is parsed and freed. Avoid the error leak by not
> assigning the result of fwnode_property_read_u32() to 'ret'.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

...

> Changes in v4:
> - Collapsed fwnode_property_read_u32() into a single line per Vladimir's review.

Wasn't me?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-08 19:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-13  8:32 [PATCH] media: i2c: ov02a10: fix endpoint parsing use-after-free and error leak Biren Pandya
2026-07-08  8:16 ` Sakari Ailus
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox