syzbot


WARNING: refcount bug in qrtr_node_lookup

Status: fixed on 2023/04/17 07:57
Reported-by: syzbot+e50a4f7393c85a5b2dfa@syzkaller.appspotmail.com
Fix commit: aa95efa187b4 net: qrtr: Fix a refcount bug in qrtr_recvmsg()
First crash: 631d, last: 631d
Fix bisection: fixed by (bisect log) :
commit aa95efa187b4114075f312b3c4680d050b56fdec
Author: Ziyang Xuan <william.xuanziyang@huawei.com>
Date: Thu Mar 30 01:25:32 2023 +0000

  net: qrtr: Fix a refcount bug in qrtr_recvmsg()

  
Similar bugs (3)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 WARNING: refcount bug in qrtr_node_lookup C done 1 631d 631d 3/3 fixed on 2023/04/17 07:57
upstream WARNING: refcount bug in qrtr_node_lookup (2) arm-msm net C 1 631d 624d 0/28 auto-obsoleted due to no activity on 2023/07/14 08:21
upstream WARNING: refcount bug in qrtr_node_lookup arm-msm net C done done 16 1227d 1551d 0/28 auto-obsoleted due to no activity on 2022/09/28 21:58

Sample crash report:
------------[ cut here ]------------
refcount_t: addition on 0; use-after-free.
WARNING: CPU: 0 PID: 1596 at lib/refcount.c:25 refcount_warn_saturate+0x1a8/0x20c lib/refcount.c:25
Modules linked in:
CPU: 0 PID: 1596 Comm: kworker/u4:4 Not tainted 6.1.19-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
Workqueue: qrtr_ns_handler qrtr_ns_worker
pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : refcount_warn_saturate+0x1a8/0x20c lib/refcount.c:25
lr : refcount_warn_saturate+0x1a8/0x20c lib/refcount.c:25
sp : ffff800022036da0
x29: ffff800022036da0 x28: dfff800000000000 x27: ffff700004406dc8
x26: ffff800022036e60 x25: 0000000000000000 x24: 00000000003a6056
x23: ffff0000c26c58f0 x22: 0000000000000000 x21: 0000000000000002
x20: ffff0000db455498 x19: ffff800018053000 x18: ffff8000220361a0
x17: 0000000000000000 x16: ffff800012253e1c x15: 0000000000000000
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000001
x11: ff808000081b28cc x10: 0000000000000000 x9 : b18c0c206b39e600
x8 : b18c0c206b39e600 x7 : 0000000000000001 x6 : 0000000000000001
x5 : ffff800022036698 x4 : ffff800015813880 x3 : ffff800008590318
x2 : 0000000000000001 x1 : 0000000100000001 x0 : 0000000000000000
Call trace:
 refcount_warn_saturate+0x1a8/0x20c lib/refcount.c:25
 __refcount_inc include/linux/refcount.h:250 [inline]
 refcount_inc include/linux/refcount.h:267 [inline]
 kref_get include/linux/kref.h:45 [inline]
 qrtr_node_acquire net/qrtr/af_qrtr.c:202 [inline]
 qrtr_node_lookup+0xdc/0x100 net/qrtr/af_qrtr.c:398
 qrtr_send_resume_tx net/qrtr/af_qrtr.c:1003 [inline]
 qrtr_recvmsg+0x3dc/0x954 net/qrtr/af_qrtr.c:1070
 sock_recvmsg_nosec net/socket.c:1000 [inline]
 sock_recvmsg net/socket.c:1018 [inline]
 kernel_recvmsg+0x128/0x154 net/socket.c:1043
 qrtr_ns_worker+0x294/0x513c net/qrtr/ns.c:687
 process_one_work+0x868/0x16f4 kernel/workqueue.c:2289
 worker_thread+0x8e4/0xfec kernel/workqueue.c:2436
 kthread+0x24c/0x2d4 kernel/kthread.c:376
 ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:860
irq event stamp: 33478
hardirqs last  enabled at (33477): [<ffff800012332a3c>] __raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:151 [inline]
hardirqs last  enabled at (33477): [<ffff800012332a3c>] _raw_spin_unlock_irqrestore+0x48/0xac kernel/locking/spinlock.c:194
hardirqs last disabled at (33478): [<ffff800012332858>] __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:108 [inline]
hardirqs last disabled at (33478): [<ffff800012332858>] _raw_spin_lock_irqsave+0xa4/0xb4 kernel/locking/spinlock.c:162
softirqs last  enabled at (33474): [<ffff80001048f9ac>] spin_unlock_bh include/linux/spinlock.h:395 [inline]
softirqs last  enabled at (33474): [<ffff80001048f9ac>] lock_sock_nested+0xe8/0x138 net/core/sock.c:3464
softirqs last disabled at (33472): [<ffff80001048f954>] spin_lock_bh include/linux/spinlock.h:355 [inline]
softirqs last disabled at (33472): [<ffff80001048f954>] lock_sock_nested+0x90/0x138 net/core/sock.c:3460
---[ end trace 0000000000000000 ]---
==================================================================
BUG: KASAN: use-after-free in __mutex_lock_common+0x100/0x21a0 kernel/locking/mutex.c:582
Read of size 8 at addr ffff0000db455460 by task kworker/u4:4/1596

CPU: 0 PID: 1596 Comm: kworker/u4:4 Tainted: G        W          6.1.19-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
Workqueue: qrtr_ns_handler qrtr_ns_worker
Call trace:
 dump_backtrace+0x1c8/0x1f4 arch/arm64/kernel/stacktrace.c:158
 show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:165
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x108/0x170 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:284 [inline]
 print_report+0x174/0x4c0 mm/kasan/report.c:395
 kasan_report+0xd4/0x130 mm/kasan/report.c:495
 __asan_report_load8_noabort+0x2c/0x38 mm/kasan/report_generic.c:351
 __mutex_lock_common+0x100/0x21a0 kernel/locking/mutex.c:582
 __mutex_lock kernel/locking/mutex.c:747 [inline]
 mutex_lock_nested+0x38/0x44 kernel/locking/mutex.c:799
 qrtr_node_enqueue+0x31c/0x9cc net/qrtr/af_qrtr.c:371
 qrtr_send_resume_tx net/qrtr/af_qrtr.c:1015 [inline]
 qrtr_recvmsg+0x510/0x954 net/qrtr/af_qrtr.c:1070
 sock_recvmsg_nosec net/socket.c:1000 [inline]
 sock_recvmsg net/socket.c:1018 [inline]
 kernel_recvmsg+0x128/0x154 net/socket.c:1043
 qrtr_ns_worker+0x294/0x513c net/qrtr/ns.c:687
 process_one_work+0x868/0x16f4 kernel/workqueue.c:2289
 worker_thread+0x8e4/0xfec kernel/workqueue.c:2436
 kthread+0x24c/0x2d4 kernel/kthread.c:376
 ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:860

