Repository navigation
media: apple: ave: check the MCTF input picture against its plane without wrapping - #3199
Conversation
…hout wrapping The MCTF copies a whole input picture from the OUTPUT plane's data_offset on. Its bounds check added data_offset and the compressed picture size, both u32, in 32 bits before comparing with the plane size. vb2 only keeps data_offset below bytesused, so with a plane near 4 GiB and data_offset at its end the sum wraps, the check passes and the copy reads past the plane. Check the picture with check_add_overflow() on size_t, for both input formats, and refuse such a buffer already in buf_prepare, so QBUF fails with -EINVAL instead of the job failing later. The encoder video device is unchanged: it places its input itself in ave_sess_input(). Add KUnit cases for the wrapped offset at QBUF and at the copy, an offset one byte too far, and pictures that end exactly at the end of the plane. Signed-off-by: Dj <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers: none Checked:
Evidence
|
|
J714s (MacBook Pro 14" M5 Pro, T6050) row: no regression in AVE encoding. The MCTF bounds check itself isn't exercised.
|
There was a problem hiding this comment.
Verdict: MERGE at b09c1d7f (once cancelled KUnit CI checks are rerun green)
Blockers: none (code, KUnit, and hardware rows are ready; rerun the 12 cancelled KUnit checks before merge).
Checked:
drivers/media/platform/apple/ave/ave-mctf.c:158-206: verifiedave_mctf_input_fits()usescheck_add_overflow((size_t)data_offset, bytes, &end) && end <= plane_sizewithout 32-bit wrap and is enforced inave_mctf_put_picture()before advancingfromfor both lossless (APPLE_L8V0) and NV12 formats.drivers/media/platform/apple/ave/ave-v4l2.c:717-720: verifiedave_buf_prepare()refuses out-of-rangedata_offsetat QBUF with-EINVALfor MCTF OUTPUT buffers while leaving the encoder path unchanged.ave-mctf-test.c: verified KUnit coversU32_MAXwrap,SIZE_MAXwrap, exact boundary, and +1 byte past boundary at both QBUF and copy sites.- Verified J700 (Neo) MCTF + bad-
data_offsetQBUF refusal + 300/300 H.264 row and J714s (M5 Pro) no-regression row.
Evidence
- Diff reviewed at
b09c1d7f(all 4 files, 235 lines). - CI at review time: 7 passed, 0 failed, 12 cancelled.
|
Merge-train status at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: The MCTF copies each OUTPUT picture from the plane's
data_offseton. Its bounds check addeddata_offsetand the picture size in 32 bits, so with a plane near 4 GiB anddata_offsetat its end the sum wrapped, the check passed and the copy read past the plane. The sum is now taken without wrapping, and such a buffer is refused at QBUF with -EINVAL.Tested: KUnit
apple-ave-mctfon arm64 QEMU, with new cases for the wrapped offset at QBUF and at the copy, an offset one byte too far, and pictures that end exactly at the end of the plane. J700 (Neo) at63fc16c68f29, in the combined candidate 7.3.0-neo-combined1126, which carries it unchanged: H.264 1080p encode 300/300 frames with md5 identical to base, MCTF 120/120 frames, and an MCTFdata_offsetpast the plane refused at QBUF. 0 DART faults. J714s (M5 Pro) at63fc16c68f29, in the combined candidate 7.3.0-m5-rows-sec2, which carries it unchanged: AVE encode 300 frames, PSNR equal to base. 0 DART faults.Risk: two-way · Neo, the only Mac whose encoder firmware runs MCTF. Encoder buffers skip the new check.
Not yet: nothing.
Details
ave_mctf_input_fits()checksdata_offset + bytes <= plane sizewithcheck_add_overflow()onsize_t.ave_mctf_put_picture()uses it for both input formats (lossless and NV12) before copying.ave_buf_prepare()runs the same check for OUTPUT buffers of an MCTF context, with the sizeave_mctf_input_bytes()gives for the negotiated format. The bad buffer is refused at QBUF, and the copy-site check stays as the guard for the copy itself.data_offsetbelowbytesused, and the encoder places its own input inave_sess_input(). Encoder contexts therefore keep the oldbuf_prepare()behaviour.Evidence
./tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/media/platform/apple/ave/.kunitconfig. The new case isapple-ave-mctf.ave_mctf_input_offset.U32_MAXplane anddata_offset = U32_MAX - 1passed the check, and the copy ran past the plane. The new case refuses it at QBUF and at the copy.