[PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index
Benjamin Gaignard
benjamin.gaignard at collabora.com
Tue Nov 24 05:19:53 PST 2026
Le 24/11/2026 à 04:29, Nicolas Dufresne a écrit :
> Le vendredi 20 novembre 2026 à 15:31 +0100, Benjamin Gaignard a écrit :
>> Make sure that reference frame index is valid before using it.
>>
>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard at collabora.com>
>> Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder")
>> ---
>> .../platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 11 ++++++++++-
>> 1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
>> index 2a145433e6d1..5da59104a966 100644
>> --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
>> +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
>> @@ -121,7 +121,12 @@ static int rockchip_vpu981_get_frame_index(struct hantro_ctx *ctx, int ref)
>> struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls;
>> const struct v4l2_ctrl_av1_frame *frame = ctrls->frame;
>> u64 timestamp;
>> - int i, idx = frame->ref_frame_idx[ref];
>> + int i, idx;
>> +
>> + if (ref < 0 || ref >= V4L2_AV1_REFS_PER_FRAME)
>> + return AV1_INVALID_IDX;
>> +
>> + idx = frame->ref_frame_idx[ref];
>>
>> if (idx >= V4L2_AV1_TOTAL_REFS_PER_FRAME || idx < 0)
>> return AV1_INVALID_IDX;
>> @@ -1262,6 +1267,10 @@ static void rockchip_vpu981_av1_dec_set_prob(struct hantro_ctx *ctx)
>> rockchip_av1_default_coeff_probs(quantization->base_q_idx,
>> av1_dec->cdfs);
>> } else {
>> + if (frame->primary_ref_frame < 0 ||
>> + frame->primary_ref_frame >= V4L2_AV1_REFS_PER_FRAME)
>> + return;
> Just returning does not abort dec_run() and will lead to triggering the HW with
> partially initialized data. Either this should lead to some default cdf to be
> picked, or we add a return value and check it in dec_run().
>
> May I propose to validate these once once in prepare_run()?
I will do it when validating AV1 frame parameters in v4l2-ctrl-core.c
Regards,
Benjamin
>
>> +
>> rockchip_av1_get_cdfs(ctx, frame->ref_frame_idx[frame->primary_ref_frame]);
> Here, the index passed to get_cdfs() is not validated and will lead to out of
> band indexing inside that function..
>
>
>> }
>> rockchip_av1_store_cdfs(ctx, frame->refresh_frame_flags);
More information about the Linux-rockchip
mailing list