[syzbot] WARNING: refcount bug in l2cap_chan_hold

24 views
Skip to first unread message

syzbot

unread,
May 14, 2022, 11:20:22 PM5/14/22
to da...@davemloft.net, edum...@google.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, pab...@redhat.com, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 9be9ed2612b5 Merge tag 'platform-drivers-x86-v5.18-4' of g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=164544f1f00000
kernel config: https://syzkaller.appspot.com/x/.config?x=3afe599903e2c6b6
dashboard link: https://syzkaller.appspot.com/bug?extid=fd86a41b17a416a37a75
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=17285deaf00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15bd5d3ef00000

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

------------[ cut here ]------------
refcount_t: addition on 0; use-after-free.
WARNING: CPU: 2 PID: 3674 at lib/refcount.c:25 refcount_warn_saturate+0x169/0x1e0 lib/refcount.c:25
Modules linked in:
CPU: 2 PID: 3674 Comm: kworker/u19:1 Not tainted 5.18.0-rc6-syzkaller-00007-g9be9ed2612b5 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
Workqueue: hci0 hci_rx_work
RIP: 0010:refcount_warn_saturate+0x169/0x1e0 lib/refcount.c:25
Code: 09 31 ff 89 de e8 97 44 81 fd 84 db 0f 85 36 ff ff ff e8 aa 40 81 fd 48 c7 c7 80 61 26 8a c6 05 0f 00 ad 09 01 e8 e7 f5 30 05 <0f> 0b e9 17 ff ff ff e8 8b 40 81 fd 0f b6 1d f4 ff ac 09 31 ff 89
RSP: 0018:ffffc90002e17960 EFLAGS: 00010282
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff8880187b2180 RSI: ffffffff815f4a18 RDI: fffff520005c2f1e
RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000001
R10: ffffffff815ef3ee R11: 0000000000000000 R12: ffff88801c4a1000
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000003
FS: 0000000000000000(0000) GS:ffff88802cc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000555556dd1608 CR3: 00000000234d6000 CR4: 0000000000150ee0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
__refcount_add include/linux/refcount.h:199 [inline]
__refcount_inc include/linux/refcount.h:250 [inline]
refcount_inc include/linux/refcount.h:267 [inline]
kref_get include/linux/kref.h:45 [inline]
l2cap_chan_hold+0xff/0x120 net/bluetooth/l2cap_core.c:497
l2cap_global_chan_by_psm+0x3b1/0x4a0 net/bluetooth/l2cap_core.c:1986
l2cap_conless_channel net/bluetooth/l2cap_core.c:7611 [inline]
l2cap_recv_frame+0x68d/0x8e60 net/bluetooth/l2cap_core.c:7681
l2cap_recv_acldata+0xa96/0xc10 net/bluetooth/l2cap_core.c:8394
hci_acldata_packet net/bluetooth/hci_core.c:3633 [inline]
hci_rx_work+0x4d5/0xd60 net/bluetooth/hci_core.c:3824
process_one_work+0x996/0x1610 kernel/workqueue.c:2289
worker_thread+0x665/0x1080 kernel/workqueue.c:2436
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
</TASK>


---
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.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

Hillf Danton

unread,
May 15, 2022, 12:58:52 AM5/15/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 14 May 2022 20:20:20 -0700
Fix uaf by acquiring chan_list_lock after channel is fully initialized.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ 9be9ed2612b5

