Repository navigation
media: apple: avd: check HEVC tile layouts and VP9 tile counts before building jobs - #2945
Conversation
push() wrote the next instruction into job->segments[job->num] without checking that the segment exists or has room. The codecs size the table from the request before building it, so an error in that sizing became a write past the table, and a segment that filled up wrote into the next one. avd_open_build_program() only noticed a full segment after the writes. Record the number of allocated segments in the job, and have push() drop an instruction that has no segment or no room and mark the job. A marked job, or one whose segment index is past the table, is refused with -EOVERFLOW instead of being turned into a program. The H.264 path, which grows the table when a picture needs more slices, updates the count. Add KUnit cases for a full segment and a full table. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The tile tables are sized from the SPS picture size in CTBs, but explicitly sized tile columns and rows were taken from the PPS without comparing them with that size. The last column or row then took a wrapped, very large width, and building the CTB raster-to-tile-scan and tile id tables wrote outside both tables. Before building the tables, require what H.265 7.4.3.3.1 requires: no more tile columns or rows than the picture has CTBs, and explicit widths and heights that leave a non-empty last column and row. Also refuse an SPS with a zero picture width or height, or a CTB size other than 16, 32 or 64 (7.4.3.2.1), which the tables and the slice address arithmetic divide by. As a second line, the tile id table builder skips any index outside the tables. Add KUnit cases for the SPS geometry and tile layout checks that also build the tables, for accepted and refused layouts. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The VP9 job is sized with one segment per tile, computed in int from tile_rows_log2 and tile_cols_log2, and set_tiles() then walks the tile grid with u32 counts. The V4L2 core bounds tile_cols_log2 to 6 but not tile_rows_log2, and the driver checked neither, so the int product can wrap and the job be allocated smaller than the grid that is filled in. Check the tiling in avd_vp9_validate_frame(), which runs when the frame control is set and again when the frame runs: tile_rows_log2 is at most 2 and tile_cols_log2 lies between calc_min_log2_tile_cols() and calc_max_log2_tile_cols() for the frame width (VP9 6.2.13 tile_info() and 6.2.14). With the 4096-pixel coded width limit that also keeps the column count within the VP9_MAX_TILE_COLS the scratch is sized for. Compute the segment count as a size_t shift of the summed log2 values. Add a KUnit test for the tiling check. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
validate_vp9_frame() checks tile_cols_log2 against its maximum but accepts any tile_rows_log2. The VP9 tile_info() syntax (section 6.2.13) codes it as at most two one-bit increments, so it is 0, 1 or 2. Reject larger values so drivers do not each have to. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The HEVC and VP9 run paths kept pointers into the current values of the picture controls (HEVC SPS, PPS, decode parameters and scaling matrix, VP9 frame and compressed header) while they checked those values and then built the job from them. A VIDIOC_S_EXT_CTRLS that sets current values, not a request, is not serialized with the decode work, so the values could change between the checks and their use, and the tile tables and job table could be built from values that were never checked. Copy the controls under the control lock when the job starts, as the HEVC path already does for its slice and entry point arrays, and check and build from the copies. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR review at 276447127c76.
The kernel changes across all 5 commits look solid: push() bounds-checking with job->max/job->overflow, HEVC SPS CTB geometry and tile layout validation, VP9 tile_rows_log2/tile_cols_log2 bounds (both driver and v4l2-ctrls-core.c), and locked control copies for HEVC and VP9 runs are clean, overflow-safe, and leak-free. §1–§4 and §6 pass (no model gating, default cmdline, human author/committer and Signed-off-by: only, zero AI trailers in commits).
Blocker
- Failing CI (
host-tests/avd-codec-tail-tests, run 45113950356, 460/461 passed):drivers/media/platform/apple/avd/tests/program-test.py:549extractsavd_hevc_validate_sps()without extracting the newavd_hevc_check_sps_geometry(), causing-Werror=implicit-function-declarationwhen compilingprepare.c.- Even after extracting
avd_hevc_check_sps_geometry(),program-test.py:459-460initializesstruct v4l2_ctrl_hevc_sps hevcwithlog2_min_luma_coding_block_size_minus3 = 0andlog2_diff_max_min_luma_coding_block_size = 0(ctb_log2 == 3), whichavd_hevc_check_sps_geometry()now rejects with-EINVAL(breaking the depth-validation loop at line 467). program-test.py:94definesstruct avd_jobwithout the newsize_t max; bool overflow;fields now used byavd-inst.h:push()andavd-backend-open.c:avd_open_build_program(), and itsavd_init_job()/MAIN/RUN_MAIN/CONFORMANCE_MAINfixtures (plusav1-test.py/vp9-test.pywhich importPRELUDE) needjob.maxinitialized sopush()does not flag overflow on every segment.
Non-blocking note
avd_hevc_check_tiles()currently relies onv4l2-ctrls-core.cto enforcenum_tile_columns_minus1 < ARRAY_SIZE(pps->column_width_minus1)(20) andnum_tile_rows_minus1 < ARRAY_SIZE(pps->row_height_minus1)(22); checking those bounds insideavd_hevc_check_tiles()too would keep the helper self-contained if called outside the V4L2 control path.
Please update the AVD host test harness so host-tests passes green before merge.
Assisted-by: LLM (Gemini 4 Neon)
…heck The host program test models struct avd_job without the new max and overflow fields, so push() treats every job as full. Give the model the fields and set max wherever a test builds a segment table. avd_hevc_validate_sps() now calls avd_hevc_check_sps_geometry(), which the test did not extract, and the depth fixture used 8x8 CTBs, which the check refuses. Extract the helper and use 64x64 CTBs. Let the extractor find functions whose return type is on the previous line. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
avd_hevc_check_tiles() reads column_width_minus1[] and row_height_minus1[] up to the tile counts and relied on the V4L2 control code to keep the counts below the array sizes. Check that in the helper too, so it holds for any caller. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Thanks for the review. Pushed two commits (5e26308), no history rewrite:
Local results at 5e26308: |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at 5e263083adeb6e0f710aab4a5ddc271bd4f6ae5c.
Follow-up Verification (since 276447127c76)
- Prior Blocker 1 (
host-tests/avd-codec-tail-tests) — Resolved: Commit15d9bac9d8ffupdatesdrivers/media/platform/apple/avd/tests/host_source.pyto match multiline return types, addsmax/overflowtostruct avd_joband initializes them acrossprogram-test.py,av1-test.py, andvp9-test.py, extractsavd_hevc_check_sps_geometry(), and uses a valid 64×64 CTB in the HEVC depth-validation fixture. Live CIhost-tests(run45127918674) is green: 463/463 passed, including all 12 AVD host tests (avd-codec-tail-tests+--mutations,avd-av1-tail-tests+ cases + all 6 mutations). - Prior Non-blocking Note (
avd_hevc_check_tiles()PPS array bounds) — Resolved: Commit5e263083adebadds explicitARRAY_SIZE(pps->column_width_minus1)/ARRAY_SIZE(pps->row_height_minus1)checks inavd_hevc_check_tiles()along with KUnit caseavd_hevc_tiles_array_test(80/80KUnit+KASAN pass locally).
Checklist Summary (§1–§6)
- §1 No model gating: Pass — codec-generic V4L2/AVD bounds checks with zero chip, SoC, board, or firmware gates.
- §2 Production-ready: Pass — works on the default command line with no new parameters, delays, or lab-only paths.
- §3 Safety: Pass —
push()bounds-checksjob->num >= job->maxandseg->num >= AVD_MAX_INST(avd_open_build_program()returns-EOVERFLOW), HEVC checks SPS geometry + PPS array bounds + CTB tile layout, VP9 boundstile_rows_log2 <= 2andtile_cols_log2in both the driver andv4l2-ctrls-core.cusingsize_tsizing, and HEVC/VP9 jobs run from locked control copies with leak-free cleanup. - §4 Clean-room & attribution: Pass — all 7 commits carry human author/committer (
Ryan Murray <ryan@aurorasilicon.org>) and humanSigned-off-by:only, zero AI trailers in commits; PR body includesAssisted-by:; clean-room. - §5 Evidence & CI: Pass —
host-testsCI green (463/463); KUnit+KASAN (avd-pm.kunitconfig, arm64 QEMU)80/80pass (all new tests confirmed failing without fixes); M2 (T8112, default boot7.3.0-aurora-fleet82, default cmdline) A/B confirms bit-exact output across 9 decode clips and 1080p/4Kavd-bench(490/490 fps unchanged) plus clean refusal of malformed tile layouts/counts with 0 oops/KASAN/DART faults. - §6 Naming: Pass.
Non-blocking Notes
- M1-family / M4-family follow-up rows (listed under Still to run) and an explicit SELinux/systemd regression tuple (
0 SELinux denials, 0 failed units, 0 new kernel errors) are welcome when convenient.
Verdict
APPROVE — prior blocker and non-blocking note cleanly resolved, CI green, ready for MERGETRAIN-LINUX4.
Assisted-by: LLM (Gemini 4 Neon)
|
Merge-train review at 5e26308 (non-author pass): no blockers. I went through the five kernel commits looking for valid streams that now get refused, overflows that are still open, and error paths. I found nothing that blocks a merge. Every new limit comes from the codec spec: HEVC CtbLog2SizeY 4..6 and the 7.4.3.3.1 tile layout, VP9 6.2.13/6.2.14 tile counts. There are no chip, board or firmware conditions and no new parameters, and the commit trailers are human-only (author, committer and Signed-off-by). The stack still merges cleanly onto integration/aurora 5441428; the 36 commits the base has gained since b10280c do not touch avd or v4l2-core. Host tests and KUnit pass at head, and all seven mutations I made to the checks were caught by the tests. The hardware row on M2 (T8112) covers the decode path at head: the fleet82 AVD codec files are identical to b10280c, and the only kernel change after the row (5e26308) adds a check the V4L2 core already enforces. That row has HEVC and VP9 clips with output, and H.264 through clip1080-h264 and the bench. A second-generation row (M1-family or M4-family) is still listed under "Still to run". It is wanted, but I don't hold this PR on it, because the change only adds bounds and does not alter how valid jobs are built. What I checkedFalse positives (valid streams refused):
Overflow and race paths: Error handling: a refused job returns from ->run(). avd_queue's Tests (scratch worktree, detached at 5e26308):
Rows: the M2 A/B row (stock vs patched module, the same 9 clips and the bench) is identical on both arms. Note that 8 of the 9 clip md5s also differ from the software reference on the stock module, so this row proves no regression but not correctness. Two clips (av1-tiles-1080, h264-slices) produced no output at all on either arm (md5 of empty input): the M2 block has no AV1, and the H.264 multi-slice pipeline gave nothing. Second-generation row recipe: see the comment on #2946. Assisted-by: LLM (Claude:Opus 5.5) |
Problem
Two codecs size kernel tables from one control and then fill them using another, unchecked one:
tile_rows_log2andtile_cols_log2.tile_rows_log2has no bound in the driver or in the V4L2 core, and the segment count was anintproduct.push()also wrote intojob->segments[job->num]without checking that the segment exists or has room.Change
push()drops an instruction that has no segment or no room in it, and marks the job. A marked job is refused with-EOVERFLOWand never becomes a program. The job records how many segments were allocated, and the H.264 path updates that count when it grows the table.tile_rows_log2must be 0 to 2 (6.2.13) andtile_cols_log2must lie in the range the frame width allows (6.2.14). The check runs at control set and again at run time, and the segment count is now computed insize_t.validate_vp9_frame()now refusestile_rows_log2 > 2, next to the existingtile_cols_log2check.VIDIOC_S_EXT_CTRLSsets the controls while a job is being built.Conformant streams are unaffected. No new parameters, gates or tables.
Testing
avd-pm.kunitconfig): new suitesapple-avd-hevc,apple-avd-jobandapple-avd-vp9pass, and so does the rest of the module's KUnit.avd_hevc_compute_tiles, and the job-table and VP9 tiling cases fail their expectations.Still to run
Overlap
#2755 also adds an HEVC tile-layout check as part of a larger audit series; whichever lands first, the other rebases onto it.
Commits
Test details
KUnit (arm64 QEMU, KASAN,
avd-pm.kunitconfig) at the PR head on integration/aurora b10280c: 79/79 pass (apple-avd-h264, -hevc, -job, -pm, -queue, -vp9). With the fixes reverted, the HEVC tile cases hit a KASAN slab-out-of-bounds write inavd_hevc_compute_tilesand the job-table and VP9 tiling cases fail.Hardware, M2 (T8112), default boot 7.3.0-aurora-fleet82, default cmdline: the stock
apple-avd.koagainst a module built from the fleet82 AVD source plus these five commits (same signing key), swapped in user space:-EINVALat control set), no hang; 0 oops/KASAN/DART faults.Evidence (our own captures): traces/codec/20261123-avd-tile-bounds-m2.
Assisted-by: LLM (Claude:Opus 5.5)