syzbot
KASAN: vmalloc-out-of-bounds Write in tpg_fill_plane_extras
Status:
moderation: reported on 2026/11/27 06:06
Subsystems:
media
Labels:
prio:normal
[Documentation on labels]
Reported-by: syzbot+24d5ac3035dd625e60dc@syzkaller.appspotmail.com
First crash: 1h38m, last: 1h38m
✨ AI-generated root cause summary:
In tpg_fill_plane_extras() (drivers/media/common/v4l2-tpg/v4l2-tpg-core.c), when tpg->insert_eav is enabled, the function unconditionally writes a 4-byte EAV sequence (p[0..3]) at vbuf + tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3) without verifying that offset + 4 <= params->img_width. For planar YUV formats with horizontal subsampling (hdownsampling[p] == 2, twopixelsize[p] == 2, such as YUV420 or YUV422P chroma planes) and a small compose.width allowed by vivid (16 or 18, where MIN_WIDTH == 16), params->img_width is 8 or 9 bytes while offset is 5 or 6 bytes, causing p[3] at line 2441 to write 1 byte past params->img_width. When the compose rectangle reaches the bottom-right edge of the buffer on the final plane, vbuf + params->img_width coincides with the end of the vmalloc_user() buffer, producing a 1-byte vmalloc out-of-bounds write.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
The out-of-bounds write occurs in tpg_fill_plane_extras() (drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2433-2447) when tpg->insert_eav is enabled via the VIVID_CID_INSERT_EAV control (drivers/media/test-drivers/vivid/vivid-ctrls.c:596-598).
Mechanism
-
Line and buffer setup (tpg_fill_plane_buffer, drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2631-2712):
For each plane p, tpg_fill_plane_buffer() computes:
((x / tpg->hdownsampling[plane]) & tpg->hmask[plane]) * tpg->twopixelsize[plane] / 2
For every line h < tpg->compose.height, it calls tpg_fill_plane_pattern() (writing params.img_width bytes) followed by tpg_fill_plane_extras() on vbuf + buf_line * params.stride.
-
Missing bounds check in tpg_fill_plane_extras() (drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2433-2447):
When tpg->insert_eav is set, tpg_fill_plane_extras() unconditionally writes a 4-byte EAV marker (p[0..3]) starting at offset:
if (tpg->insert_eav) {
unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3);
u8 *p = vbuf + offset;
...
p[0] = 0xff;
p[1] = 0;
p[2] = 0;
p[3] = 0x80 | ...;
}
(Note that tpg->insert_sav at lines 2418-2432 likewise lacks a check against params->img_width.)
-
Out-of-bounds condition on horizontally subsampled planes:
In vivid, MIN_WIDTH is 16 (drivers/media/test-drivers/vivid/vivid-core.h:37), so vivid_try_fmt_vid_cap() and vivid_vid_cap_s_selection() (V4L2_SEL_TGT_COMPOSE) allow tpg->compose.width to be as small as 16.
For planar YUV formats with 2x horizontal chroma subsampling (tpg->hdownsampling[p] == 2 and tpg->twopixelsize[p] == 2 for planes p = 1, 2, such as V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YVU420, V4L2_PIX_FMT_YUV422P, and their multiplanar *M counterparts in tpg_s_fourcc()):
- If
tpg->compose.width == 16:
params.img_width = (16 / 2) * 2 / 2 = 8 bytes.
offset = ((16 * 2 / 3) / 2) * 2 / 2 = (10 / 2) = 5 bytes.
p[0..2] write at offsets 5, 6, 7 (within img_width), while p[3] writes at offset 8 == params.img_width (1 byte past the line).
- If
tpg->compose.width == 18:
params.img_width = 9 bytes, offset = 6 bytes, and p[3] writes at offset 9 == params.img_width (1 byte past the line).
-
Reaching the end of the vmalloc buffer:
When compose.left + compose.width == fmt_cap_rect.width and compose.top + compose.height == fmt_cap_rect.height with minimal bytesperline (for example, format width 16 or a 16-pixel-wide compose window positioned at the bottom-right of a single-planar YUV420/YUV422P buffer), on the last line of the last plane (p = 2), vbuf + params->img_width points to the exact end of the vmalloc_user() buffer allocated in vb2_vmalloc_alloc() (drivers/media/common/videobuf2/videobuf2-vmalloc.c:47). Consequently, p[3] = 0x80 | ... at drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2441 performs a 1-byte out-of-bounds write into the KASAN redzone / guard page immediately following the 18-page (73728-byte) vmalloc region.
Sample crash report:
* Struck through repros no longer work on HEAD.