[PATCH v2 0/6] media: v4l2-ctrls: bound stateless HEVC/AV1 tile counts
Michael Bommarito
michael.bommarito at gmail.com
Sun Jun 14 08:56:02 PDT 2026
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
--
2.53.0
More information about the Linux-rockchip
mailing list