KASAN: null-ptr-deref Write in kthread_stop

28 views
Skip to first unread message

syzbot

unread,
Oct 29, 2018, 5:28:04 AM10/29/18
to hver...@xs4all.nl, linux-...@vger.kernel.org, linux...@vger.kernel.org, mch...@kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 8c60c36d0b8c Add linux-next specific files for 20181019
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=16128d7b400000
kernel config: https://syzkaller.appspot.com/x/.config?x=ddc97ab84fb1ff2a
dashboard link: https://syzkaller.appspot.com/bug?extid=53d5b2df0d9744411e2e
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=124b1e83400000

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

8021q: adding VLAN 0 to HW filter on device team0
8021q: adding VLAN 0 to HW filter on device team0
8021q: adding VLAN 0 to HW filter on device team0
vivid-000: kernel_thread() failed
==================================================================
BUG: KASAN: null-ptr-deref in atomic_inc
include/asm-generic/atomic-instrumented.h:109 [inline]
BUG: KASAN: null-ptr-deref in kthread_stop+0x108/0x8f0 kernel/kthread.c:545
Write of size 4 at addr 000000000000001c by task syz-executor3/7274

CPU: 1 PID: 7274 Comm: syz-executor3 Not tainted 4.19.0-rc8-next-20181019+
#99
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+0x244/0x39d lib/dump_stack.c:113
kasan_report_error mm/kasan/report.c:352 [inline]
kasan_report.cold.8+0x6d/0x309 mm/kasan/report.c:412
check_memory_region_inline mm/kasan/kasan.c:260 [inline]
check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267
kasan_check_write+0x14/0x20 mm/kasan/kasan.c:278
atomic_inc include/asm-generic/atomic-instrumented.h:109 [inline]
kthread_stop+0x108/0x8f0 kernel/kthread.c:545
vivid_stop_generating_vid_cap+0x2bc/0x93b
drivers/media/platform/vivid/vivid-kthread-cap.c:919
vid_cap_stop_streaming+0x8d/0xe0
drivers/media/platform/vivid/vivid-vid-cap.c:259
__vb2_queue_cancel+0x171/0xca0
drivers/media/common/videobuf2/videobuf2-core.c:1668
vb2_core_streamoff+0x60/0x140
drivers/media/common/videobuf2/videobuf2-core.c:1804
__vb2_cleanup_fileio+0x73/0x160
drivers/media/common/videobuf2/videobuf2-core.c:2325
vb2_core_queue_release+0x1e/0x80
drivers/media/common/videobuf2/videobuf2-core.c:2052
vb2_queue_release drivers/media/common/videobuf2/videobuf2-v4l2.c:672
[inline]
_vb2_fop_release+0x1d2/0x2b0
drivers/media/common/videobuf2/videobuf2-v4l2.c:843
vb2_fop_release+0x77/0xc0
drivers/media/common/videobuf2/videobuf2-v4l2.c:857
vivid_fop_release+0x18e/0x440 drivers/media/platform/vivid/vivid-core.c:474
v4l2_release+0xfb/0x1a0 drivers/media/v4l2-core/v4l2-dev.c:448
__fput+0x3bc/0xa70 fs/file_table.c:279
____fput+0x15/0x20 fs/file_table.c:312
task_work_run+0x1e8/0x2a0 kernel/task_work.c:113
exit_task_work include/linux/task_work.h:22 [inline]
do_exit+0x1ad1/0x26d0 kernel/exit.c:867
do_group_exit+0x177/0x440 kernel/exit.c:970
get_signal+0x8a8/0x1970 kernel/signal.c:2517
do_signal+0x9c/0x21c0 arch/x86/kernel/signal.c:816
exit_to_usermode_loop+0x2e5/0x380 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+0x6be/0x820 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x483081
Code: 75 14 b8 23 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 d4 f8 f8 ff c3 48
83 ec 08 e8 ba 70 fd ff 48 89 04 24 b8 23 00 00 00 0f 05 <48> 8b 3c 24 48
89 c2 e8 03 71 fd ff 48 89 d0 48 83 c4 08 48 3d 01
RSP: 002b:00007ffc69ddaf10 EFLAGS: 00000293 ORIG_RAX: 0000000000000023
RAX: 0000000000000000 RBX: 000000000000fef5 RCX: 0000000000483081
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00007ffc69ddaf20
RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 00007ffc69ddb000 R11: 0000000000000293 R12: 000000000072c900
R13: 00000000000003e8 R14: 000000000000fc39 R15: 000000000000fc0c
==================================================================


