KASAN: use-after-free Read in __vb2_perform_fileio

16 views
Skip to first unread message

syzbot

unread,
Apr 14, 2019, 7:28:05 AM4/14/19
to syzkaller...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 4d552acf Linux 4.19.34
git tree: linux-4.19.y
console output: https://syzkaller.appspot.com/x/log.txt?x=12188e9f200000
kernel config: https://syzkaller.appspot.com/x/.config?x=c95a88291f095edd
dashboard link: https://syzkaller.appspot.com/bug?extid=bc09078aa44c12d92c3f
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16e2d067200000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=10d941dd200000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+bc0907...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in __vb2_perform_fileio+0x105d/0x1140
drivers/media/common/videobuf2/videobuf2-core.c:2389
Read of size 4 at addr ffff88808fa6279c by task syz-executor900/8385

CPU: 0 PID: 8385 Comm: syz-executor900 Not tainted 4.19.34 #2
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x172/0x1f0 lib/dump_stack.c:113
print_address_description.cold+0x7c/0x20d mm/kasan/report.c:256
kasan_report_error mm/kasan/report.c:354 [inline]
kasan_report mm/kasan/report.c:412 [inline]
kasan_report.cold+0x8c/0x2ba mm/kasan/report.c:396
__asan_report_load4_noabort+0x14/0x20 mm/kasan/report.c:432
__vb2_perform_fileio+0x105d/0x1140
drivers/media/common/videobuf2/videobuf2-core.c:2389
vb2_read+0x3b/0x50 drivers/media/common/videobuf2/videobuf2-core.c:2500
vb2_fop_read+0x212/0x410
drivers/media/common/videobuf2/videobuf2-v4l2.c:897
v4l2_read+0x1ce/0x230 drivers/media/v4l2-core/v4l2-dev.c:317
do_loop_readv_writev fs/read_write.c:700 [inline]
do_loop_readv_writev fs/read_write.c:687 [inline]
do_iter_read+0x495/0x650 fs/read_write.c:924
vfs_readv+0xf0/0x160 fs/read_write.c:986
do_readv+0xf6/0x290 fs/read_write.c:1019
__do_sys_readv fs/read_write.c:1106 [inline]
__se_sys_readv fs/read_write.c:1103 [inline]
__x64_sys_readv+0x75/0xb0 fs/read_write.c:1103
do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x44a4d9
Code: e8 0c e8 ff ff 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7
48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff
ff 0f 83 7b cb fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f42785d6db8 EFLAGS: 00000246 ORIG_RAX: 0000000000000013
RAX: ffffffffffffffda RBX: 00000000006dbc28 RCX: 000000000044a4d9
RDX: 0000000000000001 RSI: 0000000020000600 RDI: 0000000000000003
RBP: 00000000006dbc20 R08: 0000000000000000 R09: 0000000000000000
R10: 00007f42785d7700 R11: 0000000000000246 R12: 00000000006dbc2c
R13: 00007fffaa8dc42f R14: 00007f42785d79c0 R15: 0000000000000000

Allocated by task 8385:
save_stack+0x45/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
kasan_kmalloc mm/kasan/kasan.c:553 [inline]
kasan_kmalloc+0xce/0xf0 mm/kasan/kasan.c:531
kmem_cache_alloc_trace+0x152/0x760 mm/slab.c:3625
kmalloc include/linux/slab.h:515 [inline]
kzalloc include/linux/slab.h:709 [inline]
__vb2_init_fileio+0x1cb/0xbe0
drivers/media/common/videobuf2/videobuf2-core.c:2234
__vb2_perform_fileio+0xbff/0x1140
drivers/media/common/videobuf2/videobuf2-core.c:2368
vb2_read+0x3b/0x50 drivers/media/common/videobuf2/videobuf2-core.c:2500
vb2_fop_read+0x212/0x410
drivers/media/common/videobuf2/videobuf2-v4l2.c:897
v4l2_read+0x1ce/0x230 drivers/media/v4l2-core/v4l2-dev.c:317
do_loop_readv_writev fs/read_write.c:700 [inline]
do_loop_readv_writev fs/read_write.c:687 [inline]
do_iter_read+0x495/0x650 fs/read_write.c:924
vfs_readv+0xf0/0x160 fs/read_write.c:986
do_readv+0xf6/0x290 fs/read_write.c:1019
__do_sys_readv fs/read_write.c:1106 [inline]
__se_sys_readv fs/read_write.c:1103 [inline]
__x64_sys_readv+0x75/0xb0 fs/read_write.c:1103
do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 8389:
save_stack+0x45/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
__kasan_slab_free+0x102/0x150 mm/kasan/kasan.c:521
kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
__cache_free mm/slab.c:3503 [inline]
kfree+0xcf/0x230 mm/slab.c:3822
__vb2_cleanup_fileio+0x100/0x170
drivers/media/common/videobuf2/videobuf2-core.c:2327
vb2_core_queue_release+0x20/0x80
drivers/media/common/videobuf2/videobuf2-core.c:2050
vb2_queue_release drivers/media/common/videobuf2/videobuf2-v4l2.c:671
[inline]
_vb2_fop_release+0x1cf/0x2a0
drivers/media/common/videobuf2/videobuf2-v4l2.c:842
vb2_fop_release+0x75/0xc0
drivers/media/common/videobuf2/videobuf2-v4l2.c:856
vivid_fop_release+0x18e/0x430 drivers/media/platform/vivid/vivid-core.c:474
v4l2_release+0xfb/0x1a0 drivers/media/v4l2-core/v4l2-dev.c:448
__fput+0x2df/0x8b0 fs/file_table.c:278
____fput+0x16/0x20 fs/file_table.c:309
task_work_run+0x14a/0x1c0 kernel/task_work.c:113
exit_task_work include/linux/task_work.h:22 [inline]
do_exit+0x933/0x2fa0 kernel/exit.c:876
do_group_exit+0x135/0x370 kernel/exit.c:979
get_signal+0x399/0x1d50 kernel/signal.c:2572
do_signal+0x95/0x1950 arch/x86/kernel/signal.c:816
exit_to_usermode_loop+0x244/0x2c0 arch/x86/entry/common.c:162
prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
do_syscall_64+0x52d/0x610 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff88808fa62480
which belongs to the cache kmalloc-1024 of size 1024
The buggy address is located 796 bytes inside of
1024-byte region [ffff88808fa62480, ffff88808fa62880)
The buggy address belongs to the page:
page:ffffea00023e9880 count:1 mapcount:0 mapping:ffff88812c3f0ac0 index:0x0
compound_mapcount: 0
flags: 0x1fffc0000008100(slab|head)
raw: 01fffc0000008100 ffffea00023aa608 ffffea0002397e08 ffff88812c3f0ac0
raw: 0000000000000000 ffff88808fa62000 0000000100000007 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88808fa62680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88808fa62700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ffff88808fa62780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88808fa62800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88808fa62880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Apr 16, 2019, 9:50:05 AM4/16/19
to syzkaller...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 1ec8f1f0 Linux 4.14.111
git tree: linux-4.14.y
console output: https://syzkaller.appspot.com/x/log.txt?x=13c415bf200000
kernel config: https://syzkaller.appspot.com/x/.config?x=fdadf290ea9fc6f9
dashboard link: https://syzkaller.appspot.com/bug?extid=ec7ef6c975892200130c
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=142715e3200000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14e582cb200000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+ec7ef6...@syzkaller.appspotmail.com

audit: type=1400 audit(1555418708.493:36): avc: denied { map } for
pid=7159 comm="syz-executor108" path="/root/syz-executor108174234"
dev="sda1" ino=1426 scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023
tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1
==================================================================
BUG: KASAN: use-after-free in __vb2_perform_fileio+0xddf/0xeb0
drivers/media/v4l2-core/videobuf2-core.c:2379
Read of size 4 at addr ffff8880773c30dc by task syz-executor108/7193

CPU: 0 PID: 7193 Comm: syz-executor108 Not tainted 4.14.111 #1
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0x138/0x19c lib/dump_stack.c:53
print_address_description.cold+0x7c/0x1dc mm/kasan/report.c:252
kasan_report_error mm/kasan/report.c:351 [inline]
kasan_report mm/kasan/report.c:409 [inline]
kasan_report.cold+0xaf/0x2b5 mm/kasan/report.c:393
__asan_report_load4_noabort+0x14/0x20 mm/kasan/report.c:429
__vb2_perform_fileio+0xddf/0xeb0
drivers/media/v4l2-core/videobuf2-core.c:2379
vb2_read+0x3b/0x50 drivers/media/v4l2-core/videobuf2-core.c:2490
vb2_fop_read+0x1f5/0x3e0 drivers/media/v4l2-core/videobuf2-v4l2.c:895
v4l2_read+0x1ac/0x210 drivers/media/v4l2-core/v4l2-dev.c:309
__vfs_read+0x107/0x6b0 fs/read_write.c:411
vfs_read+0x137/0x350 fs/read_write.c:447
SYSC_read fs/read_write.c:573 [inline]
SyS_read+0xb8/0x180 fs/read_write.c:566
do_syscall_64+0x1eb/0x630 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7
RIP: 0033:0x444ef9
RSP: 002b:00007ffe79e74c88 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000444ef9
RDX: 0000000000000008 RSI: 00000000200000c0 RDI: 0000000000000003
RBP: 00000000000a2884 R08: 0000000000000004 R09: 00000000004002e0
R10: 000000000000000f R11: 0000000000000246 R12: 0000000000402090
R13: 0000000000402120 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 7193:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x45/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_kmalloc mm/kasan/kasan.c:551 [inline]
kasan_kmalloc+0xce/0xf0 mm/kasan/kasan.c:529
kmem_cache_alloc_trace+0x152/0x790 mm/slab.c:3618
kmalloc include/linux/slab.h:488 [inline]
kzalloc include/linux/slab.h:661 [inline]
__vb2_init_fileio+0x182/0xa90 drivers/media/v4l2-core/videobuf2-core.c:2224
__vb2_perform_fileio+0x9f0/0xeb0
drivers/media/v4l2-core/videobuf2-core.c:2358
vb2_read+0x3b/0x50 drivers/media/v4l2-core/videobuf2-core.c:2490
vb2_fop_read+0x1f5/0x3e0 drivers/media/v4l2-core/videobuf2-v4l2.c:895
v4l2_read+0x1ac/0x210 drivers/media/v4l2-core/v4l2-dev.c:309
__vfs_read+0x107/0x6b0 fs/read_write.c:411
vfs_read+0x137/0x350 fs/read_write.c:447
SYSC_read fs/read_write.c:573 [inline]
SyS_read+0xb8/0x180 fs/read_write.c:566
do_syscall_64+0x1eb/0x630 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7

Freed by task 7194:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x45/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_slab_free+0x75/0xc0 mm/kasan/kasan.c:524
__cache_free mm/slab.c:3496 [inline]
kfree+0xcc/0x270 mm/slab.c:3815
__vb2_cleanup_fileio+0xfc/0x150
drivers/media/v4l2-core/videobuf2-core.c:2317
vb2_core_queue_release+0x1d/0x80
drivers/media/v4l2-core/videobuf2-core.c:2040
vb2_queue_release drivers/media/v4l2-core/videobuf2-v4l2.c:669 [inline]
_vb2_fop_release+0x1cf/0x2a0 drivers/media/v4l2-core/videobuf2-v4l2.c:840
vb2_fop_release+0x75/0xc0 drivers/media/v4l2-core/videobuf2-v4l2.c:854
vivid_fop_release+0x180/0x3f0 drivers/media/platform/vivid/vivid-core.c:486
v4l2_release+0xfb/0x190 drivers/media/v4l2-core/v4l2-dev.c:446
__fput+0x277/0x7a0 fs/file_table.c:210
____fput+0x16/0x20 fs/file_table.c:244
task_work_run+0x119/0x190 kernel/task_work.c:113
exit_task_work include/linux/task_work.h:22 [inline]
do_exit+0x7df/0x2c10 kernel/exit.c:874
do_group_exit+0x111/0x330 kernel/exit.c:977
SYSC_exit_group kernel/exit.c:988 [inline]
SyS_exit_group+0x1d/0x20 kernel/exit.c:986
do_syscall_64+0x1eb/0x630 arch/x86/entry/common.c:289
entry_SYSCALL_64_after_hwframe+0x42/0xb7

The buggy address belongs to the object at ffff8880773c2dc0
which belongs to the cache kmalloc-1024 of size 1024
The buggy address is located 796 bytes inside of
1024-byte region [ffff8880773c2dc0, ffff8880773c31c0)
The buggy address belongs to the page:
page:ffffea0001dcf080 count:1 mapcount:0 mapping:ffff8880773c2040 index:0x0
compound_mapcount: 0
flags: 0x1fffc0000008100(slab|head)
raw: 01fffc0000008100 ffff8880773c2040 0000000000000000 0000000100000007
raw: ffffea000230d720 ffffea0002a4af20 ffff8880aa800ac0 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880773c2f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880773c3000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ffff8880773c3080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880773c3100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880773c3180: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc

syzbot

unread,
Dec 30, 2019, 2:42:01 AM12/30/19
to syzkaller...@googlegroups.com
syzbot suspects this bug was fixed by commit:

commit 467052f6ea5a51524992e43f02b543550495c391
Author: Alexander Popov <alex....@linux.com>
Date: Sun Nov 3 22:17:19 2019 +0000

media: vivid: Fix wrong locking that causes race conditions on
streaming stop

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=15e219fee00000
start commit: 19bb613a Linux 4.19.37
git tree: linux-4.19.y
kernel config: https://syzkaller.appspot.com/x/.config?x=2f4f1677ff80cdff
dashboard link: https://syzkaller.appspot.com/bug?extid=bc09078aa44c12d92c3f
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10087214a00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=115051cca00000

If the result looks correct, please mark the bug fixed by replying with:

#syz fix: media: vivid: Fix wrong locking that causes race conditions on
streaming stop

For information about bisection process see: https://goo.gl/tpsmEJ#bisection
Reply all
Reply to author
Forward
0 new messages