Skip to content

media: rkvdec: hevc: bound EXT SPS RPS control counts

Michael Bommarito linux-arm-kernel linux-media linux-rockchip lkml stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 3 repliesIn review
  2. v11 patch 3 repliesSuperseded

Changes in v2 from the cover letter

- Split the monolithic rkvdec-hevc-common.c validation function into dims, v4l2-core, and construction-code layers as Detlev suggested.
- Drop the rkvdec-local #defines and pr_err_ratelimited; the V4L2 framework now handles the bulk of the rejection, including the SPS count fields that drive the rkvdec loops.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3media: rkvdec: hevc: tighten EXT SPS RPS control dimensionsdrivers/media/platform/rockchip/rkvdec/rkvdec.c+2 -21 reply
2/3media: v4l2-ctrls: validate HEVC EXT SPS RPS countsdrivers/media/v4l2-core/v4l2-ctrls-core.c+15 -01 reply
3/3media: rkvdec: hevc: guard INTER_REF_PIC_SET_PRED index underflowdrivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c+3 -01 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchNicolas Dufresne
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] media: rkvdec: hevc: bound EXT SPS RPS control counts

A userspace V4L2 client that can open the Rockchip RKVDEC m2m decoder node can submit HEVC EXT SPS RPS controls whose spec-derived count fields exceed the driver's fixed hardware descriptor tables and temporary helper arrays. KASAN under a KUnit harness wrapping the real rkvdec_hevc_assemble_hw_rps() helper confirms slab-out-of-bounds writes on num_short_term_ref_pic_sets > 64, num_long_term_ref_pics_sps > 32, num_negative/positive_pics > 16, and an OOB read via u8 ref_rps_idx underflow when delta_idx_minus1 + 1 > idx.

v2 splits the single validation function from v1 into three layers at the appropriate level, per Detlev's review:

1/3 Tighten .cfg.dims on EXT_SPS_ST_RPS (65 -> 64) and
EXT_SPS_LT_RPS (65 -> 32) to match the HEVC spec limits and let the V4L2 control framework reject oversized payloads.

2/3 Add SPS ST/LT count validation plus
num_negative_pics / num_positive_pics validation in v4l2-ctrls-core.c so every consumer driver is protected.

3/3 Guard the delta_idx_minus1 underflow in
st_ref_pic_set_prediction() in the rkvdec construction code.

Changes in v2:
- Split the monolithic rkvdec-hevc-common.c validation function into dims, v4l2-core, and construction-code layers as Detlev suggested.
- Drop the rkvdec-local #defines and pr_err_ratelimited; the V4L2 framework now handles the bulk of the rejection, including the SPS count fields that drive the rkvdec loops.

Michael Bommarito (3):
media: rkvdec: hevc: tighten EXT SPS RPS control dimensions
media: v4l2-ctrls: validate HEVC EXT SPS RPS counts
media: rkvdec: hevc: guard INTER_REF_PIC_SET_PRED index underflow

 .../platform/rockchip/rkvdec/rkvdec-hevc-common.c |  3 +++
 drivers/media/platform/rockchip/rkvdec/rkvdec.c   |  4 ++--
 drivers/media/v4l2-core/v4l2-ctrls-core.c         | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32 --
2.53.0