---
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#bug-status-tracking for how to communicate with
syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Oct 30, 2018, 11:17:04 PM10/30/18
to hver...@xs4all.nl, linux-...@vger.kernel.org, linux...@vger.kernel.org, mch...@kernel.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following crash on:

HEAD commit: 6201f31a39f8 Add linux-next specific files for 20181030
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=179da7cb400000
kernel config: https://syzkaller.appspot.com/x/.config?x=2a22859d870756c1
dashboard link: https://syzkaller.appspot.com/bug?extid=53d5b2df0d9744411e2e
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=106f6999400000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17267233400000

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

sshd (5629) used greatest stack depth: 15744 bytes left
==================================================================
BUG: KASAN: null-ptr-deref in atomic_inc
include/asm-generic/atomic-instrumented.h:109 [inline]
BUG: KASAN: null-ptr-deref in kthread_stop+0x108/0x8f0 kernel/kthread.c:545
Write of size 4 at addr 0000000000000020 by task syz-executor789/5655

CPU: 1 PID: 5655 Comm: syz-executor789 Not tainted 4.19.0-next-20181030+
#101
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_usermode_loop+0x318/0x380 arch/x86/entry/common.c:166
prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
do_syscall_64+0x6be/0x820 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x400ef0
Code: 01 f0 ff ff 0f 83 b0 0a 00 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f
44 00 00 83 3d dd 57 2d 00 00 75 14 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff
ff 0f 83 84 0a 00 00 c3 48 83 ec 08 e8 3a 01 00 00
RSP: 002b:00007fff00659738 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000003 RCX: 0000000000400ef0
RDX: 0000000020000024 RSI: 0000000020000000 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000001446880 R09: 00000000004002e0
R10: 000000000000000f R11: 0000000000000246 R12: 0000000000401e00
R13: 0000000000401e90 R14: 0000000000000000 R15: 0000000000000000
==================================================================

syzbot

unread,
Nov 8, 2018, 12:44:03 PM11/8/18
to mhj...@gmail.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer still triggered
crash:
KASAN: use-after-free Read in __vb2_perform_fileio

8021q: adding VLAN 0 to HW filter on device team0
8021q: adding VLAN 0 to HW filter on device team0
vivid-000: kernel_thread() failed
vivid-000: kernel_thread() failed
==================================================================
BUG: KASAN: use-after-free in __vb2_perform_fileio+0x10e2/0x1210
drivers/media/common/videobuf2/videobuf2-core.c:2567
Read of size 4 at addr ffff8801c05aa79c by task syz-executor4/7617

CPU: 0 PID: 7617 Comm: syz-executor4 Not tainted 4.20.0-rc1+ #1
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+0x244/0x39d lib/dump_stack.c:113
print_address_description.cold.7+0x9/0x1ff mm/kasan/report.c:256
kasan_report_error mm/kasan/report.c:354 [inline]
kasan_report.cold.8+0x242/0x309 mm/kasan/report.c:412
__asan_report_load4_noabort+0x14/0x20 mm/kasan/report.c:432
__vb2_perform_fileio+0x10e2/0x1210
drivers/media/common/videobuf2/videobuf2-core.c:2567
vb2_read+0x3b/0x50 drivers/media/common/videobuf2/videobuf2-core.c:2678
vb2_fop_read+0x20a/0x400
drivers/media/common/videobuf2/videobuf2-v4l2.c:1065
v4l2_read+0x168/0x220 drivers/media/v4l2-core/v4l2-dev.c:317
__vfs_read+0x117/0x9b0 fs/read_write.c:416
vfs_read+0x17f/0x3c0 fs/read_write.c:452
ksys_read+0x101/0x260 fs/read_write.c:578
__do_sys_read fs/read_write.c:588 [inline]
__se_sys_read fs/read_write.c:586 [inline]
__ia32_sys_read+0x71/0xb0 fs/read_write.c:586
do_syscall_32_irqs_on arch/x86/entry/common.c:326 [inline]
do_fast_syscall_32+0x34d/0xfb2 arch/x86/entry/common.c:397
entry_SYSENTER_compat+0x70/0x7f arch/x86/entry/entry_64_compat.S:139
RIP: 0023:0xf7f92a29
Code: 85 d2 74 02 89 0a 5b 5d c3 8b 04 24 c3 8b 14 24 c3 8b 3c 24 c3 90 90
90 90 90 90 90 90 90 90 90 90 51 52 55 89 e5 0f 34 cd 80 <5d> 5a 59 c3 90
90 90 90 eb 0d 90 90 90 90 90 90 90 90 90 90 90 90
RSP: 002b:00000000f7f8e0cc EFLAGS: 00000296 ORIG_RAX: 0000000000000003
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000020000040
RDX: 000000000000004a RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 7617:
save_stack+0x43/0xd0 mm/kasan/kasan.c:448
set_track mm/kasan/kasan.c:460 [inline]
kasan_kmalloc+0xc7/0xe0 mm/kasan/kasan.c:553
kmem_cache_alloc_trace+0x152/0x750 mm/slab.c:3620
kmalloc include/linux/slab.h:546 [inline]
kzalloc include/linux/slab.h:741 [inline]
__vb2_init_fileio+0x1ce/0xc90
drivers/media/common/videobuf2/videobuf2-core.c:2412
__vb2_perform_fileio+0xcfd/0x1210
drivers/media/common/videobuf2/videobuf2-core.c:2546
vb2_read+0x3b/0x50 drivers/media/common/videobuf2/videobuf2-core.c:2678
vb2_fop_read+0x20a/0x400
drivers/media/common/videobuf2/videobuf2-v4l2.c:1065
v4l2_read+0x168/0x220 drivers/media/v4l2-core/v4l2-dev.c:317
__vfs_read+0x117/0x9b0 fs/read_write.c:416
vfs_read+0x17f/0x3c0 fs/read_write.c:452
ksys_read+0x101/0x260 fs/read_write.c:578
__do_sys_read fs/read_write.c:588 [inline]
__se_sys_read fs/read_write.c:586 [inline]
__ia32_sys_read+0x71/0xb0 fs/read_write.c:586
do_syscall_32_irqs_on arch/x86/entry/common.c:326 [inline]
do_fast_syscall_32+0x34d/0xfb2 arch/x86/entry/common.c:397
entry_SYSENTER_compat+0x70/0x7f arch/x86/entry/entry_64_compat.S:139

