INFO: trying to register non-static key in l2cap_sock_teardown_cb

7 views
Skip to first unread message

syzbot

unread,
Jan 1, 2021, 5:49:18 AM1/1/21
to da...@davemloft.net, johan....@gmail.com, ku...@kernel.org, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, mar...@holtmann.org, net...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 3db1a3fa Merge tag 'staging-5.11-rc1' of git://git.kernel...
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=15dccfb7500000
kernel config: https://syzkaller.appspot.com/x/.config?x=2ae878fbf640b72b
dashboard link: https://syzkaller.appspot.com/bug?extid=a41dfef1d2e04910eb2e
compiler: gcc (GCC) 10.1.0-syz 20200507

Unfortunately, I don't have any reproducer for this issue yet.

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

INFO: trying to register non-static key.
the code is fine but needs lockdep annotation.
turning off the locking correctness validator.
CPU: 0 PID: 11241 Comm: kworker/0:9 Not tainted 5.10.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events l2cap_chan_timeout
Call Trace:
__dump_stack lib/dump_stack.c:79 [inline]
dump_stack+0x107/0x163 lib/dump_stack.c:120
assign_lock_key kernel/locking/lockdep.c:935 [inline]
register_lock_class+0xf1b/0x10e0 kernel/locking/lockdep.c:1247
__lock_acquire+0xfc/0x58e0 kernel/locking/lockdep.c:4711
lock_acquire kernel/locking/lockdep.c:5437 [inline]
lock_acquire+0x29d/0x780 kernel/locking/lockdep.c:5402
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
_raw_spin_lock_bh+0x2f/0x40 kernel/locking/spinlock.c:175
spin_lock_bh include/linux/spinlock.h:359 [inline]
lock_sock_nested+0x3b/0x110 net/core/sock.c:3049
l2cap_sock_teardown_cb+0xa1/0x660 net/bluetooth/l2cap_sock.c:1520
l2cap_chan_del+0xbc/0xaa0 net/bluetooth/l2cap_core.c:618
l2cap_chan_close+0x1bc/0xaf0 net/bluetooth/l2cap_core.c:823
l2cap_chan_timeout+0x17e/0x2f0 net/bluetooth/l2cap_core.c:436
process_one_work+0x868/0x15c0 kernel/workqueue.c:2275
worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
kthread+0x3b1/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
==================================================================
BUG: KASAN: slab-out-of-bounds in l2cap_sock_teardown_cb+0x5c9/0x660 net/bluetooth/l2cap_sock.c:1522
Read of size 8 at addr ffff8880688f04c8 by task kworker/0:9/11241

CPU: 0 PID: 11241 Comm: kworker/0:9 Not tainted 5.10.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events l2cap_chan_timeout
Call Trace:
__dump_stack lib/dump_stack.c:79 [inline]
dump_stack+0x107/0x163 lib/dump_stack.c:120
print_address_description.constprop.0.cold+0xae/0x4c8 mm/kasan/report.c:385
__kasan_report mm/kasan/report.c:545 [inline]
kasan_report.cold+0x1f/0x37 mm/kasan/report.c:562
l2cap_sock_teardown_cb+0x5c9/0x660 net/bluetooth/l2cap_sock.c:1522
l2cap_chan_del+0xbc/0xaa0 net/bluetooth/l2cap_core.c:618
l2cap_chan_close+0x1bc/0xaf0 net/bluetooth/l2cap_core.c:823
l2cap_chan_timeout+0x17e/0x2f0 net/bluetooth/l2cap_core.c:436
process_one_work+0x868/0x15c0 kernel/workqueue.c:2275
worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
kthread+0x3b1/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Allocated by task 20015:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_set_track mm/kasan/common.c:56 [inline]
__kasan_kmalloc.constprop.0+0xc2/0xd0 mm/kasan/common.c:461
kmalloc include/linux/slab.h:557 [inline]
kzalloc include/linux/slab.h:682 [inline]
ops_init+0xfb/0x4a0 net/core/net_namespace.c:142
setup_net+0x2de/0x850 net/core/net_namespace.c:342
copy_net_ns+0x376/0x7b0 net/core/net_namespace.c:483
create_new_namespaces+0x3f6/0xb20 kernel/nsproxy.c:110
unshare_nsproxy_namespaces+0xbd/0x230 kernel/nsproxy.c:226
ksys_unshare+0x445/0x8e0 kernel/fork.c:2957
__do_sys_unshare kernel/fork.c:3025 [inline]
__se_sys_unshare kernel/fork.c:3023 [inline]
__x64_sys_unshare+0x2d/0x40 kernel/fork.c:3023
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Last potentially related work creation:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_record_aux_stack+0xc0/0xf0 mm/kasan/generic.c:343
__call_rcu kernel/rcu/tree.c:2965 [inline]
call_rcu+0xbb/0x730 kernel/rcu/tree.c:3038
netlink_release+0xe86/0x1e10 net/netlink/af_netlink.c:802
__sock_release+0xcd/0x280 net/socket.c:597
sock_close+0x18/0x20 net/socket.c:1256
__fput+0x285/0x930 fs/file_table.c:281
task_work_run+0xdd/0x190 kernel/task_work.c:168
exit_task_work include/linux/task_work.h:30 [inline]
do_exit+0xbbc/0x2c60 kernel/exit.c:823
do_group_exit+0x125/0x310 kernel/exit.c:920
__do_sys_exit_group kernel/exit.c:931 [inline]
__se_sys_exit_group kernel/exit.c:929 [inline]
__x64_sys_exit_group+0x3a/0x50 kernel/exit.c:929
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff8880688f0000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 1224 bytes inside of
2048-byte region [ffff8880688f0000, ffff8880688f0800)
The buggy address belongs to the page:
page:000000000a58198a refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x688f0
head:000000000a58198a order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff888011042000
raw: 0000000000000000 0000000000080008 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880688f0380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff8880688f0400: 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880688f0480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
^
ffff8880688f0500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8880688f0580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================


