From: Michael Bommarito <michael.bommarito@gmail.com>
To: Hans Verkuil <hverkuil@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Detlev Casanova <detlev.casanova@collabora.com>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Yunfei Dong <yunfei.dong@mediatek.com>,
Jonas Karlman <jonas@kwiboo.se>, Heiko Stuebner <heiko@sntech.de>,
Kees Cook <kees@kernel.org>,
linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/6] media: v4l2-ctrls: bound stateless HEVC/AV1 tile counts
Date: Sun, 14 Jun 2026 11:56:02 -0400 [thread overview]
Message-ID: <20260614155609.3107600-1-michael.bommarito@gmail.com> (raw)
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
next reply other threads:[~2026-06-14 15:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-14 15:56 Michael Bommarito [this message]
2026-06-14 15:56 ` [PATCH v2 1/6] media: v4l2-ctrls: validate HEVC and AV1 tile counts Michael Bommarito
2026-06-14 15:56 ` [PATCH v2 2/6] media: rkvdec: bound HEVC tile loops and PPS id to the array capacity Michael Bommarito
2026-06-14 15:56 ` [PATCH v2 3/6] media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer capacity Michael Bommarito
2026-06-14 15:56 ` [PATCH v2 4/6] media: verisilicon: rockchip: bound VPU981 AV1 tile loop and guard divisor Michael Bommarito
2026-06-14 15:56 ` [PATCH v2 5/6] media: mediatek: vcodec: bound AV1 tile-start copy to the array capacity Michael Bommarito
2026-06-14 15:56 ` [PATCH v2 6/6] media: v4l2-ctrls: add KUnit tests for compound control tile validation Michael Bommarito
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260614155609.3107600-1-michael.bommarito@gmail.com \
--to=michael.bommarito@gmail.com \
--cc=benjamin.gaignard@collabora.com \
--cc=detlev.casanova@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=heiko@sntech.de \
--cc=hverkuil@kernel.org \
--cc=jonas@kwiboo.se \
--cc=kees@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=sakari.ailus@linux.intel.com \
--cc=yunfei.dong@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox