Skip to content
/ linux Public

Commit da3000c

Browse files
shauryarane05gregkh
authored andcommitted
Bluetooth: L2CAP: Fix use-after-free in l2cap_unregister_user
[ Upstream commit 752a6c9 ] After commit ab4eedb ("Bluetooth: L2CAP: Fix corrupted list in hci_chan_del"), l2cap_conn_del() uses conn->lock to protect access to conn->users. However, l2cap_register_user() and l2cap_unregister_user() don't use conn->lock, creating a race condition where these functions can access conn->users and conn->hchan concurrently with l2cap_conn_del(). This can lead to use-after-free and list corruption bugs, as reported by syzbot. Fix this by changing l2cap_register_user() and l2cap_unregister_user() to use conn->lock instead of hci_dev_lock(), ensuring consistent locking for the l2cap_conn structure. Reported-by: syzbot+14b6d57fb728e27ce23c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=14b6d57fb728e27ce23c Fixes: ab4eedb ("Bluetooth: L2CAP: Fix corrupted list in hci_chan_del") Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f8b6ed2 commit da3000c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

net/bluetooth/l2cap_core.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,17 +1686,15 @@ static void l2cap_info_timeout(struct work_struct *work)
16861686

16871687
int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user)
16881688
{
1689-
struct hci_dev *hdev = conn->hcon->hdev;
16901689
int ret;
16911690

16921691
/* We need to check whether l2cap_conn is registered. If it is not, we
1693-
* must not register the l2cap_user. l2cap_conn_del() is unregisters
1694-
* l2cap_conn objects, but doesn't provide its own locking. Instead, it
1695-
* relies on the parent hci_conn object to be locked. This itself relies
1696-
* on the hci_dev object to be locked. So we must lock the hci device
1697-
* here, too. */
1692+
* must not register the l2cap_user. l2cap_conn_del() unregisters
1693+
* l2cap_conn objects under conn->lock, and we use the same lock here
1694+
* to protect access to conn->users and conn->hchan.
1695+
*/
16981696

1699-
hci_dev_lock(hdev);
1697+
mutex_lock(&conn->lock);
17001698

17011699
if (!list_empty(&user->list)) {
17021700
ret = -EINVAL;
@@ -1717,16 +1715,14 @@ int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user)
17171715
ret = 0;
17181716

17191717
out_unlock:
1720-
hci_dev_unlock(hdev);
1718+
mutex_unlock(&conn->lock);
17211719
return ret;
17221720
}
17231721
EXPORT_SYMBOL(l2cap_register_user);
17241722

17251723
void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user)
17261724
{
1727-
struct hci_dev *hdev = conn->hcon->hdev;
1728-
1729-
hci_dev_lock(hdev);
1725+
mutex_lock(&conn->lock);
17301726

17311727
if (list_empty(&user->list))
17321728
goto out_unlock;
@@ -1735,7 +1731,7 @@ void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user)
17351731
user->remove(conn, user);
17361732

17371733
out_unlock:
1738-
hci_dev_unlock(hdev);
1734+
mutex_unlock(&conn->lock);
17391735
}
17401736
EXPORT_SYMBOL(l2cap_unregister_user);
17411737

0 commit comments

Comments
 (0)