---
This report 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 issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

Hillf Danton

unread,
Jan 1, 2021, 11:33:54 PM1/1/21
to syzbot, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, mar...@holtmann.org, net...@vger.kernel.org, syzkall...@googlegroups.com
Fri, 01 Jan 2021 02:49:17 -0800
To avoid double teardown, skip scheduling work for closed channel.

--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -863,8 +863,11 @@ static inline void l2cap_set_timer(struc

/* If delayed work cancelled do not hold(chan)
since it is already done with previous set_timer */
- if (!cancel_delayed_work(work))
+ if (!cancel_delayed_work(work)) {
+ if (chan->state == BT_CLOSED)
+ return;
l2cap_chan_hold(chan);
+ }

schedule_delayed_work(work, timeout);
}

Hillf Danton

unread,
Jan 2, 2021, 5:19:22 AM1/2/21
to syzbot, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, mar...@holtmann.org, net...@vger.kernel.org, syzkall...@googlegroups.com
Fri, 01 Jan 2021 02:49:17 -0800
Because it is not a sync cancel in l2cap_set_timer(), the chance for
double teardown is not zero. Meanwhile sock can go home anytime once
SOCK_ZAPPED is set, we need to skip teardown for closed channel.

Note because of delayed work + non sync cancel, the race between the
two workers exists and any thoughts to cut are appreciated.