--- y/net/bluetooth/l2cap_core.c
+++ x/net/bluetooth/l2cap_core.c
@@ -458,10 +458,6 @@ struct l2cap_chan *l2cap_chan_create(voi
/* Set default lock nesting level */
atomic_set(&chan->nesting, L2CAP_NESTING_NORMAL);

- write_lock(&chan_list_lock);
- list_add(&chan->global_l, &chan_list);
- write_unlock(&chan_list_lock);
-
INIT_DELAYED_WORK(&chan->chan_timer, l2cap_chan_timeout);

chan->state = BT_OPEN;
@@ -473,6 +469,10 @@ struct l2cap_chan *l2cap_chan_create(voi

BT_DBG("chan %p", chan);

+ write_lock(&chan_list_lock);
+ list_add(&chan->global_l, &chan_list);
+ write_unlock(&chan_list_lock);
+
return chan;
}
EXPORT_SYMBOL_GPL(l2cap_chan_create);
--

syzbot

unread,
May 15, 2022, 1:24:11 AM5/15/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING: refcount bug in l2cap_chan_hold

------------[ cut here ]------------
refcount_t: addition on 0; use-after-free.
WARNING: CPU: 3 PID: 3688 at lib/refcount.c:25 refcount_warn_saturate+0x169/0x1e0 lib/refcount.c:25
Modules linked in:
CPU: 3 PID: 3688 Comm: kworker/u19:2 Not tainted 5.18.0-rc6-syzkaller-00007-g9be9ed2612b5-dirty #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
Workqueue: hci0 hci_rx_work
RIP: 0010:refcount_warn_saturate+0x169/0x1e0 lib/refcount.c:25
Code: 09 31 ff 89 de e8 97 44 81 fd 84 db 0f 85 36 ff ff ff e8 aa 40 81 fd 48 c7 c7 80 61 26 8a c6 05 0f 00 ad 09 01 e8 e7 f5 30 05 <0f> 0b e9 17 ff ff ff e8 8b 40 81 fd 0f b6 1d f4 ff ac 09 31 ff 89
RSP: 0018:ffffc90002ef7960 EFLAGS: 00010282
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff888021eb8080 RSI: ffffffff815f4a18 RDI: fffff520005def1e
RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000
R10: ffffffff815ef3ee R11: 0000000000000000 R12: ffff888022671000
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000003
FS: 0000000000000000(0000) GS:ffff88802cd00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000555555842708 CR3: 0000000019825000 CR4: 0000000000150ee0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
__refcount_add include/linux/refcount.h:199 [inline]
__refcount_inc include/linux/refcount.h:250 [inline]
refcount_inc include/linux/refcount.h:267 [inline]
kref_get include/linux/kref.h:45 [inline]
l2cap_chan_hold+0xff/0x120 net/bluetooth/l2cap_core.c:497
l2cap_global_chan_by_psm+0x3b1/0x4a0 net/bluetooth/l2cap_core.c:1986
l2cap_conless_channel net/bluetooth/l2cap_core.c:7611 [inline]
l2cap_recv_frame+0x68d/0x8e60 net/bluetooth/l2cap_core.c:7681
l2cap_recv_acldata+0xa96/0xc10 net/bluetooth/l2cap_core.c:8394
hci_acldata_packet net/bluetooth/hci_core.c:3633 [inline]
hci_rx_work+0x4d5/0xd60 net/bluetooth/hci_core.c:3824
process_one_work+0x996/0x1610 kernel/workqueue.c:2289
worker_thread+0x665/0x1080 kernel/workqueue.c:2436
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
</TASK>


Tested on:

commit: 9be9ed26 Merge tag 'platform-drivers-x86-v5.18-4' of g..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
console output: https://syzkaller.appspot.com/x/log.txt?x=1449db8ef00000
kernel config: https://syzkaller.appspot.com/x/.config?x=3afe599903e2c6b6
dashboard link: https://syzkaller.appspot.com/bug?extid=fd86a41b17a416a37a75
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=159a21f1f00000

Hillf Danton

unread,
May 15, 2022, 3:01:04 AM5/15/22
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, 14 May 2022 22:24:10 -0700
Fix uaf by trying to bump up refcount not zero.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ 9be9ed2612b5

--- y/net/bluetooth/l2cap_core.c
+++ x/net/bluetooth/l2cap_core.c
@@ -458,10 +458,6 @@ struct l2cap_chan *l2cap_chan_create(voi
/* Set default lock nesting level */
atomic_set(&chan->nesting, L2CAP_NESTING_NORMAL);

- write_lock(&chan_list_lock);
- list_add(&chan->global_l, &chan_list);
- write_unlock(&chan_list_lock);
-
INIT_DELAYED_WORK(&chan->chan_timer, l2cap_chan_timeout);

chan->state = BT_OPEN;
@@ -473,6 +469,10 @@ struct l2cap_chan *l2cap_chan_create(voi

BT_DBG("chan %p", chan);

+ write_lock(&chan_list_lock);
+ list_add(&chan->global_l, &chan_list);
+ write_unlock(&chan_list_lock);
+
return chan;
}
EXPORT_SYMBOL_GPL(l2cap_chan_create);
@@ -497,6 +497,14 @@ void l2cap_chan_hold(struct l2cap_chan *
kref_get(&c->kref);
}

+static struct l2cap_chan *l2cap_chan_hold_not_zero(struct l2cap_chan *c)
+{
+ if (kref_get_unless_zero(&c->kref))
+ return c;
+ else
+ return NULL;
+}
+
void l2cap_chan_put(struct l2cap_chan *c)
{
BT_DBG("chan %p orig refcnt %u", c, kref_read(&c->kref));
@@ -1983,7 +1991,7 @@ static struct l2cap_chan *l2cap_global_c
}

if (c1)
- l2cap_chan_hold(c1);
+ c1 = l2cap_chan_hold_not_zero(c1);

read_unlock(&chan_list_lock);

--

syzbot

unread,
May 15, 2022, 3:29:14 AM5/15/22
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+fd86a4...@syzkaller.appspotmail.com

Tested on:

commit: 9be9ed26 Merge tag 'platform-drivers-x86-v5.18-4' of g..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
kernel config: https://syzkaller.appspot.com/x/.config?x=3afe599903e2c6b6
dashboard link: https://syzkaller.appspot.com/bug?extid=fd86a41b17a416a37a75
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=12d8a5bef00000

Note: testing is done by a robot and is best-effort only.

syzbot

unread,
Sep 8, 2022, 8:22:20 AM9/8/22
to syzkall...@googlegroups.com
Auto-closing this bug as obsolete.
No recent activity, existing reproducers are no longer triggering the issue.
Reply all
Reply to author
Forward
0 new messages