[PATCH] media: exynos4-is: fimc: Fix reading uninitialized plane sizes

Hans Verkuil hverkuil+cisco at kernel.org
Tue Dec 1 04:37:32 PST 2026


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 at 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



More information about the linux-arm-kernel mailing list