--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -615,7 +615,13 @@ void l2cap_chan_del(struct l2cap_chan *c
BT_DBG("chan %p, conn %p, err %d, state %s", chan, conn, err,
state_to_string(chan->state));

- chan->ops->teardown(chan, err);
+ if (chan->state != BT_CLOSED) {
+ /*
+ * avoid double teardown because sock wont be put
+ * without SOCK_ZAPPED being set
+ */
+ chan->ops->teardown(chan, err);
+ }

if (conn) {
struct amp_mgr *mgr = conn->hcon->amp_mgr;

syzbot

unread,
Jan 10, 2021, 4:40:16 PM1/10/21
to da...@davemloft.net, hda...@sina.com, johan....@gmail.com, ku...@kernel.org, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, mar...@holtmann.org, net...@vger.kernel.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: 73b7a604 net: dsa: bcm_sf2: support BCM4908's integrated s..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=12ec4a48d00000
kernel config: https://syzkaller.appspot.com/x/.config?x=9ce34124da4c882b
dashboard link: https://syzkaller.appspot.com/bug?extid=a41dfef1d2e04910eb2e
compiler: gcc (GCC) 10.1.0-syz 20200507
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=166ee4cf500000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1337172f500000

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

INFO: trying to register non-static key.
the code is fine but needs lockdep annotation.
turning off the locking correctness validator.
CPU: 0 PID: 9812 Comm: kworker/0:5 Not tainted 5.11.0-rc2-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events l2cap_chan_timeout
Call Trace:
__dump_stack lib/dump_stack.c:79 [inline]
dump_stack+0x107/0x163 lib/dump_stack.c:120
assign_lock_key kernel/locking/lockdep.c:935 [inline]
register_lock_class+0x1041/0x1100 kernel/locking/lockdep.c:1247
__lock_acquire+0x101/0x54f0 kernel/locking/lockdep.c:4711
lock_acquire kernel/locking/lockdep.c:5437 [inline]
lock_acquire+0x29d/0x740 kernel/locking/lockdep.c:5402
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
_raw_spin_lock_bh+0x2f/0x40 kernel/locking/spinlock.c:175
spin_lock_bh include/linux/spinlock.h:359 [inline]
lock_sock_nested+0x3b/0x110 net/core/sock.c:3049
l2cap_sock_teardown_cb+0xa1/0x660 net/bluetooth/l2cap_sock.c:1520
l2cap_chan_del+0xbc/0xa80 net/bluetooth/l2cap_core.c:618
l2cap_chan_close+0x1bc/0xaf0 net/bluetooth/l2cap_core.c:823
l2cap_chan_timeout+0x17e/0x2f0 net/bluetooth/l2cap_core.c:436
process_one_work+0x98d/0x15f0 kernel/workqueue.c:2275
worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
kthread+0x3b1/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
==================================================================
BUG: KASAN: use-after-free in l2cap_sock_teardown_cb+0x5c9/0x660 net/bluetooth/l2cap_sock.c:1522
Read of size 8 at addr ffff88802b6ce4c8 by task kworker/0:5/9812

CPU: 0 PID: 9812 Comm: kworker/0:5 Not tainted 5.11.0-rc2-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events l2cap_chan_timeout
Call Trace:
__dump_stack lib/dump_stack.c:79 [inline]
dump_stack+0x107/0x163 lib/dump_stack.c:120
print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:230
__kasan_report mm/kasan/report.c:396 [inline]
kasan_report.cold+0x79/0xd5 mm/kasan/report.c:413
l2cap_sock_teardown_cb+0x5c9/0x660 net/bluetooth/l2cap_sock.c:1522
l2cap_chan_del+0xbc/0xa80 net/bluetooth/l2cap_core.c:618
l2cap_chan_close+0x1bc/0xaf0 net/bluetooth/l2cap_core.c:823
l2cap_chan_timeout+0x17e/0x2f0 net/bluetooth/l2cap_core.c:436
process_one_work+0x98d/0x15f0 kernel/workqueue.c:2275
worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
kthread+0x3b1/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Allocated by task 8493:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:401 [inline]
____kasan_kmalloc.constprop.0+0x82/0xa0 mm/kasan/common.c:429
kmalloc_node include/linux/slab.h:575 [inline]
kvmalloc_node+0x61/0xf0 mm/util.c:587
kvmalloc include/linux/mm.h:781 [inline]
xt_alloc_table_info+0x3c/0xa0 net/netfilter/x_tables.c:1176
do_replace net/ipv6/netfilter/ip6_tables.c:1141 [inline]
do_ip6t_set_ctl+0x4e5/0xb70 net/ipv6/netfilter/ip6_tables.c:1636
nf_setsockopt+0x83/0xe0 net/netfilter/nf_sockopt.c:101
ipv6_setsockopt+0x122/0x180 net/ipv6/ipv6_sockglue.c:1008
tcp_setsockopt+0x136/0x2440 net/ipv4/tcp.c:3597
__sys_setsockopt+0x2db/0x610 net/socket.c:2115
__do_sys_setsockopt net/socket.c:2126 [inline]
__se_sys_setsockopt net/socket.c:2123 [inline]
__x64_sys_setsockopt+0xba/0x150 net/socket.c:2123
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 8493:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:356
____kasan_slab_free+0xe1/0x110 mm/kasan/common.c:362
kasan_slab_free include/linux/kasan.h:188 [inline]
slab_free_hook mm/slub.c:1547 [inline]
slab_free_freelist_hook+0x5d/0x150 mm/slub.c:1580
slab_free mm/slub.c:3142 [inline]
kfree+0xdb/0x3b0 mm/slub.c:4124
kvfree+0x42/0x50 mm/util.c:616
__do_replace+0x6b7/0x8c0 net/ipv6/netfilter/ip6_tables.c:1103
do_replace net/ipv6/netfilter/ip6_tables.c:1156 [inline]
do_ip6t_set_ctl+0x8ec/0xb70 net/ipv6/netfilter/ip6_tables.c:1636
nf_setsockopt+0x83/0xe0 net/netfilter/nf_sockopt.c:101
ipv6_setsockopt+0x122/0x180 net/ipv6/ipv6_sockglue.c:1008
tcp_setsockopt+0x136/0x2440 net/ipv4/tcp.c:3597
__sys_setsockopt+0x2db/0x610 net/socket.c:2115
__do_sys_setsockopt net/socket.c:2126 [inline]
__se_sys_setsockopt net/socket.c:2123 [inline]
__x64_sys_setsockopt+0xba/0x150 net/socket.c:2123
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff88802b6ce000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 1224 bytes inside of
2048-byte region [ffff88802b6ce000, ffff88802b6ce800)
The buggy address belongs to the page:
page:0000000055ddf779 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2b6c8
head:0000000055ddf779 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff888010042000
raw: 0000000000000000 0000000000080008 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88802b6ce380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88802b6ce400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88802b6ce480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88802b6ce500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88802b6ce580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

syzbot

unread,
Jan 11, 2021, 12:16:07 AM1/11/21
to a...@unstable.cc, b.a.t...@lists.open-mesh.org, da...@davemloft.net, hda...@sina.com, johan....@gmail.com, ku...@kernel.org, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, mar...@holtmann.org, marekl...@neomailbox.ch, mik...@szeredi.hu, msze...@redhat.com, net...@vger.kernel.org, s...@simonwunderlich.de, syzkall...@googlegroups.com
syzbot has bisected this issue to:

commit 4680a7ee5db27772af40d83393fa0fb955b745b7
Author: Miklos Szeredi <msze...@redhat.com>
Date: Sat Oct 1 05:32:33 2016 +0000

fuse: remove duplicate cs->offset assignment

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=11fc80e7500000
start commit: 73b7a604 net: dsa: bcm_sf2: support BCM4908's integrated s..
git tree: net-next
final oops: https://syzkaller.appspot.com/x/report.txt?x=13fc80e7500000
console output: https://syzkaller.appspot.com/x/log.txt?x=15fc80e7500000
Reported-by: syzbot+a41dfe...@syzkaller.appspotmail.com
Fixes: 4680a7ee5db2 ("fuse: remove duplicate cs->offset assignment")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

syzbot

unread,
Nov 30, 2021, 11:19:11 AM11/30/21
to a...@unstable.cc, b.a.t...@lists.open-mesh.org, bobo.sh...@huawei.com, da...@davemloft.net, hda...@sina.com, johan....@gmail.com, ku...@kernel.org, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, luiz.vo...@intel.com, mar...@holtmann.org, marekl...@neomailbox.ch, mik...@szeredi.hu, msze...@redhat.com, net...@vger.kernel.org, s...@simonwunderlich.de, syzkall...@googlegroups.com
syzbot suspects this issue was fixed by commit:

commit 1bff51ea59a9afb67d2dd78518ab0582a54a472c
Author: Wang ShaoBo <bobo.sh...@huawei.com>
Date: Wed Sep 1 00:35:37 2021 +0000

Bluetooth: fix use-after-free error in lock_sock_nested()

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=134c881eb00000
start commit: 73b7a6047971 net: dsa: bcm_sf2: support BCM4908's integrat..
git tree: net-next
If the result looks correct, please mark the issue as fixed by replying with:

#syz fix: Bluetooth: fix use-after-free error in lock_sock_nested()

Dmitry Vyukov

unread,
Dec 4, 2021, 4:32:12 AM12/4/21
to syzbot, a...@unstable.cc, b.a.t...@lists.open-mesh.org, bobo.sh...@huawei.com, da...@davemloft.net, hda...@sina.com, johan....@gmail.com, ku...@kernel.org, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, luiz....@gmail.com, luiz.vo...@intel.com, mar...@holtmann.org, marekl...@neomailbox.ch, mik...@szeredi.hu, msze...@redhat.com, net...@vger.kernel.org, s...@simonwunderlich.de, syzkall...@googlegroups.com
A use-after-free can lead to other random consequences, and there
actually was a KASAN report after the lockdep report in the original
report. So w/o a better candidate let's do:
Reply all
Reply to author
Forward
0 new messages