Re: [PATCH v2 3/3] media: iris: fix out-of-bounds read in gen1 sequence change event

From: bod

Date: Tue Dec 01 2026 - 07:13:21 EST


On 2026-11-26 21:29 +0000, Hungyu Lin wrote:
> iris_hfi_gen1_read_changed_params() walks the properties of a
> HFI_EVENT_SESSION_SEQUENCE_CHANGED event. The number of properties comes
> from the firmware in event_data2 and the payload is never checked against
> the size of the packet. A count that is larger than what the packet holds
> makes the loop read past the end of the packet and, if it is large enough,
> past the end of the response buffer. The values that are read end up in
> the formats and in the crop rectangle that user space can query.
>
> The same code in venus was fixed by commit 06d6770ff0d8 ("media: venus:
> Fix OOB read due to missing payload bound check"). Do the same here: keep
> track of the bytes that are left in the packet and put the instance into
> the error state when a property does not fit.
>
> Fixes: 84e17adae3e3 ("media: iris: add support for dynamic resolution change")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
> ---
> .../qcom/iris/iris_hfi_gen1_response.c | 73 ++++++++++++++-----
> 1 file changed, 54 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c b/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c
> index ffa98139f0eb..a5b43a408e55 100644
> --- a/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c
> +++ b/drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c
> @@ -34,72 +34,102 @@ static void iris_hfi_gen1_read_changed_params(struct iris_inst *inst,
> struct hfi_framesize *frame_sz;
> struct vb2_queue *dst_q;
> struct v4l2_ctrl *ctrl;
> - u32 full_range, ptype;
> + u32 full_range, ptype, rem_bytes;
> + u32 size_read = 0;
> +
> + rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt);
>
> do {
> + if (rem_bytes < sizeof(u32))
> + goto error;
> ptype = *((u32 *)data_ptr);
> +
> + data_ptr += sizeof(u32);
> + rem_bytes -= sizeof(u32);
> +

This part is obviously correct a good reduction.

> switch (ptype) {
> case HFI_PROPERTY_PARAM_FRAME_SIZE:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_framesize))
> + goto error;
> +
> frame_sz = (struct hfi_framesize *)data_ptr;
> event.width = frame_sz->width;
> event.height = frame_sz->height;
> - data_ptr += sizeof(*frame_sz);
> + size_read = sizeof(struct hfi_framesize);
> break;
> case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_profile_level))
> + goto error;
> +
> profile_level = (struct hfi_profile_level *)data_ptr;
> event.profile = profile_level->profile;
> event.level = profile_level->level;
> - data_ptr += sizeof(*profile_level);
> + size_read = sizeof(struct hfi_profile_level);
> break;
> case HFI_PROPERTY_PARAM_VDEC_PIXEL_BITDEPTH:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_bit_depth))
> + goto error;
> +
> pixel_depth = (struct hfi_bit_depth *)data_ptr;
> event.bit_depth = pixel_depth->bit_depth;
> - data_ptr += sizeof(*pixel_depth);
> + size_read = sizeof(struct hfi_bit_depth);
> break;
> case HFI_PROPERTY_PARAM_VDEC_PIC_STRUCT:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_pic_struct))
> + goto error;
> +
> pic_struct = (struct hfi_pic_struct *)data_ptr;
> event.pic_struct = pic_struct->progressive_only;
> - data_ptr += sizeof(*pic_struct);
> + size_read = sizeof(struct hfi_pic_struct);
> break;
> case HFI_PROPERTY_PARAM_VDEC_COLOUR_SPACE:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_colour_space))
> + goto error;
> +
> colour_info = (struct hfi_colour_space *)data_ptr;
> event.colour_space = colour_info->colour_space;
> - data_ptr += sizeof(*colour_info);
> + size_read = sizeof(struct hfi_colour_space);
> break;
> case HFI_PROPERTY_CONFIG_VDEC_ENTROPY:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(u32))
> + goto error;
> +
> event.entropy_mode = *(u32 *)data_ptr;
> - data_ptr += sizeof(u32);
> + size_read = sizeof(u32);
> break;
> case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_buffer_requirements))
> + goto error;
> +
> bufreq = (struct hfi_buffer_requirements *)data_ptr;
> event.buf_count = bufreq->count_min;
> - data_ptr += sizeof(*bufreq);
> + size_read = sizeof(struct hfi_buffer_requirements);
> break;
> case HFI_INDEX_EXTRADATA_INPUT_CROP:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_extradata_input_crop))
> + goto error;
> +
> crop = (struct hfi_extradata_input_crop *)data_ptr;
> event.input_crop.left = crop->left;
> event.input_crop.top = crop->top;
> event.input_crop.width = crop->width;
> event.input_crop.height = crop->height;
> - data_ptr += sizeof(*crop);
> + size_read = sizeof(struct hfi_extradata_input_crop);
> break;
> case HFI_PROPERTY_PARAM_VDEC_DPB_COUNTS:
> - data_ptr += sizeof(u32);
> + if (rem_bytes < sizeof(struct hfi_dpb_counts))
> + goto error;
> +
> iris_vpu_dpb_count = (struct hfi_dpb_counts *)data_ptr;
> event.buf_count = iris_vpu_dpb_count->fw_min_count;
> - data_ptr += sizeof(*iris_vpu_dpb_count);
> + size_read = sizeof(struct hfi_dpb_counts);
> break;
> default:
> + size_read = 0;

This will treat the payload as the next type though which is not what you want.
---
bod