Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: exynos4-is: fimc: Fix reading uninitialized plane sizes
@ 2026-11-29 16:54 Lin Huiyi
  2026-12-01 12:37 ` Hans Verkuil
  0 siblings, 1 reply; 2+ messages in thread
From: Lin Huiyi @ 2026-11-29 16:54 UTC (permalink / raw)
  To: s.nawrocki
  Cc: mchehab, krzk, peter.griffin, alim.akhtar, linux-media,
	linux-arm-kernel, linux-samsung-soc, Lin Huiyi

fimc_get_sensor_frame_desc() pre-fills the media bus frame descriptor
entries from plane_fmt[].sizeimage before invoking the sensor subdev
operation. The only call site that sets the frame description
(__video_try_or_set_format(), try=true) passes a properly initialized
array, but fimc_pipeline_validate() passes a plain uninitialized stack
array and only wants to query the sensor with get_frame_desc(). The
pre-fill thus reads uninitialized stack memory and passes it to the
sensor driver.

Only fill the descriptor entries when the caller is going to set the
frame description.

Signed-off-by: Lin Huiyi <xinghui79@qq.com>
---
 .../media/platform/samsung/exynos4-is/fimc-capture.c   | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-capture.c b/drivers/media/platform/samsung/exynos4-is/fimc-capture.c
index 8d7e7b1905..ecfff86f9c 100644
--- a/drivers/media/platform/samsung/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/samsung/exynos4-is/fimc-capture.c
@@ -858,8 +858,14 @@ static int fimc_get_sensor_frame_desc(struct v4l2_subdev *sensor,
 	int i, ret;
 	int pad;
 
-	for (i = 0; i < num_planes; i++)
-		fd.entry[i].length = plane_fmt[i].sizeimage;
+	/*
+	 * Pre-fill the frame descriptor with the caller provided plane
+	 * sizes. Callers which only query the sensor pass an uninitialized
+	 * array here, so only do this when setting the frame description.
+	 */
+	if (try)
+		for (i = 0; i < num_planes; i++)
+			fd.entry[i].length = plane_fmt[i].sizeimage;
 
 	pad = sensor->entity.num_pads - 1;
 	if (try)
-- 
2.56.1



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

* Re: [PATCH] media: exynos4-is: fimc: Fix reading uninitialized plane sizes
  2026-11-29 16:54 [PATCH] media: exynos4-is: fimc: Fix reading uninitialized plane sizes Lin Huiyi
@ 2026-12-01 12:37 ` Hans Verkuil
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2026-12-01 12:37 UTC (permalink / raw)
  To: Lin Huiyi, s.nawrocki
  Cc: mchehab, krzk, peter.griffin, alim.akhtar, linux-media,
	linux-arm-kernel, linux-samsung-soc

On 29/11/2026 17:54, Lin Huiyi wrote:
> fimc_get_sensor_frame_desc() pre-fills the media bus frame descriptor
> entries from plane_fmt[].sizeimage before invoking the sensor subdev
> operation. The only call site that sets the frame description
> (__video_try_or_set_format(), try=true) passes a properly initialized
> array, but fimc_pipeline_validate() passes a plain uninitialized stack
> array and only wants to query the sensor with get_frame_desc(). The
> pre-fill thus reads uninitialized stack memory and passes it to the
> sensor driver.
> 
> Only fill the descriptor entries when the caller is going to set the
> frame description.
> 
> Signed-off-by: Lin Huiyi <xinghui79@qq.com>
> ---
>  .../media/platform/samsung/exynos4-is/fimc-capture.c   | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-capture.c b/drivers/media/platform/samsung/exynos4-is/fimc-capture.c
> index 8d7e7b1905..ecfff86f9c 100644
> --- a/drivers/media/platform/samsung/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/samsung/exynos4-is/fimc-capture.c
> @@ -858,8 +858,14 @@ static int fimc_get_sensor_frame_desc(struct v4l2_subdev *sensor,
>  	int i, ret;
>  	int pad;
>  
> -	for (i = 0; i < num_planes; i++)
> -		fd.entry[i].length = plane_fmt[i].sizeimage;
> +	/*
> +	 * Pre-fill the frame descriptor with the caller provided plane
> +	 * sizes. Callers which only query the sensor pass an uninitialized
> +	 * array here, so only do this when setting the frame description.
> +	 */
> +	if (try)
> +		for (i = 0; i < num_planes; i++)
> +			fd.entry[i].length = plane_fmt[i].sizeimage;
>  
>  	pad = sensor->entity.num_pads - 1;
>  	if (try)

I'm not sure this code is right, and it may have been wrong in the first place.

It calls set_frame_desc if try == true, but when called from fimc_cap_s_fmt_mplane()
the 'try' argument is false, and in that case fimc_get_sensor_frame_desc actually
calls get_frame_desc. That doesn't feel right.

I wonder if anyone from Samsung has a board to test with, since I think the current
code is just wrong. Not helped by poor naming.

I think that:

1) Make a fimc_set_sensor_frame_desc function that calls set_frame_desc, and the
   existing fimc_get_sensor_frame_desc just calls get_frame_desc. Both functions
   can drop the 'bool try'. For the 'set' variant initialize fd.entry[i].length
   as per your current patch.
2) Call the correct function elsewhere in the code.

Regards,

	Hans


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

end of thread, other threads:[~2026-12-01 12:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 16:54 [PATCH] media: exynos4-is: fimc: Fix reading uninitialized plane sizes Lin Huiyi
2026-12-01 12:37 ` Hans Verkuil

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