KASAN: use-after-free Read in v4l2_m2m_job_finish

Status: upstream: reported C repro on 2022/11/17 20:25
First crash: 308d, last: 308d
Fix bisection: failed (error log, bisect log)

Sample crash report:
IPVS: ftp: loaded support on port[0] = 21
BUG: KASAN: use-after-free in v4l2_m2m_try_schedule drivers/media/v4l2-core/v4l2-mem2mem.c:361 [inline]
BUG: KASAN: use-after-free in v4l2_m2m_job_finish+0x33f/0x350 drivers/media/v4l2-core/v4l2-mem2mem.c:427
Read of size 8 at addr ffff888094d36348 by task kworker/0:2/3623

CPU: 0 PID: 3623 Comm: kworker/0:2 Not tainted 4.19.211-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Workqueue: events device_work
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1fc/0x2ef lib/dump_stack.c:118
 print_address_description.cold+0x54/0x219 mm/kasan/report.c:256
 kasan_report_error.cold+0x8a/0x1b9 mm/kasan/report.c:354
 kasan_report mm/kasan/report.c:412 [inline]
 __asan_report_load8_noabort+0x88/0x90 mm/kasan/report.c:433
 v4l2_m2m_try_schedule drivers/media/v4l2-core/v4l2-mem2mem.c:361 [inline]
 v4l2_m2m_job_finish+0x33f/0x350 drivers/media/v4l2-core/v4l2-mem2mem.c:427
 device_work+0x28b/0x350 drivers/media/platform/vim2m.c:417
 process_one_work+0x864/0x1570 kernel/workqueue.c:2153
 worker_thread+0x64c/0x1130 kernel/workqueue.c:2296
 kthread+0x33f/0x460 kernel/kthread.c:259
 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:415

Allocated by task 8109:
 kmem_cache_alloc_trace+0x12f/0x380 mm/slab.c:3625
 kmalloc include/linux/slab.h:515 [inline]
 kzalloc include/linux/slab.h:709 [inline]
 v4l2_m2m_ctx_init+0x49/0x380 drivers/media/v4l2-core/v4l2-mem2mem.c:885
 vim2m_open+0x445/0x620 drivers/media/platform/vim2m.c:928
 v4l2_open+0x1af/0x350 drivers/media/v4l2-core/v4l2-dev.c:427
 chrdev_open+0x266/0x770 fs/char_dev.c:423
 do_dentry_open+0x4aa/0x1160 fs/open.c:796
 do_last fs/namei.c:3421 [inline]
 path_openat+0x793/0x2df0 fs/namei.c:3537
 do_filp_open+0x18c/0x3f0 fs/namei.c:3567
 do_sys_open+0x3b3/0x520 fs/open.c:1085
 do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293

Freed by task 8109:
 __cache_free mm/slab.c:3503 [inline]
 kfree+0xcc/0x210 mm/slab.c:3822
 vim2m_release+0xe0/0x140 drivers/media/platform/vim2m.c:961
 v4l2_release+0xf4/0x190 drivers/media/v4l2-core/v4l2-dev.c:448
 __fput+0x2ce/0x890 fs/file_table.c:278
 task_work_run+0x148/0x1c0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:193 [inline]
 exit_to_usermode_loop+0x251/0x2a0 arch/x86/entry/common.c:167
 prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
 do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296

The buggy address belongs to the object at ffff888094d36340
 which belongs to the cache kmalloc-2048 of size 2048
The buggy address is located 8 bytes inside of
 2048-byte region [ffff888094d36340, ffff888094d36b40)
The buggy address belongs to the page:
page:ffffea0002534d80 count:1 mapcount:0 mapping:ffff88813bff0c40 index:0x0 compound_mapcount: 0
flags: 0xfff00000008100(slab|head)
raw: 00fff00000008100 ffffea0002535488 ffffea0002c3d788 ffff88813bff0c40
raw: 0000000000000000 ffff888094d36340 0000000100000003 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff888094d36200: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888094d36280: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888094d36300: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
 ffff888094d36380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888094d36400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/11/17 21:00 linux-4.19.y 3f8a27f9e27b 4ba8ab94 .config console log report syz C [disk image] [vmlinux] ci2-linux-4-19 KASAN: use-after-free Read in v4l2_m2m_job_finish
2022/11/17 20:25 linux-4.19.y 3f8a27f9e27b 4ba8ab94 .config console log report info [disk image] [vmlinux] ci2-linux-4-19 KASAN: use-after-free Read in v4l2_m2m_job_finish
* Struck through repros no longer work on HEAD.