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: 1h44m, last: 1h44m
✨ AI cause bisection: introduced by (AI job) :
commit 9991deff1ac9361abbe0c5938b27f903f16d1ca0
Author: Hans Verkuil <hans.verkuil@cisco.com>
Date: Sun Mar 8 08:53:10 2015 +0000

  [media] vivid-tpg: add helper functions to simplify common calculations

✨ 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
Based on kernel commit 9437ee8b6cf6:

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

  1. 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.

  2. 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.)

  3. 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).
  4. 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.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
67113508 bisect-cause IsRelease: ❌ ❓ KASAN: vmalloc-out-of-bounds Write in tpg_fill_plane_extras 2026/11/27 05:18 2026/11/27 05:19 2026/11/27 05:55 f1f6b8bf
13dddced assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: vmalloc-out-of-bounds Write in tpg_fill_plane_extras 2026/11/27 05:12 2026/11/27 05:12 2026/11/27 06:06 f1f6b8bf

Sample crash report:
==================================================================
BUG: KASAN: vmalloc-out-of-bounds in tpg_fill_plane_extras+0x1883/0x2580 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2441
Write of size 1 at addr ffffc90006529000 by task vivid-000-vid-c/27169

CPU: 0 UID: 0 PID: 27169 Comm: vivid-000-vid-c Tainted: G             L      syzkaller #0 PREEMPT(full) 
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 print_address_description+0x55/0x1e0 mm/kasan/report.c:378
 print_report+0x58/0x70 mm/kasan/report.c:482
 kasan_report+0x117/0x150 mm/kasan/report.c:595
 tpg_fill_plane_extras+0x1883/0x2580 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2441
 tpg_fill_plane_buffer+0x1230/0x22b0 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:2709
 vivid_fillbuff drivers/media/test-drivers/vivid/vivid-kthread-cap.c:470 [inline]
 vivid_thread_vid_cap_tick+0x115c/0x6340 drivers/media/test-drivers/vivid/vivid-kthread-cap.c:629
 vivid_thread_vid_cap+0x922/0x11d0 drivers/media/test-drivers/vivid/vivid-kthread-cap.c:767
 kthread+0x38b/0x480 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

The buggy address belongs to a 18-page vmalloc region starting at 0xffffc90006517000 allocated at vb2_vmalloc_alloc+0xef/0x360 drivers/media/common/videobuf2/videobuf2-vmalloc.c:47
Memory state around the buggy address:
 ffffc90006528f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffffc90006528f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc90006529000: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
                   ^
 ffffc90006529080: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
 ffffc90006529100: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/27 05:12 upstream 9437ee8b6cf6 f1f6b8bf .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-386 KASAN: vmalloc-out-of-bounds Write in tpg_fill_plane_extras
* Struck through repros no longer work on HEAD.