Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_connect (2)

From: Hillf Danton
Date: Sun Sep 08 2024 - 07:15:40 EST


On Sat, 07 Sep 2024 07:42:26 -0700
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: 788220eee30d Merge tag 'pm-6.11-rc7' of git://git.kernel.o..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1304189f980000

#syz test

--- l/net/bluetooth/l2cap_core.c
+++ c/net/bluetooth/l2cap_core.c
@@ -1747,6 +1747,8 @@ static void l2cap_unregister_all_users(s
}
}

+static DEFINE_MUTEX(l2cap_conn_del_mutex);
+
static void l2cap_conn_del(struct hci_conn *hcon, int err)
{
struct l2cap_conn *conn = hcon->l2cap_data;
@@ -1792,14 +1794,15 @@ static void l2cap_conn_del(struct hci_co

mutex_unlock(&conn->chan_lock);

- hci_chan_del(conn->hchan);
-
if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT)
cancel_delayed_work_sync(&conn->info_timer);

+ mutex_lock(&l2cap_conn_del_mutex);
hcon->l2cap_data = NULL;
+ hci_chan_del(conn->hchan);
conn->hchan = NULL;
l2cap_conn_put(conn);
+ mutex_unlock(&l2cap_conn_del_mutex);
}

static void l2cap_conn_free(struct kref *ref)
@@ -7480,6 +7483,7 @@ void l2cap_recv_acldata(struct hci_conn
struct l2cap_conn *conn = hcon->l2cap_data;
int len;

+ mutex_lock(&l2cap_conn_del_mutex);
if (!conn)
conn = l2cap_conn_add(hcon);

@@ -7512,6 +7516,7 @@ void l2cap_recv_acldata(struct hci_conn
if (len == skb->len) {
/* Complete frame received */
l2cap_recv_frame(conn, skb);
+ mutex_unlock(&l2cap_conn_del_mutex);
return;
}

@@ -7576,6 +7581,7 @@ void l2cap_recv_acldata(struct hci_conn

drop:
kfree_skb(skb);
+ mutex_unlock(&l2cap_conn_del_mutex);
}

static struct hci_cb l2cap_cb = {
--