Freed by task 7614:
save_stack+0x43/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:3498 [inline]
kfree+0xcf/0x230 mm/slab.c:3817
__vb2_cleanup_fileio+0xf8/0x160
drivers/media/common/videobuf2/videobuf2-core.c:2505
vb2_core_queue_release+0x1e/0x80
drivers/media/common/videobuf2/videobuf2-core.c:2228
vb2_queue_release drivers/media/common/videobuf2/videobuf2-v4l2.c:837
[inline]
_vb2_fop_release+0x1d2/0x2b0
drivers/media/common/videobuf2/videobuf2-v4l2.c:1010
vb2_fop_release+0x77/0xc0
drivers/media/common/videobuf2/videobuf2-v4l2.c:1024
vivid_fop_release+0x18e/0x440 drivers/media/platform/vivid/vivid-core.c:474
v4l2_release+0x224/0x3a0 drivers/media/v4l2-core/v4l2-dev.c:456
__fput+0x385/0xa30 fs/file_table.c:278
____fput+0x15/0x20 fs/file_table.c:309
task_work_run+0x1e8/0x2a0 kernel/task_work.c:113
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_usermode_loop+0x318/0x380 arch/x86/entry/common.c:166
prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
do_syscall_32_irqs_on arch/x86/entry/common.c:341 [inline]
do_fast_syscall_32+0xcd5/0xfb2 arch/x86/entry/common.c:397
entry_SYSENTER_compat+0x70/0x7f arch/x86/entry/entry_64_compat.S:139

The buggy address belongs to the object at ffff8801c05aa480
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 796 bytes inside of
1024-byte region [ffff8801c05aa480, ffff8801c05aa880)
The buggy address belongs to the page:
page:ffffea0007016a80 count:1 mapcount:0 mapping:ffff8801da800ac0 index:0x0
compound_mapcount: 0
flags: 0x2fffc0000010200(slab|head)
raw: 02fffc0000010200 ffffea00073b0b08 ffffea000701e388 ffff8801da800ac0
raw: 0000000000000000 ffff8801c05aa000 0000000100000007 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8801c05aa680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8801c05aa700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ffff8801c05aa780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8801c05aa800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8801c05aa880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================


Tested on:

commit: b00d209241ff Merge tag 'compiler-attributes-for-linus-v4.2..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10c1545d400000
kernel config: https://syzkaller.appspot.com/x/.config?x=8f559fee2fc3375a
compiler: gcc (GCC) 8.0.1 20180413 (experimental)
userspace arch: i386
patch: https://syzkaller.appspot.com/x/patch.diff?x=13379225400000

Reply all
Reply to author
Forward
0 new messages