media: v4l2-ctrls: bound stateless HEVC/AV1 tile counts
Subsystems (6)
v2 cover media: v4l2-ctrls: bound stateless HEVC/AV1 tile counts
The stateless HEVC and AV1 V4L2 controls carry tile counts that several SoC decoder drivers consume as loop bounds when laying out fixed-size hardware descriptor buffers, but std_validate_compound() does not bound them. A process with access to a /dev/videoN stateless decoder (on a typical desktop or SBC, the active-seat local user via the logind/udev uaccess ACL, no extra capability) can set a HEVC PPS or AV1 frame control with a tile count far beyond the array capacity the drivers assume, making them loop past their fixed buffers.
Patch 1 caps the HEVC and AV1 tile counts to the uAPI array capacity in the core. Patches 2-5 add matching bounds in the consuming driver loops (and bound the driver-interpreted HEVC pic_parameter_set_id / AV1 context_update_tile_id indices the core does not reject). Patch 6 adds KUnit tests for the core validation.
I did my best to reproduce these with the hardware I have, but apologies in advance if I missed something because the soft repro.
Test matrix: patch 1 + patch 6 run the real std_validate_compound() under KASAN on x86_64 (rejects out-of-range counts, in-range and the zeroed default pass, stock and patched); all objects build clean W=1; the ARM SoC decoders are not reachable on the x86 host, so the per-driver writes are not reproduced here.
Changes since v1:
- Patch 1: only reject AV1 tile_cols/tile_rows above the array capacity; do not reject a zero count. v1 also rejected tile_cols < 1, which made std_validate_compound() return -EINVAL for the zero-initialised AV1 frame control that userspace and v4l2-compliance submit, regressing the visl compliance run (reported by the linux-media CI). The divide-by-zero that a zero tile_cols would cause is guarded where the divisor is used in the rockchip decoder (patch 4), so no functional protection is lost.
- Patch 6: drop the "zero tile_cols is rejected" KUnit case (no longer the core's behaviour) and add a benign case asserting the zero-initialised AV1 frame still validates, plus a tile_rows upper-bound case.
- No changes to patches 2-5.
Michael Bommarito (6):
media: v4l2-ctrls: validate HEVC and AV1 tile counts
media: rkvdec: bound HEVC tile loops and PPS id to the array capacity
media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer
capacity
media: verisilicon: rockchip: bound VPU981 AV1 tile loop and guard
divisor
media: mediatek: vcodec: bound AV1 tile-start copy to the array
capacity
media: v4l2-ctrls: add KUnit tests for compound control tile
validation
.../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 5 +- .../rockchip/rkvdec/rkvdec-hevc-common.c | 22 ++- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 8 +- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 2 + .../platform/verisilicon/hantro_g2_hevc_dec.c | 6 + .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 29 ++-- drivers/media/v4l2-core/Kconfig | 12 ++ .../media/v4l2-core/v4l2-ctrls-core-test.c | 130 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-core.c | 27 ++++ 9 files changed, 224 insertions(+), 17 deletions(-) create mode 100644 drivers/media/v4l2-core/v4l2-ctrls-core-test.c
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
Signature · 1 line
2.53.0
PATCH v2 1/6 media: v4l2-ctrls: validate HEVC and AV1 tile counts
The stateless HEVC and AV1 controls carry tile counts that several SoC decoder drivers consume as loop bounds when laying out fixed-size hardware descriptor buffers, but std_validate_compound() does not bound them.
For V4L2_CTRL_TYPE_HEVC_PPS with tiling enabled, num_tile_columns_minus1 and num_tile_rows_minus1 (u8) drive loops over column_width_minus1[20] and row_height_minus1[22]. For V4L2_CTRL_TYPE_AV1_FRAME, tile_info.tile_cols and tile_rows (u8) bound loops over the mi_*_starts[] / *_in_sbs_minus_1[] arrays. Reject counts beyond the uAPI array capacity with -EINVAL.
These are active-count fields (loop bounds), so bounding the upper limit here mirrors the existing num_active_dpb_entries check. Only the upper bound is enforced; a zero tile count is left to the consuming driver, so the zero-initialised AV1 frame control that existing userspace submits is not rejected, and the AV1 divisor (context_update_tile_id / tile_cols) is guarded where it is used in the rockchip decoder (patch 4).
Driver-interpreted index values (HEVC pic_parameter_set_id, AV1 context_update_tile_id) are bounded in the consuming drivers instead (patches 2 and 4).
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-core.c +23 -0
@@ -790,10 +790,25 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)return 0 ; } +static int validate_av1_tile_info (struct v4l2_av1_tile_info *t) +{ +/* Loop bounds in the stateless AV1 drivers. */ +if (t->tile_cols >V4L2_AV1_MAX_TILE_COLS ) +return -EINVAL ; + +if (t->tile_rows >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ; + +return 0 ; +} +static int validate_av1_frame (struct v4l2_ctrl_av1_frame *f) {int ret =0 ; + ret =validate_av1_tile_info (&f->tile_info); +if (ret) +return ret; ret =validate_av1_quantization (&f->quantization);if (ret)return ret;
@@ -1242,6 +1257,14 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, p_hevc_pps->flags &= ~V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED ; + }else { +/* Loop bounds in the stateless HEVC drivers. */ +if (p_hevc_pps->num_tile_columns_minus1 >= +ARRAY_SIZE (p_hevc_pps->column_width_minus1)) +return -EINVAL ; +if (p_hevc_pps->num_tile_rows_minus1 >= +ARRAY_SIZE (p_hevc_pps->row_height_minus1)) +return -EINVAL ; } if (p_hevc_pps->flags &
Signature · 1 line
2.53.0
PATCH v2 2/6 media: rkvdec: bound HEVC tile loops and PPS id to the array capacity
In reply to Michael Bommaritocompute_tiles_uniform() / compute_tiles_non_uniform() and assemble_hw_pps() loop over num_tile_columns_minus1 / num_tile_rows_minus1 to write the per-tile column_width[] / row_height[] arrays, sized to the PPS uAPI arrays column_width_minus1[20] / row_height_minus1[22]; bound the loops to that capacity. assemble_hw_pps() also indexes the fixed param_set[] table by pic_parameter_set_id, a driver-interpreted index the core does not reject; bound it to the table size before the access.
--- .../rockchip/rkvdec/rkvdec-hevc-common.c | 22 +++++++++++++++---- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 8 +++++-- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +18 -4
@@ -37,15 +37,22 @@ void compute_tiles_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size, s32 pic_in_cts_height, u16 *column_width, u16 *row_height) { const struct v4l2_ctrl_hevc_pps *pps = run->pps; +unsigned int num_cols, num_rows;int i; -for (i =0 ; i < pps->num_tile_columns_minus1 +1 ; i++) +/* Bound the loops to the column_width[]/row_height[] capacity. */ + num_cols = min_t(unsigned int, pps->num_tile_columns_minus1 + 1, +ARRAY_SIZE (pps->column_width_minus1)); + num_rows = min_t(unsigned int, pps->num_tile_rows_minus1 + 1, +ARRAY_SIZE (pps->row_height_minus1)); + +for (i =0 ; i < num_cols; i++) column_width[i] = ((i +1 ) * pic_in_cts_width) / (pps->num_tile_columns_minus1 +1 ) - (i * pic_in_cts_width) / (pps->num_tile_columns_minus1 +1 ); -for (i =0 ; i < pps->num_tile_rows_minus1 +1 ; i++) +for (i =0 ; i < num_rows; i++) row_height[i] = ((i +1 ) * pic_in_cts_height) / (pps->num_tile_rows_minus1 +1 ) - (i * pic_in_cts_height) /
@@ -57,17 +64,24 @@ void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size s32 pic_in_cts_height, u16 *column_width, u16 *row_height) { const struct v4l2_ctrl_hevc_pps *pps = run->pps; +unsigned int num_cols, num_rows;s32 sum =0 ;int i; -for (i =0 ; i < pps->num_tile_columns_minus1; i++) { +/* Leave one slot for the trailing last-tile entry written below. */ + num_cols = min_t(unsigned int, pps->num_tile_columns_minus1, +ARRAY_SIZE (pps->column_width_minus1) -1 ); + num_rows = min_t(unsigned int, pps->num_tile_rows_minus1, +ARRAY_SIZE (pps->row_height_minus1) -1 ); + +for (i =0 ; i < num_cols; i++) { column_width[i] = pps->column_width_minus1[i] +1 ; sum += column_width[i]; } column_width[i] = pic_in_cts_width - sum; sum =0 ; -for (i =0 ; i < pps->num_tile_rows_minus1; i++) { +for (i =0 ; i < num_rows; i++) { row_height[i] = pps->row_height_minus1[i] +1 ; sum += row_height[i]; }
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +6 -2
@@ -156,6 +156,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,* packet unit). so the driver copy SPS/PPS information to the exact PPS * packet unit for HW accessing. */ +if (pps->pic_parameter_set_id >=ARRAY_SIZE (priv_tbl->param_set)) +return ; hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id];memset (hw_ps,0 ,sizeof (*hw_ps));
@@ -274,9 +276,11 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,if (pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ) {/* Userspace also provide column width and row height for uniform spacing */ -for (i =0 ; i <= pps->num_tile_columns_minus1; i++) +for (i =0 ; i <= pps->num_tile_columns_minus1 && + i <ARRAY_SIZE (pps->column_width_minus1); i++)WRITE_PPS (pps->column_width_minus1[i],COLUMN_WIDTH (i)); -for (i =0 ; i <= pps->num_tile_rows_minus1; i++) +for (i =0 ; i <= pps->num_tile_rows_minus1 && + i <ARRAY_SIZE (pps->row_height_minus1); i++)WRITE_PPS (pps->row_height_minus1[i],ROW_HEIGHT (i)); }else { WRITE_PPS(((sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y) - 1,
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +2 -0
@@ -145,6 +145,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,* packet unit). so the driver copy SPS/PPS information to the exact PPS * packet unit for HW accessing. */ +if (pps->pic_parameter_set_id >=ARRAY_SIZE (priv_tbl->param_set)) +return ; hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id];memset (hw_ps,0 ,sizeof (*hw_ps));
Signature · 1 line
2.53.0
PATCH v2 3/6 media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer capacity
In reply to Michael Bommaritoprepare_tile_info_buffer() writes one entry per tile into the tile_sizes DMA buffer, sized for a grid equal to the PPS uAPI array capacity. Bound the loop to that capacity so the writes stay inside the buffer.
--- drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c +6 -0
@@ -22,6 +22,12 @@ static void prepare_tile_info_buffer(struct hantro_ctx *ctx)bool tiles_enabled, uniform_spacing;u32 no_chroma =0 ; +/* Bound the loops to the tile_sizes buffer capacity. */ + num_tile_cols = min_t(unsigned int, num_tile_cols, +ARRAY_SIZE (pps->column_width_minus1)); + num_tile_rows = min_t(unsigned int, num_tile_rows, +ARRAY_SIZE (pps->row_height_minus1)); + tiles_enabled = !!(pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ); uniform_spacing = !!(pps->flags &V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING );
Signature · 1 line
2.53.0
PATCH v2 4/6 media: verisilicon: rockchip: bound VPU981 AV1 tile loop and guard divisor
In reply to Michael Bommaritorockchip_vpu981_av1_dec_set_tile_info() divides context_update_tile_id by tile_info->tile_cols and writes one descriptor per tile into the tile_info DMA buffer, sized for AV1_MAX_TILES. tile_cols / tile_rows come straight from the bitstream; reject a zero column or row count and bound the grid to AV1_MAX_TILES so the division is safe and the writes stay in the buffer.
--- .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +20 -9
@@ -578,21 +578,32 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx)const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info;const struct v4l2_ctrl_av1_tile_group_entry *group_entry = ctrls->tile_group_entry; -int context_update_y = - tile_info->context_update_tile_id / tile_info->tile_cols; -int context_update_x = - tile_info->context_update_tile_id % tile_info->tile_cols; -int context_update_tile_id = - context_update_x * tile_info->tile_rows + context_update_y; +unsigned int tile_cols, tile_rows; +int context_update_y, context_update_x, context_update_tile_id;u8 *dst = av1_dec->tile_info.cpu;struct hantro_dev *vpu = ctx->dev;int tile0, tile1; +/* Guard the divisor and bound the grid to the tile_info buffer. */ + tile_cols = tile_info->tile_cols; + tile_rows = tile_info->tile_rows; +if (!tile_cols || !tile_rows) +return ; +if (tile_cols * tile_rows >AV1_MAX_TILES ) { + tile_cols = min_t(unsigned int, tile_cols, AV1_MAX_TILES); + tile_rows = min_t(unsigned int, tile_rows, +AV1_MAX_TILES / tile_cols); + } + + context_update_y = tile_info->context_update_tile_id / tile_cols; + context_update_x = tile_info->context_update_tile_id % tile_cols; + context_update_tile_id = context_update_x * tile_rows + context_update_y; +memset (dst,0 , av1_dec->tile_info.size); -for (tile0 =0 ; tile0 < tile_info->tile_cols; tile0++) { -for (tile1 =0 ; tile1 < tile_info->tile_rows; tile1++) { -int tile_id = tile1 * tile_info->tile_cols + tile0; +for (tile0 =0 ; tile0 < tile_cols; tile0++) { +for (tile1 =0 ; tile1 < tile_rows; tile1++) { +int tile_id = tile1 * tile_cols + tile0;u32 start, end;u32 y0 = tile_info->height_in_sbs_minus_1[tile1] +1 ;
Signature · 1 line
2.53.0
PATCH v2 5/6 media: mediatek: vcodec: bound AV1 tile-start copy to the array capacity
In reply to Michael Bommaritovdec_av1_slice_setup_tile() copies tile_cols + 1 / tile_rows + 1 start positions into mi_col_starts[] / mi_row_starts[], which hold V4L2_AV1_MAX_TILE_COLS + 1 / V4L2_AV1_MAX_TILE_ROWS + 1 entries. tile_cols and tile_rows come straight from the bitstream; bound the copy to the array capacity so the accesses stay in range.
--- .../mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c +3 -2
@@ -1299,11 +1299,12 @@ static void vdec_av1_slice_setup_tile(struct vdec_av1_slice_frame *frame, tile->uniform_tile_spacing_flag =BIT_FLAG (ctrl_tile,V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING ); -for (i =0 ; i < tile->tile_cols +1 ; i++) +/* Bound the copy to the mi_col_starts[]/mi_row_starts[] capacity. */ +for (i =0 ; i < tile->tile_cols +1 && i <V4L2_AV1_MAX_TILE_COLS +1 ; i++) tile->mi_col_starts[i] =ALIGN (ctrl_tile->mi_col_starts[i],BIT (mib_size_log2)) >> mib_size_log2; -for (i =0 ; i < tile->tile_rows +1 ; i++) +for (i =0 ; i < tile->tile_rows +1 && i <V4L2_AV1_MAX_TILE_ROWS +1 ; i++) tile->mi_row_starts[i] =ALIGN (ctrl_tile->mi_row_starts[i],BIT (mib_size_log2)) >> mib_size_log2; }
Signature · 1 line
2.53.0
PATCH v2 6/6 media: v4l2-ctrls: add KUnit tests for compound control tile validation
In reply to Michael BommaritoDrive std_validate_compound() with crafted HEVC PPS and AV1 frame controls and assert that out-of-range tile counts are rejected with -EINVAL while in-range values pass, including the zero-initialised AV1 frame default that userspace and v4l2-compliance submit. The tests are #included at the end of v4l2-ctrls-core.c to reach the static helper, gated by CONFIG_V4L2_CTRLS_KUNIT_TEST.
--- drivers/media/v4l2-core/Kconfig | 12 ++ .../media/v4l2-core/v4l2-ctrls-core-test.c | 130 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-core.c | 4 + 3 files changed, 146 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-ctrls-core-test.c
drivers/media/v4l2-core/Kconfig +12 -0
@@ -3,6 +3,18 @@ # Generic video config states # +config V4L2_CTRLS_KUNIT_TEST + bool "KUnit tests for V4L2 compound control validation" if !KUNIT_ALL_TESTS + depends on VIDEO_DEV && KUNIT=y + default KUNIT_ALL_TESTS + help + This builds KUnit tests for the stateless-codec compound control + validation in std_validate_compound(). They check that out-of-range + HEVC/AV1 tile counts and parameter-set / tile indices are rejected + before driver code consumes them as array indices or loop bounds. + + If unsure, say N. + config VIDEO_V4L2_I2C bool depends on I2C && VIDEO_DEV
drivers/media/v4l2-core/v4l2-ctrls-core-test.c new file +130 -0
130 lines not on this page · raw message
drivers/media/v4l2-core/v4l2-ctrls-core.c +4 -0
@@ -2851,3 +2851,7 @@ int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,return hdl->error; }EXPORT_SYMBOL (v4l2_ctrl_new_fwnode_properties); + +#if IS_ENABLED (CONFIG_V4L2_CTRLS_KUNIT_TEST ) +#include "v4l2-ctrls-core-test.c" +#endif
Signature · 1 line
2.53.0
Benjamin Gaignard
maintainerRe: [PATCH v2 1/6] media: v4l2-ctrls: validate HEVC and AV1 tile counts
In reply to Michael BommaritoLe 14/06/2026 à 17:56, Michael Bommarito a écrit :
Quoted 17 lines
The stateless HEVC and AV1 controls carry tile counts that several SoC decoder drivers consume as loop bounds when laying out fixed-size hardware descriptor buffers, but
std_validate_compound()does not bound them.For
V4L2_CTRL_TYPE_HEVC_PPSwith tiling enabled,num_tile_columns_minus1andnum_tile_rows_minus1(u8) drive loops over column_width_minus1[20] and row_height_minus1[22]. ForV4L2_CTRL_TYPE_AV1_FRAME, tile_info.tile_cols andtile_rows(u8) bound loops over the mi_*_starts[] / *_in_sbs_minus_1[] arrays. Reject counts beyond the uAPI array capacity with-EINVAL.These are active-count fields (loop bounds), so bounding the upper limit here mirrors the existing
num_active_dpb_entriescheck. Only the upper bound is enforced; a zero tile count is left to the consuming driver, so the zero-initialised AV1 frame control that existing userspace submits is not rejected, and the AV1 divisor (context_update_tile_id/tile_cols) is guarded where it is used in the rockchip decoder (patch 4).
Quoted 6 lines
Driver-interpreted index values (HEVC
pic_parameter_set_id, AV1context_update_tile_id) are bounded in the consuming drivers instead (patches 2 and 4).Fixes 256fa3920874 ("media: v4l: Add definitions for HEVC stateless decoding")Fixes 9de30f579980 ("media: Add AV1 uAPI")
I think you need to do a patch for each of the codec with only one "Fixes" tag on each.
Regards,
Benjamin
Quoted 51 lines
Signed-off-by Michael Bommarito <[email protected]>Assisted-by Claude:claude-opus-4-8--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/media/v4l2-core/v4l2-ctrls-core.c +23
-0@@ -790,10 +790,25 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)return 0 ; } +static int validate_av1_tile_info (struct v4l2_av1_tile_info *t) +{ +/* Loop bounds in the stateless AV1 drivers. */ +if (t->tile_cols >V4L2_AV1_MAX_TILE_COLS ) +return -EINVAL ; + +if (t->tile_rows >V4L2_AV1_MAX_TILE_ROWS ) +return -EINVAL ; + +return 0 ; +} +static int validate_av1_frame (struct v4l2_ctrl_av1_frame *f) {int ret =0 ; + ret =validate_av1_tile_info (&f->tile_info); +if (ret) +return ret; ret =validate_av1_quantization (&f->quantization);if (ret)return ret;@@ -1242,6 +1257,14 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, p_hevc_pps->flags &= ~V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED ; + }else { +/* Loop bounds in the stateless HEVC drivers. */ +if (p_hevc_pps->num_tile_columns_minus1 >= +ARRAY_SIZE (p_hevc_pps->column_width_minus1)) +return -EINVAL ; +if (p_hevc_pps->num_tile_rows_minus1 >= +ARRAY_SIZE (p_hevc_pps->row_height_minus1)) +return -EINVAL ; } if (p_hevc_pps->flags &
Benjamin Gaignard
maintainerRe: [PATCH v2 3/6] media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer capacity
In reply to Michael BommaritoLe 14/06/2026 à 17:56, Michael Bommarito a écrit :
Quoted 16 lines
prepare_tile_info_buffer()writes one entry per tile into thetile_sizesDMA buffer, sized for a grid equal to the PPS uAPI array capacity. Bound the loop to that capacity so the writes stay inside the buffer.Fixes cb5dd5a0fa51 ("media: hantro: Introduce G2/HEVC decoder")Signed-off-by Michael Bommarito <[email protected]>Assisted-by Claude:claude-opus-4-8--- drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c +0
-0
drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c static void prepare_tile_info_buffer(struct hantro_ctx *ctx) · line 30
Quoted 9 lines
drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c +6
-0@@ -22,6 +22,12 @@ static void prepare_tile_info_buffer(struct hantro_ctx *ctx)bool tiles_enabled, uniform_spacing;u32 no_chroma =0 ; +/* Bound the loops to the tile_sizes buffer capacity. */ + num_tile_cols = min_t(unsigned int, num_tile_cols, +ARRAY_SIZE (pps->column_width_minus1)); + num_tile_rows = min_t(unsigned int, num_tile_rows, +ARRAY_SIZE (pps->row_height_minus1)); +
The same code is duplicated in rkvdec driver.
To avoid this problem in the future can you create helpers to get those values where boundaries are checked ?
Regards,
Benjamin
Quoted 3 lines
drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c +0
-0tiles_enabled = !!(pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ); uniform_spacing = !!(pps->flags &V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING );
Re: [PATCH v2 4/6] media: verisilicon: rockchip: bound VPU981 AV1 tile loop and guard divisor
In reply to Michael BommaritoLe 14/06/2026 à 17:56, Michael Bommarito a écrit :
Quoted 28 lines
rockchip_vpu981_av1_dec_set_tile_info()dividescontext_update_tile_idbytile_info->tile_colsand writes one descriptor per tile into thetile_infoDMA buffer, sized forAV1_MAX_TILES.tile_cols/tile_rowscome straight from the bitstream; reject a zero column or row count and bound the grid toAV1_MAX_TILESso the division is safe and the writes stay in the buffer.Fixes 727a400686a2 ("media: verisilicon: Add Rockchip AV1 decoder")Signed-off-by Michael Bommarito <[email protected]>Assisted-by Claude:claude-opus-4-8--- .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-)drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +1
-6@@ -578,21 +578,32 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx)const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info;const struct v4l2_ctrl_av1_tile_group_entry *group_entry = ctrls->tile_group_entry; -int context_update_y = - tile_info->context_update_tile_id / tile_info->tile_cols; -int context_update_x = - tile_info->context_update_tile_id % tile_info->tile_cols; -int context_update_tile_id = - context_update_x * tile_info->tile_rows + context_update_y; +unsigned int tile_cols, tile_rows;
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx) · line 591
Quoted 10 lines
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +6
-0+int context_update_y, context_update_x, context_update_tile_id;u8 *dst = av1_dec->tile_info.cpu;struct hantro_dev *vpu = ctx->dev;int tile0, tile1; +/* Guard the divisor and bound the grid to the tile_info buffer. */ + tile_cols = tile_info->tile_cols; + tile_rows = tile_info->tile_rows; +if (!tile_cols || !tile_rows) +return ;
NACK
because you completely ignore how these values are used later in this function to set registers.
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx) · line 597
Quoted 6 lines
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +6
-0+if (tile_cols * tile_rows >AV1_MAX_TILES ) { + tile_cols = min_t(unsigned int, tile_cols, AV1_MAX_TILES); + tile_rows = min_t(unsigned int, tile_rows, +AV1_MAX_TILES / tile_cols); + } +
It isn't possible to recompute tile_cols and tile_rows like that. Please add this check in validate_av1_tile_info().
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx) · line 600
Quoted 3 lines
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +3
-0+ context_update_y = tile_info->context_update_tile_id / tile_cols; + context_update_x = tile_info->context_update_tile_id % tile_cols; + context_update_tile_id = context_update_x * tile_rows + context_update_y;
To fix the possible division by zero: initialize the variable to zero when declare them and only do the division if tile_cols isn't zero.
Thanks,
Benjamin
Quoted 12 lines
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +4
-3+memset (dst,0 , av1_dec->tile_info.size); -for (tile0 =0 ; tile0 < tile_info->tile_cols; tile0++) { -for (tile1 =0 ; tile1 < tile_info->tile_rows; tile1++) { -int tile_id = tile1 * tile_info->tile_cols + tile0; +for (tile0 =0 ; tile0 < tile_cols; tile0++) { +for (tile1 =0 ; tile1 < tile_rows; tile1++) { +int tile_id = tile1 * tile_cols + tile0;u32 start, end;u32 y0 = tile_info->height_in_sbs_minus_1[tile1] +1 ;