Allocated by task 4401:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4c/0x80 mm/kasan/common.c:52
 kasan_save_alloc_info+0x24/0x30 mm/kasan/generic.c:505
 ____kasan_kmalloc mm/kasan/common.c:374 [inline]
 __kasan_kmalloc+0xac/0xc4 mm/kasan/common.c:383
 kasan_kmalloc include/linux/kasan.h:211 [inline]
 kmalloc_trace+0x7c/0x94 mm/slab_common.c:1050
 kmalloc include/linux/slab.h:553 [inline]
 kzalloc include/linux/slab.h:689 [inline]
 qrtr_endpoint_register+0x8c/0x3f4 net/qrtr/af_qrtr.c:583
 qrtr_tun_open+0x130/0x1ac net/qrtr/tun.c:47
 misc_open+0x2f0/0x368 drivers/char/misc.c:143
 chrdev_open+0x3e8/0x4fc fs/char_dev.c:414
 do_dentry_open+0x734/0xfa0 fs/open.c:882
 vfs_open+0x7c/0x90 fs/open.c:1013
 do_open fs/namei.c:3557 [inline]
 path_openat+0x1e14/0x2548 fs/namei.c:3714
 do_filp_open+0x1bc/0x3cc fs/namei.c:3741
 do_sys_openat2+0x128/0x3d8 fs/open.c:1310
 do_sys_open fs/open.c:1326 [inline]
 __do_sys_openat fs/open.c:1342 [inline]
 __se_sys_openat fs/open.c:1337 [inline]
 __arm64_sys_openat+0x1f0/0x240 fs/open.c:1337
 __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
 invoke_syscall+0x98/0x2c0 arch/arm64/kernel/syscall.c:52
 el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
 do_el0_svc+0x64/0x218 arch/arm64/kernel/syscall.c:206
 el0_svc+0x58/0x168 arch/arm64/kernel/entry-common.c:637
 el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
 el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581

Freed by task 4401:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4c/0x80 mm/kasan/common.c:52
 kasan_save_free_info+0x38/0x5c mm/kasan/generic.c:516
 ____kasan_slab_free+0x144/0x1c0 mm/kasan/common.c:236
 __kasan_slab_free+0x18/0x28 mm/kasan/common.c:244
 kasan_slab_free include/linux/kasan.h:177 [inline]
 slab_free_hook mm/slub.c:1724 [inline]
 slab_free_freelist_hook mm/slub.c:1750 [inline]
 slab_free mm/slub.c:3661 [inline]
 __kmem_cache_free+0x2c0/0x4b4 mm/slub.c:3674
 kfree+0x104/0x228 mm/slab_common.c:1007
 __qrtr_node_release net/qrtr/af_qrtr.c:195 [inline]
 kref_put_mutex include/linux/kref.h:76 [inline]
 qrtr_node_release+0x444/0x498 net/qrtr/af_qrtr.c:211
 qrtr_endpoint_unregister+0x59c/0x6cc net/qrtr/af_qrtr.c:649
 qrtr_tun_release+0x44/0x68 net/qrtr/tun.c:131
 __fput+0x30c/0x7bc fs/file_table.c:320
 ____fput+0x20/0x30 fs/file_table.c:348
 task_work_run+0x240/0x2f0 kernel/task_work.c:179
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 do_notify_resume+0x2144/0x3470 arch/arm64/kernel/signal.c:1132
 prepare_exit_to_user_mode arch/arm64/kernel/entry-common.c:137 [inline]
 exit_to_user_mode arch/arm64/kernel/entry-common.c:142 [inline]
 el0_svc+0x9c/0x168 arch/arm64/kernel/entry-common.c:638
 el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
 el0t_64_sync+0x18c/0x190 arch/arm64/kernel/entry.S:581

The buggy address belongs to the object at ffff0000db455400
 which belongs to the cache kmalloc-512 of size 512
The buggy address is located 96 bytes inside of
 512-byte region [ffff0000db455400, ffff0000db455600)

The buggy address belongs to the physical page:
page:000000003cdd2af7 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11b454
head:000000003cdd2af7 order:2 compound_mapcount:0 compound_pincount:0
flags: 0x5ffc00000010200(slab|head|node=0|zone=2|lastcpupid=0x7ff)
raw: 05ffc00000010200 0000000000000000 dead000000000001 ffff0000c0002600
raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff0000db455300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff0000db455380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff0000db455400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                       ^
 ffff0000db455480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff0000db455500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/03/16 15:42 linux-6.1.y 6449a0ba6843 18b58603 .config console log report syz C [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan-arm64 WARNING: refcount bug in qrtr_node_lookup
* Struck through repros no longer work on HEAD.